Page 1 of 1

monitoring output from basj script

Posted: Mon Sep 09, 2019 9:27 am
by mccrakem
Hi
I have a .sh script that we run on a Unix Server

output=$(sudo /usr/bin/tail -n 1 /opt/NA/app_users/UDeployUser/lastbackups)

if [[ -z "$(sudo /bin/find /opt/NA/app_users/UDeployUser/lastbackups -mtime -1)" ]] ; then
echo "CRITICAL - Backup too old $ouput"
exit 2
else
echo "OK - Backup is recent"
exit 0
fi

When I run this from RHEL I get the following output

OK - Backup is recent


I have it setup in in Nagios
/etc/nrpe.d/check_ucard_backups.cfg
command[check_ucard_backups]=/usr/lib64/nagios/plugins/check_ucard_backups.sh

But when I run it from the NagiosXI GUI I get the following
CRITICAL =- Backup too old

but if I reverse the script like this

output=$(sudo /usr/bin/tail -n 1 /opt/XXXX/app_users/UDeployUser/lastbackup)

if [[ -z "$(sudo /bin/find /opt/XXXX/app_users/UDeployUser/lastbackups -mtime -1)" ]] ; then
echo "OK - Backup is recent"
exit 0
else
echo "CRITICAL - Backup too old $output"
exit 2
fi

Nagios reports back as OK - Backup is recent


To me it looks like Nagios running the script but its stopping at the else and not processing the entire script

Any help with this would be very much appreciated

NagiosXI version 5.2.7

Re: monitoring output from basj script

Posted: Mon Sep 09, 2019 9:36 am
by scottwilkerson
If I had to guess, I would think that the nagios user doesn't have permissions to run those sudo commands in your script.

I would suggest adding sudo to this

Code: Select all

command[check_ucard_backups]=sudo /usr/lib64/nagios/plugins/check_ucard_backups.sh
And then adding an entry to your sudoers file giving the nagios user permissions to execute that script as an elevated user

Re: monitoring output from basj script

Posted: Wed Sep 11, 2019 7:33 am
by mccrakem
Hi Scott

Thanks for the information, but I am not a Unix person can yo0u help me out and let me know what command I should but into the nrpe.cfg file for Nagios to be able to sudo to the correct user and run the script

Thanks

Re: monitoring output from basj script

Posted: Wed Sep 11, 2019 7:43 am
by scottwilkerson
Did you write the script?

You might first want to try adjusting the script to remove all the sudo commands

Code: Select all

output=$(/usr/bin/tail -n 1 /opt/NA/app_users/UDeployUser/lastbackups)

if [[ -z "$(/bin/find /opt/NA/app_users/UDeployUser/lastbackups -mtime -1)" ]] ; then
echo "CRITICAL - Backup too old $ouput"
exit 2
else
echo "OK - Backup is recent"
exit 0
fi
If you still have problems you are going to need to adjust the sudoers file on the server which would be best to have a Unix/Linux person help you with if you have one on staff