Module: check_mk
Branch: master
Commit: 227a930fa3bcdde1741ab059a9b8bfc15dfafc3e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=227a930fa3bcdd…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Jun 22 10:41:38 2018 +0200
Unified winperf_tcp_conn and tcp_conn_stats check plugins
Change-Id: I775697992f6f65c89a71cd8438ecfa7a7c787cfa
---
checks/tcp_conn_stats | 30 +++++++++++++++---
checks/tcp_connections.include | 70 ++++++++++++------------------------------
checks/winperf_tcp_conn | 57 +++++++++++++---------------------
3 files changed, 66 insertions(+), 91 deletions(-)
diff --git a/checks/tcp_conn_stats b/checks/tcp_conn_stats
index aa99bca..f91d380 100644
--- a/checks/tcp_conn_stats
+++ b/checks/tcp_conn_stats
@@ -40,20 +40,40 @@
def parse_tcp_conn_stats(info):
+ map_counter_keys = {
+ 1 : "ESTABLISHED", # connection up and passing data
+ 2 : "SYN_SENT", # session has been requested by us; waiting for
reply from remote endpoint
+ 3 : "SYN_RECV", # session has been requested by a remote endpoint
for a socket on which we were listening
+ 4 : "FIN_WAIT1", # our socket has closed; we are in the process of
tearing down the connection
+ 5 : "FIN_WAIT2", # the connection has been closed; our socket is
waiting for the remote endpoint to shut down
+ 6 : "TIME_WAIT", # socket is waiting after closing for any packets
left on the network
+ 7 : "CLOSED", # socket is not being used (FIXME. What does
mean?)
+ 8 : "CLOSE_WAIT", # remote endpoint has shut down; the kernel is
waiting for the application to close the socket
+ 9 : "LAST_ACK", # our socket is closed; remote endpoint has also
shut down; we are waiting for a final acknowledgement
+ 10 : "LISTEN", # represents waiting for a connection request from
any remote TCP and port
+ 11 : "CLOSING", # our socket is shut down; remote endpoint is shut
down; not all data has been sent
+ }
+
parsed = {}
- for tcp_state, tcp_count in info:
+ for line in info:
+ tcp_state = line[0]
if len(tcp_state) == 2:
- tcp_state = int(tcp_state, 16) # Hex
- parsed[tcp_state] = int(tcp_count)
+ tcp_state = map_counter_keys.get(int(tcp_state, 16)) # Hex
+ if tcp_state is None:
+ continue
+ try:
+ parsed[tcp_state] = int(line[1])
+ except ValueError:
+ pass
return parsed
check_info["tcp_conn_stats"] = {
'parse_function' : parse_tcp_conn_stats,
- 'check_function' : check_tcp_connections,
'inventory_function' : inventory_tcp_connections,
+ 'check_function' : check_tcp_connections,
'service_description' : 'TCP Connections',
'has_perfdata' : True,
'group' : 'tcp_conn_stats',
- 'includes' : [ "tcp_connections.include" ],
+ 'includes' : ["tcp_connections.include"],
}
diff --git a/checks/tcp_connections.include b/checks/tcp_connections.include
index 3d7ed62..a2a342f 100644
--- a/checks/tcp_connections.include
+++ b/checks/tcp_connections.include
@@ -24,31 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-tcp_conn_stats_default_levels = {}
-
-tcp_connections_state_map = [
- ("ESTABLISHED", 1), # connection up and passing data
- ("SYN_SENT", 2), # session has been requested by us; waiting for
reply from remote endpoint
- ("SYN_RECV", 3), # session has been requested by a remote endpoint
for a socket on which we were listening
- ("LAST_ACK", 9), # our socket is closed; remote endpoint has also
shut down; we are waiting for a final acknowledgement
- ("CLOSE_WAIT", 8), # remote endpoint has shut down; the kernel is
waiting for the application to close the socket
- ("TIME_WAIT", 6), # socket is waiting after closing for any packets
left on the network
- ("CLOSED", 7), # socket is not being used (FIXME. What does
mean?)
- ("CLOSING", 11), # our socket is shut down; remote endpoint is shut
down; not all data has been sent
- ("FIN_WAIT1", 4), # our socket has closed; we are in the process of
tearing down the connection
- ("FIN_WAIT2", 5), # the connection has been closed; our socket is
waiting for the remote endpoint to shut down
- ("LISTEN", 10), # represents waiting for a connection request from
any remote TCP and port
- ("BOUND", None), # Socket did a bound() but TCP stack not yet active
(Solaris)
- ("IDLE", None), # TCP endpoints are in IDLE state when first
created
-]
-# parsed can be:
-# parsed = {
-# 1 : 6,
-# 6 : 17,
-# 8 : 1,
-# 10 : 10,
-# }
# parsed = {
# "ESTABLISHED" : 6,
# "BOUND" : 17,
@@ -57,36 +33,30 @@ tcp_connections_state_map = [
# }
+tcp_conn_stats_default_levels = {}
+
+
def inventory_tcp_connections(parsed):
- if len(parsed) > 0:
+ if parsed:
return [ (None, 'tcp_conn_stats_default_levels') ]
def check_tcp_connections(item, params, parsed):
- hit = False
- for tcp_state_readable, tcp_state_int_str in tcp_connections_state_map:
- num = parsed.get(tcp_state_readable, \
- parsed.get(tcp_state_int_str, 0))
- state = 0
- perf = [tcp_state_readable, num]
- if num > 0: # Only check positive counts
- hit = True
- infotext = "%s: %d" % (tcp_state_readable, num)
- levels = params.get(tcp_state_readable)
- if levels:
- warn, crit = levels
- perf.append(warn)
- perf.append(crit)
- if num >= crit:
- state = 2
- elif num >= warn:
- state = 1
- if state > 0:
- infotext += " (warn/crit at %d/%d)" % (warn, crit)
- yield state, infotext, [ tuple(perf) ]
- else:
- yield 0, None, [ tuple(perf) ]
-
- if not hit:
+ if not parsed:
yield 0, "Currently no TCP connections"
+ return
+ for tcp_state, tcp_count in parsed.iteritems():
+ if tcp_count <= 0:
+ continue
+
+ infotext = "%s: %s" % (tcp_state, tcp_count)
+ state = 0
+ warn, crit = params.get(tcp_state, (None, None))
+ if crit is not None and tcp_count >= crit:
+ state = 2
+ elif warn is not None and tcp_count >= warn:
+ state = 1
+ if state:
+ infotext += " (warn/crit at %d/%d)" % (warn, crit)
+ yield state, infotext, [(tcp_state, tcp_count, warn, crit)]
diff --git a/checks/winperf_tcp_conn b/checks/winperf_tcp_conn
index 1d8e425..a4401a9 100644
--- a/checks/winperf_tcp_conn
+++ b/checks/winperf_tcp_conn
@@ -38,45 +38,30 @@
# 16 18437 counter
-def inventory_winperf_tcp_conn(info):
- if len(info) > 1:
- return [ (None, {}) ]
+def parse_winperf_tcp_conn(info):
+ map_counter_keys = {
+ "2": "ESTABLISHED",
+ }
-
-def check_winperf_tcp_conn(item, params, info):
- if len(info) == 1:
- raise MKCounterWrapped("Got no information from agent")
-
- fields = [
- ( 2, "Established", "ESTABLISHED" ),
- ]
- infotext = ""
- worst_state = 0
- perfdata = []
- for offset, name, param_key in fields:
- value = saveint(info[offset][1])
- infotext += "%s: %s" % (name, value)
- warn, crit = "", ""
- if params.get(param_key):
- warn, crit = params.get(param_key)
- if value >= crit:
- worst_state = 2
- infotext += "(!!) (critical at %d)" % crit
- elif value >= warn:
- worst_state = max(1, worst_state)
- infotext += "(!) (warning at %d)" % warn
- infotext += ", "
- perfdata.append( (name, value, warn, crit) )
-
- infotext = infotext[:-2]
- return worst_state, infotext, perfdata
+ parsed = {}
+ for line in info:
+ tcp_state = map_counter_keys.get(line[0])
+ if tcp_state is None:
+ continue
+ try:
+ parsed[tcp_state] = int(line[1])
+ except ValueError:
+ pass
+ return parsed
check_info["winperf_tcp_conn"] = {
- 'check_function': check_winperf_tcp_conn,
- 'inventory_function': inventory_winperf_tcp_conn,
- 'service_description': 'TCP connections',
- 'has_perfdata': True,
- 'group': 'tcp_conn_stats',
+ 'parse_function' : parse_winperf_tcp_conn,
+ 'inventory_function' : inventory_tcp_connections,
+ 'check_function' : check_tcp_connections,
+ 'service_description' : 'TCP connections',
+ 'has_perfdata' : True,
+ 'group' : 'tcp_conn_stats',
+ 'includes' : ["tcp_connections.include"],
}