Skip to main content

A nagios|icinga plugin to check diff delay with the official OpenStreetMap Planet.

Project description

.. contents::

Introduction
============


check_planet.diff is a 'Nagios like' (Nagios|Icinga|Centreon|Shinken) probe checking the delay of your OSM Planet with offical, based on minute-diff state files.

More infos here http://wiki.openstreetmap.org/wiki/Minutely_Mapnik


Install
-------

easy_install | pip witthin or not a virtualenv ::

tool paulla.check_planetdiff

zc.buildout users ::

just add paulla.check_planetdiff to your eggs list as usual.

You could simply run tests with::

bin/python setup.py test

Mayba add a symbolic link from bin/check_planetdiff to your nagios/plugins/ directory.



Nagios like configuration
---------------------------

check_planetdiff could be called localy or remotely via check_by_ssh or NRPE.

here a sample definition to check remotely by ssh ::

Command definition ::

# '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"
}

Notice the last -p arg for performance data is optionnal, remove it if don't needed.

the service itself::

# 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
=================================================


Use case


The check is simple and robust, no database query.

Delay is just datetime.datetime.utcnow() - OSM timestamp in state.txt (usaualy /home/mapnik.osmosis/state.txt)

More infos here http://wiki.openstreetmap.org/wiki/Minutely_Mapnik

We fake 3 state files with three different timestamp (see tests/ directory).

We have to fake now according to tests files states.

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

Real check is datetime.datetime.utcnow()

Warning and critical thresholds are respectively 3600 and 21600 seconds (1 and 6 hours)

Time to work

necessary stuff

>>> import glob
>>> import subprocess
>>> from datetime import datetime
>>> from pprint import pprint

::

>>> def print_lines_from_file(filename):
... with open(filename) as state_file:
... return state_file.read().splitlines()
...

Less than 1 hour returns OK
--------------------------------

>>> state_file_ok = "src/paulla/checkplanetdiff/tests/state_ok.txt"
>>> pprint(print_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)

Status code is 0 -> OK

>>> p_ok.wait()
0

String output

>>> p_ok.stdout.read()
'OK: delay : 28, sequence number : 59592\n'

with perfdata option

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

Delay between 1 hour and 6 returns WARNING
-------------------------------------------

>>> state_file_warn = "src/paulla/checkplanetdiff/tests/state_warning.txt"
>>> pprint(print_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)

Status code is 1 -> WARNING

>>> p_warn.wait()
1

String output

>>> p_warn.stdout.read()
'WARN: delay : 13227, sequence number : 59372\n'

with perfdata option

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

More than 6 hours returns CRITICAL
----------------------------------

>>> state_file_crit = "src/paulla/checkplanetdiff/tests/state_critical.txt"
>>> pprint(print_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)

Status code is 2 -> CRITICAL

>>> p_crit.wait()
2

String output

>>> p_crit.stdout.read()
'CRIT: delay : 34827, sequence number : 59012\n'

with perfdata option

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

Non existant state file returns 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)

Status code is 2 -> CRITICAL

>>> p_crit_nonexist.wait()
2

String output

>>> p_crit_nonexist.stdout.read()
'CRIT: delay : 21601, sequence number : 0\n'

with perfdata option

>>> 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.1 (2012-10-26)
----------------

- Firts version used in production at http://www.paulla.asso.org
[Jean-Philippe Camguilhem]



Credits
========
|paulla|_

* `PauLLA <http://www.paulla.asso.fr>`_
* `Contact us <mailto:contact@paulla.asso.fr>`_

.. |paulla| image:: http://www.paulla.asso.fr/logo.png
.. _paulla: http://www.paulla.asso.fr


Contributors
=============
Jean-Philippe Camguilhem, Author

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paulla.checkplanetdiff-0.1.zip (15.4 kB view details)

Uploaded Source

File details

Details for the file paulla.checkplanetdiff-0.1.zip.

File metadata

File hashes

Hashes for paulla.checkplanetdiff-0.1.zip
Algorithm Hash digest
SHA256 775f6d8ed53e5fda0ec6f34fb917202b944b3a383d099ed1b8e9c1491fcfd556
MD5 9759654b5fac0cf09f2eb534ab0647fe
BLAKE2b-256 3ed5dd7bfd9e0cd91cf2f12eb6eacb2fe3c363bf74c322cbaf26ec7c8f30d05a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page