跳转到主要内容

一个用于检查与官方OpenStreetMap Planet的diff延迟的nagios|icinga插件。

项目描述

简介

check_planet.diff是一个‘Nagios-like’(Nagios|Icinga|Centreon|Shinken)探测器,用于检查您的OSM Planet与官方的延迟,基于基于分钟的diff状态文件。

更多信息请参阅http://wiki.openstreetmap.org/wiki/Minutely_Mapnik

安装

easy_install | pip 在虚拟环境内或外使用

pip install | easy_install paulla.check_planetdiff

zc.buildout用户只需像往常一样将paulla.check_planetdiff添加到您的eggs列表中。

您可以使用以下命令运行安装或测试

bin/python setup.py install
bin/python setup.py test

可能需要从bin/check_planetdiff添加一个符号链接到您的nagios/plugins/目录

Nagios-like配置

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 arg用于性能数据是可选的,如果不需要,请删除。

服务本身

# 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的同步延迟OSM Planet检查

用例

检查简单且健壮,无需数据库查询。

延迟仅为datetime.datetime.utcnow() - 状态.txt中的OSM时间戳(通常是/home/mapnik.osmosis/state.txt)

更多信息请参阅http://wiki.openstreetmap.org/wiki/Minutely_Mapnik

我们伪造了三个具有不同时间戳的状态文件(请参阅tests/目录)。

我们必须根据测试文件的状态伪造现在。

now = datetime(2012, 10, 23, 20, 4, 30) # see test function

实际检查为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()
...

用法

-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']

检查

少于1小时返回OK

>>> 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 -> OK

>>> 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小时之间的延迟返回WARNING

>>> 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 -> WARNING

>>> 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小时返回CRITICAL

>>> 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 -> CRITICAL

>>> 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'

不存在的状态文件返回CRITICAL

>>> 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 -> CRITICAL

>>> 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'

变更日志

0.4 (2012-10-27)

  • 修复README错误

0.3 (2012-10-27)

  • 尚未有任何更改。

0.2 (2012-10-27)

  • 改进帮助用法和相应测试

0.1 (2012-10-26)

致谢

paulla

贡献者

Jean-Philippe Camguilhem,作者

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

paulla.checkplanetdiff-0.4.zip (16.5 kB 查看散列)

上传时间 源代码

支持者