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
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:
The plugin has been configured correctly as it gives the correct output on the UI for basic code such as "hello world" etc.(No output on stdout) stderr: cat: output: No such file or directory
I am guessing I am going somewhere wrong with file handling. Any help/leads would be really appreciated.