Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / pfsense_counter
blob75f8bea867fb16c9159f3d94eba49fd80d7d8bd1
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.
27 factory_settings["pfsense_counter_default_levels"] = {
28 "badoffset": (100.0, 10000.0),
29 "short": (100.0, 10000.0),
30 "memdrop": (100.0, 10000.0),
31 "normalized": (100.0, 10000.0),
32 "fragment": (100.0, 10000.0),
33 "average": 3,
37 def parse_pfsense_counter(info):
38 names = {
39 "1.0": "matched",
40 "2.0": "badoffset",
41 "3.0": "fragment",
42 "4.0": "short",
43 "5.0": "normalized",
44 "6.0": "memdrop",
47 parsed = {}
48 for end_oid, counter_text in info:
49 parsed[names[end_oid]] = int(counter_text)
50 return parsed
53 def inventory_pfsense_counter(parsed):
54 return [(None, {})]
57 def check_pfsense_counter(_no_item, params, parsed):
59 namestoinfo = {
60 "matched": "Packets that matched a rule",
61 "badoffset": "Packets with bad offset",
62 "fragment": "Fragmented packets",
63 "short": "Short packets",
64 "normalized": "Normalized packets",
65 "memdrop": "Packets dropped due to memory limitations",
68 this_time = time.time()
70 if params.get("average"):
71 backlog_minutes = params["average"]
72 yield 0, "Values averaged over %d min" % params["average"]
73 else:
74 backlog_minutes = None
76 for what in parsed:
77 rate = get_rate("pfsense_counter-%s" % what, this_time, parsed[what])
78 perfrate = ("fw_packets_" + what, rate)
80 if backlog_minutes:
81 avgrate = get_average("pfsense_counter-%srate" % what, this_time, rate, backlog_minutes)
82 check_against = avgrate
83 perfavg = ("fw_avg_packets_" + what, avgrate)
84 else:
85 perfavg = None
86 check_against = rate
87 infotext = "%s: %.2f pkts/s" % (namestoinfo[what], check_against)
89 status = 0
90 if params.get(what):
91 warn, crit = params[what]
92 perfrate += params[what]
93 if perfavg:
94 perfavg += params[what]
95 levelstext = " (warn/crit at %.2f/%.2f pkts/s)" % (warn, crit)
96 if crit and check_against >= crit:
97 status = 2
98 infotext += levelstext
99 elif warn and check_against >= warn:
100 status = 1
101 infotext += levelstext
103 perfdata = [perfrate]
104 if perfavg:
105 perfdata.append(perfavg)
107 yield status, infotext, perfdata
110 check_info["pfsense_counter"] = {
111 "default_levels_variable": "pfsense_counter_default_levels",
112 "parse_function": parse_pfsense_counter,
113 "inventory_function": inventory_pfsense_counter,
114 "check_function": check_pfsense_counter,
115 "service_description": "pfSense Firewall Packet Rates",
116 "has_perfdata": True,
117 "snmp_info": (".1.3.6.1.4.1.12325.1.200.1", [OID_END, 2]),
118 "snmp_scan_function": lambda oid: "pfsense" in oid(".1.3.6.1.2.1.1.1.0").lower(),
119 "group": "pfsense_counter",