Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use self-signed cert, NCM remove node, get node name from IP #62

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion orionsdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
from .solarwinds import SolarWinds


__version__ = "0.3.0"
__version__ = "0.3.1"
64 changes: 60 additions & 4 deletions orionsdk/solarwinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

class SolarWinds:

def __init__(self, npm_server, username, password, logger=None):
def __init__(self, npm_server, username, password, verify=False, logger=None):

self.logger = logger or logging.getLogger('__name__')

# Create the SWIS client for use throughout the instance.
self.swis = SwisClient(npm_server, username, password)
self.swis = SwisClient(npm_server, username, password, verify)

def does_node_exist(self, node_name):
""" Checks to see if a SolarWinds node exists with the given name. Calls the get_node_id method of the class
Expand Down Expand Up @@ -81,6 +81,47 @@ def get_node_uri(self, node_name):
else:
return ""

def get_node_caption_from_ip(self, ip_addr):
""" Returns the NodeCaption for the given IP_Address. Uses a SWIS query to the SolarWinds database to retrieve this
information.

Args:
ip_addr(string): An IP which should equal the IP_Address used in SolarWinds for the node object.

Returns:
node_caption(string): A node name which should equal the caption used in SolarWinds for the node object.

"""

node_caption = self.swis.query("SELECT Caption, IP_Address FROM Orion.Nodes WHERE IP_Address = @ip_addr",
ip_addr=ip_addr)
self.logger.info("get_node_caption_from_ip - node caption query results: %s.", node_caption)
if node_caption['results']:
return node_caption['results'][0]['Caption']
else:
return ""

def get_ncmnode_id(self, node_caption):
""" Returns the NCM NodeID for the given NodeName. Uses a SWIS query to the SolarWinds database to retrieve this
information.

Args:
node_name(string): A node name which should equal the caption used in SolarWinds for the node object.

Returns:
node_id (string): The ncm node id that corresponds to the specified node name.

"""

node_id = self.swis.query("SELECT NodeID, NodeCaption FROM NCM.Nodes WHERE NodeCaption = @caption",
caption=node_caption)

self.logger.info("get_ncmnode_id - NCM node uri query results: %s.", node_id)
if node_id['results']:
return node_id['results'][0]['NodeID']
else:
return ""

def add_node_using_snmp_v3(self, node_name, ip_address, snmpv3_username, snmpv3_priv_method, snmpv3_priv_pwd,
snmpv3_auth_method, snmpv3_auth_pwd):
""" Creates a new node using the supplied name an IP address. Configure with our standard SNMPv3 credentials.
Expand Down Expand Up @@ -204,7 +245,7 @@ def enable_hardware_health_on_node(self, node_name):
results = self.swis.invoke('Orion.HardwareHealth.HardwareInfo', 'EnableHardwareHealth', net_object, 9)
self.logger.info("enable_hardware_health - enable hardware health invoke results: %s", results)

def add_node_to_ncm(self, node_name):
def add_node_to_ncm(self, node_caption):
""" Adds the specified node to the SolarWinds NCM module. Executes a SWIS invoke of the
'AddNodetoNCM' verb, passing it the node's object ID.

Expand All @@ -216,8 +257,23 @@ def add_node_to_ncm(self, node_name):

"""

results = self.swis.invoke('Cirrus.Nodes', 'AddNodeToNCM', self.get_node_id(node_name))
results = self.swis.invoke('Cirrus.Nodes', 'AddNodeToNCM', self.get_node_id(node_caption))
self.logger.info("add_node_to_ncm - add node to ncm invoke results: %s", results)

def remove_node_from_ncm(self, node_caption):
""" Removes the specified node from the SolarWinds NCM module. Executes a SWIS invoke of the
'RemoveNode' verb, passing it the node's NCM node id.

Args:
node_caption(string): A node name which should equal the caption used in SolarWinds for the node object.

Returns:
None.

"""

results = self.swis.invoke('Cirrus.Nodes', 'RemoveNode', self.get_ncmnode_id(node_caption))
self.logger.info("remove_node_from_ncm - remove node from ncm invoke results: %s", results)

def add_node_to_udt(self, node_name):
udt_properties = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="orionsdk",
version="0.3.0", # Update also in __init__ ;
version="0.3.1", # Update also in __init__ ;
description="Python API for the SolarWinds Orion SDK",
long_description="Python client for interacting with the SolarWinds Orion API",
author="SolarWinds",
Expand Down