Custom Nagios check

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have 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

Postby jankogaga » Wed Oct 09, 2019 7:01 am

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

Re: Custom Nagios check

Postby scottwilkerson » Wed Oct 09, 2019 10:53 am

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 16263
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: Custom Nagios check

Postby jankogaga » Thu Oct 10, 2019 6:53 am

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

Thank you scottwilkerson!
jankogaga
 
Posts: 37
Joined: Thu Apr 19, 2018 8:16 am

Re: Custom Nagios check

Postby scottwilkerson » Thu Oct 10, 2019 7:27 am

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

Thank you scottwilkerson!

Great!

Locking
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 16263
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises


Return to Nagios Core

Who is online

Users browsing this forum: MSN [Bot], tejjubonda and 36 guests