The following patch would add a script to check for the age of the mirrorlist servers. If somebody could add the necessary nagios configuration to let this run against the proxies I would add this script to the repository.
The script makes it easy to verify that the mirrorlist containers have up-to-date data:
$ ./check_mirrorlist_pkl_age.py 02 3000 5000 WARN: mirrorlist data on proxy02 older than 3000s (3894s)
Is this a check that would make sense for the current Nagios setup? We probably need to figure out the right values for warning and critical.
Adrian
The following script can be used for nagios to contact the mirrolist servers and query the age of the pickle currently loaded.
This output of the script looks like this:
$./check_mirrorlist_pkl_age.py 02 3000 5000 WARN: mirrorlist data on proxy02 older than 3000s (3894s)
$ ./check_mirrorlist_pkl_age.py 14 5000 7000 OK: up-to-date mirrorlist data on proxy14 (3921s)
$ ./check_mirrorlist_pkl_age.py 08 2000 3000 CRIT: mirrorlist data on proxy08 older than 3000s (3938s)
Signed-off-by: Adrian Reber adrian@lisas.de --- .../nagios/plugins/check_mirrorlist_pkl_age.py | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 roles/nagios_server/files/nagios/plugins/check_mirrorlist_pkl_age.py
diff --git a/roles/nagios_server/files/nagios/plugins/check_mirrorlist_pkl_age.py b/roles/nagios_server/files/nagios/plugins/check_mirrorlist_pkl_age.py new file mode 100755 index 000000000..2aa5bb2ca --- /dev/null +++ b/roles/nagios_server/files/nagios/plugins/check_mirrorlist_pkl_age.py @@ -0,0 +1,96 @@ +#!/usr/bin/python3 +# +# Script to check the age of the data used by the mirrorlist servers. +# +# Fedora's mirrorlist server are using a python pkl which has the creation +# date embedded. Querying the mirrorlist interface with '&time' returns +# that timestamp: +# +# '# database creation time: <timestamp>' +# +# This script connects to the specified proxy and reads out that value +# and compares it with a warning and critical threshold. +# +# Tested with python2 and python3 +# +# Requires python[2,3]-requests +# +# Usage: +# check_mirrorlist_pkl_age.py <proxy-number> <warning> <critical> +# check_mirrorlist_pkl_age.py 12 3600 7200 +# +# Author: Adrian Reber adrian@lisas.de + +import requests +import sys +import time +import datetime + +if len(sys.argv) != 4: + print("Usage:") + print(" %s needs 3 parameters\n" % sys.argv[0]) + print(" %s <proxy-number> <warning> <critical>" % sys.argv[0]) + print(" %s 12 3600 7200" % sys.argv[0]) + sys.exit(3) + +proxy = sys.argv[1] +warn = int(sys.argv[2]) +crit = int(sys.argv[3]) + +check_url = 'http://proxy%s.fedoraproject.org/' % proxy +check_url += 'mirrorlist?repo=fedora-rawhide&arch=x86_64&time' + +headers = {'Host': 'mirrors.fedoraproject.org'} + +try: + r = requests.get(check_url, headers=headers) +except: + print('CRIT: getting data from proxy%s failed' % proxy) + sys.exit(2) + + +if r.status_code != 200: + print('CRIT: unexpected response (not 200) from proxy%s' % proxy) + sys.exit(2) + +for line in r.iter_lines(): + if b'database creation time' not in line: + continue + + ts = 0 + now = 0 + try: + time_from_proxy = line.decode().split(': ')[1:][0] + ts = datetime.datetime.strptime( + time_from_proxy, + '%Y-%m-%d %H:%M:%S.%f' + ) + ts = int(time.mktime(ts.timetuple())) + + now = datetime.datetime.utcnow() + now = int(time.mktime(now.timetuple())) + + except: + print('CRIT: failure parsing result from proxy%s' % proxy) + sys.exit(2) + + if (len == 0) or (now == 0): + print('CRIT: failure parsing result from proxy%s' % proxy) + sys.exit(2) + + age = int(now - ts) + + if age > crit: + print( + 'CRIT: mirrorlist data on proxy%s older than %ds (%ds)' % + (proxy, crit, age)) + sys.exit(2) + + if age > warn: + print( + 'WARN: mirrorlist data on proxy%s older than %ds (%ds)' % + (proxy, warn, age)) + sys.exit(1) + + print('OK: up-to-date mirrorlist data on proxy%s (%ds)' % (proxy, age)) + sys.exit(0)
infrastructure@lists.fedoraproject.org