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

OrionBaseAction.send_user_error()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 2
rs 10
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from st2actions.runners.pythonrunner import Action
17
from orionsdk import SwisClient
18
19
20
class OrionBaseAction(Action):
21
    def __init__(self, config):
22
        super(OrionBaseAction, self).__init__(config)
23
24
        if "orion" not in self.config:
25
            raise ValueError("Orion host details not in the config.yaml")
26
27
    def connect(self, platform):
0 ignored issues
show
Documentation introduced by
Empty method docstring
Loading history...
28
        """
29
30
        """
31
        try:
32
            self.swis = SwisClient(self.config['orion'][platform]['host'],
0 ignored issues
show
Coding Style introduced by
The attribute swis was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
33
                                   self.config['orion'][platform]['user'],
34
                                   self.config['orion'][platform]['password'])
35
        except KeyError:
36
            raise ValueError("Orion host details not in the config.yaml")
37
38
    def query(self, swql, **kargs):
0 ignored issues
show
Documentation introduced by
Empty method docstring
Loading history...
39
        """
40
41
        """
42
43
        return self.swis.query(swql, **kargs)
44
45
    def status_code_to_text(self, status):
46
        """
47
        Takes an Solarwinds Orion status code and translates it to
48
        it's text descrotion and a Slack colour.
49
        """
50
51
        if status == 0:
52
            return ("Unknown", "grey")
53
        elif status == 1:
54
            return ("Up", "good")
55
        elif status == 2:
56
            return ("Down", "danger")
57
        elif status == 3:
58
            return ("Warning", "warning")
59
        elif status == 14:
60
            return ("Critical", "danger")
61
62
    def send_user_error(self, message):
63
        print(message)
64