script.sh with always green dashboard even in error

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.
Post Reply
ggreg
Posts: 3
Joined: Mon Nov 27, 2023 7:10 am

script.sh with always green dashboard even in error

Post by ggreg »

Hello everyone,
(OS: Debian 11)

I have a problem with the dashboard, one of my personalized sensors remains always green, even in critical condition.

I will describe to you what I did:

Usually I use the default sensors or downloads from the official website. But this time, I launched a script.sh to find out if the bind9 DNS service is active or inactive.

Here it is and it works :
---------------------------------------------------------------------------------

Code: Select all

#!/bin/bash
if systemctl is-active --quiet bind9; then
     echo "OK - The Bind9 service is active."
     exit 0 # Exit code 0 for OK
else
     echo "CRITICAL - The Bind9 service is down."
     exit 2 # Exit code 2 for CRITICAL
fi
---------------------------------------------------------------------------------

I put it on my client, I put the execution rights and declare it in /etc/nagios => nrpe.cfg

I tested it on my nagios (server side), in /usr/local/nagios/libexec: with "NRPE" =>

Code: Select all

./check_nrpe -H xxx.xxx.xxx.xxx -c check_status_bind9
I get feedback that says "OK - The Bind9 service is active", so my script is working (I have resolved the problem of access rights to my file).

I declared my sensor in the "commands.cfg" file in /usr/local/nagios/etc/objects.

Here is the line from this file:

Code: Select all

## DNS service
define command{

         command_name check_status_dns
         command_line $USER1$/check_nrpe -H $HOSTADDRESS$ check_status_bind9
}
I obviously checked nagios with:

Code: Select all

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
No errors, so I restarted my nagios for everything to take effect.

But, when I voluntarily turn off my DNS, in order to create "critical" on the dashboard, nothing happens, it always remains green.
However, the output of my script when everything is fine is: 0 and when it is an error it is: 2

In theory nagios, takes the 2 which for him means "error".

I don't know if I need to add options somewhere, I tried a lot of other configs but without success. I also thought about putting " -w $ARG1$ -c $ARG2$ " in " define command " without success.

If you have any ideas, I'm interested.
Thank you.
ggreg
Posts: 3
Joined: Mon Nov 27, 2023 7:10 am

Re: script.sh with always green dashboard even in error

Post by ggreg »

I found the error.
It is located on the client, /etc/nagios => nrpe.cfg
command[check_status_dns]=sudo /usr/lib/nagios/plugins/check_status_dns.sh -a
It's just the "-a " that was missing... :evil:

Hope this helps others :)
Dever2000
Posts: 1
Joined: Fri Dec 08, 2023 3:04 am

Re: script.sh with always green dashboard even in error

Post by Dever2000 »

Did you solve the problem?
ggreg
Posts: 3
Joined: Mon Nov 27, 2023 7:10 am

Re: script.sh with always green dashboard even in error

Post by ggreg »

Dever2000 wrote: Fri Dec 08, 2023 3:06 am Did you solve the problem?
Yes, It's just the "-a " at => command[check_status_dns]=sudo /usr/lib/nagios/plugins/check_status_dns.sh -a
Post Reply