cancel
Showing results for 
Search instead for 
Did you mean: 

PowerShell script to modify a NODE Custom Property via Rest API/JSON

PowerShell script to modify a NODE Custom Property via Rest API/JSON

I needed this for a side project and i'm placing this script here. It gives a baseline to modify a node's custom property via PowerShell and SWIS without the need to install the SDK. The baseline can be modified/imported into any current POSH script.

The end goal was the change a Node Custom Property called 'SendAlert' to either true(Yes) or false(No). Then use this custom property in the alert engine to "toggle" when nodes are allowed to alert. There are a lot of variables at play so the "Time of Day" scenario didn't quite fit.

You'll need to pass the node ID, ${Node.ID}, into the script.

In the alert trigger condition, in the scope section, i added the custom property.

2016-09-08 09_05_12-Edit Alert - _ SMS_Slack Alert me when a Node has an issue (custom)_.png

Here is another link that goes into more detail around setting up a Custom Property in an alert.

I also have an example of how to change a APPLICATION custom property via Rest API.

PowerShell script to modify an APPLICATION Custom Property via Rest API/JSON

Comments

Hi Chad

Thanks for sharing!

I like your ide.

I like to update NPM with something like  "CP Critical_Trap on/off " and let alert manger look for that on/off changes.

Can I use it to update   Node/Interfaces  CP from  3 party external program when I have only  DNS/Caption  or IP ?

sja​, Yes, you can use this with 3rd party tools. The only change is that you'll need to know the Orion Node ID that you're working with on the 3rd party side.

Hi Chad,

This is awesome!  It is exactly what I was looking for.  I'm wondering, though, how do you make it available for general use?  Can it be accessed directly from the Solar Winds website?

Thanks,

Ann

theroberts​, the script is more of a "skeleton" script designed to make it easy to incorporate into an already existing script. You can't see the script from the Orion Web Console, but you can modify custom properties directly from the web console. For node based custom properties you can edit that node and look in the custom property section.

One of the ways that I've used this is for some of the automation that we were setting up. I had a large web server farm and a handful of backend DB servers. Certain servers would automatically bring themselves out of our load balancer pool, perform some clean-up/optimization tasks and then bring themselves back into the mix Once the server was brought back in we changed the custom property back to 'yes'. This allowed the automation to function without getting alerting during those times.

Help that helps.

Thank you for your quick response.  That does make sense.  I guess I'm just trying to figure out easiest way for my users to actually use it.  Asking them to change the custom properties through the console isn't something they're going to be jazzed about.  I somehow need to make this option more attractive than clicking that darn "unmanage" button!

using the below powershelll query but same is not updating the custom property of node, please suggest where i am doing the mistake.

#Used my baseline here: https://thwack.solarwinds.com/message/300039#300039

#

#Posted this script here: https://thwack.solarwinds.com/docs/DOC-187378

#Modified by Thwack user: Chad.Every Date: 2016/04/21

#

# Since the certificate in Orion for SWIS is self-signed we'll need this to ignore it.

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

$NodeID=7

#Variables

$hostname = "XYZ"

$username = "Test"   - It is not a windows account, it is web console account

$SecurePassword = "Test@123"

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

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

$swisuri = "swis://$($hostname)/Orion/Orion.Nodes/NodeID=$($NodeID)/CustomProperties"

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

# There is a Node Custom Property in Orion called 'SendAlert'

$var="krishna"

$json = @{"A_NOTE"="$var"}

$json = ConvertTo-Json $json

#Other examples

#$json = '{"SendAlert":"Custom text here"}'

#$json = '{"SendAlert": "False"}'

#$json = '{"SendAlert": "True"}'

Can you post some screenshots when running this in powershell?

created the .ps1 file in desktop with above mentioned script.

Right click on .ps1 file and run With powershell.

Script asked for Press "YES"

pastedImage_0.png

And then script is asking to username and password.

pastedImage_1.png

post provide the credential, we are not getting any error, for success and failure.

but when i am checking the node's custom property, update is not available.

thank

K

Version history
Revision #:
1 of 1
Last update:
‎11-02-2015 02:53 PM
Updated by:
 
Contributors