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.
#!/bin/bash
# Passive User Check
CFG=”/etc/nagios/send_nsca.cfg”
USERS=`/usr/lib/nagios/plugins/check_users -w 3 -c 5`
CMD=”nagpass;Users;0;$USERS”
/bin/echo $CMD | /usr/sbin/send_nsca -H 192.168.5.50 -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 192.168.5.50”. 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 users.sh and chmod 755 users.sh 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.
sh users.sh
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
}