GUI CSS: Deployed view styles for layouts (CMK-1171)
[check_mk.git] / checks / safenet_hsm
blob7baa76a1f4808338defd4c669f09ca5e7444cd85
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2017 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 def parse_safenet_hsm(info):
29 return {
30 "operation_requests": int(info[0][0]),
31 "operation_errors": int(info[0][1]),
32 "critical_events": int(info[0][2]),
33 "noncritical_events": int(info[0][3]),
38 # .--Event stats---------------------------------------------------------.
39 # | _____ _ _ _ |
40 # | | ____|_ _____ _ __ | |_ ___| |_ __ _| |_ ___ |
41 # | | _| \ \ / / _ \ '_ \| __| / __| __/ _` | __/ __| |
42 # | | |___ \ V / __/ | | | |_ \__ \ || (_| | |_\__ \ |
43 # | |_____| \_/ \___|_| |_|\__| |___/\__\__,_|\__|___/ |
44 # | |
45 # '----------------------------------------------------------------------'
47 factory_settings["safenet_hsm_events_default_levels"] = {
48 "critical_event_rate": (0.0001, 0.0005),
52 def inventory_safenet_hsm_events(parsed):
53 if parsed:
54 return [(None, {})]
57 def check_safenet_hsm_events(_no_item, params, parsed):
58 now = time.time()
60 def check_events(event_type):
61 events = parsed[event_type + "_events"]
62 infotext = "%d %s events since last reset" % (events, event_type)
63 if params.get(event_type + "_events"):
64 warn, crit = params[event_type + "_events"]
65 levelstext = " (warn, crit at %d/%d events)" % (warn, crit)
66 if events >= crit:
67 status = 2
68 elif events >= warn:
69 status = 1
70 else:
71 status = 0
72 if status:
73 infotext += levelstext
74 else:
75 status = 0
76 return status, infotext
78 def check_event_rate(event_type):
79 events = parsed[event_type + "_events"]
80 event_rate = get_rate(event_type + "_events", now, events)
81 infotext = "%.2f %s events/s" % (event_rate, event_type)
82 if params.get(event_type + "_event_rate"):
83 warn, crit = params[event_type + "_event_rate"]
84 levelstext = " (warn/crit at %.2f/%.2f 1/s)" % (warn, crit)
85 perfdata = [(event_type + "event_rate", event_rate, warn, crit)]
86 if event_rate >= crit:
87 status = 2
88 elif event_rate >= warn:
89 status = 1
90 else:
91 status = 0
92 if status:
93 infotext += levelstext
94 else:
95 perfdata = [(event_type + "_event_rate", event_rate)]
96 status = 0
97 return status, infotext, perfdata
99 yield check_events("critical")
100 yield check_events("noncritical")
101 yield check_event_rate("critical")
102 yield check_event_rate("noncritical")
105 check_info["safenet_hsm.events"] = {
106 "default_levels_variable": "safenet_hsm_events_default_levels",
107 "inventory_function": inventory_safenet_hsm_events,
108 "check_function": check_safenet_hsm_events,
109 "service_description": "HSM Safenet Event Stats",
110 "has_perfdata": True,
111 "group": "safenet_hsm_eventstats",
115 # .--Operation stats-----------------------------------------------------.
116 # | ___ _ _ |
117 # | / _ \ _ __ ___ _ __ __ _| |_(_) ___ _ __ |
118 # | | | | | '_ \ / _ \ '__/ _` | __| |/ _ \| '_ \ |
119 # | | |_| | |_) | __/ | | (_| | |_| | (_) | | | | |
120 # | \___/| .__/ \___|_| \__,_|\__|_|\___/|_| |_| |
121 # | |_| |
122 # | _ _ |
123 # | ___| |_ __ _| |_ ___ |
124 # | / __| __/ _` | __/ __| |
125 # | \__ \ || (_| | |_\__ \ |
126 # | |___/\__\__,_|\__|___/ |
127 # | |
128 # '----------------------------------------------------------------------'
130 factory_settings["safenet_hsm_default_levels"] = {"error_rate": (0.01, 0.05), "request_rate": None}
133 def inventory_safenet_hsm(parsed):
134 if parsed:
135 return [(None, {})]
138 def check_safenet_hsm(_no_item, params, parsed):
139 now = time.time()
141 def check_operation_request_rate(operation_requests):
142 request_rate = get_rate("operation_requests", now, operation_requests)
144 status, infotext, extra_perf = check_levels(
145 request_rate, "request_rate", params["request_rate"], unit="1/s", infoname="Requests")
146 perfdata = [("requests_per_second", request_rate)] + extra_perf[1:]
147 return status, infotext, perfdata
149 def check_operation_error_rate(operation_errors):
150 error_rate = get_rate("operation_errors", now, operation_errors)
151 infotext = "%.2f operation errors/s" % error_rate
152 if params.get("error_rate"):
153 warn, crit = params["error_rate"]
154 levelstext = " (warn/crit at %.2f/%.2f 1/s)" % (warn, crit)
155 perfdata = [("error_rate", error_rate, warn, crit)]
156 if error_rate >= crit:
157 status = 2
158 elif error_rate >= warn:
159 status = 1
160 else:
161 status = 0
162 if status:
163 infotext += levelstext
164 else:
165 perfdata = [("error_rate", error_rate)]
166 status = 0
167 return status, infotext, perfdata
169 def check_operation_errors(operation_errors):
170 infotext = "%d operation errors since last reset" % operation_errors
171 if params.get("operation_errors"):
172 warn, crit = params["operation_errors"]
173 levelstext = " (warn, crit at %d/%d errors)" % (warn, crit)
174 if operation_errors >= crit:
175 status = 2
176 elif operation_errors >= warn:
177 status = 1
178 else:
179 status = 0
180 if status:
181 infotext += levelstext
182 else:
183 status = 0
184 return status, infotext
186 yield check_operation_request_rate(parsed["operation_requests"])
187 yield check_operation_error_rate(parsed["operation_errors"])
188 yield check_operation_errors(parsed["operation_errors"])
191 check_info["safenet_hsm"] = {
192 "default_levels_variable": "safenet_hsm_default_levels",
193 "parse_function": parse_safenet_hsm,
194 "inventory_function": inventory_safenet_hsm,
195 "check_function": check_safenet_hsm,
196 "service_description": "HSM Operation Stats",
197 "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.12383"),
198 "snmp_info": (
199 ".1.3.6.1.4.1.12383.3.1.1",
201 "1", # hsmOperationRequests
202 "2", # hsmOperationErrors
203 "3", # hsmCriticalEvents
204 "4", # hsmNonCriticalEvents
206 "has_perfdata": True,
207 "group": "safenet_hsm_operstats",