Home Directory Plugins Remote Access Count number of terminal server sessions

Count number of terminal server sessions

Bookmark and Share

Rating
2 votes
Favoured:
0
Current Version
0.4
Last Release Date
2011-05-28
Compatible With
  • Nagios 1.x
  • Nagios 2.x
E-mail
Hits
31103
Files:
FileDescription
check_user_count.batcheck_user_count.bat
Simple bat file to query the number of active sessions on a Windows Terminal Server.

CALLING SEQUENCE:
command[nrpe_nt_check_users]=c:nrpe_ntpluginscheck_user_count.bat

Counts the number of lines returned containing 'rdp-tcp#', which are active sessions. Disconnected sessions are not counted as they are not active.
CALLING SEQUENCE: command[nrpe_nt_check_users]=c:nrpe_ntpluginscheck_user_count.bat

@ECHO OFF
SET /a COUNT=0

FOR /f "TOKENS=1 DELIMS= " %%G IN ('query session ^|find "rdp-tcp#"') DO SET /a COUNT+=1

ECHO Number of active sessions = %COUNT%
EXIT 0
Reviews (2)
byjulienchpt, January 17, 2012
1 of 1 people found this review helpful
You will find below this improving version with Critical and Warning status:

@ECHO OFF
REM -------------------------------------------
REM - Version 0.4 - By briandent@redshift.com
REM - Original Version
REM -------------------------------------------
REM - Version 0.5 - By julienchpt@gmail.com
REM - ADD CRITICAL AND WARNING STATUS
REM -------------------------------------------
REM USAGE: check_user_count warn crit
REM warn: Number of session before warning
REM crit: Number of session before Critical
REM Example: check_user_count 2 4
REM -------------------------------------------
REM CALLING SEQUENCE:
REM command[nrpe_nt_check_users]=c:nrpe_ntpluginscheck_user_count.bat $ARG1$ $ARG2$
REM -------------------------------------------

set EX=0
set MS=OK
SET /a COUNT=0
FOR /f "TOKENS=1 DELIMS= " %%G IN ('query session ^|find "rdp-tcp#"') DO SET /a COUNT+=1

REM - CRITICAL (COUNT => $2)
if %COUNT% GEQ %2 ( set EX=2 && set MS=CRITICAL && goto end )
REM - WARNING (COUNT => $1)
if %COUNT% GEQ %1 ( set EX=1 && set MS=WARNING && goto end )

:end
ECHO %MS% Number of active sessions = %COUNT%
EXIT /b %EX%


Enjoy
byNapsty, January 23, 2012
You can simply add perfdata to the output:

ECHO Number of active sessions = %COUNT%^|usersconnected=%COUNT%