Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / f5_bigip_snat
blob667a9846d1853cb5943d8ef800905e7b6d17a8a3
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.
28 def parse_f5_bigip_snat(info):
29 snats = {}
30 for line in info:
31 name = line[0]
32 snats.setdefault(name, {})
33 snats[name].setdefault("if_in_pkts", []).append(int(line[1]))
34 snats[name].setdefault("if_out_pkts", []).append(int(line[2]))
35 snats[name].setdefault("if_in_octets", []).append(int(line[3]))
36 snats[name].setdefault("if_out_octets", []).append(int(line[4]))
37 snats[name].setdefault("connections_rate", []).append(int(line[5]))
38 snats[name].setdefault("connections", []).append(int(line[6]))
39 return snats
42 def inventory_f5_bigip_snat(parsed):
43 for name in parsed.iterkeys():
44 yield name, {}
47 def check_f5_bigip_snat(item, params, parsed):
48 if item in parsed:
49 snat = parsed[item]
51 summed_values = {}
52 now = time.time()
53 # Calculate counters
54 for what in [
55 "if_in_pkts",
56 "if_out_pkts",
57 "if_in_octets",
58 "if_out_octets",
59 "connections_rate",
61 summed_values.setdefault(what, 0)
62 for idx, entry in enumerate(snat[what]):
63 rate = get_rate("%s.%s" % (what, idx), now, entry)
64 summed_values[what] += rate
66 # Calculate sum value
67 for what, function in [("connections", sum)]:
68 summed_values[what] = function(snat[what])
70 perfdata = summed_values.items()
72 # Current number of connections
73 yield 0, "Client connections: %d" % summed_values["connections"], perfdata
75 # New connections per time
76 yield 0, "Rate: %.2f/sec" % summed_values["connections_rate"]
78 # Check configured limits
79 map_paramvar_to_text = {
80 "if_in_octets": "Incoming Bytes",
81 "if_out_octets": "Outgoing Bytes",
82 "if_total_octets": "Total Bytes",
83 "if_in_pkts": "Incoming Packets",
84 "if_out_pkts": "Outgoing Packets",
85 "if_total_pkts": "Total Packets",
87 summed_values[
88 "if_total_octets"] = summed_values["if_in_octets"] + summed_values["if_out_octets"]
89 summed_values["if_total_pkts"] = summed_values["if_in_pkts"] + summed_values["if_out_pkts"]
90 for param_var, levels in params.items():
91 if param_var.endswith("_lower") and isinstance(levels, tuple):
92 levels = (None, None) + levels
93 value = summed_values[param_var.rstrip("_lower")]
94 state, infotext, _extra_perfdata = check_levels(
95 value,
96 param_var,
97 levels,
98 human_readable_func=
99 lambda x, p=param_var: get_bytes_human_readable(x, base=1000.0) if "octets" in p else str(x),
100 infoname=map_paramvar_to_text[param_var.rstrip("_lower")])
101 if state:
102 yield state, infotext
105 check_info["f5_bigip_snat"] = {
106 "parse_function" : parse_f5_bigip_snat,
107 "check_function" : check_f5_bigip_snat,
108 "inventory_function" : inventory_f5_bigip_snat,
109 "group" : "f5_bigip_snat",
110 "service_description" : "Source NAT %s",
111 "has_perfdata" : True,
112 "snmp_info" : (".1.3.6.1.4.1.3375.2.2.9.2.3.1", [
113 "1", #ltmSnatStatName
114 "2", #ltmSnatStatClientPktsIn
115 "3", #ltmSnatStatClientBytesIn
116 "4", #ltmSnatStatClientPktsOut
117 "5", #ltmSnatStatClientBytesOut
118 "7", #ltmSnatStatClientTotConns
119 "8", #ltmSnatStatClientCurConns
121 "snmp_scan_function" : lambda oid: ".1.3.6.1.4.1.3375.2" in oid(".1.3.6.1.2.1.1.2.0") \
122 and "big-ip" in oid(".1.3.6.1.4.1.3375.2.1.4.1.0").lower(),