monitoring output from basj script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
mccrakem
Posts: 129
Joined: Mon Jun 19, 2017 8:28 am

monitoring output from basj script

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: monitoring output from basj script

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
mccrakem
Posts: 129
Joined: Mon Jun 19, 2017 8:28 am

Re: monitoring output from basj script

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: monitoring output from basj script

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked