启动日志

  1. [root@bjyh-48-86 nagios]# cat nagios.log
  2. [1433471109] Nagios 4.1.0rc1 starting... (PID=5136)
  3. [1433471109] Local time is Fri Jun 05 10:25:09 CST 2015
  4. [1433471109] LOG VERSION: 2.0
  5. [1433471109] qh: Socket '/var/nagios/rw/nagios.qh' successfully initialized
  6. [1433471109] qh: core query handler registered
  7. [1433471109] nerd: Channel hostchecks registered successfully
  8. [1433471109] nerd: Channel servicechecks registered successfully
  9. [1433471109] nerd: Channel opathchecks registered successfully
  10. [1433471109] nerd: Fully initialized and ready to rock!
  11. [1433471109] wproc: Successfully registered manager as @wproc with query handler
  12. [1433471109] wproc: Registry request: name=Core Worker 5141;pid=5141
  13. [1433471109] wproc: Registry request: name=Core Worker 5140;pid=5140
  14. [1433471109] wproc: Registry request: name=Core Worker 5139;pid=5139
  15. [1433471109] wproc: Registry request: name=Core Worker 5138;pid=5138
  16. [1433471109] Warning: Service 'icmp' on host 'bjyh-48-86' has no notification time period defined!
  17. # 注意 qh & nerd & wproc

格式

  1. @service command\0
  2. @service 服务名,使用@做为前缀
  3. command 命令参数
  4. \0 结束符,表示命令结束

测试

  1. echo -e '@echo Query handler is working properly!\0' | nc -U /var/nagios/rw/nagios.qh
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8; py-indent-offset: 4 -*-
  3. import socket, sys, os
  4. nagios_qh = '/var/nagios/rw/nagios.qh'
  5. message = 'Test Message!'
  6. s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  7. s.connect(nagios_qh)
  8. s.sendall('@echo ' + message + '\0')
  9. results = s.recv(len(message))
  10. s.close()
  11. print type(results), results
  1. # python test.py
  2. <type 'str'> Test Message!

@core

  1. @core服务,获取和配置nagios process相关信息

@core squeuestats

  1. @core squeuestats\0
  2. 查询queue of scheduled jobs的信息
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8; py-indent-offset: 4 -*-
  3. import socket, sys, os
  4. nagios_qh = '/var/nagios/rw/nagios.qh'
  5. s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  6. s.connect(nagios_qh)
  7. s.sendall('@core squeuestats\0')
  8. result = ''
  9. while True:
  10. b = s.recv(1)
  11. if ord(b) == 0:
  12. break
  13. result += b
  14. s.close()
  15. # chr()函数用一个范围在range(256)内的整数作参数,返回一个对应的字符。unichr()跟它一样,只不过返回的是Unicode字符
  16. # ord()函数是chr()函数(对于8位的ASCII字符串)或unichr()函数(对于Unicode对象)的配对函数.
  17. # 以一个字符(长度为1的字符串)作为参数,返回对应的ASCII数值,或者Unicode数值,
  18. result = sorted(result.split(";"))
  19. print "\n".join(result)
  20. # The code connects to the Nagios socket, sends the @core squeuestats command, and reads the response until the \0 character is sent.
  1. # python test2.py
  2. CHECK_PROGRAM_UPDATE=1
  3. CHECK_REAPER=1
  4. COMMAND_CHECK=0
  5. EXPIRE_COMMENT=0
  6. EXPIRE_DOWNTIME=0
  7. HFRESHNESS_CHECK=0
  8. HOST_CHECK=2
  9. LOG_ROTATION=1
  10. ORPHAN_CHECK=1
  11. PROGRAM_RESTART=0
  12. PROGRAM_SHUTDOWN=0
  13. RESCHEDULE_CHECKS=0
  14. RETENTION_SAVE=1
  15. SCHEDULED_DOWNTIME=0
  16. SERVICE_CHECK=2
  17. SFRESHNESS_CHECK=1
  18. SLEEP=0
  19. SQUEUE_ENTRIES=11
  20. STATUS_SAVE=1
  21. USER_FUNCTION=0

