| Total Complexity | 5 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | #!/usr/bin/env python |
||
| 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 |