-
-
Save sts/1465953 to your computer and use it in GitHub Desktop.
CheckMK APT Check v0.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1 WARNING ; 2 CRITICAL | |
apt_repository_severity = { | |
'Debian-Security' : 2, | |
'debian-volatile' : 1, | |
'Unofficial' : 1 | |
} | |
apt_cache_max_age = 3600 | |
def inventory_apt(checkname, info): | |
if len(info) > 0: | |
return [('Upgrades', None)] | |
# the check function (dummy) | |
def check_apt(item, params, info): | |
apt_upgrades = {} | |
level = 0 | |
msg = "" | |
# Parse the agent output | |
mod_time = int(info[0][0]) | |
deb_release = info[1][0] | |
# If there are upgrades available parse them. | |
if len(info) > 2: | |
packages = info[2:] | |
for package in packages: | |
name = package[0] | |
source = package[1].split(' ')[0] | |
# Determine the severity of the situation :-) | |
level = max(level, apt_repository_severity[source]) | |
# Append to list of upgrades | |
if not source in apt_upgrades: | |
apt_upgrades[source] = [] | |
apt_upgrades[source].append(name) | |
for source in apt_upgrades: | |
msg += "%s/%s [%s] " % (source, len(apt_upgrades[source]), ",".join(apt_upgrades[source])) | |
# Determine apt cache age | |
if mod_time > apt_cache_max_age: | |
level = 0 | |
msg = "Package cache is out of date, %s seconds since last update." % mod_time | |
state = { 0 : "OK", | |
1 : "WARNING", | |
2 : "CRITICAL", | |
3 : "UNKNOWN" }.get(level) | |
return (level, "%s - %s" % ( state, msg)) | |
if level > 0: | |
return (level, "%s - %s" % ( state, msg)) | |
else: | |
return (level, state) | |
# declare the check to Check_MK | |
check_info['apt'] = \ | |
(check_apt, "APT", 0, inventory_apt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment