Nagios commandline error
Posted: Mon Apr 04, 2016 5:00 pm
Hi,
When I specify the process name in the script, there is no problem identifying the process status.
However, when I type process name on the command prompt instead of specify the process name in the script, script does not function properly.
Could you help resolving this matter?
Here is the command which I ran from the command prompt:
/usr/local/nagios/libexec/check_nrpe -H dalcpldd10 -t 30 -c check_init_service1 mccdev -n
Here is my simple script (check_init_service1) :
#!/bin/sh
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
PROGNAME=$(basename $0)
#process name is mccdev
#PROCESS="mccdev"
PROCESS="$1"
TMP_OUTPUT="/tmp/process_check.txt"
PID_EXIST=`ps -ef | grep "$PROCESS" | egrep -v "grep|$PROGNAME"`
if [ -z "$PID_EXIST" ]
then
RETURN_STATUS=$STATE_CRITICAL
FINAL_STATUS="CRITICAL"
PERFORMANCE="NOT RUNNING"
FINAL_STATUS="$FINAL_STATUS|$PERFORMANCE"
else
ps -ef | grep "$PROCESS" | egrep -v "grep|$PROGNAME" > $TMP_OUTPUT
cat "$TMP_OUTPUT" | while read -r line
do
PID=`echo $line |awk '{print $2}'`
PID_STATUS=`echo $line |awk '{print $9}'`
if [[ "$PID_STATUS" == "db2sysc" ]]
then
RETURN_STATUS=$STATE_OK
FINAL_STATUS="OK"
PERFORMANCE="$PROCESS RUNNING"
FINAL_STATUS="$FINAL_STATUS|$PERFORMANCE"
fi
done
fi
if [ -f $TMP_OUTPUT ]
then
/bin/rm -f $TMP_OUTPUT
fi
echo "$FINAL_STATUS"
exit $RETURN_STATUS
When I specify the process name in the script, there is no problem identifying the process status.
However, when I type process name on the command prompt instead of specify the process name in the script, script does not function properly.
Could you help resolving this matter?
Here is the command which I ran from the command prompt:
/usr/local/nagios/libexec/check_nrpe -H dalcpldd10 -t 30 -c check_init_service1 mccdev -n
Here is my simple script (check_init_service1) :
#!/bin/sh
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
PROGNAME=$(basename $0)
#process name is mccdev
#PROCESS="mccdev"
PROCESS="$1"
TMP_OUTPUT="/tmp/process_check.txt"
PID_EXIST=`ps -ef | grep "$PROCESS" | egrep -v "grep|$PROGNAME"`
if [ -z "$PID_EXIST" ]
then
RETURN_STATUS=$STATE_CRITICAL
FINAL_STATUS="CRITICAL"
PERFORMANCE="NOT RUNNING"
FINAL_STATUS="$FINAL_STATUS|$PERFORMANCE"
else
ps -ef | grep "$PROCESS" | egrep -v "grep|$PROGNAME" > $TMP_OUTPUT
cat "$TMP_OUTPUT" | while read -r line
do
PID=`echo $line |awk '{print $2}'`
PID_STATUS=`echo $line |awk '{print $9}'`
if [[ "$PID_STATUS" == "db2sysc" ]]
then
RETURN_STATUS=$STATE_OK
FINAL_STATUS="OK"
PERFORMANCE="$PROCESS RUNNING"
FINAL_STATUS="$FINAL_STATUS|$PERFORMANCE"
fi
done
fi
if [ -f $TMP_OUTPUT ]
then
/bin/rm -f $TMP_OUTPUT
fi
echo "$FINAL_STATUS"
exit $RETURN_STATUS