Nagios 插件编写
2014-07-04 08:53
197 查看
脚本编写步骤
1、nagios插件编写规范
Nagios的插件可以用脚本(shell、Perl、python等)C编译后的可执行程序,但必须满足以下两件事:
a、退出时有一个返回值
b、至少向标准输出设备(STDOUT)输出一行文件。(但也不能太大,默认是4K )
Plugin Return Codes(具体参考官网 http://nagios-plugins.org/doc/guidelines.html#PREFACE)
下面是一个插件,就输出一句话:
#!/usr/bin/perl -w
my(%ERRORS) = ( OK=>0, WARNING=>1, CRITICAL=>2, UNKNOWN=>3 );
my $status=$ERRORS{OK};;
if( 1 ) {
print "OK,it's 1.";
exit $status;
}
写完脚本之后,要修改它的执行权限:chmod a+x 文件名
// 注意文件有后缀名的别忘了,要文件全称。
使用 Nagios 进行注册:
在 command.cfg中添加命令:(或者在
}
最后创建一个插件的服务:
define service{
host_name localhost
service_description zccheck-disk
check_command zccheck_disk
max_check_attempts 5
normal_check_interval 5
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
这样这个插件就可以显示在网页上了。
1、nagios插件编写规范
Nagios的插件可以用脚本(shell、Perl、python等)C编译后的可执行程序,但必须满足以下两件事:
a、退出时有一个返回值
b、至少向标准输出设备(STDOUT)输出一行文件。(但也不能太大,默认是4K )
Plugin Return Codes(具体参考官网 http://nagios-plugins.org/doc/guidelines.html#PREFACE)
Numeric Value | Service Status | Status Description |
---|---|---|
0 | OK | The plugin was able to check the service and it appeared to be functioning properly |
1 | Warning | The plugin was able to check the service, but it appeared to be above some "warning" threshold or did not appear to be working properly |
2 | Critical | The plugin detected that either the service was not running or it was above some "critical" threshold |
3 | Unknown | Invalid command line arguments were supplied to the plugin or low-level failures internal to the plugin (such as unable to fork,or open a tcp socket) that prevent it from performing the specifiedoperation. Higher-level errors (such as name resolution errors,socket timeouts, etc) are outside of the control of plugins and shouldgenerally NOT be reported as UNKNOWN states. |
#!/usr/bin/perl -w
my(%ERRORS) = ( OK=>0, WARNING=>1, CRITICAL=>2, UNKNOWN=>3 );
my $status=$ERRORS{OK};;
if( 1 ) {
print "OK,it's 1.";
exit $status;
}
写完脚本之后,要修改它的执行权限:chmod a+x 文件名
// 注意文件有后缀名的别忘了,要文件全称。
使用 Nagios 进行注册:
在 command.cfg中添加命令:(或者在
/etc/nagios-plugins/config/ 目录下创建一个文件,例如mygetloadavg2.cfg,内容和下面一样)
define command{
command_name zccheck_disk
command_line /usr/lib/nagios/plugins/zccheck_disk.pl[code]mygetloadavg2.cfg
}
最后创建一个插件的服务:
define service{
host_name localhost
service_description zccheck-disk
check_command zccheck_disk
max_check_attempts 5
normal_check_interval 5
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
这样这个插件就可以显示在网页上了。
相关文章推荐
- Nagios插件编写及调试方法(shell)
- 如何编写 Nagios 插件
- nagios 插件编写:检查磁盘状况
- 自己编写Nagios 监控Mysql插件
- 【8】nagios从零学习使用 - 编写自己的nagios插件
- 用php编写Nagios插件
- 关于nagios系统下使用shell脚本自定义监控插件的编写
- Shell脚本编写Nagios插件监控程序资源占用
- 关于nagios系统下使用shell脚本自定义监控插件的编写
- 为Nagios编写自己的插件
- 如何编写nagios插件
- Nagios插件编写及调试方法(个人经验版)
- nagios 安全设置、插件编写
- Nagios插件编写及调试方法
- 用 Python 编写一个nagios监控磁盘负载的插件
- Shell脚本编写Nagios插件监控程序资源占用
- nagios插件编写及使用nrpe执行root命令
- 如何编写 Nagios 插件 (http://zener.blog.51cto.com/937811/727685)
- nagios3 添加Python编写的插件
- 通过自己编写的插件来使用 Nagios