Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / fortigate_node
blob4f9ff3b5bfa453fc45a8056e94ee16b540646959
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2015 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 # monitoring of cluster members (nodes) in fortigate high availability tree
31 # cluster info
32 # .1.3.6.1.4.1.12356.101.13.1.1.0 3
33 # .1.3.6.1.4.1.12356.101.13.1.7.0 DEPTHA-HA
35 # node info
36 # .1.3.6.1.4.1.12356.101.13.2.1.1.11.1 NODE-01
37 # .1.3.6.1.4.1.12356.101.13.2.1.1.11.2 NODE-02
38 # .1.3.6.1.4.1.12356.101.13.2.1.1.3.1 13
39 # .1.3.6.1.4.1.12356.101.13.2.1.1.3.2 1
40 # .1.3.6.1.4.1.12356.101.13.2.1.1.4.1 52
41 # .1.3.6.1.4.1.12356.101.13.2.1.1.4.2 21
42 # .1.3.6.1.4.1.12356.101.13.2.1.1.6.1 1884
43 # .1.3.6.1.4.1.12356.101.13.2.1.1.6.2 742
45 # only one node given => standalone cluster
46 # .1.3.6.1.4.1.12356.101.13.2.1.1.11.1 ""
47 # .1.3.6.1.4.1.12356.101.13.2.1.1.3.1 0
48 # .1.3.6.1.4.1.12356.101.13.2.1.1.4.1 19
49 # .1.3.6.1.4.1.12356.101.13.2.1.1.6.1 443
51 # .--Info----------------------------------------------------------------.
52 # | ___ __ |
53 # | |_ _|_ __ / _| ___ |
54 # | | || '_ \| |_ / _ \ |
55 # | | || | | | _| (_) | |
56 # | |___|_| |_|_| \___/ |
57 # | |
58 # '----------------------------------------------------------------------'
61 def parse_fortigate_node(info):
62 parsed = {}
63 if info[0]:
64 parsed["cluster_info"] = info[0][0]
66 for hostname, cpu_str, memory_str, sessions_str, oid_end in info[1]:
67 # This means we have a standalone cluster
68 if len(info[1]) == 1:
69 item_name = "Cluster"
70 elif hostname:
71 item_name = hostname
72 else:
73 item_name = "Node %s" % oid_end
75 parsed.setdefault("nodes", {})
76 parsed["nodes"].setdefault(item_name, {
77 "cpu": float(cpu_str),
78 "memory": int(memory_str),
79 "sessions": int(sessions_str),
82 return parsed
85 def inventory_fortigate_cluster(parsed):
86 if "cluster_info" in parsed:
87 return [(None, None)]
90 def check_fortigate_cluster(_no_item, _no_params, parsed):
91 map_mode = {
92 "1": "Standalone",
93 "2": "Active/Active",
94 "3": "Active/Passive",
97 if "cluster_info" in parsed:
98 system_mode, group_name = parsed["cluster_info"]
99 return 0, "System mode: %s, Group: %s" % (map_mode[system_mode], group_name)
102 check_info["fortigate_node"] = {
103 "parse_function": parse_fortigate_node,
104 "inventory_function": inventory_fortigate_cluster,
105 "check_function": check_fortigate_cluster,
106 "service_description": "Cluster Info",
107 "snmp_scan_function": lambda oid: ".1.3.6.1.4.1.12356.101.1" in oid(".1.3.6.1.2.1.1.2.0"),
108 "snmp_info": [
110 ".1.3.6.1.4.1.12356.101.13.1",
112 1, # fgHaSystemMode
113 7, # fgHaGroupName
116 ".1.3.6.1.4.1.12356.101.13.2.1.1",
118 11, # fgHaStatsHostname
119 3, # fgHaStatsCpuUsage
120 4, # fgHaStatsMemUsage
121 6, # fgHaStatsSesCount
122 OID_END
128 # .--CPU-----------------------------------------------------------------.
129 # | ____ ____ _ _ |
130 # | / ___| _ \| | | | |
131 # | | | | |_) | | | | |
132 # | | |___| __/| |_| | |
133 # | \____|_| \___/ |
134 # | |
135 # '----------------------------------------------------------------------'
137 fortigate_node_cpu_default_levels = (80.0, 90.0)
140 def inventory_fortigate_node_cpu(parsed):
141 for hostname in parsed["nodes"]:
142 yield hostname, "fortigate_node_cpu_default_levels"
145 def check_fortigate_node_cpu(item, params, parsed):
146 if item in parsed["nodes"]:
147 return check_cpu_util(parsed["nodes"][item]["cpu"], params)
150 check_info["fortigate_node.cpu"] = {
151 "inventory_function": inventory_fortigate_node_cpu,
152 "check_function": check_fortigate_node_cpu,
153 "service_description": "CPU utilization %s",
154 "has_perfdata": True,
155 "includes": ["cpu_util.include"],
159 # .--Memory--------------------------------------------------------------.
160 # | __ __ |
161 # | | \/ | ___ _ __ ___ ___ _ __ _ _ |
162 # | | |\/| |/ _ \ '_ ` _ \ / _ \| '__| | | | |
163 # | | | | | __/ | | | | | (_) | | | |_| | |
164 # | |_| |_|\___|_| |_| |_|\___/|_| \__, | |
165 # | |___/ |
166 # '----------------------------------------------------------------------'
168 #fortigate_node_memory_default_levels = (70, 80)
169 factory_settings['fortigate_node_memory_default_levels'] = {
170 'levels': (70.0, 80.0),
174 def inventory_fortigate_node_mem(parsed):
175 for hostname in parsed["nodes"]:
176 yield hostname, {}
179 def check_fortigate_node_mem(item, params, parsed):
180 if item in parsed["nodes"]:
181 status = 3
182 current = parsed["nodes"][item]["memory"]
183 # This check is only able to check the used space
184 # The checkgroup "memory" might set negative values which act as levels for free space
185 # These levels are converted to used space, too..
186 if isinstance(params, dict):
187 warn, crit = map(abs, params["levels"])
188 else:
189 warn, crit = map(abs, params)
191 if current >= crit:
192 status = 2
193 elif current >= warn:
194 status = 1
195 else:
196 status = 0
198 if status > 0:
199 wcsuffix = ", (warn/crit at %d/%d)" % (float(warn), float(crit))
200 else:
201 wcsuffix = ""
203 return status, "%s%% used%s" % (current, wcsuffix),\
204 [("mem_usage", current, warn, crit)]
207 check_info["fortigate_node.memory"] = {
208 "inventory_function": inventory_fortigate_node_mem,
209 "check_function": check_fortigate_node_mem,
210 "service_description": "Memory usage %s",
211 "has_perfdata": True,
212 "default_levels_variable": "fortigate_node_memory_default_levels",
213 "group": "fortigate_node_memory",
217 # .--Sessions------------------------------------------------------------.
218 # | ____ _ |
219 # | / ___| ___ ___ ___(_) ___ _ __ ___ |
220 # | \___ \ / _ \/ __/ __| |/ _ \| '_ \/ __| |
221 # | ___) | __/\__ \__ \ | (_) | | | \__ \ |
222 # | |____/ \___||___/___/_|\___/|_| |_|___/ |
223 # | |
224 # '----------------------------------------------------------------------'
226 fortigate_node_sessions_default_levels = (100000, 150000)
229 def inventory_fortigate_node_ses(parsed):
230 for hostname in parsed["nodes"]:
231 yield hostname, "fortigate_node_sessions_default_levels"
234 def check_fortigate_node_ses(item, params, parsed):
235 if item in parsed["nodes"]:
236 if isinstance(params, dict):
237 params = params["levels"]
238 return fortigate_sessions(parsed["nodes"][item]["sessions"], params)
241 check_info["fortigate_node.sessions"] = {
242 "inventory_function": inventory_fortigate_node_ses,
243 "check_function": check_fortigate_node_ses,
244 "service_description": "Sessions %s",
245 "has_perfdata": True,
246 "group": "fortigate_node_sessions",
247 "includes": ["fortigate_sessions.include"],