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.

Python API add node?

FormerMember
FormerMember

Is it possible to add a node using the python api? I have been trying and have been unsuccessful. Here are the requests I've tried to perform:

Using API:

r = swis.create(Orion.Nodes, {"IPAddress = " + ip + "; EngineID = 1; ObjectSubType = " + objsubtype+ "; Caption = " + caption + ";"})

Using requests:

r = requests.request("POST", "solarwinds:17778/.../Orion.Nodes", data=json.dumps("Orion.Nodes", {"IPAddress = " + ip + "; EngineID = 1; ObjectSubType = " + objsubtype+ "; Caption = " + caption + ";"}), verify=False, auth=(username, password), headers={'Content-Type': 'application/json'})

Unfortunately, all I have been able to get is a 500 response.Can anybody help?

  • I tried with the script but i get below error in response. We are using NPM 12.1

    {

        "Message": "Specified cast is not valid.",

        "ExceptionType": "System.InvalidCastException",

        "FullException": "System.InvalidCastException: Specified cast is not valid.\r\n   at SolarWinds.Data.Providers.Orion.Helpers.SnmpV3CredentialsHelper.UpdateNodesSnmpV3Credentials(Int32[] nodeIds, IDictionary`2 columnsToUpdate)\r\n   at SolarWinds.Data.Providers.Orion.CrudHandlers.NodeCrudHandler.Create(IEnumerable`1 infos, Func`2 baseCall)\r\n   at SolarWinds.InformationService.Addons.DataProvider.<Create>d__62.MoveNext()\r\n   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)\r\n   at SolarWinds.InformationService.Core.CrudProcessor.<CreateLocal>d__21.MoveNext()\r\n   at SolarWinds.InformationService.Core.CrudProcessor.<CreateInternal>d__18.MoveNext()\r\n   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)\r\n   at SolarWinds.InformationService.Core.CrudProcessor.Create(String entityType, IDictionary`2 properties, IQueryExecutionContext context)\r\n   at SolarWinds.InformationService.Core.InformationService.Create(String entityType, IDictionary`2 properties)"

    }

  • This error seems related to SNMPv3 credential setup. Are you setting node properties related to SNMPv3 credentials like SNMPV3PrivKey, SNMPV3AuthKeyIsPwd or SNMPV3PrivKeyIsPwd?

    Could you please paste relevant script part here so I can check?

  • I have a similar issue when updating Nodes, creating has never been an issue. Just like you mentioned it was related to SNMPv3.

  • {

       "SNMPV3Username":"testuser",

       "IPAddress":"10.10.10.10",

       "SNMPv3AuthKeyIsPwd":"True",

       "SNMPv3PrivKey":"testkey",

       "SNMPv3AuthMethod":"MD5",

       "Caption":"testserver",

       "SNMPv3PrivKeyIsPwd":"True",

       "SNMPv3PrivMethod":"DES56",

       "SNMPVersion":3,

       "SNMPV3AuthKey":"testkey",

       "ObjectSubType":"SNMP",

       "EngineID":1

    }

    This is the json i am using. I even tried to simulate the above json from the postman client. The error is same.

  • Unfortunately, NPM 12.1 does not handle the booleans in json correctly. See 400 Client Error: Specified cast is not valid · Issue #9 · solarwinds/orionsdk-python · GitHub . If you can use PowerShell instead, that works.

  • I have a requirement to automate deployment is CSR1000v routers and am 99% there.   I use the Orion SDK & Python 2.7 to query IPAM for IP Addresses and then use those IP Addresses to deploy the CSR1000v routers.  Once Deployed, I again use Orion SDK & Python 2.7 to mark the IP Addresses as "used" in IPAM.  Now that I have the routers deployed up and running, I need to add them to Orion for Monitoring and Alerting.  We have a requirement to only use SNMPv3 and I tried several script examples to add the new CSR1000v nodes to Orion using SNMPv3; however, It failed in every attempt.   To help my troubleshoot the issue, I figure I would at least try to add them using SNMP v2, so I started with the example python script as suggested and get the response as shown below and not really sure where to go and what to do next to resolve.  I am so close to being successful with my automation project and just need to resolve the issues with adding a to add the node as SNMPv3 and would be extremely grateful for any and all assistance/feedback, etc....

    Note:   Again, I have no problems communicating with my Orion server as I am able to get IP Addresses from IPAM as well as update their status using the Orion SDK & Python 2.7.

    Here is the script and the response when I run it. 

    def main():

      npm_server = '1.1.1.1'
       username = 'XXXXX'
       password = 'XXXXX'

       swis = SwisClient(npm_server, username, password)

       print("Add an SNMP v2c node:")

       # fill these in for the node you want to add!
       ip_address = '1.1.1.1'
       community = 'XXXXXXX'

       # set up property bag for the new node
       props = {

       'IPAddress': ip_address,

       'EngineID': 1,

       'ObjectSubType': 'SNMP',

       'SNMPVersion': 2,

       'Community': community

      }

       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()

    When I run the script, below is the output and the node is never added.   The error message does not really give me much information on where to look to resolve the issue.

    File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 937, in raise_for_status

        raise HTTPError(http_error_msg, response=self)

    requests.exceptions.HTTPError: 400 Client Error: Unable to create Node. Details : Information : Assigned default value 'Orion.Nodes' for EntityType.

    Information : Assigned default value 'False' for DynamicIP.

    Information : Assigned default value '' for Caption.

    Error : In property EngineID. Reason : Invalid EngineID. Value : 1.

    Information : Assigned default value '0' for Status.

    Information : Assigned default value '' for Location.

    Information : Assigned default value '' for Contact.

    Information : Assigned default value '' for NodeDescription.

    Information : Assigned default value '' for IOSImage.

    Information : Assigned default value '' for IOSVersion.

    Information : Assigned default value 'False' for UnManaged.

    Information : Assigned default value 'True' for Allow64BitCounters.

    Information : Assigned default value '' for SysObjectID.

    Information : Assigned default value 'Unknown' for MachineType.

    Information : Assigned default value 'Unknown' for Vendor.

    Information : Assigned default value 'Unknown.gif' for VendorIcon.

    Information : Assigned default value '120' for PollInterval.

    Information : Assigned default value '1440' for RediscoveryInterval.

    Information : Assigned default value '10' for StatCollection.

    Information : Assigned default value '-2' for BufferBgMissThisHour.

    Information : Assigned default value '-2' for BufferBgMissToday.

    Information : Assigned default value '-2' for BufferHgMissThisHour.

    Information : Assigned default value '-2' for BufferHgMissToday.

    Information : Assigned default value '-2' for BufferLgMissThisHour.

    Information : Assigned default value '-2' for BufferLgMissToday.

    Information : Assigned default value '-2' for BufferMdMissThisHour.

    Information : Assigned default value '-2' for BufferMdMissToday.

    Information : Assigned default value '-2' for BufferNoMemThisHour.

    Information : Assigned default value '-2' for BufferNoMemToday.

    Information : Assigned default value '-2' for BufferSmMissThisHour.

    Information : Assigned default value '-2' for BufferSmMissToday.

    ---------------------------------- for url: https://XXX.XXX.XXX.XXX:17778/SolarWinds/InformationService/v3/Json/Create/Orion.Nodes

    Process finished with exit code 1

  • This line tells you what the problem is:

         Error : In property EngineID. Reason : Invalid EngineID. Value : 1.

    You don't have a polling engine with EngineID=1. Use a query like this to see your EngineIDs and choose an appropriate one:

         SELECT EngineID, ServerName, ServerType FROM Orion.Engines

  • Highly recommend checking out the usage Discovery and AutoImport to add nodes. Here is info on using Discovery Context:

    Discovery · solarwinds/OrionSDK Wiki · GitHub

    Setting CreateCorePluginConfiguration details for Orion.Discovery in python

    We're successfully using this approach and have incorporated:

    - Auto selecting polling engine with lowest job weight (and excluding our Primary server)

    - Programmatically populating all the SNMP credentials so they don't have to be hard coded in the corePluginContext

    - Auto populate custom properties based on naming convention

    - Auto assign custom pollers (UnDP) based on naming convention

    It took a while to develop, but was well worth it in our large environment. If interested, I can provide some snippet examples.

  • Unfortunately my control server that runs the scripts is an Ubuntu server and only allowed to used what's already installed on the image which is python 2.7.  I'm crushed and was so close to a 100% total automation of a very large multiple aws vpc deployment.  Note: I also tried snmpv2 just to see and that too does not work for me and I have read all documentation and tried all the test and example python scripts I could find on github and other places.