8 Replies Latest reply on Jul 1, 2017 8:10 PM by Manilyn Ramos

    How do I delete a node from SW using the Orion SDK

    michael.allen

      I have a server decom script that I wrote in Powershell that removes everything from a node except for Solarwinds prior to it being removed from the network. It would be super helpful if I could automate the removal of a node as I am stuck doing this part manually, and it is the only manual part of the process.

       

      How would I write this in Powershell? I tried to modify the unmanage script that was posted on the forum, but am not having any luck with it.

       

      Thanks!

        • Re: How do I delete a node from SW using the Orion SDK
          michael.allen

          Nevermind. I figured out the solution myself.

            • Re: How do I delete a node from SW using the Orion SDK
              pjohn07

              Hi Michael,

               

              I am in the same boat.  Can you share the SQL or SWQL you used to bulk delete?

                • Re: How do I delete a node from SW using the Orion SDK
                  tdanner

                  In PowerShell the "Remove-SwisObject" cmdlet can be used to delete a node from Orion. You need to get the node's Uri first. You can use a query like this to do that:

                   

                  SELECT Uri FROM Orion.Nodes WHERE --your criteria here

                    • Re: How do I delete a node from SW using the Orion SDK
                      pjohn07

                      Thanks tdanner,

                       

                      I am coding in Perl using the REST API and figured this out using your documentation REST · solarwinds/OrionSDK Wiki · GitHub

                       

                      However, I am trying to modify some nodes now (removing interfaces without deleting the whole node).  I've also heard about this "Remove-SwisObject" from David Byrd.  Is there any kind of equivalent code I can conjure up in Perl to replicate?

                        • Re: How do I delete a node from SW using the Orion SDK
                          tdanner

                          To delete a bunch of interfaces, first get their Uris using a query, then issue a POST request to /SolarWinds/InformationService/v3/Json/BulkDelete with a body like this:

                           

                          {

                          "uris":[

                          "swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Interfaces/InterfaceID=548",

                          "swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Interfaces/InterfaceID=545",

                          "swis://dev-che-mjag-01./Orion/Orion.Nodes/NodeID=4/Interfaces/InterfaceID=546"]

                          }

                            • Re: How do I delete a node from SW using the Orion SDK
                              Manilyn Ramos

                              So, I tried your URL suggestion  using PERL script.. however,  it didn't work to remove my devices

                                • Re: How do I delete a node from SW using the Orion SDK
                                  tdanner

                                  What response code did you get from the server? Can you share the perl code you used?

                                    • Re: How do I delete a node from SW using the Orion SDK
                                      Manilyn Ramos

                                      Response code: 500

                                      JSON response document: "The body of the message cannot be read because it is empty."

                                       

                                       

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

                                       

                                       

                                      # don't verify SSL certs                                                                                                     

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

                                      $client->getUseragent()->ssl_opts(SSL_verify_mode => 'SSL_VERIFY_NONE');

                                       

                                      # add authentication header

                                      $client->setHost('https://' . $hostname . ':17778');

                                      $client->addHeader('Authorization', 'Basic ' . encode_base64("$username:$password", ''));

                                       

                                      my @itemremove ('1.1.1.1', '2.2.2.2', '3.3.3.3');

                                      foreach my $IP (@itemremove) {

                                      my $query = "SELECT uri FROM Orion.Nodes where IP_Address = '$IP'";

                                      my $response = $client->POST('/SolarWinds/InformationService/v3/Json/BulkDelete' . uri_encode($query));

                                      print 'Response code: ' . $client->responseCode() . "\n";

                                      print 'JSON response document: ' . $client->responseContent() . "\n";

                                      my $results = parse_json $client->responseContent();            #I also tried removing this.. but still to no avail... I also tried removing "my $results" but same error encountered

                                      # remove

                                       

                                       

                                      --> I also tried the delete command then, instead of POST, I used GET and query

                                      my $query = "SELECT uri FROM Orion.Nodes where IP_Address = '$IP'";

                                      my $response = $client->GET('/SolarWinds/InformationService/v3/Json/Query?query=' . uri_encode($query));

                                       

                                      foreach my $node(@{$results->{results}}){

                                      delete ($node->{uri});

                                      }

                                      }

                                       

                                      When I hit ran and the result was successful, I thought that they were removed  but when I checked my SolarWinds db, the records are still there:(

                                      so, any other idea on how to do this on PERL? Or is there any wrong with my PERL script?