2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
31 # "local_ip" : "10.1.1.99",
32 # "remote_port" : 5665,
33 # "state" : "ESTABLISHED",
35 # Other keys: local_port, remote_ip. Missing entries do not care.
38 def check_netstat_generic(item
, params
, connections
):
40 for proto
, (local_ip
, local_port
), (remote_ip
, remote_port
), connstate
in connections
:
41 # Beware: port numbers are strings here.
44 ("local_ip", local_ip
),
45 ("local_port", local_port
),
46 ("remote_ip", remote_ip
),
47 ("remote_port", remote_port
),
51 if k
in params
and str(params
[k
]) != v
:
57 infotext
= "Found %d matching entries" % found
59 if params
.get("min_states"):
60 min_warn
, min_crit
= params
["min_states"]
63 elif found
< min_warn
:
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
)]
76 elif found
>= max_warn
:
81 states
.append(max_state
)
82 infotext
+= " (warn/crit at %d/%d)" % (max_warn
, max_crit
)
84 perfdata
= [("connections", found
)]
86 yield max(states
), infotext
, perfdata