@core loadctl

  1. 获取和配置load control settings的值
  2. @core loadctl
  3. @core loadctl setting=value
  4. @core loadctl setting1=value1;setting2=value2;...
  5. # The load control settings are Nagios internal settings, we do not recommend that you modify them unless needed.
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8; py-indent-offset: 4 -*-
  3. import socket, sys, os
  4. nagios_qh = '/var/nagios/rw/nagios.qh'
  5. s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  6. s.connect(nagios_qh)
  7. s.sendall('@core loadctl\0')
  8. result = ''
  9. while True:
  10. b = s.recv(1)
  11. if ord(b) == 0:
  12. break
  13. result += b
  14. s.close()
  15. result = sorted(result.split(";"))
  16. print "\n".join(result)
  1. # python test3.py
  2. backoff_change=4723
  3. backoff_limit=2.50
  4. changes=0
  5. jobs_limit=15745
  6. jobs_max=15745
  7. jobs_min=20
  8. jobs_running=0
  9. load=0.00
  10. nofile_limit=65535
  11. nproc_limit=15845
  12. options=0
  13. rampup_change=1180
  14. rampup_limit=0.80

@nerd

  1. # NERD (Nagios Event Radio Dispatcher),允许订阅service or host check results
  2. @nerd list\0
  3. @nerd subscribe <channel>\0
  4. @nerd unsubscribe <channel>\0
  5. # echo -e '@nerd list\0' | nc -U /var/nagios/rw/nagios.qh
  6. hostchecks Host check results
  7. servicechecks Service check results
  8. opathchecks Host and service checks in gource s log format
  9. # hostchecks & servicechecks channels 接收主机及服务状态的更新信息,以行结束符\n分隔。
  10. 格式如下:
  11. 主机 <hostname> from <old_code> -> <new_code>: <description>
  12. 服务 <hostname>;<servicename> from <old_code> -> <new_code>: <description>
  13. # host exit code:
  14. 0 UP
  15. 1 DOWN
  16. 2 UNREACHABLE
  17. # service exit code:
  18. 0 OK
  19. 1 WARNING
  20. 2 CRITICAL
  21. 3 UNKNOWN
  1. # output
  2. bjyh-48-81;icmp from 0 -> 0: OK - 192.168.48.81: rta 0.511ms, lost 0%|rta=0.511ms;500.000;500.000;0; pl=0%;80;80;; rtmax=0.695ms;;;; rtmin=0.375ms;;;;
  3. bjyh-48-81 from 0 -> 0: OK - 192.168.48.81: rta 0.493ms, lost 0%|rta=0.493ms;500.000;500.000;0; pl=0%;80;80;; rtmax=0.520ms;;;; rtmin=0.464ms;;;;
  4. bjyh-48-87;icmp from 0 -> 2: CRITICAL - 192.168.48.87: rta nan, lost 100%|rta=0.000ms;500.000;500.000;0; pl=100%;80;80;; rtmax=0.000ms;;;; rtmin=0.000ms;;;;
  5. bjyh-48-87 from 0 -> 1: CRITICAL - 192.168.48.87: rta nan, lost 100%|rta=0.000ms;500.000;500.000;0; pl=100%;80;80;; rtmax=0.000ms;;;; rtmin=0.000ms;;;;
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8; py-indent-offset: 4 -*-
  3. import socket
  4. import re
  5. host_status = {'0': 'UP', '1': 'DOWN', '2': 'UNREACHABLE'}
  6. service_status = {'0': 'OK', '1': 'WARNING', '2': 'CRITICAL', '3': 'UNKNOWN'}
  7. nagios_qh = '/var/nagios/rw/nagios.qh'
  8. s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  9. s.connect(nagios_qh)
  10. s.sendall('@nerd subscribe hostchecks\0')
  11. s.sendall('@nerd subscribe servicechecks\0')
  12. while True:
  13. line = s.recv(1024)
  14. m = re.match('(.*?);(.*?) from ([0-9]+) -> ([0-9]+): (.*)$', line)
  15. if m:
  16. print '[ service ] host: %s, service: %s, check_status: %s, info: %s .' % (m.group(1), m.group(2), service_status[m.group(4)], m.group(5))
  17. else:
  18. m = re.match('(.*?) from ([0-9]+) -> ([0-9]+): (.*)$', line)
  19. print '[ host ] host: %s, check_status: %s, info: %s .' % (m.group(1), host_status[m.group(3)], m.group(4))
  20. s.close()
  1. [ service ] host: bjyh-48-87, service: icmp, check_status: CRITICAL, info: CRITICAL - 192.168.48.87: rta nan, lost 100%|rta=0.000ms;500.000;500.000;0; pl=100%;80;80;; rtmax=0.000ms;;;; rtmin=0.000ms;;;;
  2. [ host ] host: bjyh-48-87, check_status: DOWN, info: CRITICAL - 192.168.48.87: Host unreachable @ 192.168.48.86. rta nan, lost 100%|rta=0.000ms;500.000;500.000;0; pl=100%;80;80;; rtmax=0.000ms;;;; rtmin=0.000ms;;;;
  3. [ host ] host: bjyh-48-85, check_status: UP, info: OK - 192.168.48.85: rta 0.501ms, lost 0%|rta=0.501ms;500.000;500.000;0; pl=0%;80;80;; rtmax=0.608ms;;;; rtmin=0.446ms;;;;
  4. [ service ] host: bjyh-48-83, service: icmp, check_status: OK, info: OK - 192.168.48.83: rta 0.449ms, lost 0%|rta=0.449ms;500.000;500.000;0; pl=0%;80;80;; rtmax=0.505ms;;;; rtmin=0.364ms;;;;

