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

NodeStatus.run()   B

Complexity

Conditions 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 25
rs 8.8571
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 lib.actions import OrionBaseAction
17
18
19
class NodeStatus(OrionBaseAction):
20
    def run(self, node, platform):
21
        """
22
        Query Solarwinds Orion.
23
        """
24
25
        # Set up the results
26
        results = {}
27
        results['status'] = None
28
        results['color'] = None
29
30
        self.connect(platform)
31
32
        swql = "SELECT Status FROM Orion.Nodes WHERE Caption=@node"
33
        kargs = {'node': node}
34
        orion_data = self.query(swql, **kargs)
35
36
        if len(orion_data['results']) != 0:
37
            (results['status'], results['color']) = self.status_code_to_text(
38
                orion_data['results'][0]['Status'])
39
        else:
40
            error_msg = "Node not found"
41
            self.send_user_error(error_msg)
42
            raise ValueError(error_msg)
43
44
        return results
45