Completed
Push — master ( ff247a...b96a39 )
by Tomaz
23s
created

SensuAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 12
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 11 2
1
import json
2
3
from st2actions.runners.pythonrunner import Action
4
from pysensu.api import SensuAPI
5
6
7
def parseOutput(r):
8
    try:
9
        output = {}
10
        json.loads(r.text)
11
        for c in r.json():
12
            output[c['name']] = c
13
        return json.dumps(output)
14
    except:
15
        return r.text
16
17
18
class SensuAction(Action):
19
    def __init__(self, config):
20
        super(SensuAction, self).__init__(config)
21
        self.username = self.config['user']
22
        self.password = self.config['pass']
23
        if self.config['ssl']:
24
            protocol = 'https'
25
        else:
26
            protocol = "http"
27
        self.base_url = "%s://%s:%s" % (protocol, self.config['host'], self.config['port'])
28
29
        self.api = SensuAPI(url_base=self.base_url, username=self.username, password=self.password)
30