Nagios don't take exit code 2

Hello, I am a complete beginner on Nagios, I tried to write a little plugin but can’t get it to take the right exit code.
Nagios says “OK” but it should say that it’s critical.
I’ve tested the script on the commandline and there it works as it should.
Any help or guidance on this would be very appreciated.
Here is the script:


#!/bin/bash
#File: /usr/lib/nagios/plugins/check_mysql_blocked

host="`tail -n 300000 /tmp/php.log.1 | grep -m 1 -o sdw.* | awk -F'.' {'print $1'}`"

if  "`tail -n 300000 /tmp/php.log.1 | grep -m 1 blocked`" ]; then
                echo "$host is blocked, too many connection errors"
                exit 2
else
        echo "Mysql OK - No hosts are blocked"
        exit 0
fi

It’s very simple but we really need it.

Best Regards.
Andreas Andersson

Are you sure it is doing what you expect?

i use #!/bin/sh and it requires fi to close if groups…

[quote=“luca”]Are you sure it is doing what you expect?

i use #!/bin/sh and it requires fi to close if groups…[/quote]

Yes I am sure it does what i expect because I have ran it in the terminal serveral times.
Regarding the fi to close if, I am already using it?
Does Nagios have any time limit that can be set for each plugin or global?
I thought that maybe the plugin didn’t have time to finish and the defaults to OK?
But it sound kinda strange that it should default to OK thou.

/Andreas

The time out is by default 60 seconds.
and it should say something like plugn timed out… :slight_smile:

you sure it runs ok as user nagios too?

[quote=“luca”]The time out is by default 60 seconds.
and it should say something like plugn timed out… :slight_smile:

you sure it runs ok as user nagios too?[/quote]

It feels like Nagios doesn’t execute the commands as it should or something.
The script runs ok with the nagios user to yes :slight_smile:

/Andreas

i can only try to copy you my script which works :smiley:

It takes data from a mysql db and compares different values…
Depending on the reuslts of the comparision it exits or continues.

#!/bin/sh
status=3
server=$1
delay=(fetch some stuff from mysql using the server param)
updatetime=(fetch some other data from mysql) 
nowtime=`date +%s`
diff=`expr $nowtime - $updatetime`
if  $delay -lt 300 -a $diff -lt 300 ]; then
        echo "OK: delay: $delay - update: $diff"
        exit 0;
fi
if  $delay -lt 600 -a $diff -lt 600 ]; then
        echo "WARNING: delay: $delay - update: $diff"
        exit 1;
fi
if  $delay -gt 599 -o $diff -gt 599 ]; then
        echo "CRITICAL: delay: $delay - update: $diff"
        exit 2;
fi
echo "UNKNOWN: No reason known"
exit 3;