custom bash script

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
ddk
Posts: 6
Joined: Mon Aug 19, 2013 7:22 am

custom bash script

Post by ddk »

Hi all!
I wrote custom bash script for Nagios Core, but in web interface it returns:

Code: Select all

Current Status:	WARNING  
Status Information:	(null)
while in console it returns normal results, like:

Code: Select all

CRITICAL: 2
Exit codes are from manual:

Code: Select all

if [ $RESULT -ge $WARN ] && [ $RESULT -lt $CRIT ]; then
	    echo "WARNING: $RESULT warn:$WARN; crit:$CRIT $ADDINFO"
	    exit 1
	elif [ $RESULT -ge $CRIT ]
	then
	    echo "CRITICAL: $RESULT  warn:$WARN; crit:$CRIT $ADDINFO"
	    exit 2
	else
	    echo "OK - warn:$WARN; crit:$CRIT"
	    exit 0
	fi
whats wrong?
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: custom bash script

Post by slansing »

Can you share the entire script here via an attachment? That would help greatly!
ddk
Posts: 6
Joined: Mon Aug 19, 2013 7:22 am

Re: custom bash script

Post by ddk »

here it is
Attachments
mysqlcheck.sh
(1.74 KiB) Downloaded 331 times
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: custom bash script

Post by abrist »

ddk wrote:while in console it returns normal results, like:

CRITICAL: 2
Shouldn't it be returning the whole string, not just the $RESULT but also $WARN, $CRIT and $ADDINFO?

Code: Select all

CRITICAL: $RESULT  warn:$WARN; crit:$CRIT $ADDINFO
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
ddk
Posts: 6
Joined: Mon Aug 19, 2013 7:22 am

Re: custom bash script

Post by ddk »

abrist wrote:
ddk wrote:while in console it returns normal results, like:

CRITICAL: 2
Shouldn't it be returning the whole string, not just the $RESULT but also $WARN, $CRIT and $ADDINFO?

Code: Select all

CRITICAL: $RESULT  warn:$WARN; crit:$CRIT $ADDINFO
it's copy-paste fail, sorry.

it is returninng full string as it's writing in script
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: custom bash script

Post by abrist »

Are you running from the cli as the "nagios" user?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
ddk
Posts: 6
Joined: Mon Aug 19, 2013 7:22 am

Re: custom bash script

Post by ddk »

Code: Select all

# su nagios
bash-4.1$ /usr/lib64/nagios/plugins//check_mysql_query_custom -H 192.168.0.1 -d DB -w 1 -c 2 -u USER -p PASS -t 1
/bin/bash: /root/.bashrc: Permission denied
CRITICAL: 2  warn:1; crit:2 ID: 5 Desc:192.168.0.2 Date: 2013-08-19 20:07:17
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: custom bash script

Post by abrist »

Lets just make sure that it works without the bash error:
On teh remote host:

Code: Select all

su nagios
cd /home/nagios/
/usr/lib64/nagios/plugins//check_mysql_query_custom -H 192.168.0.1 -d DB -w 1 -c 2 -u USER -p PASS -t 1
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
ddk
Posts: 6
Joined: Mon Aug 19, 2013 7:22 am

Re: custom bash script

Post by ddk »

abrist wrote:Lets just make sure that it works without the bash error:
On teh remote host:

Code: Select all

su nagios
cd /home/nagios/
/usr/lib64/nagios/plugins//check_mysql_query_custom -H 192.168.0.1 -d DB -w 1 -c 2 -u USER -p PASS -t 1
there is no such directory
'nagios' home dir is - /var/spool/nagios
so:

Code: Select all

# su nagios
bash-4.1$ cd ~/
bash-4.1$ pwd
/var/spool/nagios
bash-4.1$ /usr/lib64/nagios/plugins//check_mysql_query_custom -H 192.168.0.1 -d DB -w 1 -c 2 -u USER -p PASS -t 1
/bin/bash: /root/.bashrc: Permission denied
CRITICAL: 2  warn:1; crit:2 ID: 5 Desc:192.168.0.2 Date: 2013-08-19 20:07:17
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: custom bash script

Post by abrist »

Maybe you are having an environment variable issue. What are your environment variables?

Code: Select all

env
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked