We run this PowerShell script from the windows scheduler. It overwrites a small log file every time it runs, so you can tell when it last checked. You set the variable $CPThreshhold to the number of expected CP's, and the variable $WPPRocess to the number of expected WPs.
function Get-UC4Processes
{
Begin{
$ServerName = get-content env:computername
$LogFileName = "Get-UC4Processes.log"
write-host "ServerName: $ServerName"
echo "ServerName: $ServerName" > $LogFileName
$Server = 'our.email.server'
$Subject = $ServerName + " Key Process Alert"
$From = "Alert_" + $ServerName + "@Saif.com"
$CPThreshhold = 2
$WPThreshhold = 5
# Set process variables
$CPProcess = Get-Process | Where ProcessName -Like "UCSrvC*"
$WPPRocess = Get-Process | Where ProcessName -Like "UCSrvW*"
# Capture and display the counts
$CPCount = $CPProcess.count
$WPCount = $WPProcess.count
write-host "CPCount: $CPCount, expected: $CPThreshhold"
write-host "WPCount: $WPCount, expected: $WPThreshhold"
echo "CPCount: $CPCount, expected: $CPThreshhold" >> $LogFileName
echo "WPCount: $WPCount, expected: $WPThreshhold" >> $LogFileName
}
Process{
if($CPCount -lt $CPThreshhold){$Body = "UC4 CP process count of $CPCount is less than $CPThreshhold! (PowerShell script Get-UC4Processes.ps1)";
Send-MailMessage -smtpServer $Server -to $To -from $From -subject $Subject -Body $Body -priority High;
write-host "CPCount alarm email sent!";
echo "CPCount alarm email sent!" >> $LogFileName}else{}
if($WPCount -lt $WPThreshhold){$Body = "UC4 WP process count of $WPCount is less than $WPThreshhold! (PowerShell script Get-UC4Processes.ps1)";
Send-MailMessage -smtpServer $Server -to $To -from $From -subject $Subject -Body $Body -priority High;
write-host "WPCount alarm email sent!";
echo "WPCount alarm email sent!" >> $LogFileName}else{}
echo "****** end of process ******"
echo "****** end of process ******" >> $LogFileName
}
End{
}
}
Get-UC4Processes