Module: check_mk
Branch: master
Commit: 7e93bf8c09b48141955b7bb64eb08a6cf6c0705b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7e93bf8c09b481…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Mon Nov 27 17:51:04 2017 +0100
5522 FIX mkbackup: Fix crash in case of multiple backup jobs
Previously, this check would not work (neither discovery nor checking) if more than one
backup job was configured. This has been fixed.
Change-Id: I28b4c0a76b98e97834ca6463a15ae0ec3f8a273a
---
.werks/5522 | 11 +++
checks/mkbackup | 2 +
tests/checks/test_mkbackup_check.py | 167 ++++++++++++++++++++++++++++++++++++
3 files changed, 180 insertions(+)
diff --git a/.werks/5522 b/.werks/5522
new file mode 100644
index 0000000..9434029
--- /dev/null
+++ b/.werks/5522
@@ -0,0 +1,11 @@
+Title: mkbackup: Fix crash in case of multiple backup jobs
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1511801399
+Class: fix
+
+Previously, this check would not work (neither discovery nor checking) if more than one
+backup job was configured. This has been fixed.
diff --git a/checks/mkbackup b/checks/mkbackup
index 2ff4449..b38c49a 100644
--- a/checks/mkbackup
+++ b/checks/mkbackup
@@ -51,6 +51,7 @@
# "success": true
# }
+# TODO: Refactor this.
def parse_mkbackup(info):
try:
import simplejson as json
@@ -78,6 +79,7 @@ def parse_mkbackup(info):
json_data += line
if line == "}":
job.update(json.loads(json_data))
+ json_data = ""
return parsed
diff --git a/tests/checks/test_mkbackup_check.py b/tests/checks/test_mkbackup_check.py
new file mode 100644
index 0000000..11e33d8
--- /dev/null
+++ b/tests/checks/test_mkbackup_check.py
@@ -0,0 +1,167 @@
+import pytest
+import pprint
+import sys
+
+pytestmark = pytest.mark.checks
+
+info_1 = [[u'[[[site:heute:test]]]'],
+ [u'{'],
+ [u'"bytes_per_second":', u'1578215.4167199447,'],
+ [u'"finished":', u'1511788263.410466,'],
+ [u'"next_schedule":', u'1511874660.0,'],
+ [u'"output":',
+ u'"2017-11-27',
+ u'14:11:02',
+ u'---',
+ u'Starting',
+ u'backup',
+ u'(Check_MK-klappfel-heute-test',
+ u'to',
+ u'testtgt)',
+ u'---\\n2017-11-27',
+ u'14:11:03',
+ u'Verifying',
+ u'backup',
+ u'consistency\\n2017-11-27',
+ u'14:11:03',
+ u'---',
+ u'Backup',
+ u'completed',
+ u'(Duration:',
+ u'0:00:01,',
+ u'Size:',
+ u'1.80',
+ u'MB,',
+ u'IO:',
+ u'1.51',
+ u'MB/s)',
+ u'---\\n",'],
+ [u'"pid":', u'20963,'],
+ [u'"size":', u'1883330,'],
+ [u'"started":', u'1511788262.20002,'],
+ [u'"state":', u'"finished",'],
+ [u'"success":', u'true'],
+ [u'}']]
+
+info_2 = [[u'[[[site:heute:test]]]'],
+ [u'{'],
+ [u'"bytes_per_second":', u'1578215.4167199447,'],
+ [u'"finished":', u'1511788263.410466,'],
+ [u'"next_schedule":', u'1511874660.0,'],
+ [u'"output":',
+ u'"2017-11-27',
+ u'14:11:02',
+ u'---',
+ u'Starting',
+ u'backup',
+ u'(Check_MK-klappfel-heute-test',
+ u'to',
+ u'testtgt)',
+ u'---\\n2017-11-27',
+ u'14:11:03',
+ u'Verifying',
+ u'backup',
+ u'consistency\\n2017-11-27',
+ u'14:11:03',
+ u'---',
+ u'Backup',
+ u'completed',
+ u'(Duration:',
+ u'0:00:01,',
+ u'Size:',
+ u'1.80',
+ u'MB,',
+ u'IO:',
+ u'1.51',
+ u'MB/s)',
+ u'---\\n",'],
+ [u'"pid":', u'20963,'],
+ [u'"size":', u'1883330,'],
+ [u'"started":', u'1511788262.20002,'],
+ [u'"state":', u'"finished",'],
+ [u'"success":', u'true'],
+ [u'}'],
+ [u'[[[site:heute:test2]]]'],
+ [u'{'],
+ [u'"bytes_per_second":', u'0,'],
+ [u'"finished":', u'1511788748.77112,'],
+ [u'"next_schedule":', u'null,'],
+ [u'"output":',
+ u'"2017-11-27',
+ u'14:19:07',
+ u'---',
+ u'Starting',
+ u'backup',
+ u'(Check_MK-klappfel-heute-test2',
+ u'to',
+ u'testtgt2)',
+ u'---\\n2017-11-27',
+ u'14:19:08',
+ u'Verifying',
+ u'backup',
+ u'consistency\\n2017-11-27',
+ u'14:19:08',
+ u'---',
+ u'Backup',
+ u'completed',
+ u'(Duration:',
+ u'0:00:00,',
+ u'Size:',
+ u'87.07',
+ u'MB,',
+ u'IO:',
+ u'0.00',
+ u'B/s)',
+ u'---\\n",'],
+ [u'"pid":', u'24201,'],
+ [u'"size":', u'91299840,'],
+ [u'"started":', u'1511788747.898509,'],
+ [u'"state":', u'"finished",'],
+ [u'"success":', u'true'],
+ [u'}']]
+
+info_3 = [[u'[[[system:test1]]]'],
+ [u'{'],
+ [u'"bytes_per_second":', u'0,'],
+ [u'"finished":', u'1474547810.309871,'],
+ [u'"next_schedule":', u'null,'],
+ [u'"output":',
+ u'"2016-09-22',
+ u'14:36:50',
+ u'---',
+ u'Starting',
+ u'backup',
+ u'(Check_MK_Appliance-luss028-test1',
+ u'to',
+ u'test1)',
+ u'---\\nFailed',
+ u'to',
+ u'create',
+ u'the',
+ u'backup',
+ u'directory:',
+ u'[Errno',
+ u'13]',
+ u'Permission',
+ u'denied:',
+
u'\'/mnt/auto/DIDK7838/Anwendungen/Check_MK_Appliance-luss028-test1-incomplete\'\\n",'],
+ [u'"pid":', u'29567,'],
+ [u'"started":', u'1474547810.30425,'],
+ [u'"state":', u'"finished",'],
+ [u'"success":', u'false'],
+ [u'}']]
+
+# This only tests whether the parse function crashes or not
+(a)pytest.mark.parametrize("info"info", [
+ [],
+ info_1,
+ info_2,
+ info_3,
+ ])
+def test_mkbackup_parse(check_manager, monkeypatch, info):
+ import cmk_base.checks
+ import cmk_base
+
+ check = check_manager.get_check("mkbackup")
+ check.run_parse(info)
+ cmk_base.config_cache.clear_all()