This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Remove Nodes from NCM

import requests
import solarwinds
from datetime import datetime, timedelta

def main():
    hostname = 'Solarwinds-Orion'
    username = 'xxxxx'
    password = 'xxxxx'
    verify = '/temp/solarwinds.pem'

    swis = solarwinds.SolarWinds(hostname, username, password, verify)
    results = swis.remove_node_from_ncm(swis.get_node_name_from_ip("192.168.1.100"))
    print(results)

requests.packages.urllib3.disable_warnings()

if __name__ == '__main__':
    main()
~             

  • Added a couple functions to remove nodes from NCM. NCM removal requires the NCM NodeID. One function gets the NCM NodeID from the Caption. The other function uses the NCM NodeID to remove the node from NCM. The previous post calls the functions.

    Andy

        def get_ncmnode_id(self, node_name):
            """ 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_uri = self.swis.query("SELECT NodeCaption, NodeID FROM NCM.Nodes WHERE NodeCaption = @caption",
                                       caption=node_name)
    
            self.logger.info("get_node_uri - node uri query results: %s.", node_uri)
            if node_uri['results']:
                return node_uri['results'][0]['NodeID']
            else:
                return ""
    

        def remove_node_from_ncm(self, node_name):
            """ 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_name(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_name))
            self.logger.info("remove_node_from_ncm - add node to ncm invoke results: %s", results)