GUI CSS: Removed snapin styles from py modules and added a _snapins.scss for the...
[check_mk.git] / checks / siemens_plc
blob8cc819d4647be17b54ce73fe44d8c8569b40e242
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
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 # <<<siemens_plc>>>
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---------------------------------------------------------.
49 # | _____ _ |
50 # | |_ _|__ _ __ ___ _ __ ___ _ __ __ _| |_ _ _ _ __ ___ |
51 # | | |/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \ |
52 # | | | __/ | | | | | |_) | __/ | | (_| | |_| |_| | | | __/ |
53 # | |_|\___|_| |_| |_| .__/ \___|_| \__,_|\__|\__,_|_| \___| |
54 # | |_| |
55 # +----------------------------------------------------------------------+
56 # | |
57 # '----------------------------------------------------------------------'
59 factory_settings["siemens_plc_temp_default_levels"] = {
60 "levels": (70, 80),
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):
70 for line in 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",
80 "has_perfdata": True,
81 "group": "temperature",
82 "default_levels_variable": "siemens_plc_temp_default_levels",
83 "includes": ["temperature.include"],
87 # .--State flags---------------------------------------------------------.
88 # | ____ _ _ __ _ |
89 # | / ___|| |_ __ _| |_ ___ / _| | __ _ __ _ ___ |
90 # | \___ \| __/ _` | __/ _ \ | |_| |/ _` |/ _` / __| |
91 # | ___) | || (_| | || __/ | _| | (_| | (_| \__ \ |
92 # | |____/ \__\__,_|\__\___| |_| |_|\__,_|\__, |___/ |
93 # | |___/ |
94 # +----------------------------------------------------------------------+
95 # | |
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
105 for line in info:
106 if line[1] == "flag" and line[0] + " " + line[2] == item:
107 flag_state = line[-1] == 'True'
108 if flag_state:
109 state = 0 if expected_state else 2
110 return state, 'On'
112 state = 2 if expected_state else 0
113 return state, 'Off'
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------------------------------------------------------------.
125 # | ____ _ _ |
126 # | | _ \ _ _ _ __ __ _| |_(_) ___ _ __ |
127 # | | | | | | | | '__/ _` | __| |/ _ \| '_ \ |
128 # | | |_| | |_| | | | (_| | |_| | (_) | | | | |
129 # | |____/ \__,_|_| \__,_|\__|_|\___/|_| |_| |
130 # | |
131 # +----------------------------------------------------------------------+
132 # | |
133 # '----------------------------------------------------------------------'
136 def inventory_siemens_plc_duration(info):
137 return [(l[0] + " " + l[2], {})
138 for l in info
139 if l[1].startswith("hours") or l[1].startswith("seconds")]
142 def check_siemens_plc_duration(item, params, info):
143 for line in 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
148 else:
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)
161 state = 0
162 warn, crit = params.get('duration', (None, None))
163 if crit is not None and seconds >= crit:
164 state = 2
165 elif warn is not None and seconds >= warn:
166 state = 1
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-------------------------------------------------------------.
181 # | ____ _ |
182 # | / ___|___ _ _ _ __ | |_ ___ _ __ |
183 # | | | / _ \| | | | '_ \| __/ _ \ '__| |
184 # | | |__| (_) | |_| | | | | || __/ | |
185 # | \____\___/ \__,_|_| |_|\__\___|_| |
186 # | |
187 # +----------------------------------------------------------------------+
188 # | |
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):
197 for line in 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)
208 state = 0
209 warn, crit = params.get('levels', (None, None))
210 if crit is not None and value >= crit:
211 state = 2
212 elif warn is not None and value >= warn:
213 state = 1
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----------------------------------------------------------------.
228 # | ___ __ |
229 # | |_ _|_ __ / _| ___ |
230 # | | || '_ \| |_ / _ \ |
231 # | | || | | | _| (_) | |
232 # | |___|_| |_|_| \___/ |
233 # | |
234 # +----------------------------------------------------------------------+
235 # | |
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):
244 for line in info:
245 if line[1] == "text" and line[0] + " " + line[2] == item:
246 return 0, line[-1]
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 # | \____|_| \___/ |____/ \__\__,_|\__\___| |
262 # | |
263 # +----------------------------------------------------------------------+
264 # | |
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):
273 try:
274 state = info[0][0]
275 except IndexError:
276 return
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",