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

Icinga2GetService.run()   B

Complexity

Conditions 5

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 21
rs 8.439
cc 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 Icinga2GetService(Icinga2Action):
8
        
9
    def run(self, services):
10
        api_suffix = ''
11
        if services:
12
            if len(services) == 1:
13
                api_suffix = '?service=' + urllib.quote_plus(services[0])
14
            else:
15
                api_suffix += '?'
16
                for service in services[:-1]:
17
                    api_suffix += 'services=' + urllib.quote_plus(service) + '&'
18
                api_suffix += 'services=' + urllib.quote_plus(services[-1])
19
            
20
        self.logger.debug('URL suffix: %s', api_suffix)
21
        self.set_method('get')
22
        self.set_path('/objects/services' + str(api_suffix))
23
        self.logger.debug('Action Icinga2GetService 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