Config: added apt security updates check
This commit is contained in:
parent
952741a4ec
commit
1b0cbfb27a
@ -205,3 +205,14 @@ COMMAND=nc -z -w 3 192.168.1.123 80 > /dev/null && echo "Online" || echo "Offlin
|
|||||||
DISABLED=True
|
DISABLED=True
|
||||||
ALARM_STRING_EQUAL=Core meltdown!
|
ALARM_STRING_EQUAL=Core meltdown!
|
||||||
COMMAND=echo "Core meltdown!"
|
COMMAND=echo "Core meltdown!"
|
||||||
|
|
||||||
|
|
||||||
|
[security_updates_available]
|
||||||
|
# Checks for security updates via apt (works on Debian and derivatives, like Ubuntu).
|
||||||
|
# Needs the repositories to be updated with `apt update`, but is an heavy command, so it may
|
||||||
|
# be configured to be executed daily in a command in the same cron of healthcheck.
|
||||||
|
# E.g.: place this string in /etc/cron.d/healthcheck, before the healthcheck command:
|
||||||
|
# 1 1 * * * root apt update
|
||||||
|
DISABLED=True
|
||||||
|
ALARM_STRING_EQUAL=security updates available
|
||||||
|
COMMAND=apt list --upgradable 2>/dev/null | grep -e "-security" && echo "security updates available" || echo "NO security updates available"
|
||||||
|
@ -67,7 +67,7 @@ class Main:
|
|||||||
systemLocale = os.getenv('LANG')
|
systemLocale = os.getenv('LANG')
|
||||||
if not systemLocale:
|
if not systemLocale:
|
||||||
raise ValueError('System environment variabile $LANG is not set!')
|
raise ValueError('System environment variabile $LANG is not set!')
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, systemLocale)
|
locale.setlocale(locale.LC_ALL, systemLocale)
|
||||||
|
|
||||||
''' Reads the config '''
|
''' Reads the config '''
|
||||||
@ -143,7 +143,7 @@ class Main:
|
|||||||
return "bad config: COMMAND is mandatory"
|
return "bad config: COMMAND is mandatory"
|
||||||
if not config.regexp:
|
if not config.regexp:
|
||||||
return "bad config: REGEXP is mandatory"
|
return "bad config: REGEXP is mandatory"
|
||||||
|
|
||||||
# Run command
|
# Run command
|
||||||
stdout = ""
|
stdout = ""
|
||||||
ret = subprocess.run(config.command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
ret = subprocess.run(config.command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||||
@ -157,7 +157,7 @@ class Main:
|
|||||||
ret.returncode,
|
ret.returncode,
|
||||||
'and error message "{}"'.format(ret.stderr.decode().strip()) if ret.stderr else ''
|
'and error message "{}"'.format(ret.stderr.decode().strip()) if ret.stderr else ''
|
||||||
)
|
)
|
||||||
|
|
||||||
# Parse result with regex
|
# Parse result with regex
|
||||||
match = re.search(config.regexp, stdout, re.MULTILINE)
|
match = re.search(config.regexp, stdout, re.MULTILINE)
|
||||||
if not match:
|
if not match:
|
||||||
|
Loading…
Reference in New Issue
Block a user