"如何"用于向Nagios添加插件

时间:2015-09-09 19:45:59

标签: linux perl ubuntu nagios

是否有"如何"为Nagios添加和配置插件? (特别是对于Ubuntu 14.04,但任何Linux操作系统都会有所帮助。)

到目前为止,我已经能够拼凑这么多:

  1. 将脚本放在/ usr / local / nagios / libexec /中。 (就我而言,我已经想要使用一个脚本:" check_file_age"。)
  2. 编辑/usr/local/nagios/etc/objects/commands.cfg添加插件。
  3. define command{  
        command_name check_file_age  
        command_line $USER1$/check_file_age -w $ARG1$ -c $ARG2$ -W $ARG3$ -C $ARG4$ -f $ARG5$ 
    }
    1. 在/usr/local/nagios/etc/objects/localhost.cfg中定义插件。
    2. 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
      }

      现在我可以看到"配置 - >下的插件对象类型:命令"我可以看到它列在"配置 - >对象类型:服务"。

      插件从命令行成功运行:

      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

      然后在这一点上,我很难过。我可以在服务中看到这个错误:

      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 

      如何指定要传递的参数?如何更正错误?下一步是什么? (是否有一个位置描述了如何添加一个逃脱Google-fu的插件?)

2 个答案:

答案 0 :(得分:1)

在CentOS 6.9上我可以通过重新安装提供文件的rpm包来解决问题:

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

答案 1 :(得分:0)

您可以在日志中找到答案的第一部分:

(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. 

您需要确保默认的用户宏$USER1是正确的,它包含插件的路径。根据Nagios文档:

定义用户宏

用户宏可以在resource.cfg中定义,/usr/local/nagios/etc/是可以在以下位置找到的配置文件 resource.cfg。默认情况下,您的# Path to the plugins $USER1$=/usr/local/nagios/libexec 应该包含:

/usr/libexec/nagios

在CentOS 7上,我不得不将路径更改为DATE,并且相同的错误消失了。