1 Reply Latest reply on Aug 5, 2016 3:47 PM by tdanner

    Deleting Nodes (Can't get it to work with Perl LWP or Curl)

    jdcabinetmaker

      Hello All,

      I'm working on a project that requires us to change the IP address of every server in our infrastructure. There are a number of operations that happen on different servers as part of this process. I'm using Perl for the controlling process, and it executes all these different operations on different servers. Some REST, some curl, a kerberos init, some SSH remote commands and so on. It talks to Windows and Linux as part of the process. In the case of SolarWinds, I have to perform several operations via REST; look up node ID (working), look up available IP addresses from the pool (working), delete the node (NOT working), and re-add the node when the other operations are completed at the end (untested).

       

      The issue with deleting nodes seems to be related to how the request is being sent.  I get the same results whether I send the request with LWP::Simple or a or plain old command line curl. To reiterate, the SQL queries sent via either LWP, Net::SolarWinds::REST, or Curl all work as expected, only the DELETE does not work.

       

      I can get the delete to work using WizTools RESTClient 3.5 (a freeware REST tool), using the same URL Perl and Curl are using, so I suspect there is some bit of syntax I'm missing.

       

      Here's the Perl source in question (I don't see a way to mark up source, I hope it displays well):

      The get works, the DELETE does not (error at the bottom)

      ################################################################################

      ## NAME: deleteSWNode

      ## PURPOSE: Deletes node from Solar Winds in prep for re-ip

      ## ex: my $rawDeleteOutput = deleteSWNode(drreconfigt1-1.secnet.domain.com);

      ################################################################################

      sub deleteSWNode

      {

        my $subName = "deleteSWNode";

          my ($targetNode) = @_;

          my ($browser, $request, $connString, $deleteString, $response, $req);

       

          ## set up the connection

          my $authString = "https://orion:17778/SolarWinds/InformationService/v3/Json/swis://MOSOLAR01.WINNT.secnet.domain.com/Orion/Orion.Nodes/NodeID=2512";

          $connString = "https://orion:17778/SolarWinds/InformationService/v3/Json/Query?query=SELECT+IPAddress+FROM+IPAM.IPNode+WHERE+IPAddress+LIKE+'172.27.13%'+AND+STATUS+=2";

       

        $browser = LWP::UserAgent->new;

        $browser->ssl_opts(verify_hostname => 0);

        ##$req =  HTTP::Request->new( GET => "$connString");

        $req =  HTTP::Request->new( DELETE => "$authString");

        $req->authorization_basic( "$aduser", "$adauth" );

       

          $response = $browser->request($req);

           if ($response->is_success)

           {

            print $response->decoded_content;

            return('DELETED');

        }

        else

        {

        my $stat1 = $response->decoded_content;

        my $stat2 = $response->status_line;

       

        print Dumper($stat1);

        print "\n\n";

        print Dumper($stat2);

        }

      }

       

       

       

      Delete from the command line with curl (works as expected for sending SQL):

      [jdc@vsfileq2 ~]$ curl -k -i -H "Accept: application/json" --user jdc:'PASSHOLDER' -X DELETE 'https://orion:17778/SolarWinds/InformationService/v3/Json/swis://MOSOLAR01.WINNT.secnet.domain.com/Orion/Orion.Nodes/NodeID=2512'

      HTTP/1.1 400 Bad Request

      Content-Length: 580

      Content-Type: application/json

      Server: Microsoft-HTTPAPI/2.0

      Date: Thu, 28 Jul 2016 21:52:37 GMT

       

       

       

      Both attempts produce the same error:

      {"Message":"No such entity instance.\u000d\u000aParameter name: uri","ExceptionType":"System.ArgumentException","FullException":"System.ArgumentException: No such entity instance.\u000d\u000aParameter name: uri\u000d\u000a   at SolarWinds.InformationService.Core.CrudProcessor.DeleteInternal(Boolean bulkMode, SwisUriResolver uriResolver, IQueryExecutionContext context)\u000d\u000a   at SolarWinds.InformationService.Core.CrudProcessor.Delete(SwisUri uri, IQueryExecutionContext context)\u000d\u000a   at SolarWinds.InformationService.Core.InformationService.Delete(String uri)"}

       

      Any thoughts?