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.
28 # PFT01 temp Gesamt 279183569715
29 # PFT01 flag Testbit True
30 # PFT01 flag Testbit2 False
31 # RGB01 temp Gesamt 123
32 # RGB01 seconds Fahren 56
33 # RGB01 seconds Hub 48
34 # RGB01 seconds LAM1 13
35 # RGB01 temp Extern 18.7000007629
36 # RGB01 temp RBG_SCH1 0.0
37 # RGB01 temp RBG_SCH2 0.0
38 # RGB01 counter Fahren 31450
39 # RGB01 counter Hub 8100
40 # RGB01 counter LAM 5002
41 # RGB01 counter Lastzyklen 78
42 # RGB01 counter LAM1_Zyklen 115
43 # RGB01 seconds Service 109
44 # RGB01 seconds Serviceintervall 700
45 # RGB01 text Testtext HRL01-0001-0010-02-07
48 # .--Temperature---------------------------------------------------------.
50 # | |_ _|__ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
51 # | | |/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
52 # | | | __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
53 # | |_|\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
55 # +----------------------------------------------------------------------+
57 # '----------------------------------------------------------------------'
59 factory_settings
["siemens_plc_temp_default_levels"] = {
61 "device_levels_handling": "devdefault",
65 def inventory_siemens_plc_temp(info
):
66 return [(l
[0] + " " + l
[2], {}) for l
in info
if l
[1] == "temp"]
69 def check_siemens_plc_temp(item
, params
, info
):
71 if line
[1] == "temp" and line
[0] + " " + line
[2] == item
:
72 temp
= float(line
[-1])
73 return check_temperature(temp
, params
, "siemens_plc_%s" % item
)
76 check_info
['siemens_plc.temp'] = {
77 "inventory_function": inventory_siemens_plc_temp
,
78 "check_function": check_siemens_plc_temp
,
79 "service_description": "Temperature %s",
81 "group": "temperature",
82 "default_levels_variable": "siemens_plc_temp_default_levels",
83 "includes": ["temperature.include"],
87 # .--State flags---------------------------------------------------------.
89 # | / ___|| |_ __ _| |_ ___ / _| | __ _ __ _ ___ |
90 # | \___ \| __/ _` | __/ _ \ | |_| |/ _` |/ _` / __| |
91 # | ___) | || (_| | || __/ | _| | (_| | (_| \__ \ |
92 # | |____/ \__\__,_|\__\___| |_| |_|\__,_|\__, |___/ |
94 # +----------------------------------------------------------------------+
96 # '----------------------------------------------------------------------'
99 def inventory_siemens_plc_flag(info
):
100 return [(l
[0] + " " + l
[2], False) for l
in info
if l
[1] == "flag"]
103 def check_siemens_plc_flag(item
, params
, info
):
104 expected_state
= params
106 if line
[1] == "flag" and line
[0] + " " + line
[2] == item
:
107 flag_state
= line
[-1] == 'True'
109 state
= 0 if expected_state
else 2
112 state
= 2 if expected_state
else 0
116 check_info
['siemens_plc.flag'] = {
117 "inventory_function": inventory_siemens_plc_flag
,
118 "check_function": check_siemens_plc_flag
,
119 "service_description": "Flag %s",
120 "group": "siemens_plc_flag",
124 # .--Duration------------------------------------------------------------.
126 # | | _ \ _ _ _ __ __ _| |_(_) ___ _ __ |
127 # | | | | | | | | '__/ _` | __| |/ _ \| '_ \ |
128 # | | |_| | |_| | | | (_| | |_| | (_) | | | | |
129 # | |____/ \__,_|_| \__,_|\__|_|\___/|_| |_| |
131 # +----------------------------------------------------------------------+
133 # '----------------------------------------------------------------------'
136 def inventory_siemens_plc_duration(info
):
137 return [(l
[0] + " " + l
[2], {})
139 if l
[1].startswith("hours") or l
[1].startswith("seconds")]
142 def check_siemens_plc_duration(item
, params
, info
):
144 if (line
[1].startswith("hours") or
145 line
[1].startswith("seconds")) and line
[0] + " " + line
[2] == item
:
146 if line
[1].startswith("hours"):
147 seconds
= int(line
[-1]) * 3600
149 seconds
= int(line
[-1])
151 perfdata
= [(line
[1], seconds
)]
153 key
= 'siemens_plc.duration.%s' % item
154 old_seconds
= get_item_state(key
, None)
155 if old_seconds
is not None and old_seconds
> seconds
:
156 return 2, 'Reduced from %s to %s' % (get_age_human_readable(old_seconds
),
157 get_age_human_readable(seconds
)), perfdata
159 set_item_state(key
, seconds
)
162 warn
, crit
= params
.get('duration', (None, None))
163 if crit
is not None and seconds
>= crit
:
165 elif warn
is not None and seconds
>= warn
:
168 return state
, get_age_human_readable(seconds
), perfdata
171 check_info
['siemens_plc.duration'] = {
172 "inventory_function": inventory_siemens_plc_duration
,
173 "check_function": check_siemens_plc_duration
,
174 "service_description": "Duration %s",
175 "has_perfdata": True,
176 "group": "siemens_plc_duration",
180 # .--Counter-------------------------------------------------------------.
182 # | / ___|___ _ _ _ __ | |_ ___ _ __ |
183 # | | | / _ \| | | | '_ \| __/ _ \ '__| |
184 # | | |__| (_) | |_| | | | | || __/ | |
185 # | \____\___/ \__,_|_| |_|\__\___|_| |
187 # +----------------------------------------------------------------------+
189 # '----------------------------------------------------------------------'
192 def inventory_siemens_plc_counter(info
):
193 return [(l
[0] + " " + l
[2], {}) for l
in info
if l
[1].startswith("counter")]
196 def check_siemens_plc_counter(item
, params
, info
):
198 if line
[1].startswith("counter") and line
[0] + " " + line
[2] == item
:
199 value
= int(line
[-1])
200 perfdata
= [(line
[1], value
)]
202 key
= 'siemens_plc.counter.%s' % item
203 old_value
= get_item_state(key
, None)
204 if old_value
is not None and old_value
> value
:
205 return 2, 'Reduced from %s to %s' % (old_value
, value
), perfdata
206 set_item_state(key
, value
)
209 warn
, crit
= params
.get('levels', (None, None))
210 if crit
is not None and value
>= crit
:
212 elif warn
is not None and value
>= warn
:
215 return state
, '%d' % value
, perfdata
218 check_info
['siemens_plc.counter'] = {
219 "inventory_function": inventory_siemens_plc_counter
,
220 "check_function": check_siemens_plc_counter
,
221 "service_description": "Counter %s",
222 "has_perfdata": True,
223 "group": "siemens_plc_counter",
227 # .--Info----------------------------------------------------------------.
229 # | |_ _|_ __ / _| ___ |
230 # | | || '_ \| |_ / _ \ |
231 # | | || | | | _| (_) | |
232 # | |___|_| |_|_| \___/ |
234 # +----------------------------------------------------------------------+
236 # '----------------------------------------------------------------------'
239 def inventory_siemens_plc_info(info
):
240 return [(l
[0] + " " + l
[2], {}) for l
in info
if l
[1] == "text"]
243 def check_siemens_plc_info(item
, _no_params
, info
):
245 if line
[1] == "text" and line
[0] + " " + line
[2] == item
:
249 check_info
['siemens_plc.info'] = {
250 "inventory_function": inventory_siemens_plc_info
,
251 "check_function": check_siemens_plc_info
,
252 "service_description": "Info %s",
256 # .--CPU-State-----------------------------------------------------------.
257 # | ____ ____ _ _ ____ _ _ |
258 # | / ___| _ \| | | | / ___|| |_ __ _| |_ ___ |
259 # | | | | |_) | | | |____\___ \| __/ _` | __/ _ \ |
260 # | | |___| __/| |_| |_____|__) | || (_| | || __/ |
261 # | \____|_| \___/ |____/ \__\__,_|\__\___| |
263 # +----------------------------------------------------------------------+
265 # '----------------------------------------------------------------------'
268 def inventory_siemens_plc_cpu_state(info
):
269 return [(None, None)]
272 def check_siemens_plc_cpu_state(_no_item
, _no_params
, info
):
278 if state
== "S7CpuStatusRun":
279 return 0, "CPU is running"
280 elif state
== "S7CpuStatusStop":
281 return 2, "CPU is stopped"
282 return 3, "CPU is in unknown state"
285 check_info
['siemens_plc_cpu_state'] = {
286 "inventory_function": inventory_siemens_plc_cpu_state
,
287 "check_function": check_siemens_plc_cpu_state
,
288 "service_description": "CPU state",