1
votes

Is there a "how to" for adding and configuring a plugin to Nagios? (for Ubuntu 14.04 specifically, but any Linux OS would be helpful.)

I've been able to cobble this much so far:

  1. Place the script in /usr/local/nagios/libexec/. (In my case there was already a script I wanted to use: "check_file_age".)
  2. Edit /usr/local/nagios/etc/objects/commands.cfg to add the plugin.
define command{  
    command_name check_file_age  
    command_line $USER1$/check_file_age -w $ARG1$ -c $ARG2$ -W $ARG3$ -C $ARG4$ -f $ARG5$ 
}
  1. Define the plugin in /usr/local/nagios/etc/objects/localhost.cfg.
define service{
    use             generic-service     ; Name of service template to use
    host_name           localhost
    service_description     File Age
    check_command           check_file_age
    notifications_enabled       1
}

Now I can see the plugin under "Configuration -> Object Type: Command" and I can see it listed in "Configuration -> Object Type: Services".

The plugin runs successfully from the command line:

user@host:/usr/local/nagios/libexec$ perl ./check_file_age -w 3600 -c 5400 -W -1 -C -1 -f somefile.txt 
FILE_AGE OK: somefile.txt is 2932 seconds old and 59 bytes | age=2932s;3600;5400 size=59B;-1;-1;0

Then at this point I'm stumped. I can see this error in Services:

File Age
CRITICAL    
09-09-2015 14:24:21 
0d 0h 32m 1s    
3/3 
(No output on stdout) stderr: Can't locate utils.pm in @INC (you may need to install the utils module) (@INC contains: . /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl) at /usr/local/nagios/libexec/check_file_age line 30. 
HTTP
Notifications for this service have been disabled
OK  09-09-2015 14:30:53 0d 4h 3m 30s    1/4 

How do I specify what arguments to pass? How do I correct the error? What's next? (Is there a single location that describes how to add a plugin that escaped my Google-fu?)

3

3 Answers

5
votes

Issue 1:

The check_file_age plugin is a perl script that requires another perl module called utils.pm. Are they both in the same folder? If not, find the location of utils.pm:

find / -name "utils.pm" -type f

You will need to add the path of the folder containing utils.pm to your $PERL5LIB environment variable for your nagios user or whatever user is running the nagios daemon service.

Take the path to the folder of utils.pm and add it to a shell script that we'll place in the /etc/profile.d/ folder. For example, if the results of your find command were /usr/local/nagios/libexec/utils.pm then execute something like this:

echo "export PERL5LIB=$PERL5LIB:/usr/local/nagios/libexec" >> /etc/profile.d/nagiosplugins.sh
chmod a+x /etc/profile.d/nagiosplugins.sh
source /etc/profile

With any luck, that should take care of the Can't locate utils.pm in @INC error.

Issue 2:

You need to fix your service definition to pass in the expected arguments to check_file_age. Arguments passed into the check_command field of the service definition follow the command name and are delimited by ! exclamation points. Modify the File age service definition in /usr/local/nagios/etc/objects/localhost.cfg to look something like this:

define service {
    use             generic-service     ; Name of service template to use
    host_name           localhost
    service_description     File Age
    check_command           check_file_age!3600!5400!200!100!somefile.txt
    notifications_enabled       1
}

Ok, now time to verify your configuration files don't have any errors in them:

nagios -v /usr/local/nagios/etc/nagios.cfg

(...or whatever is the correct path to your nagios.cfg file)

If there are no errors, restart your nagios service:

service nagios restart
1
votes

On CentOS 6.9 I could fix the problem by reinstalling the rpm package which provides the file:

yum reinstall /usr/lib64/nagios/plugins/utils.pm

1
votes

You can find the first part of the answer here in your logs:

(No output on stdout) stderr: Can't locate utils.pm in @INC (you may need to install the utils module) (@INC contains: . /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl) at /usr/local/nagios/libexec/check_file_age line 30. 

You need to make sure the default user macro $USER1 is correct, it contains the path to your plugins. Per the Nagios documentation:

Defining A User Macro

User macros can be defined in resource.cfg, a configuration file that can be found at /usr/local/nagios/etc/. By default, your resource.cfg should contain:

# Path to the plugins
$USER1$=/usr/local/nagios/libexec

On CentOS 7 I had to change the path to /usr/libexec/nagios and the same error went away.