This post shows a Powershell script I use to monitor the status of my Lync services.
This state can be manually checked on the Lync console (Lync 2010 in my scenario):
And with the Get-CsWindowsService powershell command:
PS C:\> Get-CsWindowsService
Status Name ActivityLevel
------ ---- -------------
Running MASTER
Running REPLICA
Running RTCSRV Incoming Requests per Second=0,Mess...
Running RTCCAA Concurrent Calls=0
Running RTCCAS Concurrent Conferences=0
Running RTCRGS Current Active Calls=0
Running RTCCPS Total Parked Calls=0
Running RTCATS Current Active Calls=0
Running RTCIMMCU Active Conferences=0,Connected User...
Running RTCDATAMCU Active Conferences=0
Running RTCAVMCU Number of Conferences=1,Number of U...
Running RTCASMCU Active Conferences=1,Connected User...
Running RTCMEDSRV Current Outbound Calls=0,Current In...
Running RTCMEETINGMCU Active Conferences=0
Running FTA
The script takes advantage of the Nagios passive checks and the configurations shown on my previous post "Nagios – Using passive checks without agent".
If any of the services is in state different of "Running", Nagios raises a critical alert:
Here is the code (can also be downloaded here):
$SCRIPT_PATH="D:\Scripting\NAGIOS\LyncServiceStatus"
$LYNC_SERVER="MYLYNC"
$NAGIOS_SERVER="MYNAGIOS"
$NAGIOS_PORT="3333"
Get-CsWindowsService | fl status > $SCRIPT_PATH\TEMP.txt
$STATUS = Get-Content $SCRIPT_PATH\TEMP.txt
$DATETIMESTAMP = "[{0:G}]" -f [int][double]::Parse((Get-Date -UFormat %s))
$LASTRESULTFILE = "$SCRIPT_PATH\LASTRESULT.txt"
$RESULT = 0
foreach ($STAT in $STATUS)
{
if ($STAT.Length -gt 0)
{
if (-not $STAT.Endswith("Running"))
{
$RESULT+=1
}
}
}
if ($RESULT -gt 0)
{
$MSGTMP = " PROCESS_SERVICE_CHECK_RESULT;$LYNC_SERVER;ServiceStatus;2;There are $RESULT services NOT running"
}
else
{
$MSGTMP = " PROCESS_SERVICE_CHECK_RESULT;$LYNC_SERVER;ServiceStatus;0;All services are OK"
}
$MSG = $DATETIMESTAMP + $MSGTMP
If (Test-Path $LASTRESULTFILE)
{
$MSGTMP2 = Get-Content $LASTRESULTFILE
if ($MSGTMP.CompareTo($MSGTMP2) -ne 0)
{
$MSG | .\nc.exe $NAGIOS_SERVER $NAGIOS_PORT
$MSGTMP > $LASTRESULTFILE
}
}
else
{
$MSG | .\nc.exe $NAGIOS_SERVER $NAGIOS_PORT
$MSGTMP > $LASTRESULTFILE
}
Note that you have to:
- Configure the parameters (in red at the beginning of the script)
- Configure a Nagios host and service (in this example the name of the service would ServiceStatus) that accepts passive copies
- Configure Nagios to accept passive checks remotely ("Nagios – Using passive checks without agent".)
Schedule it to be executed every some minutes and your Lync services status are monitored.