livepatch-charmers team mailing list archive
-
livepatch-charmers team
-
Mailing list archive
-
Message #00208
[Merge] ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master
Barry Price has proposed merging ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master.
Commit message:
Clearer check output, and warn if the client output format changes (i.e. if checkState or patchState go away).
Requested reviews:
Livepatch charm developers (livepatch-charmers)
For more details, see:
https://code.launchpad.net/~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm/+merge/355822
--
Your team Livepatch charm developers is requested to review the proposed merge of ~barryprice/canonical-livepatch-charm/+git/canonical-livepatch-charm:master into canonical-livepatch-charm:master.
diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py
index 7878169..60a7821 100755
--- a/files/check_canonical-livepatch.py
+++ b/files/check_canonical-livepatch.py
@@ -51,18 +51,28 @@ def check_status():
with open(livepatch_output_path, 'r') as canonical_livepatch_log:
for line in canonical_livepatch_log:
line = line.strip()
- if 'State:' in line:
+ checkStateFound = False
+ patchStateFound = False
+ if 'checkState:' in line:
+ checkStateFound = True
if 'apply-failed' in line:
err_lines.append('Livepatch failed to apply patches.')
elif 'check-failed' in line:
err_lines.append('Livepatch failed to check the remote service for patches.')
elif 'unknown' in line:
err_lines.append('Livepatch reports an unknown error.')
- elif 'kernel-upgrade-required' in line:
+ elif 'patchState:' in line:
+ patchStateFound = True
+ if 'kernel-upgrade-required' in line:
err_lines.append('A kernel upgrade (and reboot) is required.')
elif 'Machine is not enabled' in line:
err_lines.append('Machine is not enabled.')
+ if not checkStateFound:
+ err_lines.append('Livepatch is not reporting a checkState.')
+ if not patchStateFound:
+ err_lines.append('Livepatch is not reporting a patchState.')
+
if err_lines:
err = " ".join(err_lines)
raise nagios_plugin.CriticalError(err)
@@ -71,6 +81,18 @@ def check_status():
raise nagios_plugin.WarnError(wrn)
+def get_kernel_version():
+ livepatch_output_path = '/var/lib/nagios/canonical-livepatch-status.txt'
+ kernel_version = 'unknown'
+
+ with open(livepatch_output_path, 'r') as canonical_livepatch_log:
+ for line in canonical_livepatch_log:
+ line = line.strip()
+ if '- kernel:' in line:
+ kernel_version = line.split(' ')[2]
+ return kernel_version
+
+
def lsb_release():
"""Return /etc/lsb-release in a dict"""
d = {}
@@ -114,7 +136,8 @@ def main():
else:
nagios_plugin.try_check(check_package_installed)
nagios_plugin.try_check(check_status)
- print("OK - canonical-livepatch seems to be installed and working")
+ kernel_version = get_kernel_version()
+ print("OK - canonical-livepatch is active on kernel {}".format(kernel_version))
##############################################################################
References