62 Replies Latest reply on Aug 16, 2017 1:39 PM by tdanner Branched to a new discussion.

    SWIS REST/JSON API

    tdanner

      Starting with NPM 10.4, SWIS now supports a REST/JSON API in addition to the existing SOAP API. The operations supported by each API are identical: the six basic operations of Query, Invoke, Create, Read, Update, and Delete; and the data you can access through each API is the same. The difference is that the REST/JSON API avoids the complexities of XML and SOAP, though it gives up the ability to have a client wrapper generated from WSDL.

       

      Both APIs will be supported by the product indefinitely - the SOAP API is not deprecated or replaced by the REST API.

       

      Request and Response Formats

      Query

      Request

      GET https://localhost:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+Uri+FROM+Orion.Pollers+ORDER+BY+PollerID+WITH+ROWS+1+TO+3+WITH+TOTALROWS HTTP/1.1
      Authorization: Basic YWRtaW46
      User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
      Host: localhost:17778
      Accept: */*

      Response

      HTTP/1.1 200 OK
      Content-Length: 244
      Content-Type: application/json
      Server: Microsoft-HTTPAPI/2.0
      Date: Fri, 27 Jul 2012 19:38:52 GMT
      {"totalRows":13,"results":[{"Uri":"swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=4"},{"Uri":"swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=6"},{"Uri":"swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=7"}]}

       

      Body reformatted for easier reading
      {

       

          "totalRows": 13,

          "results": [

              { "Uri": "swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=4" },

              { "Uri": "swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=6" },

              { "Uri": "swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=7" }

          ]

      }

      Query with Parameters

      Request

      POST https://localhost:17778/SolarWinds/InformationService/v3/Json/Query HTTP/1.1
      Authorization: Basic YWRtaW46
      User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
      Host: localhost:17778
      Accept: */*
      Content-Type: application/json
      Content-Length: 130
      {"query":"SELECT Uri FROM Orion.Pollers WHERE PollerID=@p ORDER BY PollerID WITH ROWS 1 TO 3 WITH TOTALROWS","parameters":{"p":9}}

       

      Response

      HTTP/1.1 200 OK
      Content-Length: 99
      Content-Type: application/json
      Server: Microsoft-HTTPAPI/2.0
      Date: Tue, 07 Aug 2012 17:36:27 GMT
      {"totalRows":1,"results":[{"Uri":"swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=9"}]}

      Invoke

      Request

      POST https://localhost:17778/SolarWinds/InformationService/v3/Json/Invoke/Metadata.Entity/GetAliases HTTP/1.1
      Authorization: Basic YWRtaW46
      User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
      Host: localhost:17778
      Accept: */*
      Content-Type: application/json
      Content-Length: 39
      ["SELECT B.Caption FROM Orion.Nodes B"]

      Response

      HTTP/1.1 200 OK
      Content-Length: 19
      Content-Type: application/json
      Server: Microsoft-HTTPAPI/2.0
      Date: Fri, 27 Jul 2012 19:23:27 GMT
      {"B":"Orion.Nodes"}

      The Metadata.GetAliases verb takes one string argument and returns a PropertyBag.

      Create

      Request

      POST https://localhost:17778/SolarWinds/InformationService/v3/Json/Create/Orion.Pollers HTTP/1.1
      Authorization: Basic YWRtaW46
      User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
      Host: localhost:17778
      Accept: */*
      Content-Type: application/json
      Content-Length: 92
      {"PollerType":"hi from curl 2", "NetObject":"N:123", "NetObjectType":"N", "NetObjectID":123}

      Response

      HTTP/1.1 200 OK
      Content-Length: 69
      Content-Type: application/json; charset=utf-8
      Server: Microsoft-HTTPAPI/2.0
      Date: Fri, 27 Jul 2012 19:27:11 GMT
      "swis:\/\/tdanner-dev.swdev.local\/Orion\/Orion.Pollers\/PollerID=19"

      Read

      Request

      GET https://localhost:17778/SolarWinds/InformationService/v3/Json/swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=6 HTTP/1.1
      Authorization: Basic YWRtaW46
      User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
      Host: localhost:17778
      Accept: */*

      Response

      HTTP/1.1 200 OK
      Content-Length: 245
      Content-Type: application/json
      Server: Microsoft-HTTPAPI/2.0
      Date: Fri, 27 Jul 2012 19:30:02 GMT
      {"PollerID":6,"PollerType":"V.Details.SNMP.Generic","NetObject":"V:1","NetObjectType":"V","NetObjectID":1,"DisplayName":null,"Description":null,"InstanceType":"Orion.Pollers","Uri":"swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=6"}

      Update

      Request

      POST https://localhost:17778/SolarWinds/InformationService/v3/Json/swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=6 HTTP/1.1
      Authorization: Basic YWRtaW46
      User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
      Host: localhost:17778
      Accept: */*
      Content-Type: application/json
      Content-Length: 29
      {"PollerType":"hi from curl"}

      Response

      HTTP/1.1 200 OK
      Content-Length: 0
      Server: Microsoft-HTTPAPI/2.0
      Date: Fri, 27 Jul 2012 19:32:06 GMT

      Delete

      Request

      DELETE https://localhost:17778/SolarWinds/InformationService/v3/Json/swis://tdanner-dev.swdev.local/Orion/Orion.Pollers/PollerID=16 HTTP/1.1
      Authorization: Basic YWRtaW46
      User-Agent: curl/7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
      Host: localhost:17778
      Accept: */*

      Response

      HTTP/1.1 200 OK
      Content-Length: 0
      Server: Microsoft-HTTPAPI/2.0
      Date: Fri, 27 Jul 2012 19:37:33 GMT
        • Re: SWIS REST/JSON API
          rhether

          Does anyone have an example of how to get this into a C# application ?

            • Re: Re: SWIS REST/JSON API
              tdanner

              Here's a quick and dirty C# client that does queries. Hopefully that will be enough to get you started.

                • Re: Re: SWIS REST/JSON API
                  rhether

                  My select query is working:

                  JObject results = client.Query("SELECT NodeID, Comments FROM Orion.NodesCustomProperties WHERE NodeID = 469",new JObject {{"vendor", "Cisco"}});

                   

                  However I can't get an update query to work to do the actual change.

                  JObject results = client.Query("UPDATE Orion.NodesCustomProperties SET Comments= 'It Worked' WHERE NodeID = 469", new JObject { { "vendor", "Cisco" } });

                  Error: (400) Bad Request

                  I am using Json.NET 4.5.0.0

                   

                  Thanks,

                  Richard

                    • Re: SWIS REST/JSON API
                      kevincrouch4

                      In words, what are you trying to do, "Select NodeID and comments from Orion.NodesCustomerProperties, but only where NodeId is 469 " and then what?

                      • Re: SWIS REST/JSON API
                        tdanner

                        Looks like I missed this question in December. Sorry about that, Richard! And thanks Kevin for reviving it.

                         

                        The SWIS query interface is strictly readonly. You can't update this way.

                         

                        However, you can set custom property values through an update call. Make a POST request to https://servername:17778/SolarWinds/InformationService/v3/Json/swis://servername/Orion/Orion.Nodes/NodeID=469/CustomProperties with a body containing:

                         

                        { "Comments": "It worked" }

                          • Re: SWIS REST/JSON API
                            scottfraley

                            Hey Tim,

                             

                            What if I want to set two or more custom properties at a time?  I currently have /{"NetDeviceID":"65348180-53b7-4c13-9ce8-68a54e2556d7","OrionInstance":"WEST"}/ but apparently the resulting string is a Node Uri as if I'd just done a Create rather than a CustomProperties call.

                             

                            Thoughts?

                             

                             

                            Thanks,

                            Scott

                              • Re: SWIS REST/JSON API
                                tdanner

                                Setting multiple properties in one call should work fine. Could you post more details about what request you are sending, especially the URL?

                                  • Re: SWIS REST/JSON API
                                    scottfraley

                                    Okay, I realized multiple at a time is ok cuz I saw a post where I'm doing that and it works.

                                     

                                    The problem is that I did a 'create a node' call with the following Uri / body data;

                                    https://OurServer:17778/SolarWinds/InformationService/v3/Json/Create/Orion.Nodes

                                     

                                    (changed a couple of fields to protect the innocent.)
                                    {"EntityType":"Orion.Nodes", "IPAddress":"<ip addr>", "IPAddressGUID":"nnnnnnnn-0000-0000-0000-000000000000", "Caption":"DEVICE NAME", "DynamicIP": false, "EngineID": 1, "Status": 1, "UnManaged": false, "Allow64BitCounters": false, "SysObjectID": "", "MachineType": "", "VendorIcon": "", "ObjectSubType": "SNMP", "SNMPVersion": 2, "Community":"public"}

                                     

                                    And at this point, it looks like So Far, So Good;
                                    (From my debug log:)
                                    Create an Orion.Node POST returned: swis://BN1MINSWONWB501.mgmt.live/Orion/Orion.Nodes/NodeID=996

                                     

                                    Then, I want to populate a couple of the Custom Properties fields of the newly created node. So, I create the following Uri and body data; (Going to show you what my log contains so that you can see that I got what looks like another Create Node return value in the form of a Node Uri.) The |'s are just my delimiters and were not passed to Orion.

                                     

                                    29-Oct-2014 18:40:12.8028 DEBUG SetNewNodeCustomProperties(): The URI is: |https://lsdorionwest:17778/SolarWinds/InformationService/v3/Json/swis://OurOrionSvr/Orion/Orion.Nodes/NodeID=996/CustomProperties|
                                    29-Oct-2014 18:40:12.8048 DEBUG SetNewNodeCustomProperties(): Payload: |{"NetDeviceID":"65348180-53b7-4c13-9ce8-68a54e2556d7","OrionInstance":"WEST"}|
                                    29-Oct-2014 18:40:13.9888 DEBUG SetNewNodeCustomProperties(): response content: |swis://BN1MINSWONWB501.mgmt.live/Orion/Orion.Nodes/NodeID=997|

                                     

                                    It looks like I created another node which was given the NodeID of 997, despite having put 996 into the Uri for doing the custom properties update.

                                     

                                    Now, this all happens is pretty quick succession. Do I need to set up some kind of a delay or something?


                                    Thanks again,
                                    Scott Fraley

                                      • Re: SWIS REST/JSON API
                                        tdanner

                                        Well, that is bizarre. Indeed, the response you are getting indicates that it has in fact created a new node. All I can think to suggest is that your code is doing something quite different from what the logging indicates. Could that be the case?

                                          • Re: SWIS REST/JSON API
                                            scottfraley

                                            Well color me several shades of blush. The logs were correct, but were not showing the fact that I was indeed using the Create Uri in both places.  D'OH!

                                             

                                            Thanks for your help,

                                            Scott

                                              • Re: SWIS REST/JSON API
                                                tdanner

                                                I'm glad this is back on track!

                                                  • Re: SWIS REST/JSON API
                                                    kvesterling

                                                    I'm seriously perplexed...  I've generated the URL properly to update the custom properties.

                                                    Using the API I have create the Node, but when I go to update the custom properties the result indicates "200 OK", as if the update had been performed, yet when I go to the SolarWinds site to examine, none of the changes have taken place...

                                                     

                                                    I'm using perl and REST::Client...

                                                     

                                                    Here's the dump for the response I get back from the REST::Client->POST()

                                                    As I understand it, that should have worked...  No error was returned...  What gives?

                                                     

                                                    $VAR1 = bless( {

                                                                     '_config' => {

                                                                                    'useragent' => bless( {

                                                                                                            'max_redirect' => 7,

                                                                                                            'ssl_opts' => {

                                                                                                                            'verify_hostname' => 0

                                                                                                                          },

                                                                                                            'protocols_forbidden' => undef,

                                                                                                            'show_progress' => undef,

                                                                                                            'handlers' => {

                                                                                                                            'response_header' => bless( [

                                                                                                                                                          {

                                                                                                                                                            'owner' => 'LWP::UserAgent::parse_head',

                                                                                                                                                            'callback' => sub { "DUMMY" },

                                                                                                                                                            'm_media_type' => 'html',

                                                                                                                                                            'line' => '/Users/kvesterling/perl5/lib/perl5/site_perl/LWP/UserAgent.pm:684'

                                                                                                                                                          }

                                                                                                                                                        ], 'HTTP::Config' )

                                                                                                                          },

                                                                                                            'no_proxy' => [],

                                                                                                            'protocols_allowed' => undef,

                                                                                                            'local_address' => undef,

                                                                                                            'use_eval' => 1,

                                                                                                            'requests_redirectable' => [

                                                                                                                                         'GET',

                                                                                                                                         'HEAD'

                                                                                                                                       ],

                                                                                                            'timeout' => 300,

                                                                                                            'def_headers' => bless( {

                                                                                                                                      'user-agent' => 'REST::Client/272'

                                                                                                                                    }, 'HTTP::Headers' ),

                                                                                                            'proxy' => {},

                                                                                                            'max_size' => undef

                                                                                                          }, 'LWP::UserAgent' )

                                                                                  },

                                                                     '_res' => bless( {

                                                                                        '_protocol' => 'HTTP/1.1',

                                                                                        '_content' => 'null',

                                                                                        '_rc' => '200',

                                                                                        '_headers' => bless( {

                                                                                                               'client-response-num' => 1,

                                                                                                               'date' => 'Mon, 09 Mar 2015 17:11:45 GMT',

                                                                                                               'client-ssl-cert-issuer' => '/CN=SolarWinds-Orion',

                                                                                                               'client-ssl-cipher' => 'AES256-SHA',

                                                                                                               'client-peer' => '172.20.194.23:17778',

                                                                                                               'content-length' => '4',

                                                                                                               '::std_case' => {

                                                                                                                                 'client-response-num' => 'Client-Response-Num',

                                                                                                                                 'client-ssl-cert-issuer' => 'Client-SSL-Cert-Issuer',

                                                                                                                                 'client-ssl-cipher' => 'Client-SSL-Cipher',

                                                                                                                                 'client-peer' => 'Client-Peer',

                                                                                                                                 'client-date' => 'Client-Date',

                                                                                                                                 'client-ssl-warning' => 'Client-SSL-Warning',

                                                                                                                                 'client-ssl-cert-subject' => 'Client-SSL-Cert-Subject',

                                                                                                                                 'client-ssl-socket-class' => 'Client-SSL-Socket-Class'

                                                                                                                               },

                                                                                                               'client-date' => 'Mon, 09 Mar 2015 17:11:47 GMT',

                                                                                                               'client-ssl-warning' => 'Peer certificate not verified',

                                                                                                               'content-type' => 'application/json',

                                                                                                               'client-ssl-cert-subject' => '/CN=SolarWinds-Orion',

                                                                                                               'server' => 'Microsoft-HTTPAPI/2.0',

                                                                                                               'client-ssl-socket-class' => 'Net::SSL'

                                                                                                             }, 'HTTP::Headers' ),

                                                                                        '_msg' => 'OK',

                                                                                        '_request' => bless( {

                                                                                                               '_content' => '{"Comments": "Testing"}',

                                                                                                               '_uri' => bless( do{\(my $o = 'https://asbwdnmsswapp01.vlab.corp.tnsi.com:17778/SolarWinds/InformationService/v3/Json/swis://asbwdnmsswapp01.vlab.corp.tnsi.com/Orion/Orion.Nodes/NodeID=11/CustomProperties')}, 'URI::https' ),

                                                                                                               '_headers' => bless( {

                                                                                                                                      'user-agent' => 'REST::Client/272',

                                                                                                                                      'content-type' => 'application/json',

                                                                                                                                      'content-length' => 23,

                                                                                                                                      '::std_case' => {

                                                                                                                                                        'if-ssl-cert-subject' => 'If-SSL-Cert-Subject'

                                                                                                                                                      },

                                                                                                                                      'authorization' => 'Basic YXV0b2JvdG9yaW9uOk1lZUZhSDAwY2g6

                                                    '

                                                                                                                                    }, 'HTTP::Headers' ),

                                                                                                               '_method' => 'POST',

                                                                                                               '_uri_canonical' => $VAR1->{'_res'}{'_request'}{'_uri'}

                                                                                                             }, 'HTTP::Request' )

                                                                                      }, 'HTTP::Response' )

                                                                   }, 'REST::Client' );

                                                      • Re: SWIS REST/JSON API
                                                        tdanner

                                                        I'd like to try to reproduce the problem you are seeing. Could you post the code used to send the request? This dump doesn't seem to include the request body.

                                                          • Re: SWIS REST/JSON API
                                                            kvesterling

                                                                 my $uri = "https://$swhostname:$swport/SolarWinds/InformationService/v3/Json/swis://$swhostname/Orion/Orion.Nodes/NodeID=$NodeID/CustomProperties";

                                                                 my $rest = REST::Client->new();

                                                                 $rest->getUseragent()->proxy(['https']);

                                                                 my $headers = {

                                                                    Authorization => 'Basic ' . MIME::Base64::encode_base64($username . ':' . $password),

                                                                   'Content-Type' => 'application/json'

                                                                 };

                                                                 my $json = JSON->new->allow_nonref->utf8;

                                                                 #my $json_text = $json->encode($NodesCustomProperties);

                                                                 my $json_text = $json->space_after->encode({ 'Comments' => 'Testing' });

                                                                 my $response = $rest->POST($uri, $json_text, $headers);

                                                                 print Dumper $response;

                                                                 my $JSONResults = $json->decode($rest->responseContent);

                                                              • Re: SWIS REST/JSON API
                                                                tdanner

                                                                Oops - the dump actually did show the request body. And it looks fine to me. I tried out this script (with appropriate "use" statements and variable definitions) and it worked for me. I got a 200 response and the changes stuck.

                                                                 

                                                                What version of Orion are you using?

                                                                  • Re: SWIS REST/JSON API
                                                                    Mark Roberts

                                                                    Karl is using v11.5 and SDK 1.10

                                                                      • Re: SWIS REST/JSON API
                                                                        tdanner

                                                                        That should work. The one noteworthy change I had to make to the script was to add a line after REST::Client->new():

                                                                         

                                                                        $rest->getUseragent()->ssl_opts(verify_hostname => 0);

                                                                         

                                                                        But the config posted above already has "verify_hostname => 0" and the response above does not indicate that you had an SSL error, so that's probably not it. Some older versions of perl defaulted to accepting self-signed certs.

                                                                         

                                                                        Next step would be to look at the Audit events in Orion. By default, an audit event is logged when custom property value are changed. http://$yourserver$/Orion/NetPerfMon/OrionMessages.aspx?ShowOrionMessageTypes=audit%3b

                                                                         

                                                                        If that shows that the custom property was changed, but you don't see the results when you look at the node, then something really weird is going on. If that does not show that the custom property was changed, then it's time to look at the SWIS log file for clues: C:\ProgramData\SolarWinds\InformationService\v3.0\Orion.InformationService.log.

                                                                          • Re: SWIS REST/JSON API
                                                                            kvesterling

                                                                            Dobbs and I notice that if you add the node using the API, then you cannot update the custom properties.  However, if you add the node using the Web GUI, then you can add the CustomProperties without an issue...

                                                                             

                                                                            So I suspect we're missing something, OR...  The JSON Rest API is missing either adequate documentation, or may (emphasis on may) be broken in some obscure way...  Dobbs speculated on pollers, and/or suggested that we may be able to monitor the database to see what other tables may have had information added to them in order to determine what we MAY (emphasis on may) be missing.  Reverse engineering the API is not in my scope of work, so any HINTS, or step-by-step instructions on what the order of operations is would be VERY MUCH appreciated.

                                                                              • Re: SWIS REST/JSON API
                                                                                c.gura

                                                                                We use the API to add Nodes, there is more to adding a node than just creating it.  I am assuming you know how to make the other API calls for adding a Poller_type to the Pollers table.

                                                                                 

                                                                                You will need to also configure some default poller_types as well.  Here is a list of defaults that I add to the Pollers table.

                                                                                 

                                                                                N.Status.ICMP.Native

                                                                                N.ResponseTime.ICMP.Native

                                                                                 

                                                                                Once I add the poller_types I then issue PollNow via the API on the Node.

                                                                                 

                                                                                I have also noticed that it is necessary to have these other values populated for the Node.

                                                                                I do an SNMP call to the device to get the SysObjectID.  The Vendor icon is the Enterprise OID number with .gif on it.  You can get the Vendor Name from the Vendors table by looking up the Icon. (ex: 22269.gif => Charles A Gura) 

                                                                                 

                                                                                                       'Caption'=>$system_name,

                                                                                                       'IPAddress'=>$ipaddress,

                                                                                                       'IPAddressGUID' => ip2guid($ipaddress),

                                                                                                       'DynamicIP'=>0,

                                                                                                       'EngineID'=>$swql->engine_id,

                                                                                                       'Status'=>1,

                                                                                                       'Allow64BitCounters'=>1,

                                                                                                       'ObjectSubType'=>$object_type,

                                                                                                       'SNMPVersion'=>2,

                                                                                                       'BufferNoMemThisHour'=>-2,

                                                                                                       'BufferNoMemToday'=>-2,

                                                                                                       'BufferSmMissThisHour'=>-2,

                                                                                                       'BufferSmMissToday'=>-2,

                                                                                                       'BufferMdMissThisHour'=>-2,

                                                                                                       'BufferMdMissToday'=>-2,

                                                                                                       'BufferBgMissThisHour'=>-2,

                                                                                                       'BufferBgMissToday'=>-2,

                                                                                                       'BufferLgMissThisHour'=>-2,

                                                                                                       'BufferLgMissToday'=>-2,

                                                                                                       'BufferHgMissThisHour'=>-2,

                                                                                                       'BufferHgMissToday'=>-2

                                                                                    $properties->{SysObjectID}  = $machine_info->{SysObjectID};

                                                                                    $properties->{MachineType}  = $machine_info->{MachineType};

                                                                                    $properties->{Vendor}  = $machine_info->{Vendor};

                                                                                    $properties->{VendorIcon}  = $machine_info->{VendorIcon};

                                                                                    $properties->{NodeDescription}  = $machine_info->{NodeDescription};

                                                                                    $properties->{RediscoveryInterval}  = 5; # In Minutes: 5...525600(=1 year)

                                                                                    $properties->{PollInterval}  = 60;        # In Seconds: 1...1200

                                                                                    $properties->{StatCollection}  = 2;      # In Minutes: 1...600

                                                                                 

                                                                                Let me know if this helps.

                                                                                • Re: SWIS REST/JSON API
                                                                                  tdanner

                                                                                  We have a bug in NPM 11.5 (and other releases based on the Orion Platform 2015.1 release) that makes custom properties not work for nodes created through the API. Jan Pelousek posted a workaround here: Re: Upgrade from NMP 11.0.1 to 11.5 breaks SDK 1.10 set CustomProperties

                                                                                    • Re: SWIS REST/JSON API
                                                                                      kvesterling

                                                                                      Yeah, trying desperately to get the workaround working, the SWSQL query they cite is "Insert into NodesCustomProperties (NodeID) VALUES ("13")".

                                                                                      The SWSQL studio will not attempt it (sad...  very disappointing...) presenting an error that it's expecting "SELECT", so the only way to test is with the API...  And it takes > 2 mins for the API to come back with a response "200 OK"...   Overall I'm entirely unimpressed....

                                                                                       

                                                                                      When is this bug/feature going to be corrected?  It's really holding up our delivery of the integration.  Because this is what I get back from the JSON/REST API:

                                                                                       

                                                                                      {"Message":"mismatched input 'Insert' expecting 'SELECT'","ExceptionType":"SolarWinds.Data.SWQL.SWQLSyntaxException","FullException":"SolarWinds.Data.SWQL.SWQLSyntaxException: mismatched input 'Insert' expecting 'SELECT' ---> Antlr.Runtime.MismatchedTokenException: A recognition error occurred.\u000d\u000a   at SolarWinds.Data.SWQL.Parser.SWQLParser.MismatchIsUnwantedToken(IIntStream input, Int32 ttype)\u000d\u000a   at Antlr.Runtime.BaseRecognizer.RecoverFromMismatchedToken(IIntStream input, Int32 ttype, BitSet follow)\u000d\u000a   at Antlr.Runtime.BaseRecognizer.Match(IIntStream input, Int32 ttype, BitSet follow)\u000d\u000a   at SolarWinds.Data.SWQL.Parser.SWQLParser.selectClause()\u000d\u000a   --- End of inner exception stack trace ---\u000d\u000a   at SolarWinds.Data.SWQL.Parser.SWQLParser.selectClause()\u000d\u000a   at SolarWinds.Data.SWQL.Parser.SWQLParser.selectFrom()\u000d\u000a   at SolarWinds.Data.SWQL.Parser.SWQLParser.queryRule()\u000d\u000a   at SolarWinds.Data.SWQL.Parser.SWQLParser.selectStatement()\u000d\u000a   at SolarWinds.Data.SWQL.Parser.SWQLParser.statement()\u000d\u000a   at SolarWinds.Data.SWQL.SWQLParser.Parse(String query)\u000d\u000a   at SolarWinds.Data.Query.Engine.QueryProcessor.ProcessInternal(String query, IQueryExecutionContext context)\u000d\u000a   at SolarWinds.InformationService.Core.QueryPlanCache.GetQueryPlan(String query, String username, Func`1 buildQueryPlan)\u000d\u000a   at SolarWinds.InformationService.Core.InformationService.RunQuery(String query, IDictionary`2 parameters, IDataSerializer serializer)"}

                                                                                        • Re: SWIS REST/JSON API
                                                                                          tdanner

                                                                                          The "Query" API in SWIS only accepts SWQL SELECT queries. To do this insert, you need to use an Invoke call. On the json endpoint, that would look like this:

                                                                                           

                                                                                          POST https://servername:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Reporting/ExecuteSQL
                                                                                          
                                                                                          ["Insert into NodesCustomProperties (NodeID) VALUES (13)"]
                                                                                          


                                                                                          I can't promise when the fix will be delivered. If you want to check on it via support, the bug # is CORE-291.

                                                                                          1 of 1 people found this helpful
                                                                                            • Re: SWIS REST/JSON API
                                                                                              kvesterling

                                                                                              I'm a bit new to this API, so I'm a bit fuzzy on this... So I need more insight.

                                                                                               

                                                                                              It's now producing this error:

                                                                                               

                                                                                              {"Message":"Verb Orion.Reporting.ExecuteSQL requires at least 1 parameters not 0","ExceptionType":"SolarWinds.InformationService.Verb.VerbExecutorException","FullException":"SolarWinds.InformationService.Verb.VerbExecutorException: Verb Orion.Reporting.ExecuteSQL requires at least 1 parameters not 0\u000d\u000a   at SolarWinds.InformationService.Verb.VerbExecutorContext.UnpackageParameters(JArray parameters)\u000d\u000a   at SolarWinds.InformationService.Core.InformationService.InvokeInternal[T](String entity, String verb, Action`1 setupParameters, Func`2 extractReturnValue)\u000d\u000a   at SolarWinds.InformationService.Core.InformationService.SolarWinds.InformationService.Core.IRestInformationService.Invoke(String entity, String verb, Object parameters)"}

                                                                                               

                                                                                              I suspect that it's not quite the same as it is for Query operations, and I'm probably not formatting the JSON correctly. 

                                                                                               

                                                                                              This is what I'm posting:

                                                                                               

                                                                                              {"query":"Insert into NodesCustomProperties (NodeID) VALUES (13)"}

                                                                                               

                                                                                              I suspect that the parameter name may not be "query" for this URL, but exactly what it may be is not immediately apparent to me.  I'm missing some details here....

                                                                                               

                                                                                              The URL i'm generating is formatted thusly:

                                                                                              https://asbwdnmsswapp01.vlab.corp.tnsi.com:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Reporting/ExecuteSQL

                                                                                              • Re: SWIS REST/JSON API
                                                                                                kvesterling

                                                                                                Yeah, I see that, just as it was in the other thread...

                                                                                                 

                                                                                                This is the URL I am using:

                                                                                                https://asbwdnmsswapp01.vlab.corp.tnsi.com:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Reporting/ExecuteSQL

                                                                                                 

                                                                                                This is the Insert I am sending:

                                                                                                Insert into NodesCustomProperties (NodeID) VALUES (13)

                                                                                                 

                                                                                                This is the response I get:

                                                                                                "Encountered unexpected character 'i'."

                                                                                                 

                                                                                                I must be missing something...  I just can't figure out what it may be...

                                                                                                • Re: SWIS REST/JSON API
                                                                                                  taylor5042

                                                                                                  Hopefully this helps someone trying to figure out how to do this in PHP.

                                                                                                  Be sure to change the SolarWindsUser, SolarWindsPass, NodeID and solarwindsserver url.

                                                                                                   

                                                                                                  <?php
                                                                                                  $SolarWindsAuth = base64_encode($SolarWindsUser . ':' . $SolarWindsPass);
                                                                                                  
                                                                                                  
                                                                                                  $NodeID = '12418';
                                                                                                  AddHardwareHealthSensors ($SolarWindsAuth,$NodeID);
                                                                                                  
                                                                                                  
                                                                                                  function AddHardwareHealthSensors ($SolarWindsAuth,$NodeID) {
                                                                                                    $curl = curl_init();
                                                                                                  
                                                                                                  
                                                                                                    curl_setopt_array($curl, array(
                                                                                                    CURLOPT_PORT => "17778",
                                                                                                    CURLOPT_URL => "https://solarwindsserver:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Reporting/ExecuteSQL",
                                                                                                    CURLOPT_RETURNTRANSFER => true,
                                                                                                    CURLOPT_ENCODING => "",
                                                                                                    CURLOPT_SSL_VERIFYHOST => 0,
                                                                                                    CURLOPT_SSL_VERIFYPEER => 0,
                                                                                                    CURLOPT_MAXREDIRS => 10,
                                                                                                    CURLOPT_TIMEOUT => 30,
                                                                                                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                                                                                                    CURLOPT_CUSTOMREQUEST => "POST",
                                                                                                    CURLOPT_POSTFIELDS => "[\"INSERT INTO NodeSettings (NodeID, SettingName, SettingValue) VALUES ('$NodeID', 'NeedsInventory', 'HWH')\"]",
                                                                                                    CURLOPT_HTTPHEADER => array(
                                                                                                    "authorization: Basic $SolarWindsAuth",
                                                                                                    "content-type: application/json"
                                                                                                    ),
                                                                                                    ));
                                                                                                  
                                                                                                  
                                                                                                    $response = curl_exec($curl);
                                                                                                    $err = curl_error($curl);
                                                                                                  
                                                                                                  
                                                                                                    curl_close($curl);
                                                                                                  
                                                                                                  
                                                                                                    if ($err) {
                                                                                                    echo "cURL Error #:" . $err;
                                                                                                    } else {
                                                                                                    echo $response;
                                                                                                    }
                                                                                                  
                                                                                                  
                                                                                                  }
                                                                                                  
                                                                                                  
                                                                                                  ?>
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  

                                                                                                   

                                                                                                  A successful response looks like this:

                                                                                                  {
                                                                                                    "results": []
                                                                                                  }
                                                                                                  
                                                                                                  1 of 1 people found this helpful
                                                                                                  • Re: SWIS REST/JSON API
                                                                                                    tdanner

                                                                                                    This was fixed in NPM 11.5.3.

                                                            • Re: SWIS REST/JSON API
                                                              jfoley

                                                              Does anybody have a quick and dirty PHP client, prehaps? I'm just trying to do straight HTTPRequest using a client for Chrome:

                                                               

                                                              I get:

                                                              Response does not contain any data.


                                                              My Request:

                                                               

                                                              User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36

                                                               

                                                               

                                                              Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo

                                                               

                                                               

                                                              Authorization: Basic YWRtaW4=

                                                               

                                                               

                                                              Content-Type: application/x-www-form-urlencoded

                                                               

                                                               

                                                              Accept: */*

                                                               

                                                               

                                                              Accept-Encoding: gzip,deflate,sdch

                                                               

                                                               

                                                              Accept-Language: en-US,en;q=0.8

                                                               

                                                               

                                                              Cookie: ASP.NET_SessionId=xpcllv0adkiikknl3pjalh44; SelectedTab=3; Orion_IsSessionExp=TRUE; __utma=1.895714814.1391008906.1391021778.1392054254.3; __utmb=1.29.10.1392054254; __utmc=1; __utmz=1.1391008906.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); .ASPXAUTH=15EA7F01540DEDED02766145CA7E47C1B6169B986CD2E6B318D5045C0E438D7679FAF5764C0F55B7DA9D249188E6DDEBF89D84866F1580E3846141B72E429D8A2842DB6C602291AE0770744E1E830B4C537EF2BC7BD2F65162CC588FDDCE42CE125591D8E399E04A96F0E849
                                                              Payload: query=SELECT+Caption+FROM+Orion.Nodes+WHERE+NodeID%3D1

                                                               

                                                              • Re: SWIS REST/JSON API
                                                                medzed

                                                                Hello ,

                                                                I'm programming a little application in android to retrieve data from the SOLARWINDS.

                                                                 

                                                                I'm trying to send a POST request to :

                                                                 

                                                                https://192.168.56.101:17778/SolarWinds/InformationService/v3/Json/Query

                                                                 

                                                                With the given headers above and :

                                                                 

                                                                Request : {"query":"SELECT PollerID FROM Orion.Pollers "}

                                                                 

                                                                Error: "The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details."

                                                                 

                                                                And then i tried to send a Get Request like this :

                                                                 

                                                                Request :https://192.168.56.101:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+AlertName+FROM+Orion.Alerts

                                                                 

                                                                Error: {"Message":"Cannot resolve property AlertName"}

                                                                 

                                                                 

                                                                This Request works fine :

                                                                Request : Request :https://192.168.56.101:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+AlertID+FROM+Orion.Alerts

                                                                 

                                                                I

                                                                Really need some help.

                                                                (by the way, i used NetTool - Web & Network Debugging Tool to send the request because of the SSL certificate problem and it didnt worked with the java Code neither)

                                                                • Re: SWIS REST/JSON API
                                                                  kvesterling

                                                                  Question folks;

                                                                   

                                                                  With regard to the delete functionality, if I were to need to delete a node, does the JSON/REST API take care of deletion of other attributes (pollers, etc) if I delete a node?

                                                                   

                                                                  I'm assuming that Node deletion would be:

                                                                  https://<hostname>:<port>/SolarWinds/InformationService/v3/Json/swis://tdanner-dev.swdev.local/Orion/Orion.Nodes/NodeID=<NodeID>

                                                                   

                                                                  Or is it more of a process, whereby you delete the pollers, (perhaps other informaiton), then finally delete the node?

                                                                  • Re: SWIS REST/JSON API
                                                                    kvesterling

                                                                    Invoke Manage/Unmanage?

                                                                     

                                                                    I'm curious...  Because the API has an example for GetAliases:

                                                                    POST https://localhost:17778/SolarWinds/InformationService/v3/Json/Invoke/Metadata.Entity/GetAliases HTTP/1.1

                                                                    With some sort of parameter such as:

                                                                    ["SELECT B.Caption FROM Orion.Nodes B"]

                                                                     

                                                                    But when I look at the SOAP sample.pl in another section I see this:

                                                                    # Example of Invoke operation: Unmanage node 1 for 24 hours, starting now

                                                                    #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime(time);

                                                                    #my $now = sprintf "%4d-%02d-%02dT%02d:%02d:%02dZ\n", $year+1900,$mon+1,$mday,$hour,$min,$sec;

                                                                    #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime(time+86400);

                                                                    #my $later = sprintf "%4d-%02d-%02dT%02d:%02d:%02dZ\n", $year+1900,$mon+1,$mday,$hour,$min,$sec;

                                                                    print $swis->Invoke("Orion.Nodes", "Unmanage", ["N:1", $now, $later, "false"]);


                                                                    I'm confused as to what the URL would be for the JSON/Rest API:

                                                                    Perhaps?

                                                                    https://localhost:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Nodes/Unmanage

                                                                    Do I have that right?

                                                                    • Re: SWIS REST/JSON API
                                                                      johnny ringo

                                                                      I need some help converting these examples into REST calls via PowerShell.  For the above DELETE example, do I need to specify the "/qa-brn-jpel-02.swdev.local/Orion/Orion.Nodes/NodeID=1/Volumes/VolumeID=1" as a object of the body parameter?

                                                                       

                                                                      Here is the code I have so far but it never completes.  I think it is because I am specifying something using -body incorrectly.

                                                                      # Connect to SWIS

                                                                       

                                                                      $hostname = "IPADDRESS"

                                                                       

                                                                      $username = "admin"

                                                                       

                                                                      $SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString

                                                                       

                                                                      $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $Securepassword

                                                                       

                                                                      $swis = Connect-Swis -host $hostname -cred $cred

                                                                       

                                                                      #REST

                                                                       

                                                                      $r= //IPADDRESS/Orion/Orion.Nodes/NodeID=67/Volumes/VolumeID=1

                                                                       

                                                                      Invoke-WebRequest -Uri http://IPADDRESS:17778/SolarWinds/InformationService/v3/Json/swis: -Credential $cred -Method Delete -body $r 

                                                                       

                                                                      Thanks for the help.

                                                                        • Re: SWIS REST/JSON API
                                                                          tdanner

                                                                          If you are working PowerShell, why not use the PowerShell snapin instead of Invoke-WebRequest? If you install the SDK (from http://downloads.solarwinds.com/solarwinds/Release/Orion/OrionSDK-v1.10.zip or (beta) Releases · solarwinds/OrionSDK · GitHub), then you can delete a node with Remove-SwisObject.

                                                                            • Re: SWIS REST/JSON API
                                                                              johnny ringo

                                                                              Thanks, I saw that.  I need to use REST for something else, so I thought I would try out this functionality in the API as well.  But I can use Powershell for this until better examples percolate onto the forums.

                                                                                • Re: SWIS REST/JSON API
                                                                                  tdanner

                                                                                  You can call the REST endpoint from PowerShell, but you need a few changes. The URL is https, not http, and the SWIS URI part should be included in the URL, not the request body. Also, since the certificated used by Orion on port 17778 is self-signed, you will get a certificate error from Invoke-WebRequest. You can avoid that by overriding the certificate validation. Here's one that just trusts everything:

                                                                                   

                                                                                  add-type @"

                                                                                      using System.Net;

                                                                                      using System.Security.Cryptography.X509Certificates;

                                                                                      public class TrustAllCertsPolicy : ICertificatePolicy {

                                                                                          public bool CheckValidationResult(

                                                                                              ServicePoint srvPoint, X509Certificate certificate,

                                                                                              WebRequest request, int certificateProblem) {

                                                                                              return true;

                                                                                          }

                                                                                      }

                                                                                  "@

                                                                                  [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

                                                                                   

                                                                                  Once that is in place, code like this should work:

                                                                                   

                                                                                  $hostname = "IPADDRESS"

                                                                                  $username = "admin"

                                                                                  $SecurePassword = Read-Host -Prompt "Enter password" -AsSecureString

                                                                                  $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $Securepassword

                                                                                  $swisuri = "swis://IPADDRESS/Orion/Orion.Nodes/NodeID=67/Volumes/VolumeID=1"

                                                                                  $url = "https://$($hostname):17778/SolarWinds/InformationService/v3/Json/$swisuri"

                                                                                  Invoke-WebRequest -Uri $url -Credential $cred -Method Delete

                                                                                  1 of 1 people found this helpful
                                                                                    • Re: SWIS REST/JSON API
                                                                                      johnny ringo

                                                                                      Thanks I actually did like you said and looked at the powershell snappin commands and they were pretty easy to use for delete operations.  But thanks anyway for this example!  I will likely use it as well.

                                                                                      • Re: SWIS REST/JSON API
                                                                                        KMSigma

                                                                                        I actually added a PowerShell function (and dot-included in the future).  This isn't the first time that I've run into this self-certificate issue. :-)

                                                                                         

                                                                                         

                                                                                        function Trust-AllCertificates
                                                                                        {
                                                                                            Add-Type @"
                                                                                                using System.Net;
                                                                                                using System.Security.Cryptography.X509Certificates;
                                                                                                public class TrustAllCertsPolicy : ICertificatePolicy {
                                                                                                    public bool CheckValidationResult(
                                                                                                        ServicePoint srvPoint, X509Certificate certificate,
                                                                                                        WebRequest request, int certificateProblem) {
                                                                                                        return true;
                                                                                                    }
                                                                                                }
                                                                                        "@
                                                                                            [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
                                                                                        }


                                                                                        1 of 1 people found this helpful
                                                                                • Re: SWIS REST/JSON API
                                                                                  ccfc1986

                                                                                  I am trying to do an Event read to pull out all the Event data. I am using a Perl script to do this. Using the examples of perl here as my template, i used my own data (SW server, port, user, pass) and generated my URL to be:

                                                                                   

                                                                                  Start Script:

                                                                                  use REST::Client;

                                                                                  use Data::Dumper;

                                                                                  use MIME::Base64;

                                                                                  use JSON;

                                                                                   

                                                                                  my $swhostname = "XX.XX.XX.XX";

                                                                                  my $swport = "17778";

                                                                                  my $username = "username";

                                                                                  my $password = "password";

                                                                                   

                                                                                  my $uri = "https://$swhostname:$swport/SolarWinds/InformationService/v3/Json/Query?query=SELECT EventID, EventTime, NetworkNode, NetObjectID, EventType, Message, Acknowledged,

                                                                                  NetObjectType, TimeStamp, DisplayName, Description, InstanceType, Uri FROM Orion.Events";

                                                                                   

                                                                                  my $rest = REST::Client->new();

                                                                                  $rest->getUseragent()->proxy(['https']);

                                                                                  $rest->getUseragent()->ssl_opts(verify_hostname => 0);

                                                                                  my $headers = {

                                                                                          Authorization => 'Basic ' . MIME::Base64::encode_base64($username . ':' . $password),

                                                                                          'Content-Type' => 'application/json'

                                                                                  };

                                                                                   

                                                                                  my $json = JSON->new->allow_nonref->utf8;

                                                                                  my $json_text = $json->space_after->encode(\@verbArguments);

                                                                                   

                                                                                  my $response = $rest->POST($uri, $json_text, $headers); #, $json_text, $headers);

                                                                                  print Dumper $response;

                                                                                   

                                                                                  END SCRIPT

                                                                                   

                                                                                  The response is that i get an 'Internal Server Error' with an error code of 500. The content is this: '_content' => '"Request must include a query."',

                                                                                   

                                                                                  When i use the URL that is in the URI area:

                                                                                   

                                                                                  '_uri' => bless( do{\(my $o = 'https://XX.XX.XX.XX:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT%20EventID,%20EventTime,%20NetworkNode,%20NetObjectID,%20EventType,%20Message,%20Acknowledged,%20NetObjectType,%20TimeStamp,%20DisplayName,%20Description,%20InstanceType,%20Uri%20FROM%20Orion.Events')}

                                                                                   

                                                                                  Via a web broswer, i get the full JSON response as I would expect. Does anyone have any thoughts on this? Thanks in advance!

                                                                                    • Re: SWIS REST/JSON API
                                                                                      tdanner

                                                                                      There are two ways to run a SWQL query over the REST interface:

                                                                                       

                                                                                      1. Put the query in the Url as a query string parameter called "query" and make a GET request.

                                                                                      2. Put the query in the request body as the "query" property of a json object and make a POST request.

                                                                                       

                                                                                      You are mixing these two - you put the query in the Url, but sent it using a POST request. When you tried it in the browser, that was a GET request, so it worked.

                                                                                       

                                                                                      See REST · solarwinds/OrionSDK Wiki · GitHub for examples.

                                                                                    • Re: SWIS REST/JSON API
                                                                                      sivakumar0

                                                                                      Where do I want to execute these  request query?, I cant get this one can you please Explain me !!

                                                                                      • Re: SWIS REST/JSON API
                                                                                        jimdnorris

                                                                                        In the CREATE example, the response shows that it should be in JSON format; however, it is not.

                                                                                         

                                                                                        RESPONSE

                                                                                        HTTP/1.1 200 OK
                                                                                        Content-Length: 69
                                                                                        Content-Type:
                                                                                        application/json; charset=utf-8
                                                                                        Server: Microsoft-HTTPAPI/2.0
                                                                                        Date: Fri, 27 Jul 2012 19:27:11 GMT
                                                                                        "swis:\/\/tdanner-dev.swdev.local\/Orion\/Orion.Pollers\/PollerID=19"

                                                                                         

                                                                                        We are seeing the same results using NPM 7.5.1 (Core 2016.2.100) as shown below:

                                                                                         

                                                                                        Request:

                                                                                        {

                                                                                        "ObjectSubType" : "SNMP",
                                                                                        "IPAddress" : "10.1.2.3",

                                                                                        "EngineID" : "1",

                                                                                        "SNMPVersion" : "2",

                                                                                        "Caption" : "Router1"

                                                                                        }

                                                                                        Response:

                                                                                        "swis://NPM01/Orion/Orion.Nodes/NodeID=4223"

                                                                                         

                                                                                        Expected response: should be a JSON name/value pair such as:

                                                                                        {

                                                                                        "swis” : “//NPM01/Orion/Orion.Nodes/NodeID=4223"

                                                                                        }