This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Exception adding Orion.Container with dynamic query via Python

FormerMember
FormerMember

Below is what i'm using to invoke CreateContainer call and the trace is below it. What am i doing wrong here? I've tried this with both filter:/Orion.Nodes[CustomProperties.Site={0}] and filter:/Orion.Nodes[CustomProperties.Site='{0}'] thinking maybe since the filter is a string that's why it couldn't cast my member definition correctly but it's still bombing with the same error.

group_member_def = '''

<ArrayOfMemberDefinitionInfo xmlns:i="http://www.w3.org/2001/XMLSchema-instance"

    xmlns="http://schemas.solarwinds.com/2008/Orion">

<MemberDefinitionInfo>

<Name>{0}_Devices</Name>

<Definition>filter:/Orion.Nodes[CustomProperties.Site={0}]</Definition>

</MemberDefinitionInfo></ArrayOfMemberDefinitionInfo>

'''

swis.invoke(

    'Orion.Container',

    'CreateContainer',

    'name', #name

    'Core', #owner

    60, #frequency

    0, #statusCalculator

    'description', #description

    'true', #pollingEnable

    group_member_def.format('test') #memberDef

)

'SolarWinds.InformationService.Verb.VerbExecutorException: Verb Orion.Container.CreateContainer cannot unpackage parameter 6 with type SolarWinds.Data.Providers.Orion.Containers.DataProvider.MemberDefinitionInfo[] ---> Newtonsoft.Json.JsonSerializationException: Error converting value "<ArrayOfMemberDefinitionInfo xmlns:i="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://schemas.solarwinds.com/2008/Orion"><MemberDefinitionInfo><Name>test_Devices</Name><Definition>filter:/Orion.Nodes[CustomProperties.Site=test]</Definition></MemberDefinitionInfo></ArrayOfMemberDefinitionInfo>" to type \'SolarWinds.Data.Providers.Orion.Containers.DataProvider.MemberDefinitionInfo[]\'. Path \'\'. ---> System.ArgumentException: Could not cast or convert from System.String to SolarWinds.Data.Providers.Orion.Containers.DataProvider.MemberDefinitionInfo[].\r\n   at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)\r\n   at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)\r\n   --- End of inner exception stack trace ---\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n   at SolarWinds.InformationService.Verb.VerbExecutorContext.<>c__DisplayClass22_0.<UnpackageParameters>b__0(Int32 index)\r\n   --- End of inner exception stack trace ---\r\n   at SolarWinds.InformationService.Verb.VerbExecutorContext.<>c__DisplayClass22_0.<UnpackageParameters>b__0(Int32 index)\r\n   at SolarWinds.InformationService.Verb.VerbExecutorContext.CreateParameters(Func`2 getParameterAt, Int32 parametersCount, Stream stream)\r\n   at SolarWinds.InformationService.Verb.VerbExecutorContext.UnpackageParameters(JArray parameters)\r\n   at SolarWinds.InformationService.Core.InformationService.Invoke[T](String entity, String verb, Action`1 setupParameters, Func`2 extractReturnValue)'

  • The python client uses the json endpoint for SWIS, so verb arguments need to be encoded as json. The python SwisClient wrapper takes care of this for you, so you can just pass regular python lists and dicts. No ugly XML.

    I just put a sample of creating a group from python on GitHub: https://github.com/solarwinds/orionsdk-python/blob/master/samples/groups.py

  • Thanks for that sample! I'm running into an interesting problem with it though. I kept everything the same except the following

    results = swis.invoke(rest of code)

    and at the end:

    print(results)

    When I run this script against my 12.0 instance of Solarwinds it works perfectly and returns back the new containerID which I need to progress with the rest of the script I would like to write. I can then view the group in the GUI and I see the database entry.

    When I run this script against my 12.0.1 instance of Solarwinds it acts like it works, even returning back a new containerID, but it doesn't actually put anything in the database, therefore it's not in the GUI either. The container ID continues to iterate: for example ID 151 is the latest ContainerID in the database. if I run the script, it returns a containerID of 152, even though the group isn't actually created. If I then create a group through the GUI, that container ID is 153.

    I get no exceptions or errors. There is nothing in the information service logs that I see.

    If I remove the changes I made, it still behaves this way, I just don't see the return of the containerID, but the ID continues to iterate without "doing" anything.

    Any thoughts?

  • hmm... just tried groups.py sample against my instance of NPM 12.0.1 and it works just fine. Maybe some other changes you made(e.g. can you redownload the sample?)? Or difference between versions? I used Python 2.7.12, Requests 2.11.1 and latest swisclient module from orionsdk-python/swisclient.py at master · solarwinds/orionsdk-python · GitHub

  • Could you please show the script you are using?

    The problem may be in filter:/Orion.Nodes[CustomProperties.Site={0}]

    Attribute Site is not in schema for CustomProperties,

    instead please use following:

    filter:/Orion.Nodes[CustomProperties.OrionSite.Host='{0}']

    You can use any attribute from Orion.Site schema (Host, Name, SiteID..)

  • Thanks for the response!

    I finally found found the issue. My service account had an account limitation for a single group. It was just weird that instead of saying I didn't have permission, it acted like it worked.

  • The response from tomas.vrabel was written before you found the root cause, but it got held up in the moderation queue and only got posted now.

    Glad you got it working!

  • FormerMember
    0 FormerMember in reply to tdanner

    Now i'm getting a different problem. I can't really explain why this isn't working anymore. I used your above example to insert groups for custom property 'site' in a deployment I did in October and didn't have any issues. When I went back and grabbed that code to re-use it for another, it no longer seems to work(on either server). Just to make sure i'm not screwing up the API call, I used the example you've posted on github on both servers and got the same exact result.

    From python client:

    requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://10.114.128.21:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Container/CreateContainer

    From information service log on servers:

    2017-02-17 21:48:52,312 [94] ERROR SolarWinds.InformationService.Core.InformationService - (null) (null) Exception for Operation: <root type="array">

      <item type="string">Sample Python Group</item>

      <item type="string">Core</item>

      <item type="number">60</item>

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

      <item type="string">Group created by the Python sample script.</item>

      <item type="boolean">true</item>

      <item type="array">

        <item type="object">

          <Definition type="string">filter:/Orion.Nodes[Vendor='Cisco']</Definition>

          <Name type="string">Cisco Devices</Name>

        </item>

        <item type="object">

          <Definition type="string">filter:/Orion.Nodes[Vendor='Windows']</Definition>

          <Name type="string">Windows Devices</Name>

        </item>

      </item>

    </root>

    2017-02-17 21:48:52,312 [94] ERROR SolarWinds.InformationService.Core.InformationService - (null) (null) Exception caught in method SolarWinds.InformationService.Core.InformationService.Invoke

    System.NullReferenceException: Object reference not set to an instance of an object.

       at SolarWinds.InformationService.Verb.VerbExecutor.Invoke(Object hostInstance, Object[] parameters)

       at SolarWinds.InformationService.Verb.VerbExecutorContext.Invoke()

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