cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 7

Deleting a Node using API and Azure Functions

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

})




0 Kudos
5 Replies
Product Manager
Product Manager

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

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

0 Kudos

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?

0 Kudos

Serena,

I can gather my team together and setup a zoom meeting so we can all confer and hopefully help each other out.

Let me know where I can contact you for this.

Thank You

-Sean

0 Kudos

atomiczombie  wrote:

Serena,

I can gather my team together and setup a zoom meeting so we can all confer and hopefully help each other out.

Let me know where I can contact you for this.

Thank You

-Sean

Great Sean! I'll direct message you for scheduling.

0 Kudos