2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 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 ntp_default_levels
= (10, 200.0, 500.0) # stratum, ms offset
29 factory_settings
["ntp_time_default_levels"] = {
30 "ntp_levels": ntp_default_levels
,
31 "alert_delay": (300, 3600),
34 # Example output from agent:
36 # Reference ID : 212.18.3.18 (ntp1.m-online.net)
38 # Ref time (UTC) : Tue Aug 19 16:56:21 2014
39 # System time : 0.000000353 seconds fast of NTP time
40 # Frequency : 10.725 ppm slow
41 # Residual freq : 195.475 ppm
43 # Root delay : 0.027455 seconds
44 # Root dispersion : 0.024512 seconds
47 # 506 Cannot talk to daemon
50 def parse_chrony(info
):
54 varname
, value
= " ".join(line
).split(":", 1)
55 parsed
[varname
.strip()] = value
.strip()
59 # We monitor all servers we have reached at least once
60 def inventory_chrony(info
):
61 parsed
= parse_chrony(info
)
66 def check_chrony(_no_item
, params
, info
):
67 parsed
= parse_chrony(info
)
69 yield 2, "No status information, chronyd probably not running"
73 if isinstance(params
, tuple):
76 "alert_delay": (300, 3600),
78 crit_stratum
, warn
, crit
= params
["ntp_levels"]
80 # Check offset and stratum, output a few info texsts
81 offset
= float(parsed
["System time"].split()[0]) * 1000 # converted to ms
82 stratum
= int(parsed
["Stratum"])
85 infotext
= "stratum %d" % stratum
86 if stratum
>= crit_stratum
:
87 yield 2, infotext
+ " (maximum allowed is %d)" % (crit_stratum
- 1)
93 infotext
= "offset %.4f ms" % offset
94 if abs(offset
) >= crit
:
96 elif abs(offset
) >= warn
:
99 infotext
+= " (warn/crit at %.4f/%.4f ms)" % (warn
, crit
)
100 yield status
, infotext
, [("offset", offset
, warn
, crit
, 0, None)]
102 # Show additional information
103 yield 0, "reference: %s" % parsed
["Reference ID"]
106 check_info
["chrony"] = {
107 'check_function': check_chrony
,
108 'inventory_function': inventory_chrony
,
109 'service_description': 'NTP Time',
110 'has_perfdata': True,
112 'default_levels_variable': "ntp_time_default_levels",