29 Replies Latest reply on May 2, 2018 4:38 PM by Manilyn Ramos

    Can any one supply a REST example of how to define a Node in Solarwinds

    emoloney

      I am developing an integration agent for SolarWindws and would like to use the REST API to add nodes to SolarWindws and change the system name

          • Re: Can any one supply a REST example of how to define a Node in Solarwinds
            emoloney

            Hi yaquaholic

             

            I had a look and found the following powershell example

            https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/CRUD.AddNode.ps1

             

            Was looking for an example of the REST Call todo similar.

             

            Thanks

            E.J.

              • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                tdanner

                The CRUD API for adding nodes works best when you are adding consistent node types. With this API you are responsible for knowing what poller types to assign (there are a lot - see Poller Types · solarwinds/OrionSDK Wiki · GitHub). With the Discovery API (Discovery · solarwinds/OrionSDK Wiki · GitHub) Orion will take care of determining which poller types are applicable. We have a Python sample that uses the REST API to add a node via the Discovery API: orionsdk-python/discover_one_node.py at master · solarwinds/orionsdk-python · GitHub

                  • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                    emoloney

                    Hi

                    Thanks for above I found it very usefull.

                    I am a java developer and trying to create similar to the python script.

                    I can run the sample python script correctly but when I try a similar operation in Java I get an exception.

                     

                    The sample code I am running is:

                    String corePluginContext="{\"Credentials\": [{\"CredentialID\": 3, \"Order\": 1}], \"WmiRetryIntervalMiliseconds\": 1000, \"BulkList\": [{\"Address\": \"192.168.2.254\"}], \"WmiRetriesCount\": 0}";

                    target = client .target("https://" + HOSTNAME + ":17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Discovery/CreateCorePluginConfiguration");

                    response = target.request().post(Entity.entity(corePluginContext, MediaType.APPLICATION_JSON));

                     

                    I get the following error message:

                    the response was InboundJaxrsResponse{context=ClientResponse{method=POST, uri=https://SolarWinds-Orion:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Discovery/CreateCorePluginConfiguration, status=400, reason=Bad Request}}

                    {"Message":"Verb Orion.Discovery.CreateCorePluginConfiguration requires 1 parameters not 0","ExceptionType":"SolarWinds.InformationService.Verb.VerbExecutorException","FullException":"SolarWinds.InformationService.Verb.VerbExecutorException: Verb Orion.Discovery.CreateCorePluginConfiguration requires 1 parameters not 0\u000d\u000a   at SolarWinds.InformationService.Verb.VerbExecutorContext.CreateParameters(Func`2 getParameterAt, Int32 parametersCount, Stream stream)\u000d\u000a   at SolarWinds.InformationService.Verb.VerbExecutorContext.UnpackageParameters(JArray parameters)\u000d\u000a   at SolarWinds.InformationService.Core.InformationService.Invoke[T](String entity, String verb, Action`1 setupParameters, Func`2 extractReturnValue)"}

                     

                    2017-04-14 13:15:08,689 [57] ERROR SolarWinds.InformationService.Core.InformationService - (null) (null)     Exception caught in method SolarWinds.InformationService.Core.InformationService.Invoke

                    SolarWinds.InformationService.Verb.VerbExecutorException: Verb Orion.Discovery.CreateCorePluginConfiguration requires 1 parameters not 0

                       at SolarWinds.InformationService.Verb.VerbExecutorContext.CreateParameters(Func`2 getParameterAt, Int32 parametersCount, Stream stream)

                       at SolarWinds.InformationService.Verb.VerbExecutorContext.UnpackageParameters(JArray parameters)

                       at SolarWinds.InformationService.Core.InformationService.Invoke[T](String entity, String verb, Action`1 setupParameters, Func`2 extractReturnValue)

                    2017-04-14 13:18:45,844 [58] ERROR SolarWinds.InformationService.Core.InformationService - (null) (null)     Exception for Operation: <root type="object">

                      <Credentials type="array">

                        <item type="object">

                          <CredentialID type="number">3</CredentialID>

                          <Order type="number">1</Order>

                        </item>

                      </Credentials>

                      <WmiRetryIntervalMiliseconds type="number">1000</WmiRetryIntervalMiliseconds>

                      <BulkList type="array">

                        <item type="object">

                          <Address type="string">192.168.2.254</Address>

                        </item>

                      </BulkList>

                      <WmiRetriesCount type="number">0</WmiRetriesCount>

                    </root>

                    2017-04-14 13:18:45,844 [58] ERROR SolarWinds.InformationService.Core.InformationService - (null) (null)     Exception caught in method SolarWinds.InformationService.Core.InformationService.Invoke

                    SolarWinds.InformationService.Verb.VerbExecutorException: Verb Orion.Discovery.CreateCorePluginConfiguration requires 1 parameters not 0

                       at SolarWinds.InformationService.Verb.VerbExecutorContext.CreateParameters(Func`2 getParameterAt, Int32 parametersCount, Stream stream)

                       at SolarWinds.InformationService.Verb.VerbExecutorContext.UnpackageParameters(JArray parameters)

                    I looked in the file I find the followiing related entry

                     

                     

                    And assistance would be much appreciated

                      • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                        tdanner

                        The request body for all POSTs to .../Invoke/... needs to be a JSON array. Just wrap your current input in [brackets] and try again.

                          • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                            emoloney

                            Hi I have a java program that can create a node but its not performing snmp polling or discovery when the ndoe isnt using the community string public.

                            Can some one show me a REST example of how to define an SNMPv2 community string when discovering a node , Below is what I have tried so far

                             

                            String corePluginContext = "[{\"Credentials\": [{\"CredentialID\":3,\"Order\": 1}],\"Community\":\"testpublic\",\"WmiRetryIntervalMiliseconds\": 1000,\"BulkList\": [{\"Address\": \= ipaddress + "\"}],\"WmiRetriesCount\": 0}]";

                             

                            Also tried adding to the discovery code

                            [{\"Name\": \"javadiscovery\",\"EngineID\":1,\"JobTimeoutSeconds\":3600,\"SearchTimeoutMiliseconds\":5000,\"SnmpTimeoutMiliseconds\":5000,\"SnmpRetries\":2,\"RepeatIntervalMiliseconds\":1000,\"SnmpPort\":161,\"Community\":\""+community+"\",\"HopCount\":0,\"PreferredSnmpVersion\":\"SNMP2c\",\"DisableIcmp\":\"False\",\"AllowDuplicateNodes\":\"False\",\"IsAutoImport\":\"True\",\"IsHidden\":\"True\",\"PluginConfigurations\":[{\"PluginConfigurationItem\":" + m_config + "}]}]";

                              • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                tomas.vrabel

                                I look into this and seems like providing SNMP credentials for discovery is possible only from Credential table using related CredentialID.

                                 

                                At first you need to add your community string to Credential table in Orion DB.

                                Please run query "SELECT [ID],[Name],[Description],[CredentialType],[CredentialOwner] FROM [SolarWindsOrion].[dbo].[Credential]" in OrionDB and check if you see specific commnunity string in Name column where

                                CredentialType = SolarWinds.Orion.Core.Models.Credentials.SnmpCredentialsV2.

                                 

                                If you can see it, please note down related ID.

                                 

                                If required community string is missing you need to add it to the Credential table.

                                Unfortunately I found only one supportred way how to do this - create discovery profile (Settings->Network Discovery->Add new discovery) and on SNMP step add new community string (additionaly to existing "public" and "private").

                                Check this link for more information: http://www.solarwinds.com/documentation/en/flarehelp/npm/content/core-snmp-credentials-sw3710.htm

                                Then finish the discovery wizard and on last step (Discovery scheduling) don't schedule the profile just save it. Only now the community string is saved to Credential table.

                                Please check if community string is in DB table using query above and note down related ID.

                                You can delete discovery profile now, community string will not be removed from Orion.

                                 

                                When community string is in Credential table and you checked related ID, you can setup disovery using Orion SDK.

                                 

                                You can adjust example https://github.com/solarwinds/orionsdk-python/blob/master/samples/discover_one_node.py this way:

                                When initializing corePluginContext set CredentialID to ID of your community string in Credential table (that was noted down in steps above).

                                 

                                Python example can be ported to Java too.

                                 

                                You do not have to provide community string in corePluginContext or discoveryProfile, they accept only CredentialID from Credential table.

                                 

                                When you provide CredentialID your discovery should use specified community string.. I hope this will work for you.

                                 

                                 

                                 

                                You can also add multiple community strings for discovery:

                                corePluginContext = {

                                    'BulkList': [{'Address': target_node_ip}],

                                    'Credentials': [

                                    {

                                    'CredentialID': 2,

                                    'Order': 1

                                    },

                                  {

                                    'CredentialID': 3,

                                    'Order': 2

                                    },

                                  {

                                    'CredentialID': 10,

                                    'Order': 3

                                    }

                                    ],

                                    'WmiRetriesCount': 0,

                                    'WmiRetryIntervalMiliseconds': 1000

                                    }

                          • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                            Manilyn Ramos

                            Hi tdanner,

                             

                            do you have sample of adding node with WMI Polling Method using Python? The reason why I am asking this is because I am confused about the variable for the Credentials I even checked the Credentials table and I only see "ID", "NAME", and etc. but I am aware that I cannot use this (I assume) because my script will get confused.....

                             

                            I have already tried the ff:

                             

                             

                            ip_address = '1.1.1.1'

                             


                            props = {

                               'EntityType': 'Orion.Nodes',

                               'IPAddress': ip_address,

                               'EngineID':1,

                               'Status': 1,

                               'NodeName': "SolarWinds",

                               'ObjectSubType': 'WMI',

                               'CredentialID': 5

                                 #i also tried

                                  'CredentialName': "ServiceAccount"

                                 #I also tried adding a new credential

                                'Choose credential:' "<New Credential>",

                                 'Credential name:' "Service Account",

                                 'User name:' "dns'\'Solarwinds",

                                 'Password:' "P@ssw0rd",

                                 'Confirm password:' "P@ssw0rd"

                            }

                             

                            Looking forward for your response

                              • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                tdanner

                                Here's a sample for adding a WMI node via PowerShell: OrionSDK/CRUD.AddWMINode.ps1 at master · solarwinds/OrionSDK · GitHub If you have questions about doing the same operations from Python, let me know.

                                 

                                The WMI credential is associated with the node though an entry in Orion.NodeSettings with SettingName="WMICredential" and SettingValue=the id of the credential.

                                  • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                    Manilyn Ramos

                                    here's the code I created

                                     

                                    from __future__ import print_function

                                    import re

                                    import requests

                                    from orionsdk import SwisClient

                                     

                                     

                                    def main():

                                     

                                     

                                        npm_server = '10.1.1.1'

                                        username = 'admin'

                                        password = '*****'

                                     

                                     

                                     

                                     

                                        swis = SwisClient(npm_server, username, password)

                                     

                                     

                                     

                                     

                                        ip_address = '10.1.1.2'   

                                        CredentialName = 'Service Account'

                                     

                                     

                                    #Getting the credentialID

                                        credentialID =  "SELECT ID from Orion.CredentialName where Name = " + str (CredentialName)

                                        credentialidquery = swis.query(credentialID)

                                            #####if (!credentialID){

                                             #####   TypeError: "Can't find the Credential with the provided Credential name", CredentialName.

                                            #####}

                                       

                                     

                                     

                                        props = {

                                        'EntityType': 'Orion.Nodes',

                                        'IPAddress': ip_address,

                                        'EngineID':1,

                                        #######'Status': 1,

                                        'NodeName': "SolarWinds",

                                        'ObjectSubType': 'WMI',

                                        'Credential.Name': credentialidquery 

                                        }

                                     

                                     

                                     

                                     

                                     

                                    #extract the nodeID from the result

                                        nodeid = re.search('(\d+)$', results).group(0)

                                        print(nodeid)

                                     

                                     

                                        pollers_enabled = {

                                            'N.Status.ICMP.Native':True,

                                            'N.ResponseTime.ICMP.Native':True,

                                            'N.Details.WMI.Vista':True,

                                            'N.Uptime.WMI.XP':True,

                                            'N.Cpu.WMI.Windows':True,

                                            'N.Memory.WMI.Windows':True

                                        }

                                     

                                     

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

                                     

                                     

                                    And same error I got before:

                                     

                                        raise HTTPError(http_error_msg, response=self)

                                    requests.exceptions.HTTPError: 400 Client Error: no viable alternative at input 'Account' in Where clause for url: https://<IP>:17778/SolarWinds/InformationService/v3/Json/Query

                                     

                                     

                                    ---- My test server is using the latest version of SolarWinds

                                      • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                        tdanner

                                        In your script you have these lines:

                                         

                                            CredentialName = 'Service Account'

                                           #Getting the credentialID

                                            credentialID =  "SELECT ID from Orion.CredentialName where Name = " + str (CredentialName)

                                            credentialidquery = swis.query(credentialID)

                                         

                                        This is sending a query to swis that looks like this:

                                         

                                             SELECT ID from Orion.CredentialName where Name = Service Account

                                         

                                        Notice that Service Account is not quoted in this query. You can change it like this to send the credential name as a query parameter instead:

                                         

                                            CredentialName = 'Service Account'

                                           #Getting the credentialID

                                            credentialID =  "SELECT ID from Orion.CredentialName where Name = @name"

                                            credentialidquery = swis.query(credentialID, name=CredentialName)

                            • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                              emoloney

                              Hi Tim

                               

                              Thanks that did it.

                              If you think it will be usefull

                              When I have tidied up the code and create a maven project can submit for a sample example.

                               

                               

                              Thanks Again

                              E.J.

                                • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                  emoloney

                                  Hi I have a java program that can create a node but its not performing snmp polling or discovery when the ndoe isnt using the community string public.

                                  Can some one show me a REST example of how to define an SNMPv2 community string when discovering a node , Below is what I have tried so far

                                   

                                  String corePluginContext = "[{\"Credentials\": [{\"CredentialID\":3,\"Order\": 1}],\"Community\":\"testpublic\",\"WmiRetryIntervalMiliseconds\": 1000,\"BulkList\": [{\"Address\": \= ipaddress + "\"}],\"WmiRetriesCount\": 0}]";

                                   

                                  Also tried adding to the discovery code

                                  [{\"Name\": \"javadiscovery\",\"EngineID\":1,\"JobTimeoutSeconds\":3600,\"SearchTimeoutMiliseconds\":5000,\"SnmpTimeoutMiliseconds\":5000,\"SnmpRetries\":2,\"RepeatIntervalMiliseconds\":1000,\"SnmpPort\":161,\"Community\":\""+community+"\",\"HopCount\":0,\"PreferredSnmpVersion\":\"SNMP2c\",\"DisableIcmp\":\"False\",\"AllowDuplicateNodes\":\"False\",\"IsAutoImport\":\"True\",\"IsHidden\":\"True\",\"PluginConfigurations\":[{\"PluginConfigurationItem\":" + m_config + "}]}]";

                                    • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                      joe121534

                                      I am newer to Python and I am trying to create a node with custom properties defined and use a saved SNMP V3 credential set. I have the scrip for creating a node working with manually defined SNMP parameters defined but can not get the add node by credentials piece working. Please advise if anyone has gotten this working.

                                       

                                      SWQL Studio Query of SELECT ID from Orion.Credential where Name='READONLY_USER SHA1 AES128' returns the proper credential ID of 64

                                       

                                      Debug output

                                      dd an SNMP v3 node:

                                      {u'results': [{u'ID': 64}]}

                                      Adding node 10.242.220.50... Traceback (most recent call last):

                                        File "C:\Users\xxxxxxxxx\workspace\Solarwinds\Cisco\Switch\Add_Cisco_SW_2960_Manual_SNMPV3_With_CredSet.py", line 122, in <module>

                                          main()

                                        File "C:\Users\xxxxxxx\workspace\Solarwinds\Cisco\Switch\Add_Cisco_SW_2960_Manual_SNMPV3_With_CredSet.py", line 61, in main

                                          results = swis.create('Orion.Nodes', **props)

                                        File "C:\Python27\lib\site-packages\orionsdk\swisclient.py", line 34, in create

                                          "Create/" + entity, properties).json()

                                        File "C:\Python27\lib\site-packages\orionsdk\swisclient.py", line 59, in _req

                                          resp.raise_for_status()

                                        File "C:\Python27\lib\site-packages\requests\models.py", line 935, 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 '' 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 'public' for Community.

                                       

                                       

                                      Error : In property SNMPV3Username. Reason : SNMPV3Username is not provided in the input. It is Mandatory.

                                       

                                       

                                      Information : Assigned default value '' for SNMPV3Context.

                                       

                                       

                                      Error : In property SNMPV3PrivMethod. Reason : SNMPV3PrivMethod is not provided in the input. It is Mandatory.

                                       

                                       

                                      Information : Assigned default value 'True' for SNMPV3PrivKeyIsPwd.

                                       

                                       

                                      Error : In property SNMPV3AuthMethod. Reason : SNMPV3AuthMethod is not provided in the input. It is Mandatory.

                                       

                                       

                                      Information : Assigned default value 'True' for SNMPV3AuthKeyIsPwd.

                                       

                                       

                                      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 '30' for RediscoveryInterval.

                                       

                                       

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

                                       

                                       

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

                                       

                                       

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

                                       

                                      ***********************************************************************************************************************

                                      Config

                                       

                                      from __future__ import print_function

                                      import re

                                      import requests

                                      from orionsdk import SwisClient

                                      import getpass

                                       

                                       

                                      def main():

                                          requests.packages.urllib3.disable_warnings()

                                        

                                          npm_server = '10.xxx.xxx.xxx'

                                          username = 'XXXXXXXXX'

                                          password = 'XXXXXXXXXXXXX'

                                       

                                       

                                          swis = SwisClient(npm_server, username, password)

                                          print("Add an SNMP v3 node:")

                                        

                                          # fill these in for the node you want to add!

                                          # Support Levels = 8x5xNBD,

                                          ip_address = "10.242.220.50"

                                          Caption = "TEST_2960"

                                          CredentialName = 'READONLY_USER SHA1 AES128'

                                          Imported_From_NCM = "False"

                                          Maintenance_Provider = "Cisco"

                                          Model = "2960"

                                          Regional_Center_IP = "False"

                                          Support_Level = "8x5xNBD"

                                          Office_IP = '15'

                                        

                                          #Getting the credentialID

                                          credentialID =  "SELECT ID from Orion.Credential where Name='" + str (CredentialName) + "'"

                                          credentialidquery = swis.query(credentialID)

                                          print(credentialidquery)

                                            

                                          # Setup properties for the new node

                                          props = {

                                              'EntityType':'Orion.Nodes',

                                              'DynamicIP': 'False',

                                              'Caption': Caption,

                                              'IPAddress': ip_address,

                                              'PollInterval': 60,

                                              'Status': 1,

                                              'StatCollection': 10,

                                              'EngineID': 1,

                                              'ObjectSubType': 'SNMP',

                                              'SNMPVersion': 3,      

                                              'CredentialID': credentialidquery

                                          }

                                        

                                          # Create the node

                                          print("Adding node {}... ".format(props['IPAddress']), end="")

                                          results = swis.create('Orion.Nodes', **props)

                                          print("DONE!")

                                        

                                          # Extract nodeID from the results

                                          nodeid = re.search('(\d+)$', results).group(0)

                                          print("Node Name {}... ".format(Caption), end="")

                                          print("Node ID {}... ".format(nodeid), end="")

                                        

                                          # Setup poller status for the node

                                          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

                                          }

                                       

                                       

                                          # Add node to pollers

                                          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!")

                                       

                                       

                                          # Poll the node

                                          swis.invoke('Orion.Nodes', 'PollNow', 'N:' + nodeid)

                                          print("Custom Property Update:")

                                          # Add custom properties

                                          custom_props = {

                                              'Imported_From_NCM': Imported_From_NCM,

                                              'Maintenance_Provider': Maintenance_Provider,

                                              'Model': Model,

                                              'Regional_Center_IP': Regional_Center_IP,

                                              'Support_Level': Support_Level,

                                              'Office_IP': Office_IP,

                                          }

                                        

                                          for k,v in custom_props.items():

                                              print("  Adding custom property: {} with value {}... ".format(k, v), end="")

                                              swis.update(results + '/CustomProperties', **{k: v})

                                              print("DONE!")

                                              print("!!!Node Sucessfully added!!!:")

                                        

                                      if __name__ == '__main__':

                                          main()

                                      if __name__ == '__main__':

                                          pass

                                        • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                          tdanner

                                          For SNMPv3 with a saved credential set, I recommend using the discovery API to add a node. Here's a sample:

                                           

                                          https://github.com/solarwinds/orionsdk-python/blob/master/samples/discover_one_node.py

                                            • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                              joe121534

                                              Thank you for your response. I am able to get both the node discover script and custom properties script working correctly from the below samples in two separate Python scripts. How can I extract the discovered node id and get a combined script (Discover and Custom properties)s similar to the below working? Any help is much appreciated.

                                               

                                               

                                              orionsdk-python/samples at master · solarwinds/orionsdk-python · GitHub

                                               

                                               

                                                  # Extract nodeID from the results that works when adding a node via python but not during a discover via Python

                                                  nodeid = re.search('(\d+)$', results).group(0)

                                                  print("Node Name {}... ".format(Caption), end="")

                                                  print("Node ID {}... ".format(nodeid), end="")

                                               

                                               

                                              Config*************************************************************************************************************************

                                               

                                               

                                               

                                               

                                              #https://www.networkmanagementsoftware.com/solarwinds-orion-api-sdk-scripting-with-python-part-3/

                                              #https://github.com/solarwinds/orionsdk-python/blob/master/samples/custom_property_update.py

                                              #https://thwack.solarwinds.com/thread/100046

                                              #https://thwack.solarwinds.com/thread/111255   credential set #16 or READONLY_USER SHA1 AES128

                                               

                                               

                                              '''

                                              Created on Apr 27, 2018

                                               

                                               

                                               

                                               

                                              '''

                                               

                                              from __future__ import print_function

                                              import re

                                              import requests

                                              from orionsdk import SwisClient

                                               

                                              def main():

                                                  npm_server = 'XXXXXXXXX'

                                                  username = 'XXXXXXXXXXXXXX'

                                                  password = 'XXXXXXXXX'

                                                    

                                                  # fill these in for the node you want to add!

                                                  # Support Levels = 8x5xNBD,

                                                  target_node_ip = '10.242.20.1'

                                                  ip_address = "10.242.20.1"

                                                  Caption = "TEST_2960"

                                                  Imported_From_NCM = "False"

                                                  Maintenance_Provider = "Cisco"

                                                  Model = "2960"

                                                  Regional_Center_IP = "False"

                                                  Support_Level = "8x5xNBD"

                                                  Office_IP = '15'

                                                  snmpv3_credential_id = 64

                                                  orion_engine_id = 1

                                               

                                                  swis = SwisClient(npm_server, username, password)

                                                  print("Add an SNMP v3 node:")

                                               

                                               

                                                  corePluginContext = {

                                                      'BulkList': [{'Address': target_node_ip}],

                                                      'Credentials': [

                                                          {

                                                              'CredentialID': snmpv3_credential_id,

                                                              'Order': 1

                                                          }

                                                      ],

                                                      'WmiRetriesCount': 0,

                                                      'WmiRetryIntervalMiliseconds': 1000

                                                  }

                                               

                                               

                                                  corePluginConfig = swis.invoke('Orion.Discovery', 'CreateCorePluginConfiguration', corePluginContext)

                                               

                                               

                                                  discoveryProfile = {

                                                      'Name': 'discover_one_node.py',

                                                      'EngineID': orion_engine_id,

                                                      'JobTimeoutSeconds': 3600,

                                                      'SearchTimeoutMiliseconds': 5000,

                                                      'SnmpTimeoutMiliseconds': 5000,

                                                      'SnmpRetries': 2,

                                                      'RepeatIntervalMiliseconds': 1800,

                                                      'SnmpPort': 161,

                                                      'HopCount': 0,

                                                      'PreferredSnmpVersion': 'SNMP3',

                                                      'DisableIcmp': False,

                                                      'AllowDuplicateNodes': False,

                                                      'IsAutoImport': True,

                                                      'IsHidden': True,

                                                      'PluginConfigurations': [{'PluginConfigurationItem': corePluginConfig}]

                                                  }

                                               

                                               

                                                  print("Running discovery...")

                                                  result = swis.invoke('Orion.Discovery', 'StartDiscovery', discoveryProfile)

                                                  print("Returned discovery profile id {}".format(result))

                                                  print("Discovery Complete")

                                                 

                                                  swis = SwisClient(npm_server, username, password)

                                                  print("Custom Property Update Test:")

                                                  results = swis.query("SELECT Uri FROM Orion.Nodes WHERE NodeID=@id",id=1334)

                                                  print results

                                                  uri = results['results'][0]['Uri']

                                                

                                                  swis.update(uri + '/CustomProperties', Imported_From_NCM=Imported_From_NCM, Maintenance_Provider=Maintenance_Provider, Model=Model,

                                                  Regional_Center_IP=Regional_Center_IP, Support_Level=Support_Level, Office_IP=Office_IP)

                                                  obj = swis.read(uri + '/CustomProperties')

                                                  print (obj)

                                                

                                                

                                              requests.packages.urllib3.disable_warnings()

                                               

                                               

                                                

                                              if __name__ == '__main__':

                                                  main()

                                                • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                                  tdanner

                                                  As you have probably learned, the "StartDiscovery" verb returns immediately and the actually discovery job runs in the background and completes some number of seconds or minutes later. So your script prints "Discovery Complete" and tries to set the custom properties long before the new node actually exists in the system.

                                                   

                                                  The PowerShell sample for using the discovery API includes code that repeatedly queries the discovery status until it is complete, then queries for what objects it discovered and prints them as well. You should be able to adapt this for python, but let me know if you have questions about how to do that.

                                                   

                                                  General information about the discovery API: https://github.com/solarwinds/OrionSDK/wiki/Discovery

                                                  PowerShell sample for discovery: https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/DiscoverSnmpV3Node.ps1#L68

                                                    • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                                      clarv02

                                                      If you check out this thread, I posted on Nov 16, 2017, my Python script does:

                                                       

                                                      • Programmatically builds the Credentials list, rather than hard code them all in the corePluginContext
                                                      • Selects the polling engine with lowest job weight (if you have multiple pollers)
                                                      • Performs the discovery
                                                      • Uses RegEx to filter and select only the right interfaces (right for our environment, but easily customizable)
                                                      • Auto imports the devices after discovery
                                                      • Waits for the discovery to complete (which includes importing the nodes)

                                                       

                                                      If you're interested, I can share more of our script, which after the wait, uses the NodeIDs to:

                                                        Populate custom properties

                                                        Assign custom UnDP pollers

                                                        Assign NCM connection profile and device templates

                                                       

                                                        • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                                          joe121534

                                                          I was able to get a combined Node discovery  and Modify custom properties script working using a 20 second sleep timer after discovery. Would be very interested to see what you did with UnDP, NCM and adding a node to UDT.

                                                          Thanks

                                                           

                                                          from __future__ import print_function

                                                          import re

                                                          import requests

                                                          from orionsdk import SwisClient

                                                          import getpass

                                                          import time

                                                           

                                                           

                                                          def main():

                                                              npm_server = 'XXXXXXXXX'

                                                              username = 'XXXXXXXXXXXX'

                                                              password = 'XXXXXXXXXXXXXXXXXXXXXX'

                                                                

                                                              # fill these in for the node you want to add!

                                                              # Support Levels = 8x5xNBD,

                                                              target_node_ip = '10.242.10.250'

                                                              ip_address = "10.242.10.250"

                                                              Caption = "TestSNMP"

                                                              Imported_From_NCM = "False"

                                                              Maintenance_Provider = "Cisco"

                                                              Model = "2960"

                                                              Regional_Center_IP = "False"

                                                              Support_Level = "8x5xNBD"

                                                              Office_IP = '15'

                                                              snmpv3_credential_id = 64

                                                              orion_engine_id = 1

                                                           

                                                           

                                                              swis = SwisClient(npm_server, username, password)

                                                              print("Add an SNMP v3 node:")

                                                           

                                                           

                                                              corePluginContext = {

                                                                  'BulkList': [{'Address': target_node_ip}],

                                                                  'Credentials': [

                                                                      {

                                                                          'CredentialID': snmpv3_credential_id,

                                                                          'Order': 1

                                                                      }

                                                                  ],

                                                                  'WmiRetriesCount': 0,

                                                                  'WmiRetryIntervalMiliseconds': 1000

                                                              }

                                                           

                                                           

                                                              corePluginConfig = swis.invoke('Orion.Discovery', 'CreateCorePluginConfiguration', corePluginContext)

                                                           

                                                           

                                                              discoveryProfile = {

                                                                  'Name': 'discover_one_node.py',

                                                                  'EngineID': orion_engine_id,

                                                                  'JobTimeoutSeconds': 3600,

                                                                  'SearchTimeoutMiliseconds': 5000,

                                                                  'SnmpTimeoutMiliseconds': 5000,

                                                                  'SnmpRetries': 2,

                                                                  'RepeatIntervalMiliseconds': 1800,

                                                                  'SnmpPort': 161,

                                                                  'HopCount': 0,

                                                                  'PreferredSnmpVersion': 'SNMP3',

                                                                  'DisableIcmp': False,

                                                                  'AllowDuplicateNodes': False,

                                                                  'IsAutoImport': True,

                                                                  'IsHidden': True,

                                                                  'PluginConfigurations': [{'PluginConfigurationItem': corePluginConfig}]

                                                              }

                                                           

                                                           

                                                              print("Running discovery...")

                                                              result = swis.invoke('Orion.Discovery', 'StartDiscovery', discoveryProfile)

                                                              print("Returned discovery profile id {}".format(result))

                                                              print("Discovery In Progress")

                                                            

                                                            

                                                              # Delay for 1 minute (20 seconds)May need to increase time.

                                                              print("20 Second sleep Timer for Discovery to complete.")

                                                              time.sleep(20) 

                                                              print("Sleep Timer complete.")

                                                            

                                                              #Query Node ID

                                                              nodelist = swis.query("SELECT NodeID, Caption AS NodeName, IPAddress FROM Orion.Nodes WHERE Caption='" + Caption + "'")

                                                              print(nodelist)

                                                            

                                                              #Custom Properties update

                                                              swis = SwisClient(npm_server, username, password)

                                                              print("Custom Property Update Test:")

                                                              results = swis.query("SELECT Uri FROM Orion.Nodes WHERE NodeID=@id",id=nodelist['results'][0]['NodeID'])

                                                              print (results)

                                                              uri = results['results'][0]['Uri']

                                                            

                                                              swis.update(uri + '/CustomProperties', Imported_From_NCM=Imported_From_NCM, Maintenance_Provider=Maintenance_Provider, Model=Model,

                                                              Regional_Center_IP=Regional_Center_IP, Support_Level=Support_Level, Office_IP=Office_IP)

                                                              obj = swis.read(uri + '/CustomProperties')

                                                              print (obj)

                                                            

                                                            

                                                          requests.packages.urllib3.disable_warnings()

                                                           

                                                           

                                                            

                                                          if __name__ == '__main__':

                                                              main()

                                                  • Re: Can any one supply a REST example of how to define a Node in Solarwinds
                                                    Manilyn Ramos

                                                    please complete your SNMPv3 credentials

                                                     

                                                     

                                                    ex

                                                     

                                                     

                                                                'SNMPVersion': 3,

                                                                'SNMPV3AuthKey': '<fillout>',

                                                                'SNMPv3AuthKeyIsPwd': True,

                                                                'SNMPv3AuthMethod': '<fillout>',

                                                                'SNMPv3PrivKey':'<fillout>',

                                                                'SNMPv3PrivKeyIsPwd': True,

                                                                'SNMPv3PrivMethod': '<fillout',

                                                                'SNMPV3Username': '<fillout>',