Completed
Pull Request — master (#515)
by
unknown
03:08
created

ListNodesStatus   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
D run() 0 33 8
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
            # Duplicate names will cause issues, so skip
42
            if orion_data['results'].count(node) > 1:
43
                continue
44
45
            if node["Status"] == 1:
46
                results['nodes_up'].append(node['Caption'])
47
            elif node["Status"] == 2:
48
                results['nodes_down'].append(node['Caption'])
49
            elif node["Status"] == 0:
50
                results['nodes_unknown'].append(node['Caption'])
51
52
        return results
53