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

How to mute node with Powershell

Jump to solution

I have a script working now to unmanage nodes, however cannot get anything to work to mute them.  Please advise if anyone knows.

Import-Module SwisPowerShell

$swis = Connect-Swis -Credential $mycredentials -Hostname ....

$nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE'dbprod1a'"

$now =[DateTime]::Now

$later =$now.AddYears(99)

Invoke-SwisVerb $swis Orion.AlertSuppression SuppressAlerts @("N:$nodeid",[DateTime]::UtcNow) | Out-Null

0 Kudos
1 Solution
Level 14

My brain is bumping into a lack of PowerShell knowledge and it's a little late on a Friday, but after the line where you set $nodeUri using the SELECT query you need this:

$nodeUri = $nodeUri |% {[string]$_}

Once you have that it should clean up the string that you get back and resolve it.

I got that from the initial example I had shared. I did two tests and was able to recreate your problem if I didn't do that transform, but if I follow along with the example where that's included it works.

I think I kind of understand what it's doing if I think about how I would be doing it in Python (where I normally code), but when I tried to compare the variable before and after I couldn't tell a difference, but it works after that's done.

View solution in original post

12 Replies
Level 14

Unless I'm misreading this, it looks like you need the URIs not the nodeIDs:

OrionSDK/AlertSuppression.ps1 at master · solarwinds/OrionSDK · GitHub

Level 8

Could you give me an example of what the syntax should be, (from a VERY beginner level)?

0 Kudos
Level 15
Import-Module SwisPowerShell
$swis = Connect-Swis -Credential $mycredentials -Hostname ....
$nodeUri = Get-SwisData $swis "SELECT Uri FROM Orion.Nodes WHERE SysName LIKE'dbprod1a'"
$now =[DateTime]::Now
$later =$now.AddYears(99)
Invoke-SwisVerb $swis Orion.AlertSuppression SuppressAlerts @( @( $nodeUri ), $now, $later )

this should work for you

edit for typo in the $nodeUri

Level 8

This is what I've been getting:

Invoke-SwisVerb : Verb Orion.AlertSuppression.SuppressAlerts cannot unpackage parameter 0 of type System.String[]

At C:\Scripts\solarwinds_mute.ps1:6 char:1

+ Invoke-SwisVerb $swis Orion.AlertSuppression SuppressAlerts @( @( $ur ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [Invoke-SwisVerb], FaultException`1

    + FullyQualifiedErrorId : SwisError,SwisPowerShell.InvokeSwisVerb

0 Kudos
Level 14

I think there's a small mistake in the last line, instead of @( $uri ) it should be @( $nodeUri ) , correct?

Level 8

Correct, that was the first one I tried.

0 Kudos
Level 14

Then your $nodeUri variable is empty due to your query not returning a result. You can use the SWQL to confirm your query returns the expected result prior to using it in the script or adjust it to something since you're using:

$nodeUri = Get-SwisData $swis "SELECT Uri FROM Orion.Nodes WHERE SysName LIKE'dbprod1a'" 

You could us instead either:

$nodeUri = Get-SwisData $swis "SELECT Uri FROM Orion.Nodes WHERE SysName LIKE '%dbprod1a%'" 

In order to make sure the pattern matches (especially if it's an FQDN).

Or use $nodeUri = Get-SwisData $swis "SELECT Top 1 Uri FROM Orion.Nodes"

If you just want to test with the first node as with the examples.

0 Kudos
Level 8

Something with that last line... just can't get it to work. 

pastedImage_0.png

0 Kudos
Level 8

try to change the time variable to:

$now = [DateTime]::UtcNow

0 Kudos
Level 14

My brain is bumping into a lack of PowerShell knowledge and it's a little late on a Friday, but after the line where you set $nodeUri using the SELECT query you need this:

$nodeUri = $nodeUri |% {[string]$_}

Once you have that it should clean up the string that you get back and resolve it.

I got that from the initial example I had shared. I did two tests and was able to recreate your problem if I didn't do that transform, but if I follow along with the example where that's included it works.

I think I kind of understand what it's doing if I think about how I would be doing it in Python (where I normally code), but when I tried to compare the variable before and after I couldn't tell a difference, but it works after that's done.

View solution in original post

Level 8

Thanks, that seemed to work.  Now I have to figure out why the $swis variable doesn't propagate down through the script blocks. 

Level 15

did you get this part figured out? ($swis propogation)

0 Kudos