/
mbg_lantime_state
102 lines (87 loc) · 4.29 KB
/
mbg_lantime_state
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2013 mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. check_mk is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
mbg_lantime_state_statemap = {
'0': 'notSynchronized',
'1': 'noGoodRefclock',
'2': 'syncToExtRefclock',
'3': 'syncToSerialRefclock',
'4': 'normalOperationPPS',
'5': 'normalOperationRefclock',
}
# stratum, refclock_offset (in microseconds)
mbg_lantime_state_default_levels = (0, 0, 500, 1000)
def inventory_mbg_lantime_state(info):
if len(info) > 0 and len(info[0]) == 5:
return [(None, None, "mbg_lantime_state_default_levels")]
def check_mbg_lantime_state(item, params, info):
if len(info) > 0 and len(info[0]) == 5:
ntp_state, stratum, refclock_id, refclock_name, refclock_offset = info[0]
state = 0
state_txt = []
# Handle the reported state
thr_txt = ''
if ntp_state in [ '0', '1' ]:
state = max(state, 2)
thr_txt = ' (!!)'
state_txt.append('State: %s%s' % (mbg_lantime_state_statemap.get(ntp_state, 'UNKNOWN'), thr_txt))
# handle the reported stratum
thr_txt = ''
if params[0] is not None and int(stratum) > params[1]:
state = max(state, 2)
thr_txt = ' (!!)'
elif params[1] is not None and int(stratum) > params[0]:
state = max(state, 1)
thr_txt = ' (!)'
state_txt.append('Stratum: %s%s' % (stratum, thr_txt))
# Add refclock information
state_txt.append('Refclock: %s (%s)' % (refclock_name, refclock_id))
thr_txt = ''
pos_refclock_offset = abs(savefloat(refclock_offset))
if params[2] is not None and pos_refclock_offset > params[3]:
state = max(state, 2)
thr_txt = ' (!!)'
elif params[3] is not None and pos_refclock_offset > params[2]:
state = max(state, 1)
thr_txt = ' (!)'
state_txt.append('Refclock Offset: %0.4fms%s' % (savefloat(refclock_offset) / 1000, thr_txt))
perfdata = [('offset', refclock_offset, params[2], params[3])]
return (state, ', '.join(state_txt), perfdata)
return (3, 'Got no state information')
check_info["mbg_lantime_state"] = {
'check_function': check_mbg_lantime_state,
'inventory_function': inventory_mbg_lantime_state,
'service_description': 'LANTIME State',
'has_perfdata': True,
'snmp_info': ('.1.3.6.1.4.1.5597.3.1', [
2, # MBG-SNMP-MIB::mbgLtNtpCurrentStateVal
3, # MBG-SNMP-MIB::mbgLtNtpNtpStratum
4, # MBG-SNMP-MIB::mbgLtNtpActiveRefclockId
5, # MBG-SNMP-MIB::mbgLtNtpActiveRefclockName
7, # MBG-SNMP-MIB::mbgLtNtpActiveRefclockOffsetVal
]),
'snmp_scan_function': \
lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.5597.3",
}