check_by_ssh (bash issues?)

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
devildog31415
Posts: 48
Joined: Thu Jun 12, 2014 10:55 am

check_by_ssh (bash issues?)

Post 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
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: check_by_ssh (bash issues?)

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
devildog31415
Posts: 48
Joined: Thu Jun 12, 2014 10:55 am

Re: check_by_ssh (bash issues?)

Post 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?
devildog31415
Posts: 48
Joined: Thu Jun 12, 2014 10:55 am

Re: check_by_ssh (bash issues?)

Post 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
devildog31415
Posts: 48
Joined: Thu Jun 12, 2014 10:55 am

Re: check_by_ssh (bash issues?)

Post 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 "/".
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: check_by_ssh (bash issues?)

Post by lmiltchev »

Can you show us the actual command that you run from the CLI, along with the output of it?
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: check_by_ssh (bash issues?)

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked