I apologize for basic question. I'm trying to modify the orionsdk add node.py script to add multiple nodes from a text file list.
Thanks in advance!
==================
# add_node.py
https://github.com/solarwinds/orionsdk-python/blob/master/samples/add_node.py
from __future__ import print_function
import re
import requests
from orionsdk import SwisClient
def main():
npm_server = 'localhost'
username = 'admin'
password = ''
swis = SwisClient(npm_server, username, password)
print("Add an SNMP v2c node:")
# fill these in for the node you want to add!
ip_address = '127.0.0.1'
community = 'public'
# set up property bag for the new node
props = {
'IPAddress': ip_address,
'EngineID': 1,
'ObjectSubType': 'SNMP',
'SNMPVersion': 2,
'Community': community,
'DNS': '',
'SysName': ''
}
print("Adding node {}... ".format(props['IPAddress']), end="")
results = swis.create('Orion.Nodes', **props)
print("DONE!")
# extract the nodeID from the result
nodeid = re.search(r'(\d+)$', results).group(0)
pollers_enabled = {
'N.Status.ICMP.Native': True,
'N.Status.SNMP.Native': False,
'N.ResponseTime.ICMP.Native': True,
'N.ResponseTime.SNMP.Native': False,
'N.Details.SNMP.Generic': True,
'N.Uptime.SNMP.Generic': True,
'N.Cpu.SNMP.HrProcessorLoad': True,
'N.Memory.SNMP.NetSnmpReal': True,
'N.AssetInventory.Snmp.Generic': True,
'N.Topology_Layer3.SNMP.ipNetToMedia': False,
'N.Routing.SNMP.Ipv4CidrRoutingTable': False
}
pollers = []
for k in pollers_enabled:
pollers.append(
{
'PollerType': k,
'NetObject': 'N:' + nodeid,
'NetObjectType': 'N',
'NetObjectID': nodeid,
'Enabled': pollers_enabled[k]
}
)
for poller in pollers:
print(" Adding poller type: {} with status {}... ".format(poller['PollerType'], poller['Enabled']), end="")
response = swis.create('Orion.Pollers', **poller)
print("DONE!")
requests.packages.urllib3.disable_warnings()
if __name__ == '__main__':
main()
==================
# orion_nodes file
C:\python_scripts>more orion_nodes
10.245.0.20
10.245.0.22
10.245.0.51
10.245.0.55
10.245.0.73
10.245.0.91
10.245.0.101
10.245.0.111
10.245.0.202
C:\python_scripts>
==================
# for loop
C:\python_scripts>more testloop2.py
f = open('orion_nodes')
for line in f:
print(line)
f.close()
C:\python_scripts>
==================
# verify test loop
C:\python_scripts>python testloop2.py
10.245.0.20
10.245.0.22
10.245.0.51
10.245.0.55
10.245.0.73
10.245.0.91
10.245.0.101
10.245.0.111
10.245.0.202
C:\python_scripts>
==================
# multi node add
C:\python_scripts>more orion_add_mult_nodes.py
import orionsdk
swis = orionsdk.SwisClient("server", "username", "password")
import re
import requests
from orionsdk import SwisClient
def main():
npm_server = '10.2.0.1'
username = 'Cisco'
password = 'Cisco'
swis = SwisClient(npm_server, username, password)
print("Add an SNMP v2c node:")
# fill these in for the node you want to add!
f = open('orion_nodes')
for line in f:
ip_address = 'line'
community = 'pythonsnmp'
f.close()
# set up property bag for the new node
props = {
'IPAddress': ip_address,
'EngineID': 1,
'ObjectSubType': 'SNMP',
'SNMPVersion': 2,
'Community': community,
'DNS': '',
'SysName': ''
}
print("Adding node {}... ".format(props['IPAddress']), end="")
results = swis.create('Orion.Nodes', **props)
print("DONE!")
# extract the nodeID from the result
nodeid = re.search(r'(\d+)$', results).group(0)
pollers_enabled = {
'N.Status.ICMP.Native': True,
'N.Status.SNMP.Native': False,
'N.ResponseTime.ICMP.Native': True,
'N.ResponseTime.SNMP.Native': False,
'N.Details.SNMP.Generic': True,
'N.Uptime.SNMP.Generic': True,
'N.Cpu.SNMP.HrProcessorLoad': True,
'N.Memory.SNMP.NetSnmpReal': True,
'N.AssetInventory.Snmp.Generic': True,
'N.Topology_Layer3.SNMP.ipNetToMedia': False,
'N.Routing.SNMP.Ipv4CidrRoutingTable': False
}
pollers = []
for k in pollers_enabled:
pollers.append(
{
'PollerType': k,
'NetObject': 'N:' + nodeid,
'NetObjectType': 'N',
'NetObjectID': nodeid,
'Enabled': pollers_enabled[k]
}
)
for poller in pollers:
print(" Adding poller type: {} with status {}... ".format(poller['PollerType'], poller['Enabled']), end="")
response = swis.create('Orion.Pollers', **poller)
print("DONE!")
requests.packages.urllib3.disable_warnings()
if __name__ == '__main__':
main()
C:\python_scripts>
==================
# error
C:\python_scripts>python orion_add_mult_nodes.py
File "C:\python_scripts\orion_add_mult_nodes.py", line 28
props = {
IndentationError: unexpected indent
C:\python_scripts>
==================
@tdanner
@patrick.hubbard