Completed
Pull Request — master (#469)
by
unknown
02:24
created

Icinga2GetHost   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %
Metric Value
wmc 5
dl 0
loc 23
rs 10

1 Method

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