一个nagios icinga插件,用于检查官方openstreetmap planet的diff延迟。
paulla.checkplanetdiff的Python项目详细描述
内容
Introduction
check_planet.diff是一个“nagios-like”(nagios icinga centreon shinken)探测器,基于微小的diff状态文件,使用office检查osm星球的延迟。
这里有更多信息http://wiki.openstreetmap.org/wiki/Minutely_Mapnik
Install
易于安装pip witthin或不是虚拟机v:
pip install | easy_install paulla.check_planetdiff
用户只需像往常一样将paulla.check_planetdiff添加到您的鸡蛋列表中。
您可以使用以下命令运行安装或测试:
bin/python setup.py install bin/python setup.py test
mayba添加一个从bin/check_planetdiff到nagios/plugins/目录的符号链接
Nagios like configuration
check_planetdiff可以本地调用,也可以通过check_by_ssh或nrpe远程调用。
下面是通过ssh远程检查的示例定义
命令定义
# 'check_ssh_planetdiff' command definition define command { command_name check_ssh_planetdiff command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -C "/usr/lib/nagios/plugins/check_planetdiff -w $ARG1$ -c $ARG2$ --state-file $ARG3$ -p" }
注意,性能数据的最后一个-p参数是可选的,如果不需要,请删除它。
服务本身:
# planet diff delay define service { use paulla-service service_description delay planet diff check_command check_ssh_planetdiff!0.0:3600.0!0.0:21600.0!/home/mapnik/.osmosis/state.txt host_name biscaou }
Nagios like’ synchronise delay OSM Planet check
用例
该检查简单而健壮,没有数据库查询。
delay只是datetime.datetime.utcnow()-state.txt中的osm时间戳(usualy/home/mapnik.personis/state.txt)
这里有更多信息http://wiki.openstreetmap.org/wiki/Minutely_Mapnik
我们用三个不同的时间戳伪造了三个状态文件(参见tests/directory)。
我们现在必须根据测试文件的规定来伪造。
现在=日期时间(2012,10,23,20,4,30)参见测试函数
真正的支票是datetime.datetime.utcnow()
警告和临界阈值分别为3600秒和21600秒(1小时和6小时)
工作时间
必要的东西:
>>> import glob >>> import subprocess >>> from datetime import datetime >>> from pprint import pprint
从伪状态文件中获取行的功能:
>>> def get_lines_from_file(filename): ... with open(filename) as state_file: ... return state_file.read().splitlines() ...
Usage
-H选项
>>> cmd_h = "bin/test_check_planetdiff -h" >>> p_help = subprocess.Popen(cmd_h.split(), stdout=subprocess.PIPE) >>> pprint(p_help.stdout.readlines()) ['Usage: test_check_planetdiff [options]\n', '\n', 'Options:\n', ' --state-file=STATEFILE\n', ' -p return performance data\n', ' -v, --verbose \n', ' -H HOSTNAME, --hostname=HOSTNAME\n', ' -w WARNING, --warning=WARNING\n', ' -c CRITICAL, --critical=CRITICAL\n', ' -t TIMEOUT, --timeout=TIMEOUT\n', ' -h, --help show this help message and exit\n']
Checks
少于1小时返回正常:
>>> state_file_ok = "src/paulla/checkplanetdiff/tests/state_ok.txt" >>> pprint(get_lines_from_file(state_file_ok)) ['#Tue Oct 23 22:05:12 CEST 2012', 'sequenceNumber=59592', 'timestamp=2012-10-23T20\\:04\\:02Z'] >>> cmd_ok = "bin/test_check_planetdiff -w 0.0:3600.0 -c 0.0:21600.0 --state-file %s" % state_file_ok >>> p_ok = subprocess.Popen(cmd_ok.split(), stdout=subprocess.PIPE)
状态代码为0->;确定:
>>> p_ok.wait() 0
字符串输出:
>>> p_ok.stdout.read() 'OK: delay : 28, sequence number : 59592\n'
使用perfdata选项:
>>> cmd_ok = "bin/test_check_planetdiff -w 0.0:3600.0 -c 0.0:21600.0 --state-file %s -p" % state_file_ok >>> p_ok = subprocess.Popen(cmd_ok.split(), stdout=subprocess.PIPE) >>> p_ok.stdout.read() 'OK: delay : 28, sequence number : 59592|delayed=28s;3600;21600;;\n'
1小时到6小时之间的延迟返回警告:
>>> state_file_warn = "src/paulla/checkplanetdiff/tests/state_warning.txt" >>> pprint(get_lines_from_file(state_file_warn)) ['#Tue Oct 23 18:25:07 CEST 2012', 'sequenceNumber=59372', 'timestamp=2012-10-23T16\\:24\\:03Z'] >>> cmd_warn = "bin/test_check_planetdiff -w 0.0:3600.0 -c 0.0:21600.0 --state-file %s" % state_file_warn >>> p_warn = subprocess.Popen(cmd_warn.split(), stdout=subprocess.PIPE)
状态代码为1->;警告:
>>> p_warn.wait() 1
字符串输出:
>>> p_warn.stdout.read() 'WARN: delay : 13227, sequence number : 59372\n'
使用perfdata选项:
>>> cmd_warn = "bin/test_check_planetdiff -w 0.0:3600.0 -c 0.0:21600.0 --state-file %s -p" % state_file_warn >>> p_warn = subprocess.Popen(cmd_warn.split(), stdout=subprocess.PIPE) >>> p_warn.stdout.read() 'WARN: delay : 13227, sequence number : 59372|delayed=13227s;3600;21600;;\n'
超过6小时返回临界值:
>>> state_file_crit = "src/paulla/checkplanetdiff/tests/state_critical.txt" >>> pprint(get_lines_from_file(state_file_crit)) ['#Tue Oct 23 12:25:07 CEST 2012', 'sequenceNumber=59012', 'timestamp=2012-10-23T10\\:24\\:03Z'] >>> cmd_crit = "bin/test_check_planetdiff -w 0.0:3600.0 -c 0.0:21600.0 --state-file %s" % state_file_crit >>> p_crit = subprocess.Popen(cmd_crit.split(), stdout=subprocess.PIPE)
状态代码为2->;严重:
>>> p_crit.wait() 2
字符串输出:
>>> p_crit.stdout.read() 'CRIT: delay : 34827, sequence number : 59012\n'
使用perfdata选项:
>>> cmd_crit = "bin/test_check_planetdiff -w 0.0:3600.0 -c 0.0:21600.0 --state-file %s -p" % state_file_crit >>> p_crit = subprocess.Popen(cmd_crit.split(), stdout=subprocess.PIPE) >>> p_crit.stdout.read() 'CRIT: delay : 34827, sequence number : 59012|delayed=34827s;3600;21600;;\n'
非存在状态文件返回临界值:
>>> cmd_crit_non_exist_file = "bin/test_check_planetdiff -w 0.0:3600.0 -c 0.0:21600.0 --state-file src/non_existant.txt" >>> p_crit_nonexist = subprocess.Popen(cmd_crit_non_exist_file.split(), stdout=subprocess.PIPE)
状态代码为2->;严重:
>>> p_crit_nonexist.wait() 2
字符串输出:
>>> p_crit_nonexist.stdout.read() 'CRIT: delay : 21601, sequence number : 0\n'
使用perfdata选项:
>>> cmd_crit_non_exist_file = "bin/test_check_planetdiff -w 0.0:3600.0 -c 0.0:21600.0 --state-file src/non_existant.txt -p" >>> p_crit_nonexist = subprocess.Popen(cmd_crit_non_exist_file.split(), stdout=subprocess.PIPE) >>> p_crit_nonexist.stdout.read() 'CRIT: delay : 21601, sequence number : 0|delayed=21601s;3600;21600;;\n'
Changelog
0.4 (2012-10-27)
- 修复自述错误
0.3 (2012-10-27)
- 什么都没变。
0.2 (2012-10-27)
- 改进帮助的使用和相应的测试
0.1 (2012-10-26)
- 在http://www.paulla.asso.org生产中使用的第一个版本 [让-菲利普•卡姆吉勒姆]
Contributors
Jean-Philippe Camguilhem,作者