是否有“如何”为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的插件?)
3 回答
第1期:
check_file_age
插件是一个perl脚本,需要另一个名为utils.pm
的perl模块 . 它们都在同一个文件夹中吗?如果没有,找到utils.pm
的位置:您需要将包含
utils.pm
的文件夹的路径添加到您的nagios用户的$PERL5LIB
环境变量或运行nagios守护程序服务的任何用户 .获取utils.pm文件夹的路径,并将其添加到我们将放在
/etc/profile.d/
文件夹中的shell脚本中 . 例如,如果find命令的结果是/usr/local/nagios/libexec/utils.pm
,那么执行如下所示的操作:运气好的话,应该注意
Can't locate utils.pm in @INC
错误 .第2期:
您需要修复服务定义以将预期参数传递给
check_file_age
. 传递到服务定义的check_command
字段的参数遵循命令名称,并由!
感叹号分隔 . 修改/usr/local/nagios/etc/objects/localhost.cfg
中的File age
服务定义,如下所示:好的,现在是时候验证配置文件中没有任何错误:
(...或者是你的nagios.cfg文件的正确路径)
如果没有错误,请重新启动nagios服务:
在CentOS 6.9上,我可以通过重新安装提供文件的rpm包来解决问题:
yum reinstall /usr/lib64/nagios/plugins/utils.pm
您可以在日志中找到答案的第一部分:
您需要确保默认用户宏
$USER1
是正确的,它包含插件的路径 . 根据Nagios文档:定义用户宏
用户宏可以在
resource.cfg
中定义,该配置文件可以在/usr/local/nagios/etc/
找到 . 默认情况下,resource.cfg
应包含:在CentOS 7上,我不得不将路径更改为
/usr/libexec/nagios
,同样的错误消失了 .