Module: check_mk
Branch: master
Commit: 16493666950d8a8e3518816c3e7e918611227efe
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=16493666950d8a…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Jul 2 18:22:38 2013 +0200
win_netstat: New check for Windows for checking TCP/UDP connections
---
ChangeLog | 2 +
checks/win_netstat | 118 ++++++++++++++++++++++++++++++++++
web/plugins/wato/check_parameters.py | 68 ++++++++++++++------
3 files changed, 167 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4528939..829ce94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,8 @@
* esx_vsphere_object: make check state configurable
* mk_logwatch: support continuation lines with 'A'. Please refer to docu.
* mk_oracle: Added plugin for solaris
+ * win_netstat: New check for Windows for checking the existance of a UDP/TCP
+ connection or listener
Notifications:
* notify.py: Matching service level: Use the hosts service level if a
diff --git a/checks/win_netstat b/checks/win_netstat
new file mode 100644
index 0000000..76876c2
--- /dev/null
+++ b/checks/win_netstat
@@ -0,0 +1,118 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+
+# Example output from agent (German Windows XP)
+# <<<win_netstat>>>
+#
+# Aktive Verbindungen
+#
+# Proto Lokale Adresse Remoteadresse Status
+# TCP 0.0.0.0:135 0.0.0.0:0 ABHREN
+# TCP 0.0.0.0:445 0.0.0.0:0 ABHREN
+# TCP 0.0.0.0:2869 0.0.0.0:0 ABHREN
+# TCP 0.0.0.0:6556 0.0.0.0:0 ABHREN
+# TCP 10.1.1.99:139 0.0.0.0:0 ABHREN
+# TCP 10.1.1.99:445 10.1.1.123:52820 HERGESTELLT
+# TCP 10.1.1.99:6556 10.1.1.50:43257 WARTEND
+# TCP 10.1.1.99:6556 10.1.1.50:43288 WARTEND
+# TCP 10.1.1.99:6556 10.1.1.50:43309 WARTEND
+# TCP 127.0.0.1:1029 127.0.0.1:5354 HERGESTELLT
+# TCP 127.0.0.1:1030 0.0.0.0:0 ABHREN
+# TCP 127.0.0.1:1040 127.0.0.1:27015 HERGESTELLT
+# TCP 127.0.0.1:5354 0.0.0.0:0 ABHREN
+# TCP 127.0.0.1:5354 127.0.0.1:1029 HERGESTELLT
+# TCP 127.0.0.1:27015 0.0.0.0:0 ABHREN
+# TCP 127.0.0.1:27015 127.0.0.1:1040 HERGESTELLT
+# UDP 0.0.0.0:445 *:*
+# UDP 0.0.0.0:500 *:*
+# UDP 127.0.0.1:1042 *:*
+# UDP 127.0.0.1:1900 *:*
+
+win_netstat_states = {
+ "ABH\x99REN" : "LISTEN",
+ "HERGESTELLT" : "ESTABLISHED",
+ "WARTEND" : "TIME_WAIT",
+ # Add further states in any required language here. Sorry, Windows
+ # has no "unset LANG" ;-)
+}
+
+
+def parse_win_netstat(info):
+ connections = []
+ for line in info:
+ if line[0] == "TCP":
+ proto, local, remote, connstate = line
+ elif line[0] == "UDP":
+ proto, local, remote = line
+ connstate = "LISTEN"
+ else:
+ continue
+ connections.append( (proto, local.split(":"),
remote.split(":"),
+ win_netstat_states.get(connstate, connstate)) )
+ return connections
+
+# Item is a user defined identifier of the connection.
+# Example for params:
+# {
+# "proto" : "UDP",
+# "local_ip" : "10.1.1.99",
+# "remote_port" : 5665,
+# "state" : "ESTABLISHED",
+# }
+# Other keys: local_port, remote_ip. Missing entries do not care.
+
+
+def check_win_netstat(item, params, info):
+ connections = parse_win_netstat(info)
+ found = 0
+ for proto, (local_ip, local_port), (remote_ip, remote_port), connstate in
connections:
+ # Beware: port numbers are strings here.
+ match = True
+ for k, v in [
+ ( "local_ip", local_ip ),
+ ( "local_port", local_port ),
+ ( "remote_ip", remote_ip ),
+ ( "remote_port", remote_port ),
+ ( "proto", proto ),
+ ( "state", connstate )]:
+ if k in params and str(params[k]) != v:
+ match = False
+ break
+ if match:
+ found += 1
+
+ if found:
+ state = 0
+ else:
+ state = 2
+ return state, "Found %d matching entries" % found
+
+check_info["win_netstat"] = {
+ 'check_function' : check_win_netstat,
+ 'service_description' : "TCP Connection %s",
+ 'group' : "tcp_connections",
+}
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 186b2ae..5cc95d5 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -1028,27 +1028,6 @@ register_check_parameters(
None
)
-register_check_parameters(
- subgroup_networking,
- "tcp_conn_stats_win",
- ("TCP connection stats (Windows)"),
- Dictionary(
- elements = [
- ( "ESTABLISHED",
- Tuple(
- title = _("ESTABLISHED"),
- help = _("connection up and passing data"),
- elements = [
- Integer(title = _("Warning at"), label =
_("connections")),
- Integer(title = _("Critical at"), label =
_("connections"))
- ]
- )
- )
- ]
- ),
- None,
- "first"
-)
register_check_parameters(
subgroup_networking,
@@ -1180,6 +1159,53 @@ register_check_parameters(
"first"
)
+
+register_check_parameters(
+ subgroup_networking,
+ "tcp_connections",
+ _("Monitor specific TCP/UDP connections and listeners"),
+ Dictionary(
+ help = _("This rule allows to monitor the existance of specify TCP
connections or "
+ "TCP/UDP listeners."),
+ elements = [
+ ( "proto",
+ DropdownChoice(
+ title = _("Protocol"),
+ choices = [ ("TCP", _("TCP")), ("UDP",
_("UDP")) ],
+ default_value = "TCP",
+ ),
+ ),
+ ( "state",
+ DropdownChoice(
+ title = _("State"),
+ choices = [
+ ( "ESTABLISHED", "ESTABLISHED" ),
+ ( "SYN_SENT", "SYN_SENT" ),
+ ( "SYN_RECV", "SYN_RECV" ),
+ ( "LAST_ACK", "LAST_ACK" ),
+ ( "CLOSE_WAIT", "CLOSE_WAIT" ),
+ ( "TIME_WAIT", "TIME_WAIT" ),
+ ( "CLOSED", "CLOSED" ),
+ ( "CLOSING", "CLOSING" ),
+ ( "FIN_WAIT1", "FIN_WAIT1" ),
+ ( "FIN_WAIT2", "FIN_WAIT2" ),
+ ( "BOUND", "BOUND" ),
+ ]
+ ),
+ ),
+ ( "local_ip", IPv4Address(title = _("Local IP
address"))),
+ ( "local_port", Integer(title = _("Local port number"),
minvalue = 1, maxvalue = 65535, )),
+ ( "remote_ip", IPv4Address(title = _("Remote IP
address"))),
+ ( "remote_port", Integer(title = _("Local port number"),
minvalue = 1, maxvalue = 65535, )),
+ ]
+ ),
+ TextAscii(title = _("Connection name"), help = _("Specify an arbitrary
name of this connection here"), allow_empty = False),
+ "dict",
+ has_inventory = False,
+)
+
+
+
register_check_parameters(
subgroup_applications,
"msx_queues",