tnagios - query handler的更多相关文章

  1. solr Query[转]

    一. Query参数 1. CoreQueryParam查询的参数 1) q: 查询字符串,必须的. 2) q.op: 覆盖schema.xml的defaultOperator(有空格时用" ...

  2. JS调用JCEF方法

    坐下写这篇文章的时候,内心还是有一点点小激动的,折腾了一个多星期,踩了一个又一个的坑,终于找到一条可以走通的路,内心的喜悦相信经历过的人都会明白~~~~~今儿个老百姓啊,真呀个真高兴啊,哈哈,好了,废 ...

  3. 05 Apache Solr: 管理员界面(Admin UI)

         为了方便管理员和工程师调整Solr的配置和访问在线文档和其他的帮助,Solr提供了一个Web界面去查看Solr的配置详情,运行查询语句和分析文档字段.这个界面在第三篇里面提到过就是管理员界面 ...

  4. Solr调研总结

    http://wiki.apache.org/solr/ Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍solr的功能使用及相关注意事项;主要包括以下内容:环境 ...

  5. Nutch搜索引擎(第2期)_ Solr简介及安装

    1.Solr简介 Solr是一个高性能,采用Java5开发,基于Lucene的全文搜索服务器.同时对其进行了扩展,提供了比Lucene更为丰富的查询语言,同时实现了可配置.可扩展并对查询性能进行了优化 ...

  6. mysql cluster 名词概念解读

    Node Group [number_of_node_groups] = number_of_data_nodes / NoOfReplicas Partition When using ndbd, ...

  7. solr教程,值得刚接触搜索开发人员一看

    http://blog.csdn.net/awj3584/article/details/16963525 Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍sol ...

  8. Solr总结

    http://www.cnblogs.com/guozk/p/3498831.html Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍solr的功能使用及相关注 ...

  9. 【转载】solr教程,值得刚接触搜索开发人员一看

    转载:http://blog.csdn.net/awj3584/article/details/16963525 Solr调研总结 开发类型 全文检索相关开发 Solr版本 4.2 文件内容 本文介绍 ...

随机推荐

  1. linux上传与下载

    首先必须安装xshell这个工具 使用xshell来操作服务非常方便,传文件也比较方便.就是使用rz,sz首先,服务器要安装了rz,szyum install lrzsz当然你的本地windows主机 ...

  2. tomcat使用不同的jdk版本 liunx 装两个jdk

    原作者文章 https://blog.csdn.net/qq_34626097/article/details/83385219 看了原作者学会的!上面链接 因为公司的服务器里面是jdk1.7和tom ...

  3. maven 配置jetty 插件

    <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin ...

  4. svg 日常操作

    创建svg 文件 <svg> </svg> 详解viewBox  SVG Viewport.View Box和preserveAspectRatio 形状  标签内的值可以是百 ...

  5. IP 分段 子网掩码

    子网掩码分网段 例如 200台机器分成4个子网 [ ip 段 ] 200台机器,4个子网,那么就是每个子网50台机器,设定为192.168.10.0,C类的IP,大子网掩码应为255.255.255. ...

  6. Oracle外连接与条件的组合

    由于很少使用SQL 92语法,今天写个outer join的时候被搞晕了.参考了一些例子后整理如下.总结,"inter join on"中的条件是对table进行joining的r ...

  7. msyql操作100题

    1.1.1 开启MySQL服务 /etc/init.d/mysqld start 使用/etc/init.d/mysqld start命令启动数据库的本质就相当于执行mysqld_safe --use ...

  8. Ancoda 下的python多版本共存

    Ancoda 下的python多版本共存 virtualenv python 多版本共存 Pip, Virtualenv 和Fabric 被称为python 的三大神器,Pip 是包管理工具,Virt ...

  9. 使用xUnit为.net core程序进行单元测试

      第1部分: http://www.cnblogs.com/cgzl/p/8283610.html 第2部分: http://www.cnblogs.com/cgzl/p/8287588.html ...

  10. Python数据操作

    列表操作 保存matrix或者保存ndarray 数据类型转换 读取CSV某列 numpy数组写入到csv pandas to_csv 最左边 多一列 的问题 DataFrame对象操作