Module: check_mk
Branch: master
Commit: b1c498e0bdeaecbfe8df890b6e27c8e339c35c21
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b1c498e0bdeaec…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Fri Feb 22 09:23:16 2019 +0100
7061 FIX mbg_lantime_ng_refclock.gps: only apply satellite levels if required
The check now only applies levels for the number of connected satellites if the device
substate indicates that a satellite connection is necessary. Substates that require
a satellite connection are "GPS sync", "GPS tracking", "GPS
antenna disconnected",
"GPS warm boot", "GPS cold boot", "GPS antenna short
circuit" and "MRS GPS sync".
Change-Id: Ife770bc1aa278d41962c0eba6f4b132fcd0c41b3
---
.werks/7061 | 14 ++++++
checkman/mbg_lantime_ng_refclock | 1 -
checkman/mbg_lantime_ng_refclock.gps | 7 ++-
checks/mbg_lantime_ng_refclock | 31 ++++++------
tests/unit/checks/test_mbg_lantime_ng_refclock.py | 60 ++++++++++++++++-------
5 files changed, 78 insertions(+), 35 deletions(-)
diff --git a/.werks/7061 b/.werks/7061
new file mode 100644
index 0000000..8ccf6e3
--- /dev/null
+++ b/.werks/7061
@@ -0,0 +1,14 @@
+Title: mbg_lantime_ng_refclock.gps: only apply satellite levels if required
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1550756859
+
+The check now only applies levels for the number of connected satellites if the device
+substate indicates that a satellite connection is necessary. Substates that require
+a satellite connection are "GPS sync", "GPS tracking", "GPS
antenna disconnected",
+"GPS warm boot", "GPS cold boot", "GPS antenna short
circuit" and "MRS GPS sync".
diff --git a/checkman/mbg_lantime_ng_refclock b/checkman/mbg_lantime_ng_refclock
index 603f25e..6b03d7f 100644
--- a/checkman/mbg_lantime_ng_refclock
+++ b/checkman/mbg_lantime_ng_refclock
@@ -14,7 +14,6 @@ description:
When the refclock state is "not available" CRIT is raised and a WARN state is
issued
if the refclock state is "not synchronized".
- If the number of good satellites drops below 3, a CRIT state is raised.
inventory:
One service per non-gps refclock is created.
diff --git a/checkman/mbg_lantime_ng_refclock.gps b/checkman/mbg_lantime_ng_refclock.gps
index 7f94c44..0ca7493 100644
--- a/checkman/mbg_lantime_ng_refclock.gps
+++ b/checkman/mbg_lantime_ng_refclock.gps
@@ -14,7 +14,12 @@ description:
When the refclock state is "not available" CRIT is raised and a WARN state is
issued
if the refclock state is "not synchronized".
- If the number of good satellites drops below 3, a CRIT state is raised.
+ If the number of good satellites drops below 3 and the device substate indicates that
+ a satellite connection is necessary, a CRIT state is raised. If the substate indicates
+ that no satellite connection is necessary no information about satellites is shown.
+ Substates that require a satellite connection are "GPS sync", "GPS
tracking",
+ "GPS antenna disconnected", "GPS warm boot", "GPS cold
boot",
+ "GPS antenna short circuit" and "MRS GPS sync".
inventory:
One service per GPS refclock is created.
diff --git a/checks/mbg_lantime_ng_refclock b/checks/mbg_lantime_ng_refclock
index 9141d09..f4478b7 100644
--- a/checks/mbg_lantime_ng_refclock
+++ b/checks/mbg_lantime_ng_refclock
@@ -187,22 +187,21 @@ def check_lantime_ng_refclock_gps(item, params, info):
if substate not in ("1", "2"):
yield 0, "Next leap second: %s" % str(leapsecond_date)
- good_sats = int(status_a)
- total_sats = int(max_status_a)
- # levels are not "at" but "below" because we must be
- # compatible with old mbg_lantime_refclock check
- warn, crit = params
- if good_sats < crit:
- state = 2
- levels_txt = " (warn/crit below %d/%d)" % params
- elif good_sats < warn:
- state = 1
- levels_txt = " (warn/crit below %d/%d)" % params
- else:
- state = 0
- levels_txt = ""
-
- yield state, "Satellites: %d/%d%s" % (good_sats, total_sats,
levels_txt)
+ # Levels for satellites are checked only if we have a substate
+ # that indicates that a GPS connection is needed. For the
+ # LANTIME M600/MRS the GPS antenna is e.g. optional.
+ if substate in ("1", "2", "3", "4",
"5", "6", "150"):
+ state, levels_txt = 0, ""
+ good_sats, total_sats = int(status_a), int(max_status_a)
+ warn, crit = params
+ if good_sats < crit:
+ state = 2
+ levels_txt = " (warn/crit below %d/%d)" % params
+ elif good_sats < warn:
+ state = 1
+ levels_txt = " (warn/crit below %d/%d)" % params
+
+ yield state, "Satellites: %d/%d%s" % (good_sats, total_sats,
levels_txt)
check_info["mbg_lantime_ng_refclock.gps"] = {
diff --git a/tests/unit/checks/test_mbg_lantime_ng_refclock.py
b/tests/unit/checks/test_mbg_lantime_ng_refclock.py
index 7737cb6..fe73831 100644
--- a/tests/unit/checks/test_mbg_lantime_ng_refclock.py
+++ b/tests/unit/checks/test_mbg_lantime_ng_refclock.py
@@ -9,6 +9,9 @@ meinberg_lantime_2 = [[u'1', u'28', u'3',
u'1', u'52', u'62', u'100', u'101', u'
meinberg_lantime_5 = [[
u'1', u'14', u'3', u'1', u'150',
u'6', u'8', u'0', u'0', u'1', u'not
announced'
]]
+meinberg_lantime_6 = [[
+ u'1', u'30', u'3', u'1', u'155',
u'0', u'8', u'0', u'0', u'0',
u'2016-12-31'
+]]
@pytest.mark.parametrize(
@@ -43,6 +46,7 @@ def test_check_mbg_lantime_ng_refclock(check_manager, info, item,
params, expect
(meinberg_lantime_1, DiscoveryResult([('1',
'mbg_lantime_refclock_default_levels')])),
(meinberg_lantime_2, DiscoveryResult([])), # don't discover GPS clocks
(meinberg_lantime_5, DiscoveryResult([('1',
'mbg_lantime_refclock_default_levels')])),
+ (meinberg_lantime_6, DiscoveryResult([('1',
'mbg_lantime_refclock_default_levels')])),
])
def test_discovery_mbg_lantime_ng_refclock_gps(check_manager, info, expected):
check = check_manager.get_check("mbg_lantime_ng_refclock.gps")
@@ -50,23 +54,45 @@ def test_discovery_mbg_lantime_ng_refclock_gps(check_manager, info,
expected):
assertDiscoveryResultsEqual(check, discovery, expected)
-(a)pytest.mark.parametrize("info,item,params,expected"cted", [
- (meinberg_lantime_1, '1', (3, 3),
- CheckResult([
- BasicCheckResult(
- 1, 'Type: gps170, Usage: primary, State: not synchronized (GPS antenna
disconnected)',
- None),
- BasicCheckResult(0, 'Next leap second: 2012-06-30', None),
- BasicCheckResult(2, 'Satellites: 0/12 (warn/crit below 3/3)', None)
- ])),
- (meinberg_lantime_5, '1', (3, 3),
- CheckResult([
- BasicCheckResult(0, 'Type: gps170, Usage: primary, State: synchronized (MRS
GPS sync)',
- None),
- BasicCheckResult(0, 'Next leap second: not announced', None),
- BasicCheckResult(0, 'Satellites: 6/8', None)
- ])),
-])
+(a)pytest.mark.parametrize(
+ "info,item,params,expected",
+ [
+ (
+ meinberg_lantime_1,
+ '1',
+ (3, 3),
+ CheckResult([
+ BasicCheckResult(
+ 1,
+ 'Type: gps170, Usage: primary, State: not synchronized (GPS
antenna disconnected)',
+ None),
+ BasicCheckResult(0, 'Next leap second: 2012-06-30', None),
+ BasicCheckResult(2, 'Satellites: 0/12 (warn/crit below 3/3)',
None)
+ ]),
+ ),
+ (
+ meinberg_lantime_5,
+ '1',
+ (3, 3),
+ CheckResult([
+ BasicCheckResult(
+ 0, 'Type: gps170, Usage: primary, State: synchronized (MRS GPS
sync)', None),
+ BasicCheckResult(0, 'Next leap second: not announced', None),
+ BasicCheckResult(0, 'Satellites: 6/8', None)
+ ]),
+ ),
+ (
+ meinberg_lantime_6,
+ '1',
+ (3, 3),
+ CheckResult([
+ BasicCheckResult(
+ 0, 'Type: gps180, Usage: primary, State: synchronized (MRS NTP
sync)', None),
+ BasicCheckResult(0, 'Next leap second: 2016-12-31', None),
+ # satellites are not checked here
+ ]),
+ ),
+ ])
def test_check_mbg_lantime_ng_refclock_gps(check_manager, info, item, params, expected):
check = check_manager.get_check("mbg_lantime_ng_refclock.gps")
result = CheckResult(check.run_check(item, params, info))