I'm working on making a script work to start a discovery using REST API posts. Been testing it all in Postman since that's the easiest way so far:
I've been able to generate the CreateCorePluginConfiguration successfully:
URL: https://<hostname>:17774/SolarWinds/InformationService/v3/Json/Invoke/Orion.Discovery/CreateCorePluginConfiguration
authorization: Basic
Header: content-type application/json
JSON BODY:
<span>{</span><span>"Context"</span><span> : {</span>
<span> </span><span>"BulkList"</span><span>:[</span>
<span> {</span><span>"Address"</span><span>:</span><span>"172.23.28.45"</span><span>},</span>
<span> {</span><span>"Address"</span><span>:</span><span>"172.23.171.250"</span><span>}</span>
<span> ],</span>
<span> </span><span>"Credentials"</span><span>:[</span>
<span> {</span><span>"CredentialID"</span><span>:</span><span>"56"</span><span>,</span><span>"Order"</span><span>:</span><span>"1"</span><span>},</span>
<span> {</span><span>"CredentialID"</span><span>:</span><span>"250"</span><span>,</span><span>"Order"</span><span>:</span><span>"2"</span><span>},</span>
<span> {</span><span>"CredentialID"</span><span>:</span><span>"252"</span><span>,</span><span>"Order"</span><span>:</span><span>"3"</span><span>},</span>
<span> {</span><span>"CredentialID"</span><span>:</span><span>"265"</span><span>,</span><span>"Order"</span><span>:</span><span>"4"</span><span>}</span>
<span> ],</span>
<span> </span><span>"WMIRetriesCount"</span><span>:</span><span>"1"</span><span>,</span>
<span> </span><span>"WMIRetryIntervalMiliseconds"</span><span>:</span><span>"1000"</span><span>,</span>
<span> </span><span>"PreferredPollingMethod"</span><span>:</span><span>"WMI"</span>
<span>}}</span>
</code></div><div><code>
<span>From there I'm trying to initiate the discovery. I swear I had it work once yesterday when messing with it, but I can't figure out what I'm doing wrong now.</span>
</code></div><div><code><span>URL: <a id="" href="https://sam-prd-app01.carilion.com:17774/SolarWinds/InformationService/v3/Json/Invoke/Orion.Discovery/StartDiscovery">https://<url>:17774/SolarWinds/InformationService/v3/Json/Invoke/Orion.Discovery/StartDiscovery</a></span>
<span>Body, JSON:</span>
</code></div><div><div><div><code><span>{</span><span>"Context"</span><span> : {</span>
<span> </span><span>"Name"</span><span>: </span><span>"Scripted Discovery 2024/11/08/10:11"</span><span>,</span>
<span> </span><span>"EngineID"</span><span>: </span><span>"9"</span><span>,</span>
<span> </span><span>"JobTimeOutSeconds"</span><span>: </span><span>"1800"</span><span>,</span>
<span> </span><span>"SearchTimeoutMiliseconds"</span><span>: </span><span>"2000"</span><span>,</span>
<span> </span><span>"SnmpTimeoutMiliseconds"</span><span>: </span><span>"2000"</span><span>,</span>
<span> </span><span>"SnmpRetries"</span><span>: </span><span>"1"</span><span>,</span>
<span> </span><span>"RepeatIntervalMiliseconds"</span><span>: </span><span>"1500"</span><span>,</span>
<span> </span><span>"SnmpPort"</span><span>: </span><span>"161"</span><span>,</span>
<span> </span><span>"HopCount"</span><span>: </span><span>"0"</span><span>,</span>
<span> </span><span>"DisableIcmp"</span><span>: </span><span>"false"</span><span>,</span>
<span> </span><span>"AllowDuplicateNodes"</span><span>: </span><span>"false"</span><span>,</span>
<span> </span><span>"IsAutoImport"</span><span>: </span><span>"true"</span><span>,</span>
<span> </span><span>"IsHidden"</span><span>: </span><span>"false"</span><span>,</span>
<span> </span><span>"PreferredSNMPVersion"</span><span>: </span><span>"SNMP3"</span><span>,</span>
<span> </span><span>"PluginConfigurations"</span><span>: {</span>
<span> </span><span>"PluginConfigurationItem"</span><span>: </span><span>"<?xml vercsion=\"1.0\" encoding=\"utf-16\"?><PluginItems><knownTypes><ArrayOfstring xmlns:i=\"">www.w3.org/.../XMLSchema-instance\" xmlns=\"">schemas.microsoft.com/.../knownTypes><pluginItem><ArrayOfDiscoveryPluginConfigurationBase xmlns:i=\"">www.w3.org/.../XMLSchema-instance\" xmlns=\"">schemas.datacontract.org/.../SolarWinds.Orion.Core.Models.Discovery\"><DiscoveryPluginConfigurationBase xmlns:d2p1=\"">schemas.solarwinds.com/.../Orion\" i:type=\"d2p1:CoreDiscoveryPluginConfiguration\"><d2p1:ActiveDirectoryList /><d2p1:AddressRange /><d2p1:AgentsAddresses xmlns:d3p1=\"">schemas.microsoft.com/.../Arrays\" /><d2p1:AgentsFilterDefinition i:nil=\"true\" /><d2p1:AgentsFilterQuery i:nil=\"true\" /><d2p1:AutoImportVolumeTypes xmlns:d3p1=\"">schemas.datacontract.org/.../SolarWinds.Common.Snmp\" i:nil=\"true\" /><d2p1:BulkList xmlns:d3p1=\"">schemas.microsoft.com/.../d2p1:BulkList><d2p1:Credentials><d2p1:credentials><knownTypes><ArrayOfstring xmlns:i=\"">www.w3.org/.../XMLSchema-instance\" xmlns=\"">schemas.microsoft.com/.../Arrays\" /></knownTypes><pluginItem><d2p1:ArrayOfCredential xmlns:i=\"">www.w3.org/.../XMLSchema-instance\" /></pluginItem></d2p1:credentials></d2p1:Credentials><d2p1:DiscoverAgentNodes>false</d2p1:DiscoverAgentNodes><d2p1:PreferredPollingMethod>WMI</d2p1:PreferredPollingMethod><d2p1:SharedCredentials xmlns:d3p1=\"">schemas.microsoft.com/.../d2p1:SharedCredentials><d2p1:SubnetList /><d2p1:WMICredentials><WMIAccess><_x003C_CredentialID_x003E_k__BackingField>56</_x003C_CredentialID_x003E_k__BackingField><_x003C_Credential_x003E_k__BackingField i:nil=\"true\" /></WMIAccess><WMIAccess><_x003C_CredentialID_x003E_k__BackingField>250</_x003C_CredentialID_x003E_k__BackingField><_x003C_Credential_x003E_k__BackingField i:nil=\"true\" /></WMIAccess><WMIAccess><_x003C_CredentialID_x003E_k__BackingField>252</_x003C_CredentialID_x003E_k__BackingField><_x003C_Credential_x003E_k__BackingField i:nil=\"true\" /></WMIAccess></d2p1:WMICredentials><d2p1:WmiRetries>1</d2p1:WmiRetries><d2p1:WmiRetryInterval>PT1S</d2p1:WmiRetryInterval></DiscoveryPluginConfigurationBase></ArrayOfDiscoveryPluginConfigurationBase></pluginItem></PluginItems>"</span>
<span> }</span>
<span>}}</span>
<span></span>
When I initiate the POST, I get the following error back:
"Message": "Verb Orion.Discovery.StartDiscovery cannot unpackage parameter 'context' (#0) with type SolarWinds.Data.Providers.Orion.Verbs.Discovery+StartDiscoveryContext",
"ExceptionType": "SolarWinds.InformationService.Verb.VerbExecutorException",
"FullException": "SolarWinds.InformationService.Verb.VerbExecutorException: Verb Orion.Discovery.StartDiscovery cannot unpackage parameter 'context' (#0) with type SolarWinds.Data.Providers.Orion.Verbs.Discovery+StartDiscoveryContext ---> Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[SolarWinds.Data.Providers.Orion.Verbs.Discovery+PluginConfiguration]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'Context.PluginConfigurations.PluginConfigurationItem'.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at SolarWinds.InformationService.Verb.VerbExecutorContext.<>c__DisplayClass26_0.<UnpackageParameters>g__GetParameterByIndex|0(Int32 index)
--- End of inner exception stack trace ---
at SolarWinds.InformationService.Verb.VerbExecutorContext.<>c__DisplayClass26_0.<UnpackageParameters>g__GetParameterByIndex|0(Int32 index)
at SolarWinds.InformationService.Verb.VerbExecutorContext.CreateParameters(Func`2 getParameterAt, Int32 parametersCount, Stream stream)
at SolarWinds.InformationService.Verb.VerbExecutorContext.UnpackageParameters(JObject parameters)
at SolarWinds.InformationService.Core.InformationService.Invoke[T](String entity, String verb, Action`1 setupParameters, Func`2 extractReturnValue)"
So basically it's complaining that it requires an array? I'm not certain where it thinks I need to make the data an array.
I tried array braces [] at "PluginConfiguration": [{ "PluginConfigurationItem" : <pluginconfig>" } ]} but that didn't help.
I tried changing { "Context" : [ {then each row in it's own curly braces} ] but it keeps giving the above error.
So.. WTF am I doing wrong with my JSON here?