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

This forum is intended for the discussion of Nagios plugin development. Feature requests, patches, bug fixes, and all types of development-related discussions are welcome!

NOTE: The SourceForge.net nagiosplug-devel mailing list has been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

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

Postby ayushSid » Mon Apr 17, 2017 9:46 am

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.
ayushSid
 
Posts: 2
Joined: Mon Apr 17, 2017 9:26 am

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

Postby jfrickson » Mon Apr 17, 2017 10:14 am

You probably need to use either the full path or a relative path to your output file.
Former Nagios Employee
jfrickson
Developer
 
Posts: 188
Joined: Wed Jul 22, 2015 9:58 am

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

Postby ayushSid » Tue Apr 18, 2017 12:26 am

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!
ayushSid
 
Posts: 2
Joined: Mon Apr 17, 2017 9:26 am

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

Postby jfrickson » Tue Apr 18, 2017 9:19 am

Glad I could help!
Former Nagios Employee
jfrickson
Developer
 
Posts: 188
Joined: Wed Jul 22, 2015 9:58 am


Return to Nagios Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest