Page 1 of 1

check_by_ssh (bash issues?)

Posted: Thu Jul 10, 2014 4:21 pm
by devildog31415
If I run:
/usr/local/nagios/libexec/check_by_ssh -H 192.168.100.7 -C 'df /' | awk '{ print $5 }' | tail -n 1

I get:
70%

I want to strip out the "%" here is what happens when I try to run my script "./park_check_by_ssh_df_percent.sh" and below that is my uber beginner attempt at a script :)
Yes I haven't included any logic for "if" or different exit codes yet, but I just want to get my command/wrapper to work at all :)


[nagios@log_book libexec]$ ./park_check_by_ssh_df_percent.sh 192.168.100.7 /
./park_check_by_ssh_df_percent.sh: line 8: awk: command not found
./park_check_by_ssh_df_percent.sh: line 8: tail: command not found
./park_check_by_ssh_df_percent.sh: line 10: ${$REMOTE/%/''}: bad substitution

Code: Select all

!/bin/bash

HOSTADDRESS=$1
PATH=$2
MAXWARN=$3
MAXCRIT=$4

REMOTE=`/usr/local/nagios/libexec/check_by_ssh -H $HOSTADDRESS -C df $PATH | awk '{ print $5 }' | tail -n 1`

PERCENT="${$REMOTE/%/''}"
echo $PERCENT
exit 0
Help please

Re: check_by_ssh (bash issues?)

Posted: Thu Jul 10, 2014 11:11 pm
by Box293
Try this:

Code: Select all

#!/bin/bash

HOSTADDRESS=$1
PATH=$2
MAXWARN=$3
MAXCRIT=$4

REMOTE=`/usr/local/nagios/libexec/check_by_ssh -H $HOSTADDRESS -C "df $PATH | tail -n 1"`
PERCENT=`echo $REMOTE | /bin/awk '{print $5}' | /bin/sed s/%$//`

echo $PERCENT
exit 0

Re: check_by_ssh (bash issues?)

Posted: Fri Jul 11, 2014 9:15 am
by devildog31415
Thank you that worked!
How do get my drive space % to be graphed and view-able as a "performance graph" for the service?

Re: check_by_ssh (bash issues?)

Posted: Fri Jul 11, 2014 9:24 am
by devildog31415
BTW: here is the current command, works great!

Code: Select all

#!/bin/bash

HOSTADDRESS=$1
PATH=$2
MAXWARN=$3
MAXCRIT=$4

REMOTE=`/usr/local/nagios/libexec/check_by_ssh -H $HOSTADDRESS -C df $PATH | /bin/awk '{ print \$5 }' | /usr/bin/tail -n 1 | /bin/sed s/%$//`

if [[ "$REMOTE" -gt $MAXCRIT ]];
then
        echo "CRITICAL: $REMOTE% disk usage which is above the CRITICAL threshold of $MAXCRIT"
        exit 2
elif [[ "$REMOTE" -gt $MAXWARN ]];
        then
                echo "WARNING: $REMOTE% disk usage which is above the WARNING threshold of $MAXWARN"
                exit 1
else
        echo "OK: $REMOTE% disk usage which is below the WARNING threshold of $MAXWARN"
        exit 0
fi

Re: check_by_ssh (bash issues?)

Posted: Fri Jul 11, 2014 9:57 am
by devildog31415
ugh, turns out that no matter what PATH I put it, it still only gives me the status on "/" I don't know why though.
If I try to check my other mount points /dev or /dev/shm it still returns the % use on "/".

Re: check_by_ssh (bash issues?)

Posted: Fri Jul 11, 2014 11:31 am
by lmiltchev
Can you show us the actual command that you run from the CLI, along with the output of it?

Re: check_by_ssh (bash issues?)

Posted: Fri Jul 11, 2014 8:40 pm
by Box293
Try this:

Code: Select all

#!/bin/bash

HOSTADDRESS=$1
PATH=$2
MAXWARN=$3
MAXCRIT=$4

REMOTE=`/usr/local/nagios/libexec/check_by_ssh -H $HOSTADDRESS -C df "$PATH | tail -n 1" | /bin/awk '{ print \$5 }' | /bin/sed s/%$//`
PERFDATA="|'Disk Usage'=$REMOTE%;$MAXWARN;$MAXCRIT"

if [[ "$REMOTE" -gt $MAXCRIT ]];
then
		echo "CRITICAL: $REMOTE% disk usage which is above the CRITICAL threshold of $MAXCRIT".$PERFDATA
		exit 2
elif [[ "$REMOTE" -gt $MAXWARN ]];
		then
				echo "WARNING: $REMOTE% disk usage which is above the WARNING threshold of $MAXWARN".$PERFDATA
				exit 1
else
		echo "OK: $REMOTE% disk usage which is below the WARNING threshold of $MAXWARN".$PERFDATA
		exit 0
fi
So I run:

Code: Select all

/usr/local/nagios/libexec/ssh_test.sh 192.168.1.233 /dev 30 50
OK: 1% disk usage which is below the WARNING threshold of 30.|'Disk Usage'=1%;30;50
Which is great!

However if I run:

Code: Select all

/usr/local/nagios/libexec/ssh_test.sh 192.168.1.233 /dev
CRITICAL: 1% disk usage which is above the CRITICAL threshold of .|'Disk Usage'=1%;;
You will notice that there is no value displayed for warning or critical. This is OK if you run the script internally and always use warning and critical values however it is good practice to make sure these variables are defined before using them in if statements.

In relation to the PERFDATA String, refer to this documentation to explain how it works:
https://nagios-plugins.org/doc/guidelines.html#AEN200

Enjoy