#!/bin/bash
|
##################################################################################
|
# NAME: ./check_facts_ldr_procs
|
# PURPOSE: This script is a Nagios Plugin to test FACTS Loader processes
|
# It checks Java if certain Java processes are running or not.
|
# USAGE: ./check_facts_ldr_procs [ -p {proc_list} ] [ -P {pidfile_list} ]
|
# -p {proc_list} = Comma seperated list of Process names to grep for
|
# -P {pidfile_list} = Comma seperated lsit of PID Files. PIDs in files will
|
# be looked for.
|
#
|
# REVISIONS:
|
# Ver Date Author Description
|
# ----- ---------- ---------- ------------------------------------
|
# 2.0 2010-05-07 JD Loots 1. Modified the script for MTN FACTS purposes.
|
# Removed PORT checks.
|
# 2.1 2010-06-02 JD Loots 2. There was a bug in checking PIDs in Linux.
|
# Bug was fixed by introducing a PS variable.
|
# 2.2 2011-05-31 JD Loots 3. Added ability to specify the processes and
|
# PID files on command line (-p and -P) instead
|
# of having the processes specified inside
|
# script. Also removed Warning level procs tests.
|
# 2.3 2011-05-09 JD Loots 4. Added exit to printUsage sub.
|
##################################################################################
|
|
##################################################################################
|
#
|
# PID Files to check
|
PIDLIST="" # Will be populated from -p argument
|
# Processes to check
|
PROCLIST="" # Will be populated from -P argument
|
|
PATH="/usr/bin:/usr/sbin:/bin:/sbin"
|
|
if [ "`uname -s`" = "SunOS" ]
|
then
|
PSAUXWWW="/usr/ucb/ps -auxwww"
|
PS=/usr/bin/ps
|
elif [ "`uname -s`" = "Linux" ]
|
then
|
PSAUXWWW="/bin/ps auxwww"
|
PS=/bin/ps
|
else
|
PSAUXWWW="/bin/ps -auxwww"
|
PS=/bin/ps
|
fi
|
|
STATE_OK=0
|
STATE_WARNING=1
|
STATE_CRITICAL=2
|
STATE_UNKNOWN=3
|
STATE_DEPENDENT=4
|
|
print_gpl() {
|
echo "This program is free software; you can redistribute it and/or modify"
|
echo "it under the terms of the GNU General Public License as published by"
|
echo "the Free Software Foundation; either version 2 of the License, or"
|
echo "(at your option) any later version."
|
echo ""
|
echo "This program is distributed in the hope that it will be useful,"
|
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
|
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
|
echo "GNU General Public License for more details."
|
echo ""
|
echo "You should have received a copy of the GNU General Public License"
|
echo "along with this program; if not, write to the Free Software"
|
echo "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA"
|
}
|
|
printUsage(){
|
echo ""
|
echo "FACTS Loader process and port check script for Nagios."
|
echo ""
|
echo "USAGE: $0 [ -p {proc_list} ] [ -P {pidfile_list} ]"
|
echo "-p {proc_list} = Comma seperated list of Process names to grep for"
|
echo "-P {pidfile_list} = Comma seperated lsit of PID Files. PIDs in files will"
|
echo " be looked for."
|
echo ""
|
echo "EXAMPLE: $0 -p StatsGW,NotificationManager,DownloadManager,serviceManager,ViewManager,factsbi/cs/jboss \\"
|
echo " -P /app/factsbi/es/tmp/es.pid,/app/factsbi/en1/tmp/en.pid"
|
print_gpl
|
exit 1
|
}
|
|
check_processes()
|
{
|
PROCESS="0"
|
ERROR_PROCS=""
|
for PROC in `echo $PROCLIST`
|
do
|
if [ `${PSAUXWWW} | grep $PROC | grep -v grep | wc -l` -lt 1 ]
|
then
|
PROCESS=1
|
ERROR_PROCS="$ERROR_PROCS""$PROC ";
|
fi
|
done
|
|
if [ $PROCESS -eq "1" ]
|
then
|
exit_proc=$STATE_CRITICAL
|
elif [ $PROCESS -eq "0" ]
|
then
|
exit_proc=$STATE_OK
|
fi
|
}
|
|
check_pids()
|
{
|
PROCESS="0"
|
ERROR_PIDS=""
|
for PIDFILE in `echo $PIDLIST`
|
do
|
if [ ! -r ${PIDFILE} ]
|
then
|
PROCESS=1
|
ERROR_PIDS="${ERROR_PIDS} ${PIDFILE}"
|
else
|
PID=`cat ${PIDFILE} | head -1`
|
${PS} -p ${PID} > /dev/null 2>&1
|
CODE=$?
|
if [ ${CODE} -gt 0 ]
|
then
|
PROCESS=1
|
ERROR_PIDS="${ERROR_PIDS} ${PIDFILE}"
|
fi
|
fi
|
done
|
|
if [ $PROCESS -eq "1" ]
|
then
|
exit_pid=$STATE_CRITICAL
|
elif [ $PROCESS -eq "0" ]
|
then
|
exit_pid=$STATE_OK
|
fi
|
}
|
#
|
# MAIN
|
#
|
|
if [ "$1" = "" ]
|
then
|
echo "ERROR:No argument specified." >&2
|
printUsage
|
fi
|
|
# Decode command-line arguments
|
while [ "$1" != "" ]
|
do
|
case "$1" in
|
'-p' ) PROCLIST=$2
|
shift 2
|
;;
|
'-P' ) PIDLIST=$2
|
shift 2
|
;;
|
'-h' ) printUsage
|
shift
|
;;
|
*) # In case all parameters were passed as one, decode with awk
|
if [ "$1" != "" ] && [ "$2" = "" ]
|
then
|
NF=`echo $1 | awk '{print NF}'`
|
let i=1
|
while [ $i -lt $NF ]
|
do
|
let j=i+1 # Make j 1 more than i
|
ONE=`echo $1 | awk '{print $'${i}'}'`
|
TWO=`echo $1 | awk '{print $'${j}'}'`
|
case "${ONE}" in
|
'-p' ) PROCLIST=$TWO
|
let i=i+2 # shift 2
|
;;
|
'-P' ) PIDLIST=`echo "scale=0;$TWO * ${SCALE} / 1" |bc`
|
let i=i+2 # shift 2
|
;;
|
'-h' ) printUsage
|
let i=i+1 # shift
|
;;
|
*) echo "Unknown argument: \"$ONE\"" >&2
|
printUsage
|
;;
|
esac
|
done
|
shift
|
else
|
echo "Unknown argument: \"$1\"" >&2
|
printUsage
|
fi
|
;;
|
esac
|
done
|
|
# At this stage, PROCLIST and PIDLIST are Comma Seperated Lists.
|
# Replace Comma's with spaces in these values.
|
PIDLIST=`echo ${PIDLIST} | sed 's/,/ /g'`
|
PROCLIST=`echo ${PROCLIST} | sed 's/,/ /g'`
|
|
# Do the Process checks
|
check_processes
|
check_pids
|
|
final_exit=`expr $exit_proc + $exit_pid`
|
|
if [ $final_exit -eq "0" ]
|
then
|
echo "SYSTEM OK - All monitored resources OK. Processes: ${PROCLIST}. PID Files: ${PIDLIST}."
|
exitstatus=$STATE_OK
|
else
|
echo "SYSTEM CRITICAL - Processes DOWN! Processes: ${ERROR_PROCS} ${ERROR_PIDS}."
|
exitstatus=$STATE_CRITICAL
|
fi
|
|
exit $exitstatus
|