7 Replies Latest reply on Dec 1, 2016 5:31 PM by equalswql

    REST HTTP Post  SWIS Invoke Orion.NodesCustomProperties/ModifyCustomProperty Syntax

    equalswql

      Hello Thwack Community,

       

      Trying to create automation to keep our custom properties in sync across multiple instances of Orion.

      I am attempting to do so using a HTTP Post to utilize REST with INVOKE function - Getting 500 Error which is likely related to the syntax of my JSON array/post data being incorrect.

      Can someone please advise how to properly set the json array for the "Values" verbargument? I've been able to do this successfully in Powershell, but the same format doesn't work..

       

      tdanner - I tried to use the same formatting using the json array you referenced in a previous post - but I know I'm missing something (big or small).

      Thanks for the help again btw, I was able to work several other verbs into my automation(like auto-alert acknowledgement with ticket update in alert notes) due to your assistance.

       

      URL:

       

      https://localhost:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.NodesCustomProperties/ModifyCustomProperty

       

      POST DATA:

       

      [

          "Site_Code",

          "3 character site code identifier",

          4000,

          [

          {"value" =  "Site_Code_Value_1"},

          {"value" =  "Site_Code_Value_2"},

          {"value" =  "Site_Code_Value_3"},

          {"value" =  "Site_Code_Value_4"},

          {"value" =  "Site_Code_Value_5"}

          ]

      ]

       

      I've also tried:

       

      [

          "Site_Code",

          "3 character site code identifier",

          4000,

        [

          {"values[0]" =  "Site_Code_Value_1"},

          {"values[1]" =  "Site_Code_Value_2"},

          {"values[2]" =  "Site_Code_Value_3"},

          {"values[3]" =  "Site_Code_Value_4"},

          {"values[4]" =  "Site_Code_Value_5"}

         ]

      ]

       

       

      Thank you,

       

      =SWQL

        • Re: REST HTTP Post  SWIS Invoke Orion.NodesCustomProperties/ModifyCustomProperty Syntax
          KMSigma

          From what one of the PowerShell documents say, it looks like the CreateCustomPropertyWithValues verb requires 11 parameters (Creating Custom Properties · solarwinds/OrionSDK Wiki · GitHub )

           

          You may need to add nulls into the JSON content for the parameters that don't require information.

           

          I was able to do this bypassing the following JSON:

          [
              "SiteCode",
              "Site Code for Location",
              "string",
              3,
              null,
              null,
              null,
              null,
              null,
              null,
              [
                  "SC1",
                  "SC2",
                  "SC3",
                  "SC4"
              ]
          ]
          

           

          These match up with the following fields:

          PropertyName - String

          Description  - String

          ValueType    - String = {"string", "integer", "datetime", "single", "double", "boolean" }

          Size         - integer (for ValueType = "string") or ignored

          ValidRange   - ignored - pass null

          Parser       - ignored - pass null

          Header       - ignored - pass null

          Alignment    - ignored - pass null

          Format       - ignored - pass null

          Units        - ignored - pass null

          Value        - array of values

           

          I made the call with PowerShell's Invoke-RestMethod (because I'm more familiar with that) and this is what I ended up with:

          SiteCodeCreation.png

          1 of 1 people found this helpful
            • Re: REST HTTP Post  SWIS Invoke Orion.NodesCustomProperties/ModifyCustomProperty Syntax
              KMSigma

              I'm including my PowerShell script for completeness.

               

              Adding via PowerShell SWIS Snapin area is commented out, but including so that everything is in one place.

               

              #################################
              # Add-CustomProperty.ps1
              #################################
              #region Values for Array
              # List of Properties
              # Example provided on: https://github.com/solarwinds/OrionSDK/wiki/Creating-Custom-Properties
              $PropertyName = "SiteCode"
              $Description  = "Site Code for Location"
              $ValueType    = "string"
              $Size         = 3
              $ValidRange   = $null
              $Parser       = $null
              $Header       = $null
              $Alignment    = $null
              $Format       = $null
              $Units        = $null
              $Value        = "SC1", "SC2", "SC3", "SC4"
              
              # I decided to put these into an array just to make it easier to read
              $Arguments = @( $PropertyName, $Description, $ValueType, $Size, $ValidRange, $Parser, $Header, $Alignment, $Format, $Units, $Value )
              #endregion Values for Array
              
              #region Credential Builder
              # The username for a user with admin  level permissions
              $SwisUsername = "admin"
              # The password for said user (in plain text)
              $SwisPassword = "MyComplexIfPlainTextPassword"
              # The IP, machine name, or alias for the associated Orion  Instance
              $SwisHost    = "10.1.1.1"
              $SwisCredentails = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $SwisUsername, ( ConvertTo-SecureString -String $SwisPassword -AsPlainText -Force ) 
              #endregion Credential Builder
              
              <#
              ############################
              ##Using SWIS Object
              ############################
              #region Check for SolarWinds Snapin
              if ( -not ( Get-Command -Name Connect-Swis -ErrorAction SilentlyContinue ) )
              {
                  Add-PSSnapin -Name SwisSnapin -ErrorAction Stop
              }
              #endregion Check for SolarWinds Snapin
              # Connect to SWIS
              $SwisConnection  = Connect-Swis -Hostname $SwisHost -Credential $SwisCredentails
              
              # Call the REST Verb
              Invoke-SwisVerb -SwisConnection $SwisConnection `
                  -EntityName "Orion.NodesCustomProperties" `
                  -Verb "CreateCustomPropertyWithValues" `
                  -Arguments $Arguments `
                  -Verbose
              #>
              
              <#
              *** Using REST API ***
              #>
              
              # This is required because I'm running it from a remote machine.  If local to Orion Server, this is probably not necessary (because the certificate is trusted).
              Trust-AllWebCertificates
              
              $JsonArguments = @"
              [
                  "SiteCode",
                  "Site Code for Location",
                  "string",
                  3,
                  null,
                  null,
                  null,
                  null,
                  null,
                  null,
                  [
                      "SC1",
                      "SC2",
                      "SC3",
                      "SC4"
                  ]
              ]
              "@
              
              Invoke-RestMethod -Uri "https://$( $SwisHost ):17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.NodesCustomProperties/CreateCustomPropertyWithValues" -Method Post -Credential $SwisCredentails -Body $JsonArguments -ContentType "application/json"
              
              <#
              .SYNOPSIS
                This function completely disables the back-check for certificates
              .DESCRIPTION
                This function prevents Windows from blocking unrecognized certificates - namely those that are self-signed.
              .EXAMPLE
                Trust-AllWebCertificates
              .OUTPUT
                None
              .NOTES
                PoshCode #624 (http://poshcode.org/624)
              #>
              function Trust-AllWebCertificates
              {
                  ## Create a compilation environment
                  $Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
                  $Compiler=$Provider.CreateCompiler()
                  $Params=New-Object System.CodeDom.Compiler.CompilerParameters
                  $Params.GenerateExecutable=$False
                  $Params.GenerateInMemory=$True
                  $Params.IncludeDebugInformation=$False
                  $Params.ReferencedAssemblies.Add("System.DLL") | Out-Null
              $TASource=@'
                namespace Local.ToolkitExtensions.Net.CertificatePolicy{
                  public class TrustAll : System.Net.ICertificatePolicy {
                    public TrustAll() { 
                    }
                    public bool CheckValidationResult(System.Net.ServicePoint sp,
                      System.Security.Cryptography.X509Certificates.X509Certificate cert, 
                      System.Net.WebRequest req, int problem) {
                      return true;
                    }
                  }
                }
              '@ 
                  $TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
                  $TAAssembly=$TAResults.CompiledAssembly
                  ## We now create an instance of the TrustAll and attach it to the ServicePointManager
                  $TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
                  [System.Net.ServicePointManager]::CertificatePolicy=$TrustAll
              }
              
              1 of 1 people found this helpful
              • Re: REST HTTP Post  SWIS Invoke Orion.NodesCustomProperties/ModifyCustomProperty Syntax
                equalswql

                Thank you for the suggestion KMSigma -

                For the "ModifyCustomProperty" verb that I'm attempting to use, The verb arguments are as follows:

                 

                0   PropertyNameSystem.String

                1   Description System.String

                2   SizeSystem.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

                3   Values  System.String[]

                4   Usages  System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

                5   Mandatory   System.Boolean

                6   Default System.String

                 

                Here is my updated post based on your suggestion:

                 

                [

                    "Site_Code",

                    "3 character site code identifier",

                    4000,

                    [

                    "Site_Code_Value_1",

                    "Site_Code_Value_2",

                    "Site_Code_Value_3",

                    "Site_Code_Value_4",

                    "Site_Code_Value_5"

                    ],

                null,

                null,

                null

                ]

                 

                 

                but no dice...

                 

                Any other suggestions? Maybe I'm formatting something incorrectly still?

                 

                Thank you,

                 

                =SWQL

                • Re: REST HTTP Post  SWIS Invoke Orion.NodesCustomProperties/ModifyCustomProperty Syntax
                  equalswql

                  Thank you KMSigma - The null values were definitely the fix. I never get sick of saying it - the Thwack community is awesome!

                  Thank you tdanner for the awareness on the boolean value (DOH!). I'm more used to doing queries successfully through rest, but updates are a different story... I'm learning however thanks to your help.

                   

                  Just for completeness here is what I posted with success:

                   

                  [

                  "Site_Code",

                  "3 character site code identifier",

                  4000,

                  [

                  "Site_Code_Value_1",

                  "Site_Code_Value_2",

                  "Site_Code_Value_3",

                  "Site_Code_Value_4",

                  "Site_Code_Value_5"

                  ],

                  null,

                  false,

                  null

                  ]

                   

                  Thank you both again,

                   

                  = SWQL