启动日志

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

格式

@service command\0

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

测试

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

@core

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

@core squeuestats

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

@core loadctl

获取和配置load control settings的值

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

@nerd

# NERD (Nagios Event Radio Dispatcher),允许订阅service or host check results
@nerd list\0
@nerd subscribe <channel>\0
@nerd unsubscribe <channel>\0 # echo -e '@nerd list\0' | nc -U /var/nagios/rw/nagios.qh
hostchecks Host check results
servicechecks Service check results
opathchecks Host and service checks in gource s log format # hostchecks & servicechecks channels 接收主机及服务状态的更新信息,以行结束符\n分隔。
格式如下:
主机 <hostname> from <old_code> -> <new_code>: <description>
服务 <hostname>;<servicename> from <old_code> -> <new_code>: <description> # host exit code:
0 UP
1 DOWN
2 UNREACHABLE # service exit code:
0 OK
1 WARNING
2 CRITICAL
3 UNKNOWN
# output
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;;;; 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;;;; 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;;;; 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;;;;
#!/usr/bin/env python
# -*- encoding: utf-8; py-indent-offset: 4 -*- import socket
import re host_status = {'0': 'UP', '1': 'DOWN', '2': 'UNREACHABLE'}
service_status = {'0': 'OK', '1': 'WARNING', '2': 'CRITICAL', '3': 'UNKNOWN'} nagios_qh = '/var/nagios/rw/nagios.qh' s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(nagios_qh)
s.sendall('@nerd subscribe hostchecks\0')
s.sendall('@nerd subscribe servicechecks\0') while True:
line = s.recv(1024) m = re.match('(.*?);(.*?) from ([0-9]+) -> ([0-9]+): (.*)$', line)
if m:
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))
else:
m = re.match('(.*?) from ([0-9]+) -> ([0-9]+): (.*)$', line)
print '[ host ] host: %s, check_status: %s, info: %s .' % (m.group(1), host_status[m.group(3)], m.group(4)) s.close()
[ 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;;;;
[ 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;;;;
[ 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;;;;
[ 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. zabbix监控java内存的脚本

    #!/bin/bash # 截取java的pid号 java_pid=`netstat -lnpt |grep |awk -F '/' '{print $1'}` # 截取$jstat命令的位置 js ...

  2. ARM,CPU相关概念

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 相关链接: ARM内核和架构都是什么意思,它们到底是什么关系?:ht ...

  3. 页面布局常用,让子级div排排坐

    画页面的时候经常遇到页面布局的问题,父级div包裹多个子div很常见,代码如下: <div> <div style='width:100px;height: 100px;backgr ...

  4. hau1021 Fibonacci Again(递归)

    Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. Jupyter notebook介绍以及安装

    一.Jupyter介绍 Jupyter Notebook是以web交互式的编程接口,是IPython notebook的升级版本.主要是针对python,另外支持运行 40 多种编程语言.Jupyte ...

  6. tomcat+nginx+memcache

    tomcat安装 tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/ cd /usr/local/ ln -s jdk1.7.0_79/ java ]# ...

  7. 在IntelliJ IDEA中配置Google Java Code Style及代码格式化快捷键

    google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...

  8. 在Pycharm上编写WordCount程序

    本篇博客将给大家介绍怎么在PyCharm上编写运行WordCount程序. 第一步 下载安装PyCharm 下载Pycharm PyCharm的下载地址(Linux版本).下载完成后你将得到一个名叫: ...

  9. jconsole如何查看

    https://www.jdon.com/idea/jvm-gc.html 场景: https://www.cnblogs.com/yszzu/p/9648579.html    查看大对象到底占用多 ...

  10. Java升级替换java version "1.5.0"

    首先进行java安装 http://www.cnblogs.com/someone9/p/8670585.html 2. 然后查看版本信息,仍然是1.5.0 [root@OKC java]# java ...