WUG.ninja

Search

How do I monitor all of my Windows services?

The problem

Out of the box, WhatsUp® Gold does not monitor any Windows services. There is a built-in active monitor type called “Service Monitor” which allows you to create monitors for each individual service that is critical to you. But, what if you want to monitor every service on every system without manually creating monitors for each unique service name?

The solution

I worked this script up in a hurry one day, finding that it’s not always effective as there are many services set to run automatically on my system which are stopped purposely after they do their thing following a reboot of the system. However, I accommodated for this by adding an ignore section.

###Configuration
#Put a comma separated list of the ones to ignore. 
#Example: "Service DisplayName 1","Service DisplayName 2"
$ServicesToIgnore = "Avira Mail Protection","Google Update Service (gupdate)","Software Protection","Backblaze Service","Microsoft .NET Framework NGEN v4.0.30319_X86","Microsoft .NET Framework NGEN v4.0.30319_X64"
###End Configuration

#Default to up
$bDown = 0
#Get device information
$ip = $Context.GetProperty("Address");
$DnsEntry = [System.Net.DNS]::GetHostByAddress($ip)
$DnsName = [string]$DnsEntry.HostName;
# Get the Windows credentials
$WinUser = $Context.GetProperty("CredWindows:DomainAndUserid");
$WinPass = $Context.GetProperty("CredWindows:Password");
$pwd = ConvertTo-SecureString $WinPass -asplaintext -force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $WinUser,$pwd
$Query = ""
$Query = "select * from win32_service where StartMode like '%Auto%' and State != 'Running'"
ForEach($Service in $ServicesToIgnore){
$Query = $Query + " and DisplayName != '$Service'"
}
#Get all services that are set to 'Auto' and are not in 'Running' state
$Services = (gwmi -ComputerName $DnsName -Credential $cred -Query $Query).DisplayName
If($Services.Length -gt 0){
$bDown = 1
ForEach($service in $Services){
$sMsg += "`r `n$service"
}
}
$Context.SetResult($bDown, $sMsg)


Share This Post

More To Explore

WhatsUp Gold

WhatsUp Gold Tip #3: Monitor your systems

Focus on what is important It’s nice to have detailed monitoring information for every system on your network, but if a non-critical system is unavailable

Blog Posts

WhatsUp Gold Tip #2: Discover your systems

Introduction When you finish adding your credentials to WhatsUp Gold, the next step to success is configuring the discovery process in WhatsUp Gold to work for you.

credentials
Blog Posts

WhatsUp Gold Tip #1: Add your credentials first

Introduction Following installation, the first step to success is adding credentials for your infrastructure. WhatsUp Gold Network Monitoring and Log Management is an agentless solution