Tuesday, March 8, 2011

Nagios Check - check_users (Windows)

   I wrote a check for Nagios to tell you the number of users logged in to a machine, as well as the last person logged in.

   This check will check both the number of users logged in to a Windows system, as well as the last logged in user. It can return critical if the last logged in user does not match the one defined. It can also return warning/critical if the number of users logged in is not within range. You can also just use it for informational purposes, if warnings/criticals are not defined. It is very useful for servers that must have someone logged in.

   You must copy the check_users.exe file to the NSClient++ script folder. Then you must add the following line to the NRPE Handlers section of your NSC.ini file in the NSClient++ folder:

check_users=scripts\check_users.exe $ARG1$

   The arguments for the check are as follows:

check_users.exe [-l] [-u username] [-n] [-w warning] [-c critical]
-l Displays the last logged in user. You can define a critical return with the -u option, which will check if the defined user was NOT the last logged in user. If username is not defined, status will always be ok.
-n  Displays the number of users currently logged in to the server. You can set warning or critical ranges with -w and -c respectively. You must set both a warning and a critical for the check to return a status other than OK.

Some sample checks would look like:

   This will check to see if there if at least one user logged in and return critical status if no one is logged in:
check_nrpe -H $HOSTADDRESS$ -c check_users -a "-n -w 1 -c 1"

   This will check to see if the user admin on domain mydomain was the last one logged in and return a critical status if someone else was:
check_nrpe -H $HOSTADDRESS$ -c check_users -a "-l -u mydomainadmin"

   This check will be for informational purposes and will just return the last user logged in (status will always be OK):
check_nrpe -H $HOSTADDRESS$ -c check_users -a "-l"

   Tested on Windows Server 2003/2008, and Windows XP.

Download check_users.exe
Source code (written in AutoIT):


  1. Hey I have no idea if you keep up on this blog anymore, but I am having issues using NRPE to run a .bat file containing either a .au3 or .exe of a autoIT script. It runs localy in test mode from windows command line but if I try to run it from my nagios line it throws out a time out error. Any clues? I am able to run a simple batch to create a blank file from nagios but if I try to run this batch containing a .au3 it does nothing but start a blank .au3 process in windows with nothing happening. The .au3 opens firefox, moves the mouse and does a search term.

  2. Download doesn't work :O

  3. The download link does not work, can someone mail to me the file.
    mail: gilbertuliu@gmail.com