博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tnagios - query handler
阅读量:5209 次
发布时间:2019-06-14

本文共 6562 字,大约阅读时间需要 21 分钟。

启动日志

[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, osnagios_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 
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, osnagios_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 += bs.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=1CHECK_REAPER=1COMMAND_CHECK=0EXPIRE_COMMENT=0EXPIRE_DOWNTIME=0HFRESHNESS_CHECK=0HOST_CHECK=2LOG_ROTATION=1ORPHAN_CHECK=1PROGRAM_RESTART=0PROGRAM_SHUTDOWN=0RESCHEDULE_CHECKS=0RETENTION_SAVE=1SCHEDULED_DOWNTIME=0SERVICE_CHECK=2SFRESHNESS_CHECK=1SLEEP=0SQUEUE_ENTRIES=11STATUS_SAVE=1USER_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, osnagios_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 += bs.close()result = sorted(result.split(";"))print "\n".join(result)
# python test3.py backoff_change=4723backoff_limit=2.50changes=0jobs_limit=15745jobs_max=15745jobs_min=20jobs_running=0load=0.00nofile_limit=65535nproc_limit=15845options=0rampup_change=1180rampup_limit=0.80

@nerd

# NERD (Nagios Event Radio Dispatcher),允许订阅service or host check results@nerd list\0@nerd subscribe 
\0@nerd unsubscribe
\0# echo -e '@nerd list\0' | nc -U /var/nagios/rw/nagios.qhhostchecks Host check resultsservicechecks Service check resultsopathchecks Host and service checks in gource s log format# hostchecks & servicechecks channels 接收主机及服务状态的更新信息,以行结束符\n分隔。格式如下:主机
from
->
:
服务
;
from
->
:
# host exit code:0 UP1 DOWN2 UNREACHABLE# service exit code:0 OK1 WARNING2 CRITICAL3 UNKNOWN
# outputbjyh-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 socketimport rehost_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;;;;
posted on
2015-06-05 10:31 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/liujitao79/p/4553993.html

你可能感兴趣的文章
配置BeanUtils包,同时也是对导入第三包的步骤说明
查看>>
CodeForces 366C Dima and Salad
查看>>
[转]利用模式窗口:实现子、父窗体的相互传值
查看>>
git命令将本地代码提交到github
查看>>
MS SQL 合并结果集并求和 分类: SQL Server 数据库 ...
查看>>
大型网站架构演化(八)——使用NoSQL和搜索引擎
查看>>
2018牛客网暑假ACM多校训练赛(第三场)D Encrypted String Matching 多项式 FFT
查看>>
Codeforces 542E Playing on Graph 其他
查看>>
iOS10.1不能调试解决方案
查看>>
之前编写的Symfony教程已经可以观看了
查看>>
WPF中资源的引用方法
查看>>
MIME媒体类型
查看>>
使用svc优雅的启用与退出程序
查看>>
oracle之二数据字典表和动态性能视图
查看>>
flex小记
查看>>
HTML基础知识
查看>>
IJ配置项目的TOMCAT
查看>>
@Resource注解
查看>>
PHP基础示例:简单的在线文件管理
查看>>
深度理解微信小程序的思想
查看>>