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 # Example output from agent (Linux) - note missing LISTENING column for UDP
29 # tcp 0 0 0.0.0.0:6556 0.0.0.0:* LISTENING
30 # tcp 0 0 127.0.0.1:445 0.0.0.0:* LISTENING
31 # tcp 0 0 10.1.1.50:445 0.0.0.0:* LISTENING
32 # tcp 0 0 127.0.0.1:57573 127.0.0.1:80 ESTABLISHED
33 # tcp 0 0 10.1.1.50:38692 178.248.246.154:993 ESTABLISHED
34 # tcp 0 0 127.0.0.1:34929 127.0.0.1:5000 TIME_WAIT
35 # tcp 0 0 127.0.0.1:34922 127.0.0.1:5000 TIME_WAIT
36 # tcp 0 0 127.0.0.1:80 127.0.0.1:57454 TIME_WAIT
37 # tcp 0 0 127.0.0.1:35005 127.0.0.1:5000 TIME_WAIT
38 # tcp 0 0 10.1.1.50:38612 178.248.246.154:993 ESTABLISHED
39 # tcp 0 0 127.0.0.1:80 127.0.0.1:57548 TIME_WAIT
40 # tcp 0 0 127.0.0.1:34981 127.0.0.1:5000 TIME_WAIT
41 # tcp 0 0 127.0.0.1:54552 127.0.0.1:13419 ESTABLISHED
42 # tcp 0 0 127.0.0.1:35012 127.0.0.1:5000 TIME_WAIT
43 # tcp 0 0 127.0.0.1:34910 127.0.0.1:5000 TIME_WAIT
44 # tcp 0 0 127.0.0.1:34915 127.0.0.1:5000 TIME_WAIT
45 # tcp 0 0 127.0.0.1:80 127.0.0.1:57546 TIME_WAIT
46 # tcp 0 0 127.0.0.1:34935 127.0.0.1:5000 TIME_WAIT
47 # tcp 0 0 127.0.0.1:34984 127.0.0.1:5000 TIME_WAIT
48 # tcp 0 0 127.0.0.1:80 127.0.0.1:57488 TIME_WAIT
49 # tcp 0 0 127.0.0.1:34967 127.0.0.1:5000 TIME_WAIT
50 # udp 0 0 10.1.2.255:137 0.0.0.0:*
51 # udp 0 0 10.1.2.160:137 0.0.0.0:*
52 # udp 0 0 0.0.0.0:137 0.0.0.0:*
54 # Example Output for AIX:
55 # tcp4 0 0 127.0.0.1.1234 127.0.0.1.5678 ESTABLISHED
58 def parse_netstat(info
):
59 def split_ip_address(ip_address
):
61 return ip_address
.rsplit(":", 1)
62 return ip_address
.rsplit(".", 1)
67 proto
, _recv_q
, _send_q
, local
, remote
, connstate
= line
68 if proto
.startswith("tcp"): # also tcp4 and tcp6
70 elif proto
.startswith("udp"):
72 # Ubuntu recently deviced to use "LISTEN" instead of "LISTENING"
73 if connstate
== "LISTEN":
74 connstate
= "LISTENING"
76 if len(line
) == 5: # handles UDP listeners
77 proto
, _recv_q
, _send_q
, local
, remote
= line
78 if proto
.startswith("udp"):
80 connstate
= "LISTENING"
82 connections
.append((proto
, split_ip_address(local
), split_ip_address(remote
), connstate
))
86 check_info
["netstat"] = {
87 'parse_function': parse_netstat
,
88 'check_function': check_netstat_generic
,
89 'service_description': "TCP Connection %s",
90 'group': "tcp_connections",
91 'includes': ["netstat.include"],