1、工作原理:
相比与主动模式中服务器主动去被监控机上轮询获取监控数据的方式,被动模式则是在被监控机上面通过插件或脚本获取监控数据,然后将数据通过send_nsca发往监控机,最后监控机通过Nsca接收并解析数据,并传递给Nagios。这样做的一个很大的优势就是将除去处理数据的其他工作都放在了被监控机上面(包括了数据的传输),这样就避免了被监控机数量大时,一次轮询时间过长而导致监控反应延迟,这也是被动模式能承担更大监控量的关键。
在MonitorClient上面,使用nagios-plugins提供的插件,得出监控数据,然后将数据存为一个文件,利用输入重定向,通过send_nsca将数据发往MonitorServer。MonitorServer上面运行一个nsca的daemon(默认开启5667端口),用来接收这些数据,然后做一个简单的处理(会和nagios的service文件进行对应,将多余的监控数据排除),然后将数据进行格式的转换,发给nagios的“外部命令文件”(默认配置为“/usr/local/nagios/var/rw/nagios.cmd”在nagios.cfg中定义的)。该文件是一个管道文件,也是nagios主程序的一个接口(用来接收监控数据),使用cat查看该文件时候,会出来经nsca处理后的数据格式。然后nagios主程序对数据进行处理(前台展示,警报)。
2、组成:
Nsca (安装在MonitorServer上,用来接收并解析MonitorClient发来的监控数据,传递给nagios)
Send_nsca(安装在MonitorClient上,用来发送监控数据。)
3、实现过程:
1)、修改nagios配置文件
vim /usr/local/nagios/etc/nagios.cfg
check_external_commands = 1 (enable commands file)
command_check_interval = -1 (check the external command file as often as possible )
2)、添加模板
vim /usr/local/nagios/etc/objects/template.cfg
define service{
name passive_service
use generic-service
max_check_attempts 3
active_checks_enabled 0
passive_checks_enabled 1
normal_check_interval 5
retry_check_interval 1
notifications_enabled 1
notification_interval 5
notification_period 24x7
contact_groups admins
register 0
}
3)、定义一个command
vim /usr/local/nagios/etc/objects/command.cfg
define command{
command_name check_dummy
command_line /usr/local/nagios/libexec/check_dummy $ARG1$
}
4)、定义一台主机需要被监控的服务
vim /usr/local/nagios/etc/objects/XH_DemoTrade.cfg
define service{
use passive_service
host_name XH_DemoTrade
service_description load
check_command check_dummy
contact_groups admins
}
define service{
use passive_service
host_name XH_DemoTrade
service_description disk
check_command check_dummy
contact_groups admins
}
define service{
use passive_service
host_name XH_DemoTrade
service_description logonService_aufront_common
check_command check_dummy
contact_groups admins
}