Completed
Pull Request — master (#552)
by
unknown
02:27
created

Icinga2GetService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 23
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 21 5
1
#!/usr/bin/env python
2
from lib.icinga2action import Icinga2Action
3
4
import sys
5
import urllib
6
7
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