Disable Solarwinds Alerting With PowerShell

A customer is currently using solarwinds to monitor there virtual infastructure, when they do there patching they need to login to the solarwinds console, and manually step though each of the virtual machines/objects they are going to patch and put them into maintenance mode so the on-call guy doesnt get flooded with alerts.

To help matters and save a bit of time i used the below piece of powershell scripting to take away that manual task and only require a text file with a list of the servers to be modified (this is assuming you have the swisPowershell installed:

1
Install-Module -Name SwisPowerShell

swmaintme.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Check if the powershell module that is used is actually loaded and if not load it up
Import-Module SwisPowerShell  
# Hours passed when running script e.g (./swmaintme.ps1 12) will set maintance for 12 hours
$hours=$args[0]
# Where is the server file located (file is a text file with just server names not FQDN)
$serverlist = Get-Content -Path "'path to imput text file'\unmanageme.txt"
# What is the solarwinds server (can only be ran from here as port 17777 is not open remotely :( )  
$strsolarWindServer="Solarwinds Server name Here"  
# Lets connected to the server listed above nice and trusted
$swis = Connect-Swis -Hostname $strsolarWindServer -Trusted
# For each time you look at a line in the text file above do this >>>>>
foreach($server in $serverlist){  
 
    $strQuery = "SELECT uri FROM Orion.Nodes WHERE SysName LIKE '" + "$server" + "%'"  
    $uris = Get-SwisData $swis $strQuery
#   Important line where we actually set the server to unmanaged and status 9 and then set it to maintance from when script was run to the hours we said at start  
    $uris | ForEach-Object { Set-SwisObject $swis $_ @{Status=9;Unmanaged=$true;UnmanageFrom=[DateTime]::UtcNow;UnmanageUntil=[DateTime]::UtcNow.AddHours($hours)}}  
}

Once you maintenance is finished and i the following script will take the same input file and put them back into monitoring mode, unless of course you wish to wait till your maintenance period you specified in the first script ends.

swunmaintme.ps1

1
2
3
4
5
6
7
8
9
10
Import-Module SwisPowerShell  
$serverlist = Get-Content -Path "'path to imput text file'"\unmanageme.txt"
$strsolarWindServer="
Solarwinds Server name Here"  
$swis = Connect-Swis -Hostname $strsolarWindServer -Trusted

foreach($server in $serverlist){  
    $strQuery = "
SELECT uri FROM Orion.Nodes WHERE SysName LIKE '" + "$server" + "%'"  
    $uris = Get-SwisData $swis $strQuery
    $uris | ForEach-Object { Set-SwisObject $swis $_ @{Status=1;Unmanaged=$false}}  
}

1 Comment

  1. Work like a charm;

Leave a Reply

Your email address will not be published. Required fields are marked *