| Total Complexity | 5 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | #!/usr/bin/env python |
||
| 8 | class Icinga2GetService(Icinga2Action): |
||
| 9 | |||
| 10 | def run(self, services): |
||
| 11 | api_suffix = '' |
||
| 12 | if services: |
||
| 13 | if len(services) == 1: |
||
| 14 | api_suffix = '?service=' + urllib.quote_plus(services[0]) |
||
| 15 | else: |
||
| 16 | api_suffix += '?' |
||
| 17 | for service in services[:-1]: |
||
| 18 | api_suffix += 'services=' + urllib.quote_plus(service) + '&' |
||
| 19 | api_suffix += 'services=' + urllib.quote_plus(services[-1]) |
||
| 20 | |||
| 21 | self.logger.debug('URL suffix: %s', api_suffix) |
||
| 22 | self.set_method('get') |
||
| 23 | self.set_path('/objects/services' + str(api_suffix)) |
||
| 24 | self.logger.debug('Action Icinga2GetService 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 |