Page 1 of 1

Custom Nagios check

Posted: Wed Oct 09, 2019 7:01 am
by jankogaga
Hi,

I am running Nagios Core 4.4.3.
I have been trying to create a custom check on my Nagios server.

Code: Select all

vi /usr/local/nagios/libexec/third-party-resources.sh
#!/bin/bash

number_of_char=$(~/third-party-resources-checker-master/bin/third-party-resources-checker -w ~/third-party-resources-checker-master/whitelist.json https://website|wc -m)

if (($number_of_char == 0)); then

    echo "OK";
exit 0
elif (($number_of_char > 0)); then
    echo "WARNING -new third party resources found:"
    ~/third-party-resources-checker-master/bin/third-party-resources-checker -w ~/third-party-resources-checker-master/whitelist.json https://website
    exit 1
elif (($number_of_char < 0)); then 
    #CRITICAL - never happens  
    # It is just to make an example on all possible exits
    exit 2
else echo "UNKNOWN"
    exit 3
fi


chown nagios: /usr/local/nagios/libexec/third-party-resources.sh
chmod 755 /usr/local/nagios/libexec/third-party-resources.sh

nrpe.cfg:
command[third-party-resources]=/usr/local/nagios/libexec/third-party-resources.sh 

commands.cfg:
define command{
        command_name third-party-resources
        command_line /usr/local/nagios/libexec/third-party-resources.sh
}

monitor.cfg:
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios_server
        service_description             third-party-resources
        check_command                   third-party-resources
        notifications_enabled           1
        }

service nagios restart
/usr/local/nagios/libexec/third-party-resources.sh
returns a good outcome: WARNING

but in Nagios GUI I am seeing: OK (what is not supposed to be)

Please advise.

Thanks,
Dragan

Re: Custom Nagios check

Posted: Wed Oct 09, 2019 10:53 am
by scottwilkerson
Without even looking to far I see this

Code: Select all

~/third-party-resources....
You need to use full paths to all files, don't start them with ~/ as nagios is going to interpret that differently than a logged in user

Also, make sure that the nagios user has permissions for all necessary scripts and files

finally, test the plugin after switching user to the nagios user

Code: Select all

su nagios

Re: Custom Nagios check

Posted: Thu Oct 10, 2019 6:53 am
by jankogaga
This solved the problem.
Once I moved ~/third-party-resources... to / everything works like a charm.

Thank you scottwilkerson!

Re: Custom Nagios check

Posted: Thu Oct 10, 2019 7:27 am
by scottwilkerson
jankogaga wrote:This solved the problem.
Once I moved ~/third-party-resources... to / everything works like a charm.

Thank you scottwilkerson!
Great!

Locking