5 Replies Latest reply on Dec 9, 2019 2:04 PM by serena

    Deleting a Node using API and Azure Functions

    atomiczombie

      Here is my Code that got Azure App to work being able to Delete a Node from SWOrion

       

      It's clunky and its ugly but it's mine.

       

      LOL

       

      Hope it helps someone.

       

       

       

      using namespace System.Net

       

      # Input bindings are passed in via param block.

      param($Request, $TriggerMetadata)


      # Interact with query parameters or the body of the request

      # to get the name of the VM to be removed from Solarwinds.

      $nodename = $Request.Query.nodename

      if (-not $nodename) {

         $nodename = $Request.Body.nodename

      }


      #Variable Load

       

         $SubscriptionName="AZURE-Subscription"

         $KeyVaultName="KeyVaultNameSpace"

         $SubscriptionContext = Get-AZContext -ListAvailable | Where-Object { $_.Subscription.Name -eq $SubscriptionName }

         $SecretUsername = (Get-AZKeyVaultSecret -VaultName $KeyVaultName -Name "ServiceAccount-Username" -DefaultProfile $SubscriptionContext).SecretValueText

         $SecretPassword = (Get-AZKeyVaultSecret -VaultName $KeyVaultName -Name "ServiceAccount-Password" -DefaultProfile $SubscriptionContext).SecretValueText

         $SecretPassword =$SecretPassword | ConvertTo-SecureString -AsPlainText -Force

         $cred = New-Object System.Management.Automation.PSCredential ($SecretUsername, $SecretPassword)

         $hostname = "SolarwindsWebURL.Coml"

         $query = "SELECT NodeID FROM Orion.Nodes WHERE NodeName LIKE '${nodename}'"

         $fullquery = "https://${hostname}:17778/SolarWinds/InformationService/v3/Json/Query?query=$query"

         $response = Invoke-RestMethod -Uri $fullquery -Credential $cred -ContentType "application/json" -SkipCertificateCheck

         $NodeID = $response.results.NodeID

         $uri = "https://${hostname}:17778/SolarWinds/InformationService/v3/Json/swis://databasename./Orion/Orion.Nodes/NodeID=$NodeID"



         If($NodeID){

        Invoke-RestMethod -Uri $uri -method Delete -Credential $cred -SkipCertificateCheck

        }


      #Success

      if ($NodeID) {

         $status = [HttpStatusCode]::OK

         $body = "$nodename Has been removed from SAM"

      }

      #Failure

      if (!$NodeID) {

         $status = [HttpStatusCode]::OK

         $body = "$nodename was not found in SAM"

      }


      # Associate values to output bindings by calling 'Push-OutputBinding'.

      Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{

        StatusCode = $status

        Body = $body

      })




        • Re: Deleting a Node using API and Azure Functions
          serena

          Sean this is great stuff! Just checking, is this to handle ephemeral nodes that are no longer active in Azure from Orion ?

            • Re: Deleting a Node using API and Azure Functions
              atomiczombie

              Serena,

               

              Apologies for not getting back to you sooner. 

               

              Our environment is distributed between Nutanix, AWS, Azure, and Vmware(ESX).  We are trying to disassociate all of our procedures from needing a special touch.  So it was decided to take all of our Ansible and Terraform and Puppet and Special one off Scripts and smoosh them all together into a few Azure Functions that can be kicked off by Service Now via a ticket.

               

              The rather unorthodox method of programming that function is simply because it was what I was familiar with.  I am currently working on getting together an Add Node function at this time.  Expect to see a new post from me or a newspaper headline about my admission to a loony bin. 

               

              -Sean

                • Re: Deleting a Node using API and Azure Functions
                  serena

                  atomiczombie  wrote:

                   

                  Serena,

                   

                  Apologies for not getting back to you sooner. 

                   

                  Our environment is distributed between Nutanix, AWS, Azure, and Vmware(ESX).  We are trying to disassociate all of our procedures from needing a special touch.  So it was decided to take all of our Ansible and Terraform and Puppet and Special one off Scripts and smoosh them all together into a few Azure Functions that can be kicked off by Service Now via a ticket.

                   

                  The rather unorthodox method of programming that function is simply because it was what I was familiar with.  I am currently working on getting together an Add Node function at this time.  Expect to see a new post from me or a newspaper headline about my admission to a loony bin. 

                   

                  -Sean

                  Sean,

                  Your environment and the scenario you described is the perfect combination of all the things I am interested to know how we can improve our monitoring for.

                  If you're at a point where you're admitting yourself to the loony bin, would you mind if we scheduled a call with you to get more details and feedback from you?