Merge ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:master into ~livepatch-charmers/charm-canonical-livepatch:master

Proposed by Barry Price
Status: Merged
Approved by: Barry Price
Approved revision: 4e9598e06d7e034548efdc078f57826d4273ec42
Merged at revision: d26a5d4d3281e777bce1fdcdcde5c503d1bc7312
Proposed branch: ~barryprice/charm-canonical-livepatch/+git/canonical-livepatch-charm:master
Merge into: ~livepatch-charmers/charm-canonical-livepatch:master
Diff against target: 76 lines (+11/-11)
1 file modified
files/check_canonical-livepatch.py (+11/-11)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+355975@code.launchpad.net

Commit message

Port Nagios check to python3

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Stuart Bishop (stub) wrote :

Yup

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision d26a5d4d3281e777bce1fdcdcde5c503d1bc7312

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/files/check_canonical-livepatch.py b/files/check_canonical-livepatch.py
index a40936a..0d2a1a3 100755
--- a/files/check_canonical-livepatch.py
+++ b/files/check_canonical-livepatch.py
@@ -1,9 +1,9 @@
1#!/usr/bin/env python1#!/usr/bin/env python3
22
3# Copyright (C) 2016 Canonical Ltd.3# Copyright (C) 2016 Canonical Ltd.
44
5import os5import os
6import nagios_plugin6import nagios_plugin3
7from subprocess import check_output, call7from subprocess import check_output, call
8from yaml import safe_load8from yaml import safe_load
99
@@ -16,7 +16,7 @@ def check_snap_installed():
16 try:16 try:
17 check_output(cmd, universal_newlines=True)17 check_output(cmd, universal_newlines=True)
18 except Exception:18 except Exception:
19 raise nagios_plugin.CriticalError('canonical-livepatch snap is not installed')19 raise nagios_plugin3.CriticalError('canonical-livepatch snap is not installed')
2020
2121
22def load_status():22def load_status():
@@ -35,19 +35,19 @@ def check_serious_errors():
3535
36 # if it's empty, something's definitely wrong36 # if it's empty, something's definitely wrong
37 if livepatch_status == '':37 if livepatch_status == '':
38 raise nagios_plugin.CriticalError('No output from canonical-livepatch status')38 raise nagios_plugin3.CriticalError('No output from canonical-livepatch status')
3939
40 # in some cases, it's obviously not valid YAML40 # in some cases, it's obviously not valid YAML
41 try:41 try:
42 livepatch_yaml = safe_load(livepatch_status)42 livepatch_yaml = safe_load(livepatch_status)
43 except Exception:43 except Exception:
44 raise nagios_plugin.CriticalError(livepatch_status.replace('\n', ' '))44 raise nagios_plugin3.CriticalError(livepatch_status.replace('\n', ' '))
4545
46 # in other cases, it's less obvious until we try to parse46 # in other cases, it's less obvious until we try to parse
47 try:47 try:
48 livepatch_yaml['status']48 livepatch_yaml['status']
49 except TypeError:49 except TypeError:
50 raise nagios_plugin.CriticalError(livepatch_status.replace('\n', ' '))50 raise nagios_plugin3.CriticalError(livepatch_status.replace('\n', ' '))
5151
5252
53def active_kernel_version():53def active_kernel_version():
@@ -80,7 +80,7 @@ def check_status():
80 errors.append(patch_state_error)80 errors.append(patch_state_error)
8181
82 if errors:82 if errors:
83 raise nagios_plugin.CriticalError(' '.join(errors))83 raise nagios_plugin3.CriticalError(' '.join(errors))
8484
8585
86def check_check_state(check_state):86def check_check_state(check_state):
@@ -142,15 +142,15 @@ def is_container():
142def main():142def main():
143 arch = os.uname()[4]143 arch = os.uname()[4]
144 if arch not in supported_archs:144 if arch not in supported_archs:
145 raise nagios_plugin.CriticalError(145 raise nagios_plugin3.CriticalError(
146 "canonical-livepatch not supported on this architecture ({}).".format(arch)146 "canonical-livepatch not supported on this architecture ({}).".format(arch)
147 )147 )
148 elif is_container():148 elif is_container():
149 print("canonical-livepatch not needed in OS containers.")149 print("canonical-livepatch not needed in OS containers.")
150 else:150 else:
151 nagios_plugin.try_check(check_snap_installed)151 nagios_plugin3.try_check(check_snap_installed)
152 nagios_plugin.try_check(check_serious_errors)152 nagios_plugin3.try_check(check_serious_errors)
153 nagios_plugin.try_check(check_status)153 nagios_plugin3.try_check(check_status)
154 kernel_version = active_kernel_version()154 kernel_version = active_kernel_version()
155 print("OK - canonical-livepatch is active on kernel {}".format(kernel_version))155 print("OK - canonical-livepatch is active on kernel {}".format(kernel_version))
156156

Subscribers

People subscribed via source and target branches