#================================================================================= # RP.SolarWinds.Node health monitoring script # # Author: Jesper Rune Larsen # v1.0 #================================================================================= param($Username,$Password) # Constants section - modify stuff here: #================================================================================= # Assign script name variable for use in event logging. $ScriptName = "RP.SolarWinds.Node.NodeHealth.Monitor.DataSource.ps1" $EventID = "2002" $ComputerName = [System.Net.Dns]::GetHostByName($env:computername).Hostname #================================================================================= # Starting Script section - All scripts get this #================================================================================= # Gather the start time of the script $StartTime = Get-Date #Set variable to be used in logging events $whoami = whoami # Load MOMScript API $momapi = New-Object -comObject MOM.ScriptAPI # Load PropertyBag function $bag = $momapi.CreatePropertyBag() #Log script event that we are starting task $momapi.LogScriptEvent($ScriptName,$EventID,0,"`n Script is starting. `n Running as ($whoami).") #================================================================================= # Begin MAIN script section #================================================================================= [securestring]$secStringPassword = ConvertTo-SecureString $Password -AsPlainText -Force [pscredential]$credobject = New-Object System.Management.Automation.PSCredential ($Username, $secStringPassword) $SolarWindsRESTAPI = "https://" + $ComputerName + ":17778/SolarWinds/InformationService/v3/Json/Query?query=" # Trust all certificates policy to fix self-signed certificate trust issue add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-object TrustAllCertsPolicy [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extension") # Get Health #$query = "SELECT ast.AlertMessage, p.Caption, p.IPAddress, p.Severity, p.Status, p.StatusDescription, p.DetailsUrl, o.AlertConfigurations.Name AS RuleName FROM Orion.AlertActive AS aa JOIN Orion.AlertObjects AS o ON aa.alertobjectid = o.alertobjectid INNER JOIN Orion.Nodes AS p ON p.nodeid = o.relatednodeid INNER JOIN Orion.AlertStatus AS ast ON ast.alertobjectid = o.alertobjectid LEFT JOIN Orion.alerthistory AS ah ON ah.AlertActiveID = aa.AlertActiveID AND ah.EventType IN (0)" $query = "SELECT Caption, Status, StatusDescription, NodeStatusRootCause, DetailsUrl FROM Orion.Nodes" $Nodes = Invoke-RestMethod -Method GET -uri "$($SolarWindsRESTAPI + $query)" -Credential $credobject for($Count = 0; $Count -lt $nodes.results.count; $Count++) { $bag = $momapi.CreatePropertyBag() $bag.AddValue("Name",$Nodes.results[$Count].Caption) $bag.AddValue("Status",$Nodes.results[$Count].Status) $bag.AddValue("StatusDescription",$Nodes.results[$Count].StatusDescription) $bag.AddValue("DetailsUrl",$Nodes.results[$Count].DetailsUrl) $bag.AddValue("NodeStatusRootCause",$Nodes.results[$Count].NodeStatusRootCause) $bag Clear-Variable $bag $AlertMessage = $Nodes.results[$Count].AlertMessage } # End of script section #================================================================================= #Log an event for script ending and total execution time. $EndTime = Get-Date $ScriptTime = ($EndTime - $StartTime).TotalSeconds $momapi.LogScriptEvent($ScriptName,$EventID,0,"`n Script Completed. `n Script Runtime: ($ScriptTime) seconds.") #================================================================================= # End of script