57 How to mute alert of multiple systems in Solarwinds for certain time duration?
In the below PowerShell script:-
- Please change the path where this script you are going to save.
- Name the script as “Set-Mulitple_System_Mute_In_Solarwinds.PS1″.
- Create one text file “ComputerList.txt”.
- In this text file, save the computer name (under ComputerList.txt) one per row.
- The output will be displayed on the PowerShell screen.
- When you will run the script it will ask for the minutes to mute the list of computers.
Note:
- Only change the path that is highlighted below in bold with your folder path.
- Don’t add blank/null value or extra spacing while adding the computer names into the text file.
In case of any hurdle, please Contact Us
<###########################################################
#
# Variables
#
###########################################################>
# Since the AD Site Name is stored as the "Location" for WMI and Agent Managed Windows Servers in Orion, we can just do a filter on that.
$Comps = Get-Content "C:\Temp\ComputerList.txt"
# Suppress alerts for how much time?
$MuteMinutes = Read-Host 'Enter the time in minutes for which node/s needs to be muted? (E.g. 10)'
<###########################################################
#
# Orion Stuff!
#
###########################################################>
if ( -not ( Get-Module -Name SwisPowerShell -ErrorAction SilentlyContinue ) )
{
try
{
Import-Module -Name SwisPowerShell -Verbose
}
catch
{
Write-Error -Message "'SwisPowerShell' module is unavailable. Please install it with 'Install-Module -Name 'SwisPowerShell'"
}
}
if ( -not ( $SwisCreds ) )
{
$SwisCreds = Get-Credential -Message "Enter your Orion Credentials:"
}
$SwisHost = "solarwinds"
$SwisConnection = Connect-Swis -Hostname $SwisHost -Credential $SwisCreds
# Query Details:
# 1) Location matches above variable
# 2) Vendor is Windows
# 3) Monitoring Type is Agent or WMI (Haven't tested it for SNMP, but pretty sure it uses the 'sysLocation' field)
$sqlC = '';
foreach($c in $comps) {$sqlC += "'$c',"}
$sqlC= $sqlC.TrimEnd(",")
$Nodes = Get-SwisData -SwisConnection $SwisConnection -Query @"
SELECT Caption, IP_Address, Uri AS [EntityUri]
FROM Orion.Nodes
WHERE SysName in ($sqlC)
AND Vendor = 'Windows'
AND ObjectSubType IN ( 'Agent', 'WMI' )
ORDER BY Caption
"@
ForEach ( $Node in $Nodes )
{
# Let's cycle through each and see if it's already set to be muted
$IsMuted = Get-SwisData -SwisConnection $SwisConnection -Query @"
SELECT EntityUri, SuppressFrom, SuppressUntil
FROM Orion.AlertSuppression
WHERE EntityUri = '$( $Node.EntityUri )'
"@
if ( $IsMuted )
{
Write-Host "$( $Node.Caption ) ($( $Node.IP_Address )) is in muted state!" -ForegroundColor Yellow
}
else
{
Write-Host "$( $Node.Caption ) ($( $Node.IP_Address )) is NOT muted!" -ForegroundColor Green
try
{
Write-Host "`Muting $( $Node.Caption ), rerun to check status" -ForegroundColor Green
$Results = Invoke-SwisVerb -SwisConnection $SwisConnection -EntityName Orion.AlertSuppression -Verb SuppressAlerts -Arguments @( @( $Node.EntityUri ), ( Get-Date ).ToUniversalTime(), ( ( Get-Date ).AddMinutes($MuteMinutes) ).ToUniversalTime() )
}
catch
{
Write-Host "Something went wrong" -ForegroundColor Red
}
}
}