Page 1 of 1

No Performance Counter Displauyed in Status Information

Posted: Tue Feb 21, 2012 11:21 am
by hotriver
I created a shell script plugin and defined my own performance counter.But the counter is not displayed in the Nagios Status Information.
CCS: check_jms_queue

OK 02-21-2012 11:17:17 4d 1h 35m 22s 1/3 OK: JMS Message Queue: QueueNumber
There should be a counter after JMS Message Queue:

The plugin just read one counter from my Oracle database. I run the command in terminal and it works.

Please see the command definition:

Code: Select all

#! /bin/sh

#For queue messages the bigger, the worse
#{1} Critical level 
#{2} Warning  level

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

if test -x /usr/bin/printf; then
	ECHO=/usr/bin/printf
else
	ECHO=echo
fi


   if [ ${1} -lt ${2} ] ; then
	echo "UNKNOWN - Warning level is bigger then Crit"
	exit $STATE_UNKNOWN
    fi
    result=`sqlplus -s statjms/statjms_D3@ORCA << EOF
set pagesize 0
set numf '9999999'
select count(1) FROM JMS_MESSAGES;
EOF`

    if [ -n "`echo $result | grep ORA-`" ] ; then
      error=` echo "$result" | grep "ORA-" | head -1`
      echo "CRITICAL - $error"
      exit $STATE_CRITICAL
    fi

    queuenum=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'`
    queuenumx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'`  
   
    if [ $queuenum -ge ${1} ] ; then
  	echo "${1} CRITICAL - JMS Message Queue:" $queuenumx "Exceed Critical QueueNumber|QueueNumber=$queuenumx"
	exit $STATE_CRITICAL
    fi
    if [ $queuenum -le ${1} -a $queuenum -ge ${2} ] ; then
  	echo "${2} WARNING  - JMS Message Queue:" $queuenumx "Exceed Warning QueueNumber|QueueNumber=$queuenumx"
	exit $STATE_WARNING
    fi
    echo "OK: JMS Message Queue: $queuenumx QueueNumber|QueueNumber=$queuenumx"

    exit $STATE_OK
    ;;

Re: No Performance Counter Displauyed in Status Information

Posted: Wed Feb 22, 2012 11:37 am
by agriffin
I found your script pretty hard to read, so I rewrote certain parts of it while I was looking at it. Use or don't use my changes. Anyway, when you run it from the command line are you running it as the root user or as the nagios user? Often these kinds of issues are permission problems, and will work when run as run but not as some other user. You should try testing it like this:

Code: Select all

# su nagios -c 'check_jms_queue opts...'

Code: Select all

#!/bin/sh -e

#For queue messages the bigger, the worse
#{1} Critical level
#{2} Warning  level

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

if [ "$1" -lt "$2" ]; then
	echo "UNKNOWN - Warning level is bigger then Crit"
	exit $STATE_UNKNOWN
fi

result=`sqlplus -s statjms/statjms_D3@ORCA <<- EOF
		set pagesize 0
		set numf '9999999'
		select count(1) FROM JMS_MESSAGES;
	EOF`

if echo "$result" | grep -q ORA-; then
	error=`echo "$result" | grep "ORA-" | head -1`
	echo "CRITICAL - $error"
	exit $STATE_CRITICAL
fi

queuenum=`echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}'`
queuenumx=`echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}'` 
	
if [ "$queuenum" -ge "$1" ]; then
	echo "$1 CRITICAL - JMS Message Queue: $queuenumx Exceed Critical QueueNumber|QueueNumber=$queuenumx"
	exit $STATE_CRITICAL
elif [ "$queuenum" -ge "$2" ]; then
	echo "$2 WARNING  - JMS Message Queue: $queuenumx Exceed Warning QueueNumber|QueueNumber=$queuenumx"
	exit $STATE_WARNING
else
	echo "OK: JMS Message Queue: $queuenumx QueueNumber|QueueNumber=$queuenumx"
	exit $STATE_OK
fi

Re: No Performance Counter Displauyed in Status Information

Posted: Wed Feb 22, 2012 4:07 pm
by hotriver
Hi Agriffin,

Thank you very much for the reply.

I did changed the permission for the plugin. the owner is nagios now, but still same problem. The Nagios can run the command and just does not display the performace data I defined. It displayed other output messages.

I also tried Nagios -c, but I got a -c is not a valid option.

I tried your code, but there is a warning: here-document at line 22 delimited by end-of-file (wanted `EOF')

Re: No Performance Counter Displauyed in Status Information

Posted: Wed Feb 22, 2012 5:58 pm
by agriffin
I didn't actually test my changes since I don't have an Oracle database to run it against. Most of my changes were only cosmetic anyway, feel free to revert anything that doesn't work back to how you had it.

I think you missed the 'su' command that I put in front of 'nagios' in my last post. Try running it again with the 'su' in there. I didn't mean to imply that the permissions on the command should be owned by nagios - only that the command needs to be run as nagios (that's what the 'su' command accomplishes).

Re: No Performance Counter Displauyed in Status Information

Posted: Thu Feb 23, 2012 12:01 pm
by hotriver
Hi Agrifin,

Thank you for the reply again.

I tried to login as nagios and re start nagios service. I have same problem.

The Nagios can run the check command, but It can not display the variable I defined in my shell script plugin


What is wrong with this echo statement.

Code: Select all

echo "OK: JMS Message Queue:${queuenumx}|QueueNumber=$queuenumx"
queuenumx is a variable I defined. It can be displayed in terminal but why Nagios can not see it? Because it is a local variable?

Re: No Performance Counter Displauyed in Status Information

Posted: Thu Feb 23, 2012 12:24 pm
by mguthrie
The $ sign is a special character for nagios used for Macros. If you want to display:
echo "OK: JMS Message Queue:${queuenumx}|QueueNumber=$queuenumx"
Then it would need to be escaped like the following:
echo "OK: JMS Message Queue:\\$${queuenumx}|QueueNumber=\\$$queuenumx"

Re: No Performance Counter Displauyed in Status Information

Posted: Thu Feb 23, 2012 8:48 pm
by hotriver
HI mguthrie
Thank you very much.
I just want to display value of queuenumx which is a variable I defined. I do not want to display the $ sign.
I tried

Code: Select all

echo "OK: JMS Message Queue:$queuenumx|QueueNumber=$queuenumx"
But it does not work either.

The queuenumx is a number returned from sqlplus in my shell script.
$queuenumx =`echo "$result"`. In this way it can be displayed in terminal but not Nagios

But if I assigned $queuenumx a constant like
$queuenumx =27
Then the value can be displayed in the Nagios. WHY? Why I can not assign a variable to another variable?