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
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
Hi there,
A really good place to start - OrionSDK/Samples at master · solarwinds/OrionSDK · GitHub
Regards,
Rich
Hi yaquaholic
I had a look and found the following powershell example
github.com/.../CRUD.AddNode.ps1
Was looking for an example of the REST Call todo similar.
Thanks
E.J.
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">
<Address type="string">192.168.2.254</Address>
</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
I looked in the file I find the followiing related entry
And assistance would be much appreciated
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
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 + "}]}]";
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:
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
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
'EntityType':'Orion.Nodes',
'DynamicIP': 'False',
'Caption': Caption,
'PollInterval': 60,
'StatCollection': 10,
'EngineID': 1,
'ObjectSubType': 'SNMP',
'SNMPVersion': 3,
'CredentialID': credentialidquery
# Create the node
print("Adding node {}... ".format(props['IPAddress']), end="")
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)
# 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("!!!Node Sucessfully added!!!:")
if __name__ == '__main__':
pass
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
please complete your SNMPv3 credentials
ex
'SNMPV3AuthKey': '<fillout>',
'SNMPv3AuthKeyIsPwd': True,
'SNMPv3AuthMethod': '<fillout>',
'SNMPv3PrivKey':'<fillout>',
'SNMPv3PrivKeyIsPwd': True,
'SNMPv3PrivMethod': '<fillout',
'SNMPV3Username': '<fillout>',