#!/bin/bash # # Usage: .//check_system_procs # # Description: # This plugin determines whether the server # is running properly. It will check the following: # * Are all required processes running? # * Are all the required TCP/IP ports open? # # Created: 27.01.2006 (FBA) # # Changes: 28.01.2006 added yellow check (FBA) # 29.01.2006 change "px -ef" to "ps -ax" (FBA). Problems with long arguments # 31.01.2006 added all OK Status with all procs and ports (FBA) # 15.07.2006 change "ps -ax" to "ps ax" (FBA). Also problems with long arguments under RedHat 3/4 # # ################################################################################## # You may have to change this, depending on where you installed your # Nagios plugins # # Processes to check PROCLIST_RED="master sshd syslogd crond klogd httpd postgres mysqld imapd pop3d vsftpd" PROCLIST_YELLOW="hpasm cmathreshd" # Ports to check PORTLIST="25" PATH="/usr/bin:/usr/sbin:/bin:/sbin" LIBEXEC="/usr/local/nagios/libexec" . $LIBEXEC/utils.sh ################################################################################ print_usage() { echo "Usage: $PROGNAME" echo "Usage: $PROGNAME --help" } print_help() { echo "" print_usage echo "" echo "System process and port 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 check_processes_red() { PROCESS="0" ERROR_PROCS="" for PROC in `echo $PROCLIST_RED`; do if [ `ps ax | grep $PROC | grep -v grep | wc -l` -lt 1 ]; then PROCESS=1 ERROR_PROCS="$ERROR_PROCS""$PROC "; fi done if [ $PROCESS -eq 1 ]; then echo "SYSTEM CRITICAL - One or more processes ($ERROR_PROCS) not running" exitstatus=$STATE_CRITICAL exit $exitstatus fi } check_processes_yellow() { PROCESS="0" WARNING_PROCS="" for PROC in `echo $PROCLIST_YELLOW`; do if [ `ps ax | grep $PROC | grep -v grep | wc -l` -lt 1 ]; then PROCESS=1 WARNING_PROCS="$ERROR_PROCS""$PROC "; fi done if [ $PROCESS -eq 1 ]; then echo "SYSTEM WARNING - One or more processes ($WARNING_PROCS) not running" exitstatus=$STATE_WARNING exit $exitstatus fi } check_ports() { PORTS="0" ERROR_PORTS="" for NUM in `echo $PORTLIST`; do if [ `netstat -an | grep LISTEN | grep $NUM | grep -v grep | wc -l` -lt 1 ]; then PORTS=1; ERROR_PORTS="$ERROR_PORTS""$NUM "; fi done if [ $PORTS -eq 1 ]; then echo "SYSTEM: CRITICAL - One or more TCP/IP ports ($ERROR_PORTS) not listening." exitstatus=$STATE_CRITICAL exit $exitstatus fi } check_processes_red check_processes_yellow check_ports echo "SYSTEM: OK - All monitoring processes are running. Process: $PROCLIST_RED $PROCLIST_YELLOW. Ports: $PORTLIST" exitstatus=$STATE_OK exit $exitstatus