【问题标题】:"How To" for adding a plugin to Nagios将插件添加到 Nagios 的“操作方法”
【发布时间】:2015-12-05 22:03:49
【问题描述】:

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

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

  1. 将脚本放在 /usr/local/nagios/libexec/ 中。 (就我而言,已经有一个我想使用的脚本:“check_file_age”。)
  2. 编辑 /usr/local/nagios/etc/objects/commands.cfg 以添加插件。
定义命令{
    command_name check_file_age
    命令行 $USER1$/check_file_age -w $ARG1$ -c $ARG2$ -W $ARG3$ -C $ARG4$ -f $ARG5$
}
  1. 在 /usr/local/nagios/etc/objects/localhost.cfg 中定义插件。
定义服务{
    使用通用服务;要使用的服务模板的名称
    主机名本地主机
    service_description 文件年龄
    check_command check_file_age
    通知_启用 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 是 2932 秒和 59 个字节 |年龄=2932s;3600;5400 大小=59B;-1;-1;0

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

文件时代
危急
09-09-2015 14:24:21
0d 0h 32m 1s
3/3
(stdout 上没有输出) stderr: Can't locate utils.pm in @INC(您可能需要安装 utils 模块)(@INC 包含:. /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) 在/usr/local/nagios/libexec/check_file_age 第 30 行。
HTTP
此服务的通知已被禁用
OK 09-09-2015 14:30:53 0d 4h 3m 30s 1/4 

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

【问题讨论】:

    标签: linux perl ubuntu nagios


    【解决方案1】:

    问题 1:

    check_file_age 插件是一个 perl 脚本,它需要另一个名为 utils.pm 的 perl 模块。它们都在同一个文件夹中吗?如果没有,找到utils.pm的位置:

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

    您需要将包含 utils.pm 的文件夹的路径添加到您的 nagios 用户或运行 nagios 守护程序服务的任何用户的 $PERL5LIB 环境变量中。

    获取 utils.pm 文件夹的路径并将其添加到我们将放置在 /etc/profile.d/ 文件夹中的 shell 脚本中。例如,如果您的 find 命令的结果是 /usr/local/nagios/libexec/utils.pm,则执行如下操作:

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

    如果运气好的话,应该可以解决Can't locate utils.pm in @INC 错误。

    问题 2:

    您需要修复您的服务定义以将预期的参数传递给check_file_age。传递到服务定义的check_command 字段的参数跟在命令名称之后,并由! 感叹号分隔。修改/usr/local/nagios/etc/objects/localhost.cfg 中的File age 服务定义,如下所示:

    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
    }
    

    好的,现在是时候验证您的配置文件中没有任何错误:

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

    (...或者你的 nagios.cfg 文件的正确路径)

    如果没有错误,重启你的nagios服务:

    service nagios restart
    

    【讨论】:

    • 优秀的答案。我唯一的疑问是 register 1 不应该是必需的,因为 register is not inherited 和 1 是默认值。
    • 你是对的。刚刚在文档中找到它。更新我的答案。感谢您的提醒!
    • utils.pm 在同一目录中,我将导出添加到 profile.d 没有运气。
    • user@host:/usr/local/nagios/libexec$ ll 总计 7904 drwxrwxr-x 2 nagios nagios 4096 Sep 9 10:54 ./ drwxr-xr-x 9 root root 4096 9 月 8 日 19:43 ../ -rwxr-xr-x 1 nagios nagios 224674 9 月 9 日 10:53 check_apt* -rwxr-xr-x 1 nagios nagios 2309 9 月 9 日 10:53 check_breeze* ... -rwxr-xr- x 1 nagios nagios 3542 9 月 9 日 10:53 check_file_age* ... -rwxr-xr-x 1 nagios nagios 1932 9 月 9 日 10:53 utils.pm* -rwxr-xr-x 1 nagios nagios 2791 9 月 9 日 10:53 utils .sh*
    • 我会将此标记为已解决,但我找到的修复(有点)来自myfreshthoughts.blogspot.com/2008/09/…。我在check_file_age 中将use lib "."; 更改为use lib "/usr/local/nagios/libexec";
    【解决方案2】:

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

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

    【讨论】:

      【解决方案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. 
      

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

      定义用户宏

      可以在resource.cfg 中定义用户宏,该配置文件位于 /usr/local/nagios/etc/。默认情况下,您的 resource.cfg 应包含:

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

      在 CentOS 7 上,我不得不将路径更改为 /usr/libexec/nagios,同样的错误消失了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-29
        • 2015-04-27
        • 1970-01-01
        • 2011-12-10
        相关资源
        最近更新 更多