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