Cleanup config.nodes_of
[check_mk.git] / checks / netstat.include
blobb07dac3bf8ab3c5306ea67c714a73cb8de84fc9b
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 # Item is a user defined identifier of the connection.
28 # Example for params:
29 # {
30 # "proto" : "UDP",
31 # "local_ip" : "10.1.1.99",
32 # "remote_port" : 5665,
33 # "state" : "ESTABLISHED",
34 # }
35 # Other keys: local_port, remote_ip. Missing entries do not care.
38 def check_netstat_generic(item, params, connections):
39 found = 0
40 for proto, (local_ip, local_port), (remote_ip, remote_port), connstate in connections:
41 # Beware: port numbers are strings here.
42 match = True
43 for k, v in [
44 ("local_ip", local_ip),
45 ("local_port", local_port),
46 ("remote_ip", remote_ip),
47 ("remote_port", remote_port),
48 ("proto", proto),
49 ("state", connstate),
51 if k in params and str(params[k]) != v:
52 match = False
53 break
54 if match:
55 found += 1
57 infotext = "Found %d matching entries" % found
58 states = [0]
59 if params.get("min_states"):
60 min_warn, min_crit = params["min_states"]
61 if found < min_crit:
62 min_state = 2
63 elif found < min_warn:
64 min_state = 1
65 else:
66 min_state = 0
67 if min_state:
68 states.append(min_state)
69 infotext += " (warn/crit below %d/%d)" % (min_warn, min_crit)
71 if params.get("max_states"):
72 max_warn, max_crit = params["max_states"]
73 perfdata = [("connections", found, max_warn, max_crit)]
74 if found >= max_crit:
75 max_state = 2
76 elif found >= max_warn:
77 max_state = 1
78 else:
79 max_state = 0
80 if max_state:
81 states.append(max_state)
82 infotext += " (warn/crit at %d/%d)" % (max_warn, max_crit)
83 else:
84 perfdata = [("connections", found)]
86 yield max(states), infotext, perfdata