是否有向 Nagios 添加和配置插件的“方法”? (特别针对 Ubuntu 14.04,但任何 Linux 操作系统都会有所帮助。)
到目前为止,我已经能够拼凑这么多:
- 将脚本放在/usr/local/nagios/libexec/中。 (在我的例子中,已经有一个我想使用的脚本:“check_file_age”。)
- 编辑/usr/local/nagios/etc/objects/commands.cfg 添加插件。
define command{ command_name check_file_age command_line $USER1$/check_file_age -w $ARG1$ -c $ARG2$ -W $ARG3$ -C $ARG4$ -f $ARG5$ }
- 在/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 }
现在我可以在“配置 -> 对象类型:命令”下看到该插件,并且可以在“配置 -> 对象类型:服务”中看到它。
插件从命令行成功运行:
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 的插件?)
最佳答案
问题 1:
check_file_age
插件是一个 perl 脚本,需要另一个名为 utils.pm
的 perl 模块。它们都在同一个文件夹中吗?如果没有,找到utils.pm
的位置:
find / -name "utils.pm" -type f
您需要将包含 utils.pm
的文件夹路径添加到您的 $PERL5LIB
环境变量中,以供您的 nagios 用户或任何运行 nagios 守护程序服务的用户使用.
获取 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
关于linux - "How To"用于向 Nagios 添加插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32487965/