14 Replies Latest reply on Sep 1, 2017 3:28 PM by tdanner

    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 + "}]}]";