This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

How to mute node with Powershell

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

Parents Reply Children
  • 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

  • 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

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

  • Correct, that was the first one I tried.

  • 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.

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

    pastedImage_0.png

  • 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.

  • try to change the time variable to:

    $now = [DateTime]::UtcNow

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

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