Completed
Pull Request — master (#515)
by
unknown
02:55
created

ListNodesStatus.run()   C

Complexity

Conditions 7

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
c 1
b 0
f 0
dl 0
loc 29
rs 5.5
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 ListNodesStatus(OrionBaseAction):
20
    def run(self, platform, whitelist=None):
21
        """
22
        List the Status of Solarwinds Orion Nodes.
23
        """
24
25
        # Set up the results
26
        results = {"nodes_down": [],
27
                   "nodes_unknown": [],
28
                   "nodes_up": []}
29
30
        self.connect(platform)
31
32
        swql = "SELECT Caption,Status FROM Orion.Nodes"
33
        kargs = {}
34
        orion_data = self.query(swql, **kargs)
35
36
        for node in orion_data['results']:
37
            if whitelist is not None:
38
                if not node['Caption'] in whitelist:
39
                    continue
40
41
            if node["Status"] == 1:
42
                results['nodes_up'].append(node['Caption'])
43
            elif node["Status"] == 2:
44
                results['nodes_down'].append(node['Caption'])
45
            elif node["Status"] == 0:
46
                results['nodes_unknown'].append(node['Caption'])
47
48
        return results
49