Nagios Training: Passive Checks for Users

by Mike on September 15, 2009

in Nagios

Passive Service Check of Users
Here is a test script on the client.  Note it is using the check_users plugin from Nagios so you will have to be sure they are installed.

Lesson 6 | Lesson 8

# Passive User Check
USERS=`/usr/lib/nagios/plugins/check_users -w 3 -c 5`
/bin/echo $CMD | /usr/sbin/send_nsca -H -d ‘;’ -c $CFG

Join our upcoming Nagios Training Class and start taking lessons from a Nagios instructor.

Regional Nagios Server Setup

CFG is a variable that contains the path to the send_nsca.cfg file.  This file of course must contain the password and encryption type for communicating with  the Nagios server.  Remember, the password on the client must be the same password on the server so they can communicate.  See the Nagios server set up for passive checks if this is unclear.
The USERS variable is the command that will execute a plugin.  Note it uses backtics around the command.  It also contains settings for warning (-w) and critical (-c), adjust that to your needs.
The CMD variable is message that will be send via send_nsca.  It contains the hostname, name_of_service, status and the USERS variable, must have preceding “$”.  The “Users” is the name of the service and it must match the service description on the Nagios server in services.cfg in order to work. Example:

service_description     Users

The CMD variable is piped in to the send_nsca command with the Nagios server indicated by the “-H”.  Change the IP or hostname for your Nagios server.  The delimiter is indicated by the “-d ‘;’” which shows that it is the semi-colon and finally the configuration file is sent using the CFG variable.
Create a directory on your client server for all of the scripts you will end up writing so they are in one place.  Save the script above as and chmod 755 to make it executable.  Then run the script, making sure your send_nsca.cfg file contains the same password and encryption type as on the Nagios server.

define service{
use                     generic-service
host_name               nagpass
service_description     Users
passive_checks_enabled  1
active_checks_enabled   0
flap_detection_enabled  0
check_command           check_null

Previous post:

Next post: