First, I'll share the script. Then, I'll explain why we need it and how it helps us in our environment.
To use the script you must have the Orion SDK installed on the monitored node.
Take the text below, paste in Powershell ISE and save it as a PS1.
------------------------------------ Start PS1 -----------------------------------------------------------------
# 2014-07-21 Node Unmanage script for SolarWinds SDK Powershell
# by Joe Dissmeyer | Thwack - @JoeDissmeyer | Twitter - @JoeDissmeyer | www.joedissmeyer.com
# This script will unmanage a single node in the Orion database. First, it finds the node number in the Orion database, then it will unmanage it for 99 years.
# This script assumes you are running it LOCALLY from an already managed node AND that the machine has the Orion SDK v1.9 installed on it.
# If the machine is not already managed in SolarWinds this script will fail without warning.
# Replace ORIONSERVERNAME with the appropriate values.
# ORIONSERVERNAME = Your Orion poller instance. (Ex. 'SOLARWINDS01.DOMAIN.LOCAL'). Single quotes are important.
# Load the SolarWinds Powershell snapin. Needed in order to execute the script. Requires the Orion SDK 1.9 installed on the machine this script is running from.
Add-PSSnapin SwisSnapin
# SolarWinds user name and password section. Create an Orion local account that only has node management rights. Enter the user name and password here.
$username = "SWnodemanagement"
$password = "MyP@44w0$d"
# This section allows the password to be embedded in this script. Without it the script will not work.
$secstr = New-Object -TypeName System.Security.SecureString
$password .ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$secstr
# The actual job
$ORIONSERVERNAME = 'SWServer1.domain.local'
$nodename = $env:COMPUTERNAME
$swis = Connect-Swis -Credential $cred -host $orionservername
$nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"
$now =[DateTime ]:: Now
$later =$now.AddYears(99)
Invoke-SwisVerb $swis Orion.Nodes Unmanage @("N: $nodeid ", $now ,$later , "false")
------------------------------------ End PS1 -----------------------------------------------------------------
And now the Remanage script. Again, save as a .PS1 file.
------------------------------------ Start PS1 -----------------------------------------------------------------
# 2014-07-21 Node Remanage script for SolarWinds SDK Powershell
# by Joe Dissmeyer | Thwack - @JoeDissmeyer | Twitter - @JoeDissmeyer | www.joedissmeyer.com
# This script will remanage a single node in the Orion database.
# This script assumes you are running it LOCALLY from an already managed node AND that the machine has the Orion SDK v1.9 installed on it.
# If the machine is not already managed in SolarWinds this script will fail without warning.
# Replace ORIONSERVERNAME with the appropriate values.
# ORIONSERVERNAME = Your Orion poller instance. (Ex. 'SOLARWINDS01.DOMAIN.LOCAL'). Single quotes are important.
# Load the SolarWinds Powershell snapin. Needed in order to execute the script. Requires the Orion SDK 1.9 installed on the machine this script is running from.
Add-PSSnapin SwisSnapin
# SolarWinds user name and password section. Create an Orion local account that only has node management rights. Enter the user name and password here.
$username = "SWnodemanagement"
$password = "MyP@44w0%d"
# This section allows the password to be embedded in this script. Without it the script will not work.
$secstr = New-Object -TypeName System.Security.SecureString
$password .ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$secstr
# The actual job
$ORIONSERVERNAME = 'SWServer1.domain.local'
$nodename = $env:COMPUTERNAME
$swis = Connect-Swis -Credential $cred -host $orionservername
$nodeid = Get-SwisData $swis "SELECT NodeID FROM Orion.Nodes WHERE SysName LIKE '$nodename%'"
$now =[DateTime ]:: Now
$later =$now.AddYears(99)
Invoke-SwisVerb $swis Orion.Nodes Remanage @("N: $nodeid ", $now ,$later , "false")
------------------------------------ End PS1 -----------------------------------------------------------------
Explanation:
My company had a very unique need to monitor our enterprise Windows application that runs not only on standard desktop PCs, but also runs on mobile tablets connected to WiFi access points. These tablets run the standard Windows 7 Professional OS so it makes it easy to set up application monitoring in SolarWinds SAM for these machines. However, the problem comes at the end of the day when these tablets are turned off and placed in their charging docks for the night. As you can imagine, this creates an administrative nightmare (not to mention an email alert flood) in SolarWinds when this happens.
SolarWinds Orion NPM and SAM is designed to always keep an eye on a node or application that is entered in it's database. It is not designed to monitor an application or node only "part of the time" --- well, at least it isn't designed for this purpose out of the box. So instead, we have to create a workaround that will suit our needs. What we needed to do was figure out how to automatically "unmanage" these Windows tablet PCs in SolarWinds when they are shut down for the night, but also automatically "re-manage" them once they boot up. This is where the script comes into play.
The idea is to take the Unmanage script and apply it as a shut down script in Group Policy, then take the Remanage script and apply it as a boot up script in Group Policy.
Here is why this works for us:
The business is supposed to gracefully shut down the tablet by clicking Start > Shut down. If not, then an email alert triggers that informs us that the application is down on the machine.
If the tablet goes offline in the middle of the day for any reason, we will receive an email alert about that node.
When the machine is shut down properly, the node is automatically unmanaged in SolarWinds.
When the machine boots up and someone logs into the machine, the node is automatically remanaged in SolarWinds.
But here is an even better use for these scripts --- Scheduled Server Maintenance! How many times have we, server administrators, had to patch Windows Servers during scheduled maintenance hours? Normally you would have to go into SolarWinds and unmanage the node first BEFORE rebooting as not to trigger an email alert. Well with these scripts you wouldn't have to worry about that as much since this would be automatic.
Final notes:
Of course, this is just one way to go about auto-managing nodes in SolarWinds. There are some alternatives to doing this using the Orion SDK and Powershell which is to, instead, use the built-in .NET properties in Powershell 2.0 to access the Orion SQL database directly, find the node ID, and unmanage it in that manner. For those that are interested in how do to this without the Orion SDK, let me know and I'd be happy to elaborate.