Page 1 of 1

Custom Nagios check works on CLI but not properly on web UI

Posted: Mon Apr 17, 2017 9:46 am
by ayushSid
Hi all,
I am trying to create a custom nagios check plugin using Bash Script which reads data from a file and accordingly returns the exit code to the Nagios.

Code: Select all

#!/bin/bash

# script will check for the value of 'calculatedstatus' from the file

cat output | grep -A 1 -i "calculatedStatus" >> test.txt

if [ "$(cat test.txt | head -2 | tail -1 | cut -d " " -f2)" == "\"critical\"," ]; then
echo "exit 0"
exit 0
elif [ "$(cat test.txt | head -2 | tail -1 | cut -d " " -f2)" == "\"major\"," ]; then
echo "exit 1"
exit 1
elif [ "$(cat test.txt | head -2 | tail -1 | cut -d " " -f2)" == "\"minor\"," ]; then
echo "output is 2"
exit 2
elif [ "$(cat test.txt | head -2 | tail -1 | cut -d " " -f2)" == "\"operable\"," ]; then
echo "exit 3"
exit 3
fi

rm -rf test.txt
The Script works perfectly on the Nagios Command Line and returns the accurate output and the exit code.
Also, note that this plugin has been installed on the localhost itself and I am running the script from Nagios localhost CLI only.

The problem arrives when I run the script on the web UI, it always returns the exit code as 0 along with the following message:
(No output on stdout) stderr: cat: output: No such file or directory
The plugin has been configured correctly as it gives the correct output on the UI for basic code such as "hello world" etc.

I am guessing I am going somewhere wrong with file handling. Any help/leads would be really appreciated.

Re: Custom Nagios check works on CLI but not properly on web

Posted: Mon Apr 17, 2017 10:14 am
by jfrickson
You probably need to use either the full path or a relative path to your output file.

Re: Custom Nagios check works on CLI but not properly on web

Posted: Tue Apr 18, 2017 12:26 am
by ayushSid
jfrickson wrote:You probably need to use either the full path or a relative path to your output file.
Thanks, it works like a charm now!

Re: Custom Nagios check works on CLI but not properly on web

Posted: Tue Apr 18, 2017 9:19 am
by jfrickson
Glad I could help!