Custom Nagios check

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
jankogaga
Posts: 37
Joined: Thu Apr 19, 2018 8:16 am

Custom Nagios check

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Custom Nagios check

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
jankogaga
Posts: 37
Joined: Thu Apr 19, 2018 8:16 am

Re: Custom Nagios check

Post by jankogaga »

This solved the problem.
Once I moved ~/third-party-resources... to / everything works like a charm.

Thank you scottwilkerson!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Custom Nagios check

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked