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

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
ayushSid
Posts: 2
Joined: Mon Apr 17, 2017 9:26 am

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

Post 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.
jfrickson

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

Post by jfrickson »

You probably need to use either the full path or a relative path to your output file.
ayushSid
Posts: 2
Joined: Mon Apr 17, 2017 9:26 am

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

Post 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!
jfrickson

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

Post by jfrickson »

Glad I could help!
Locked