Hi all,
I've created a script that assigns pollers to certain interfaces over network devices like a switch, etc.
This script was written in Python and tested successfully, as a premise it receives the node name (caption) and SwisClient connection.
It uses the AddInterfacesOnNode Verb to assign the Pollers and uses DiscoverInterfacesOnNode Verb to discover the interfaces on the given node.
def discover_interface_on_node(node_name, swis):
try:
Q_NID = """ SELECT
nodeID as node_id
from Orion.Nodes
where
caption like @node_name"""
logger.info(f"Looking ID for node {node_name} in database")
results = swis.query(Q_NID, node_name=node_name)
if len(results["results"]) != 1:
logger.error(
f"Expecting a single result from query, instead {len(results['results'])} records were found <<discover_interface_on_node>>")
raise LookupError(
f"Expecting a single result from query, instead {len(results['results'])} records were found. <<discover_interface_on_node>>")
else:
node_id = results["results"][0]["node_id"]
logger.info(f"ID {node_id} was found for node {node_name}")
#print('results', results)
logger.info("Starting interface discovery...")
alt = swis.invoke("Orion.NPM.Interfaces",
"DiscoverInterfacesOnNode", node_id)
array_interfaces = []
if alt["DiscoveredInterfaces"]:
logger.info(
"interface discovery done. Proceeding to filter out interfaces...")
logger.info("Interfaces Trunk or Uplink to be filtered")
for interface in alt["DiscoveredInterfaces"]:
#Filtering interfaces whose names include Trunk or
if (str(interface["Caption"]).upper().find("TRUNK") != -1 or str(interface["Caption"]).upper().find("UPLINK") != -1):
# FILTER ONLY INTERFACES WITH STATUS UP
if (int(interface["ifOperStatus"]) == 1):
inter = {
"Caption": interface["Caption"],
"ifIndex": interface["ifIndex"],
"ifType": interface["ifType"],
"ifSubType": interface["ifSubType"],
"InterfaceID": interface["InterfaceID"],
"Manageable": interface["Manageable"],
"ifSpeed": interface["ifSpeed"],
"ifAdminStatus": interface["ifAdminStatus"],
"ifOperStatus": interface["ifOperStatus"]
}
array_interfaces.append(inter)
logger.info(
f'Interface { interface["Caption"]} discovered. Poller to be assigned')
else:
logger.info(
f"Found Interface {interface['Caption']} but it is down. No pollers to be assigned on the interface at this time.")
logger.info(
f"A total of {len(array_interfaces)} interfaces have been found. Pollers will be assigned now...")
swis.invoke("Orion.NPM.Interfaces", "AddInterfacesOnNode",
node_id, array_interfaces, "AddDefaultPollers")
logger.info("Done!")
except Exception as e:
return e
return array_interfaces
Hope this helps anyone.