×

扫描二维码登录本站

QQ登录

只需一步,快速开始

nagios之passive_check

标签: 暂无标签
来自:网络



title: “nagios/passive_check”术语被动模式工作原理:原理图优缺点nagios 配置被动检测提交的格式:通过外部命令文件提交结果nrdp 的提交方式通过mod_gearman提交结果参考

layout: post
title: “nagios/passive_check”术语                          nagios培训

  • 被监控机(MC:Monitor Client)
  • 监控机 (MS:Monitor Server)
被动模式工作原理:在被 MC 上面,使用nagios-plugins提供的插件,得出监数据,将数据发送到 MS 端,MS上面运行的daemon(常见的是nsca,或 nrdp,mod_gearman )用来接收这些数据,按照预定义的格式传递给nagios,nagios核心进程将会对数据进行处理(前台展示,警报)。

  • nsca 插件采用的是将检测结果写入外部命令文件,该文件是一个管道文件,也是nagios主程序的一个接口(用来接收监控数据),(ubuntu14.04 nagios 默认配置是 “/var/lib/nagios3/rw/nagios.cmd”);
  • nrdp 插件除了将检测结果写入外部命令文件,还可以将检测结果直接写入到Nagios内核的spool目录,(ubuntu14.04 nagios 默认配置是 “/var/lib/nagios3/spool/checkresults”);
  • mod_gearman 使用事件代理模式,会将结果注入nagios结果环形缓冲区数据结构中,不会被FIFO的IO限制
原理图
优缺点优点:相比与主动模式,被动模式能很大程度地降低nagios负载
缺点:当监控的主机规模进一步扩大,会被"外部命令文件"I/O局限所拖累,(事件代理模式除外)
nagios 配置注意:(本文是ubuntu14.04为基础环境,创建被动模式的配置,以下分别用术语中定义的简称 MS,MC)             nagios实施

  • 开启被动监控
/etc/nagios3/nagios.cfg
check_external_commands = 1  (enable  commands  file) # 允许检测结果写入外部命令文件command_check_interval = -1  (check  the  external  command file as often as possible)

  • 定被模板
添加模板,修改配置文件 template.cfg,添加如下内容:
define service{        name                         passive_service        use                          generic-service        max_check_attempts           1        active_checks_enabled        0 #(关闭主动检测)        passive_checks_enabled       1 #(开启被动检测)        normal_check_interval        5        retry_check_interval         1        check_freshness              1 # (开启强制刷新)        notifications_enabled        1        notification_interval        5        notification_period          24x7        contact_groups               admins        register                     0 #(必须)           }

  • 定义被动监控指令
/etc/nagios3/commands.cfg
define command {    command_name check_dummy    command_line /usr/lib/nagios/plugins/check_dummy $ARG1$ $ARG2$}check_dummy指令实际上不检查任何东西,指定两个参数,一个是状态,一个是输出,始终返回这两个参数。                   监控软件
# /usr/lib/nagios/plugins/check_dummy 0 successfulOK: successful# /usr/lib/nagios/plugins/check_dummy 1 failedWARNING: failed# /usr/lib/nagios/plugins/check_dummy 2 failedCRITICAL: failed# /usr/lib/nagios/plugins/check_dummy 3 failedUNKNOWN: failed

  • 定义要被动监控的主机
define service {        use                             passive_service        host_name                       localhost        service_description             check_disk_passive        freshness_threshold             86400 # 主服务端强制刷新的时间(s)        check_command check_dummy!1!"Check failed No return data for 24 hours}被动检测提交的格式:主机检测格式:    [<timestamp>] PROCESS_HOST_CHECK_RESULT;<host_name>;<host_status>;<plugin_output>timestamp:                unix时间戳PROCESS_HOST_CHECK_RESULT  外部命令host_name:                监控的主机地址host_status:              主机的状态( 0 = OK,1 = WARNING,2 =CRITICAL,3 = UNKNOWN)plugin_output:            主机检查的文本输出服务检测格式:    [<timestamp>] PROCESS_SERVICE_CHECK_RESULT;<host_name>;<svc_description>;<return_code>;<plugin_output>timestamp:                   unix时间戳PROCESS_SERVICE_CHECK_RESULT  外部命令host_name:                   监控的主机地址svc_description:             服务的描述名称(与nagios服务端配置定义的必须一致)return_code:                 服务的状态( 0 = OK,1 = WARNING,2 =CRITICAL,3 = UNKNOWN)plugin_output:               主机检查的文本输出如:通过外部命令文件提交结果外部应用程序可以通过向外部命令文件写入检测结果:
# echo "[`date +%s`] PROCESS_HOST_CHECK_RESULT;mc_hostname;0;ping is ok" >> /var/lib/nagios3/rw/nagios.cmd# echo "[`date +%s`] PROCESS_SERVICE_CHECK_RESULT;mc_hostname;check_ssh_passive;0;test is ok " >> /var/lib/nagios3/rw/nagios.cmdnrdp 的提交方式外部应用程序可以向 Nagios内核的spool目录写入存放检测结果的文件(ubuntu14.04 nagios 默认配置是 “/var/lib/nagios3/spool/checkresults”):
主机检测结果文件:cpjCd4i
### NRDP Check ###start_time=1415871546.0# Time: Thu, 13 Nov 2014 09:39:06 +0000host_name=cdn-gc-      nagios配置
### NRDP Check ###start_time=1415871546.0# Time: Thu, 13 Nov 2014 09:39:06 +0000host_name=cdn-gc-dongguan1service_description=SSHcheck_type=1early_timeout=1exited_ok=1return_code=1output=WARNING: Danger Will Robinson!|perfdata\n通过mod_gearman提交结果当nagios加载 broker_module=/usr/lib/mod_gearman/mod_gearman.o 后,会在gearman-job-server中创建一个名为check_results 的任务队列,client请求任务,worker 处理后,最终将结果写入check_results 的任务队列,mod_gearman.o 取回结果传递给nagios核心进程,完成一次任务的分发处理。
以python_gearman 编程接口为例,(这货貌似好久没有更新了,也不支持加密传输)                         开源监控软件
#!/usr/bin/env pythonimport gearmangm_client = gearman.GearmanClient(['localhost:4730'] )completed_job_request = gm_client.submit_job("check_results", "type=passive host_name=cdn-tx-wuhan-ctc3 core_start_time=1415807730.0 start_time=1415807730.19546  finish_time=1415807730.105364 return_code=2 exited_ok=0 output=PING_OK\n")mod_gearman C源码片断
gearman_util.c
提交结果的主要部分:add_job_to_queue(...) {   task = gearman_client_add_task_low_background( client, NULL, NULL, queue, uniq, ( void * )crypted_data, ( size_t )size, &ret1 );    gearman_task_give_workload(task,crypted_data,size);}          nagios安装

想做Nagios Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流  QQ群号 476809427





上一篇:nagios---nrdp
下一篇:nagios+centreon总结(8)——Centreon 添加nagios检查命令
monicazhang

写了 2297 篇文章,拥有财富 12859,被 21 人关注

您需要登录后才可以回帖 登录 | 立即注册
B Color Link Quote Code Smilies

成为第一个吐槽的人

手机版|小黑屋|最新100贴|论坛版块|ITIL先锋论坛 |粤ICP备11099876号|网站地图
Powered by Discuz! X3.4 Licensed  © 2001-2017 Comsenz Inc.
返回顶部