Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2e6ab4

Browse files
Merge pull request #62 from andylittle/master
use self-signed cert, NCM remove node, get node name from IP
2 parents a57b5b9 + a1e5ff0 commit a2e6ab4

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

orionsdk/solarwinds.py

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
class SolarWinds:
1616

17-
def __init__(self, npm_server, username, password, logger=None, port=17774):
18-
17+
def __init__(self, npm_server, username, password, logger=None, port=17774, verify=False):
18+
1919
self.logger = logger or logging.getLogger('__name__')
2020

2121
# Create the SWIS client for use throughout the instance.
22-
self.swis = SwisClient(npm_server, username, password, port)
22+
self.swis = SwisClient(npm_server, username, password, port, verify)
2323

2424
def does_node_exist(self, node_name):
2525
""" Checks to see if a SolarWinds node exists with the given name. Calls the get_node_id method of the class
@@ -82,6 +82,47 @@ def get_node_uri(self, node_name):
8282
else:
8383
return ""
8484

85+
def get_node_caption_from_ip(self, ip_addr):
86+
""" Returns the NodeCaption for the given IP_Address. Uses a SWIS query to the SolarWinds database to retrieve this
87+
information.
88+
89+
Args:
90+
ip_addr(string): An IP which should equal the IP_Address used in SolarWinds for the node object.
91+
92+
Returns:
93+
node_caption(string): A node name which should equal the caption used in SolarWinds for the node object.
94+
95+
"""
96+
97+
node_caption = self.swis.query("SELECT Caption, IP_Address FROM Orion.Nodes WHERE IP_Address = @ip_addr",
98+
ip_addr=ip_addr)
99+
self.logger.info("get_node_caption_from_ip - node caption query results: %s.", node_caption)
100+
if node_caption['results']:
101+
return node_caption['results'][0]['Caption']
102+
else:
103+
return ""
104+
105+
def get_ncmnode_id(self, node_caption):
106+
""" Returns the NCM NodeID for the given NodeName. Uses a SWIS query to the SolarWinds database to retrieve this
107+
information.
108+
109+
Args:
110+
node_name(string): A node name which should equal the caption used in SolarWinds for the node object.
111+
112+
Returns:
113+
node_id (string): The ncm node id that corresponds to the specified node name.
114+
115+
"""
116+
117+
node_id = self.swis.query("SELECT NodeID, NodeCaption FROM NCM.Nodes WHERE NodeCaption = @caption",
118+
caption=node_caption)
119+
120+
self.logger.info("get_ncmnode_id - NCM node uri query results: %s.", node_id)
121+
if node_id['results']:
122+
return node_id['results'][0]['NodeID']
123+
else:
124+
return ""
125+
85126
def add_node_using_snmp_v3(self, node_name, ip_address, snmpv3_username, snmpv3_priv_method, snmpv3_priv_pwd,
86127
snmpv3_auth_method, snmpv3_auth_pwd):
87128
""" Creates a new node using the supplied name an IP address. Configure with our standard SNMPv3 credentials.
@@ -205,7 +246,7 @@ def enable_hardware_health_on_node(self, node_name):
205246
results = self.swis.invoke('Orion.HardwareHealth.HardwareInfo', 'EnableHardwareHealth', net_object, 9)
206247
self.logger.info("enable_hardware_health - enable hardware health invoke results: %s", results)
207248

208-
def add_node_to_ncm(self, node_name):
249+
def add_node_to_ncm(self, node_caption):
209250
""" Adds the specified node to the SolarWinds NCM module. Executes a SWIS invoke of the
210251
'AddNodetoNCM' verb, passing it the node's object ID.
211252
@@ -217,8 +258,23 @@ def add_node_to_ncm(self, node_name):
217258
218259
"""
219260

220-
results = self.swis.invoke('Cirrus.Nodes', 'AddNodeToNCM', self.get_node_id(node_name))
261+
results = self.swis.invoke('Cirrus.Nodes', 'AddNodeToNCM', self.get_node_id(node_caption))
221262
self.logger.info("add_node_to_ncm - add node to ncm invoke results: %s", results)
263+
264+
def remove_node_from_ncm(self, node_caption):
265+
""" Removes the specified node from the SolarWinds NCM module. Executes a SWIS invoke of the
266+
'RemoveNode' verb, passing it the node's NCM node id.
267+
268+
Args:
269+
node_caption(string): A node name which should equal the caption used in SolarWinds for the node object.
270+
271+
Returns:
272+
None.
273+
274+
"""
275+
276+
results = self.swis.invoke('Cirrus.Nodes', 'RemoveNode', self.get_ncmnode_id(node_caption))
277+
self.logger.info("remove_node_from_ncm - remove node from ncm invoke results: %s", results)
222278

223279
def add_node_to_udt(self, node_name):
224280
udt_properties = {

orionsdk/swisclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def _json_serial(obj):
1111

1212

1313
class SwisClient:
14-
def __init__(self, hostname, username, password, port=17774, timeout=30, verify=False, session=None):
14+
def __init__(self, hostname, username, password, port=17774, verify=False, session=None, timeout=30):
1515
self.url = "https://{}:{}/SolarWinds/InformationService/v3/Json/".\
1616
format(hostname, port)
1717
self._session = session or requests.Session()

0 commit comments

Comments
 (0)