Cleanup config.nodes_of
[check_mk.git] / checks / mbg_lantime_ng_refclock
blobf4478b79ba5598ebbe3fb6a8d2fcdd5b3343e05c
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | "_ \ / _ \/ __| |/ / | |\/| | " / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2013 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # .--general-------------------------------------------------------------.
28 # | _ |
29 # | __ _ ___ _ __ ___ _ __ __ _| | |
30 # | / _` |/ _ \ '_ \ / _ \ '__/ _` | | |
31 # | | (_| | __/ | | | __/ | | (_| | | |
32 # | \__, |\___|_| |_|\___|_| \__,_|_| |
33 # | |___/ |
34 # +----------------------------------------------------------------------+
36 mbg_lantime_ng_refclock_types = {
37 "0": "unknown",
38 "1": "gps166",
39 "2": "gps167",
40 "3": "gps167SV",
41 "4": "gps167PC",
42 "5": "gps167PCI",
43 "6": "gps163",
44 "7": "gps168PCI",
45 "8": "gps161",
46 "9": "gps169PCI",
47 "10": "tcr167PCI",
48 "11": "gps164",
49 "12": "gps170PCI",
50 "13": "pzf511",
51 "14": "gps170",
52 "15": "tcr511",
53 "16": "am511",
54 "17": "msf511",
55 "18": "grc170",
56 "19": "gps170PEX",
57 "20": "gps162",
58 "21": "ptp270PEX",
59 "22": "frc511PEX",
60 "23": "gen170",
61 "24": "tcr170PEX",
62 "25": "wwvb511",
63 "26": "mgr170",
64 "27": "jjy511",
65 "28": "pzf600",
66 "29": "tcr600",
67 "30": "gps180",
68 "31": "gln170",
69 "32": "gps180PEX",
70 "33": "tcr180PEX",
71 "34": "pzf180PEX",
72 "35": "mgr180",
73 "36": "msf600",
74 "37": "wwvb600",
75 "38": "jjy600",
76 "39": "gps180HS",
77 "40": "gps180AMC",
78 "41": "esi180",
79 "42": "cpe180",
80 "43": "lno180",
81 "44": "grc180",
82 "45": "liu",
83 "46": "dcf600HS",
84 "47": "dcf600RS",
85 "48": "mri",
86 "49": "bpe",
87 "50": "gln180Pex",
88 "51": "n2x",
89 "52": "rsc180",
90 "53": "lneGb",
91 "54": "lnePpg180",
92 "55": "scg",
93 "56": "mdu300",
94 "57": "sdi",
95 "58": "fdm180",
96 "59": "spt",
97 "60": "pzf180",
98 "61": "rel1000",
102 def mbg_lantime_ng_generalstate(clock_type, usage, state, substate):
103 refclock_usages = {
104 "0": "not available",
105 "1": "secondary",
106 "2": "compare",
107 "3": "primary",
110 refclock_states = {
111 "0": (2, "not available"),
112 "1": (0, "synchronized"),
113 "2": (1, "not synchronized"),
116 # Translation for values of MBG-SNMP-LTNG-MIB::mbgLtNgRefclockSubstate
117 refclock_substates = {
118 "0": "not available",
119 "1": "GPS sync",
120 "2": "GPS tracking",
121 "3": "GPS antenna disconnected",
122 "4": "GPS warm boot",
123 "5": "GPS cold boot",
124 "6": "GPS antenna short circuit",
125 "50": "LW never sync",
126 "51": "LW not sync",
127 "52": "LW sync",
128 "100": "TCR not sync",
129 "101": "TCT sync",
130 "149": "MRS internal oscillator sync",
131 "150": "MRS GPS sync",
132 "151": "MRS 10Mhz sync",
133 "152": "MRS PPS in sync",
134 "153": "MRS 10Mhz PPS in sync",
135 "154": "MRS IRIG sync",
136 "155": "MRS NTP sync",
137 "156": "MRS PTP IEEE 1588 sync",
138 "157": "MRS PTP over E1 sync",
139 "158": "MRS fixed frequency in sync",
140 "159": "MRS PPS string sync",
141 "160": "MRS variable frequency GPIO sync",
142 "161": "MRS reserved",
143 "162": "MRS DCF77 PZF sync",
144 "163": "MRS longwave sync",
145 "164": "MRS GLONASS GPS sync",
146 "165": "MRS HAVE QUICK sync",
147 "166": "MRS external oscillator sync",
148 "167": "MRS SyncE",
151 state, state_txt = refclock_states[state]
152 detailed_state_txt = (' (%s)' % refclock_substates[substate] if substate != '0' else '')
153 infotext = "Type: %s, Usage: %s, State: %s%s" % (mbg_lantime_ng_refclock_types[clock_type],
154 refclock_usages[usage], state_txt,
155 detailed_state_txt)
157 return state, infotext
161 # .--gps refclocks-------------------------------------------------------.
162 # | __ _ _ |
163 # | __ _ _ __ ___ _ __ ___ / _| ___| | ___ ___| | _____ |
164 # | / _` | '_ \/ __| | '__/ _ \ |_ / __| |/ _ \ / __| |/ / __| |
165 # | | (_| | |_) \__ \ | | | __/ _| (__| | (_) | (__| <\__ \ |
166 # | \__, | .__/|___/ |_| \___|_| \___|_|\___/ \___|_|\_\___/ |
167 # | |___/|_| |
168 # +----------------------------------------------------------------------+
170 # number of good satellites
171 mbg_lantime_refclock_default_levels = (3, 3)
174 def inventory_lantime_ng_refclock_gps(info):
175 for line in info:
176 if mbg_lantime_ng_refclock_types[line[1]].startswith("gps"):
177 yield (line[0], 'mbg_lantime_refclock_default_levels')
180 def check_lantime_ng_refclock_gps(item, params, info):
181 for (index, clock_type, usage, state, substate, status_a, max_status_a, _, _, _,
182 leapsecond_date) in info:
184 if item == index:
185 yield mbg_lantime_ng_generalstate(clock_type, usage, state, substate)
187 if substate not in ("1", "2"):
188 yield 0, "Next leap second: %s" % str(leapsecond_date)
190 # Levels for satellites are checked only if we have a substate
191 # that indicates that a GPS connection is needed. For the
192 # LANTIME M600/MRS the GPS antenna is e.g. optional.
193 if substate in ("1", "2", "3", "4", "5", "6", "150"):
194 state, levels_txt = 0, ""
195 good_sats, total_sats = int(status_a), int(max_status_a)
196 warn, crit = params
197 if good_sats < crit:
198 state = 2
199 levels_txt = " (warn/crit below %d/%d)" % params
200 elif good_sats < warn:
201 state = 1
202 levels_txt = " (warn/crit below %d/%d)" % params
204 yield state, "Satellites: %d/%d%s" % (good_sats, total_sats, levels_txt)
207 check_info["mbg_lantime_ng_refclock.gps"] = {
208 "check_function": check_lantime_ng_refclock_gps,
209 "inventory_function": inventory_lantime_ng_refclock_gps,
210 "service_description": "LANTIME Refclock %s",
211 "has_perfdata": True,
215 # .--other refclocks-----------------------------------------------------.
216 # | _ _ |
217 # | ___ | |_| |__ ___ _ __ |
218 # | / _ \| __| '_ \ / _ \ '__| |
219 # | | (_) | |_| | | | __/ | |
220 # | \___/ \__|_| |_|\___|_| |
221 # | |
222 # | __ _ _ |
223 # | _ __ ___ / _| ___| | ___ ___| | _____ |
224 # | | '__/ _ \ |_ / __| |/ _ \ / __| |/ / __| |
225 # | | | | __/ _| (__| | (_) | (__| <\__ \ |
226 # | |_| \___|_| \___|_|\___/ \___|_|\_\___/ |
227 # | |
228 # +----------------------------------------------------------------------+
231 def inventory_lantime_ng_refclock(info):
232 for line in info:
233 if not mbg_lantime_ng_refclock_types[line[1]].startswith("gps"):
234 yield (line[0], None)
237 def check_lantime_ng_refclock(item, _no_params, info):
239 for (index, clock_type, usage, state, substate, status_a, max_status_a, status_b, max_status_b,
240 _, _) in info:
242 if item == index:
243 yield mbg_lantime_ng_generalstate(clock_type, usage, state, substate)
245 field_strength = round(float(status_b) / float(max_status_b) * 100.0)
246 perfdata = [("field_strength", field_strength)]
248 yield 0, "Field strength: %d%%" % field_strength, perfdata
250 # only used for longwave - pzf refclocks
251 if max_status_a != "0":
252 correlation = round(float(status_a) / float(max_status_a) * 100.0)
253 perfdata = [("correlation", correlation)]
254 yield 0, "Correlation: %d%%" % correlation, perfdata
257 check_info["mbg_lantime_ng_refclock"] = {
258 "check_function": check_lantime_ng_refclock,
259 "inventory_function": inventory_lantime_ng_refclock,
260 "service_description": "LANTIME Refclock %s",
261 "has_perfdata": True,
262 "snmp_info": (
263 ".1.3.6.1.4.1.5597.30.0.1.2.1",
265 1, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockIndex
266 2, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockType
267 3, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockUsage
268 4, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockState
269 5, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockSubstate
270 6, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockStatusA
271 7, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockMaxStatusA
272 8, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockStatusB
273 9, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockMaxStatusB
274 10, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockAdditionalInfo
275 11, # MBG-SNMP-LTNG-MIB::mbgLtNgRefclockLeapSecondDate
277 "snmp_scan_function": snmp_scan_mbg_lantime_ng_hw,
278 "includes": ["mbg_lantime.include"],