Skip to content

Instantly share code, notes, and snippets.

@mrxinu
Last active September 10, 2021 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrxinu/223c73c6f3636ff489a4 to your computer and use it in GitHub Desktop.
Save mrxinu/223c73c6f3636ff489a4 to your computer and use it in GitHub Desktop.
import re
from swisclient import SwisClient
from pprint import pprint as pp
class NodeManager:
def __init__(self):
self._swis = SwisClient(
'orionhost',
'apiuser',
'apipassword')
def add_local_node(self):
self._add_node_element()
self._add_pollers()
self._pollnow()
def _add_node_element(self):
props = {
# 'Caption': 'L1HDSandbox.lan',
'IPAddress': '192.168.5.4',
# 'IPAddressGUID': '0405A8C0-0000-0000-0000-000000000000',
'DynamicIP': False,
'EngineID': 1,
## 'Status': 1,
'Allow64BitCounters': 1,
'ObjectSubType': 'SNMP',
'SNMPVersion': 2,
## 'BufferNoMemThisHour': -2,
## 'BufferNoMemToday': -2,
## 'BufferSmMissThisHour': -2,
## 'BufferSmMissToday': -2,
## 'BufferMdMissThisHour': -2,
## 'BufferMdMissToday': -2,
## 'BufferBgMissThisHour': -2,
## 'BufferBgMissToday': -2,
## 'BufferLgMissThisHour': -2,
## 'BufferLgMissToday': -2,
# 'SysObjectID': '1.3.6.1.4.1.8072.3.2.10',
# 'MachineType': 'net-snmp - Linux',
# 'Vendor': 'net-snmp',
# 'VendorIcon': '8072.gif',
'RediscoveryInterval': 30,
'PollInterval': 120,
'ChildStatus': 1,
'StatCollection': 10,
'Community': 'solarwinds',
# 'NodeDescription': 'Linux L1HDSandbox.lan 2.6.32-504.23.4.el6.x86_64 #1 SMP Tue Jun 9 20:57:37 UTC 2015 x86_64',
# Setting this conflicts with MachineType.
#'Description': 'net-snmp - Linux'
}
print("Adding node {}... ".format(props['IPAddress']), end="")
results = self._swis.create('Orion.Nodes', **props)
print("DONE!")
self._nodeid = self._parse_node(results)
def _parse_node(self, results):
return re.search('(\d+)$', results).group(0)
def _add_pollers(self):
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.Status.SNMP.Native': False,
'N.ResponseTime.SNMP.Native': False,
'N.Topology_Layer3.SNMP.ipNetToMedia': False,
'N.Routing.SNMP.Ipv4CidrRoutingTable': False
}
pollers = []
for k in pollers_enabled:
pollers.append(
{
'PollerType': k,
'NetObject': 'N:' + self._nodeid,
'NetObjectType': 'N',
'NetObjectID': self._nodeid,
'Enabled': pollers_enabled[k]
}
)
for poller in pollers:
print(" Adding poller type: {} with status {}... ".\
format(poller['PollerType'],
poller['Enabled']),
end="")
response = self._swis.create('Orion.Pollers', **poller)
print("DONE!")
def _configure_custom_properties(self):
pass
def _pollnow(self):
print(" Forcing a polling now... ", end="")
self._swis.invoke('Orion.Nodes', 'PollNow', 'N:' + self._nodeid)
print("DONE!")
def main():
nm = NodeManager()
nm.add_local_node()
if __name__ == '__main__':
main()
@edurguti
Copy link

Hi
I am getting the following:
python addnew.py
File "addnew.py", line 54
print("Adding node {}... ".format(props['IPAddress']), end="")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment