Completed
Push — master ( 84e890...c23c43 )
by
unknown
22s
created

Icinga2GetHost   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 23
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 21 5
1
#!/usr/bin/env python
2
from lib.icinga2action import Icinga2Action
3
4
import sys
5
import urllib
6
7
8
class Icinga2GetHost(Icinga2Action):
9
10
    def run(self, hosts):
11
        api_suffix = ''
12
        if hosts:
13
            if len(hosts) == 1:
14
                api_suffix = '?host=' + urllib.quote_plus(hosts[0])
15
            else:
16
                api_suffix += '?'
17
                for host in hosts[:-1]:
18
                    api_suffix += 'hosts=' + urllib.quote_plus(host) + '&'
19
                api_suffix += 'hosts=' + urllib.quote_plus(hosts[-1])
20
21
        self.logger.debug('URL suffix: %s', api_suffix)
22
        self.set_method('get')
23
        self.set_path('/objects/hosts' + str(api_suffix))
24
        self.logger.debug('Action Icinga2GetHost started')
25
        client = self.get_client()
26
        client.make_call()
27
        if self.get_error() == 0:
28
            return self.get_body()
29
        else:
30
            sys.exit(self.get_error())
31