2006-06-01 00:00:00
This script was written at the time I was hired by KPN i-Diensten. It is reproduced/shared here with their permission.
A very simply script that takes a list of processes, instead of a single processes name (as is the case with check_process). This should make monitoring a basic list of processes a lot easier. I really should change the script in such a way that it takes the process list from the command line, instead of from the $LIST variable that's defined internally. I'll do that when I have the time.
Until I've made those change, I use the script by copying check_processes to a new file which is used specifically for one purpose. For example check_linux_processes and check_solaris_processes check a list of processes that should be up and running on Linux and Solaris respectively.
This check script should work on just about any UNIX OS.
#!/bin/bash # # Process monitor plugin for Nagios # Written by Thomas Sluyter (nagiosATkilalaDOTnl) # By request of KPN-IS, i-Provide, the Netherlands # Last Modified: 13-07-2006 # # Usage: ./check_solaris_processes # # Description: # This script couldn't be simpler than it is. It just checks to see # whether a predefined list of processes is up and running. # # Limitations: # This script should work properly on all implementations of Linux, Solaris # and Mac OS X. # # Output: # If there one of the processes is down, a CRIT is issued. # # You may have to change this, depending on where you installed your # Nagios plugins PROGNAME="check_linux_processes" PATH="/usr/bin:/usr/sbin:/bin:/sbin" LIBEXEC="/usr/local/nagios/libexec" . $LIBEXEC/utils.sh ### DEFINING THE PROCESS LIST ### LIST="init" ### REQUISITE NAGIOS COMMAND LINE STUFF ### print_usage() { echo "Usage: $PROGNAME" echo "Usage: $PROGNAME --help" } print_help() { echo "" print_usage echo "" echo "Basic processes list monitor plugin for Nagios" echo "" echo "This plugin not developped by the Nagios Plugin group." echo "Please do not e-mail them for support on this plugin, since" echo "they won't know what you're talking about :P" echo "" echo "For contact info, read the plugin itself..." } while test -n "$1" do case "$1" in --help) print_help; exit $STATE_OK;; -h) print_help; exit $STATE_OK;; *) print_usage; exit $STATE_UNKNOWN;; esac done ### FINALLY THE MAIN ROUTINE ### COUNT="0" DOWN="" for PROCESS in `echo $LIST` do if [ `ps -ef | grep -i $PROCESS | grep -v grep | wc -l` -lt 1 ] then let COUNT=$COUNT+1 DOWN="$DOWN $PROCESS" fi done if [ $COUNT -gt 0 ] then echo "NOK - $COUNT processes not running: $DOWN" exit $STATE_CRITICAL fi # Nothing caused us to exit early, so we're okay. echo "OK - All requisite processes running." exit $STATE_OK
kilala.nl tags: nagios, unix, programming,
View or add comments (curr. 2)
Posted by Harry Nguyen (website)
Hi,
My name is Harry. I just try to use your Nagios's check_processes script to check my environment. Your check_processes script works perfect from command line.
E.g: nagios#sftest$./check_processes
Not OK - 2 processes NOT running: cvs mysql
However, when i apply this script on Nagios configuration, here what i do:
1) Copy check_processes file to /usr/local/nagios/libexec/ path (this is all-plugins located)
2) Add lines in /usr/local/nagios/etc/checkcommands.cfg
define command {
command_name check_processes
command_line /usr/local/nagios/libexec/check_processes
}
3) Add lines in /usr/local/nagios/etc/services.cfg
define service {
use generic-service
host_name dbinhouse
service_description Check processes
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
contact_groups sveng-admin
notification_interval 60
notification_period 24x7
notification_options c,r
check_command check_processes
}
Here is what i see from Nagios Web interface:
1) Check processes CRITICAL 03-06-2008 14:35:53 3d 2h 48m 37s 3/3 -------------------------------------------
All dot-dot shows at "status information" column.
2) There is nothing listed like when do it from command line (e.g: Not OK - 2 processes NOT running: cvs mysql)
Can you help? Anything i miss?
Thanks,
Harry-
Posted by Aslak
The script has to be run remote by ssh or nrpe
create ssh tunnel between remoteserver and nagiosserver
and in /usr/local/nagios/etc/services.cfg
define command {
command_name check_processes
command_line /usr/local/nagios/libexec/check_by_ssh -H $HOSTADDRESS$ -t 15 "/path/on/remoteserver/where/you/put/check_processes"
}
Hope this might help others
- Sharing is careing!
/Aslak
All content, with exception of "borrowed" blogpost images, or unless otherwise indicated, is copyright of Tess Sluijter. The character Kilala the cat-demon is copyright of Rumiko Takahashi and used here without permission.
You are free to use this specific work, to share and distribute it and to adapt it for your own purposes. However, you must attribute this work as mine and you must share all of your alterations. Click on the logo, or follow this link for full details.