Projet

Général

Profil

Révision 58c54d79

ID58c54d796ebcdc0e51a755f26b80f4558c247ee7
Parent f477021d
Enfant 9f9a503e

Ajouté par Tim Small il y a presque 14 ans

Minor tidy up and doc fixes

Voir les différences:

plugins/other/tcp
1 1
#!/bin/sh
2
#
3
# tcp: Plugin to monitor IPV4/6 TCP socket status on a Linux host.
4
#
5
# License: GPLv2
6
#
7
# Copyright 2009 Tim Small - tim@seoss.co.uk
8
#
9
# Parameters supported:
10
#
11
#    config
12
#    autoconf
13
#
14
#
15
# Magic markers?
16
#%# family=auto
17
#%# capabilities=autoconf suggest
2

  
3
: <<EOF
4

  
5
=head1 NAME
6

  
7
tcp - Plugin to monitor IPV4/6 TCP socket status on a Linux host.
8

  
9
=head1 AUTHOR
10

  
11
Copyright 2009 Tim Small <tim@seoss.co.uk>
12

  
13
=head1 LICENSE
14

  
15
GPLv2
16

  
17
=begin comment
18

  
19
This program is free software; you can redistribute it and/or modify
20
it under the terms of the GNU General Public License as published by
21
the Free Software Foundation; version 2 dated June, 1991.
22

  
23
This program is distributed in the hope that it will be useful, but
24
WITHOUT ANY WARRANTY; without even the implied warranty of
25
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26
General Public License for more details.
27

  
28
You should have received a copy of the GNU General Public License
29
along with this program; if not, write to the Free Software
30
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
31
USA.
32

  
33
=end comment
34

  
35
=head1 MAGIC MARKERS
36

  
37
 #%# family=manual
38
 #%# capabilities=autoconf
39

  
40
=cut
41

  
42
EOF
18 43

  
19 44
case $1 in
20 45
    config)
......
25 50
graph_args -l 0
26 51
graph_info TCP socket states for the local machine
27 52
EOF
28
	for i in established syn_sent syn_recv fin_wait1 fin_wait2 time_wait close close_wait last_ack listen closing
29
	do
30
		echo ${i}.label $i
31
		echo ${i}.draw LINE2
32
		echo ${i}.info Sockets in state $i
33
	done
34 53

  
54
		for i in established syn_sent syn_recv fin_wait1 \
55
			fin_wait2 time_wait close close_wait last_ack \
56
			listen closing
57
		do
58
			echo ${i}.label $i
59
			echo ${i}.draw LINE2
60
			echo ${i}.info Sockets in state $i
61
		done
62
		
35 63
        exit 0
36
	;;
64
		;;
37 65
    autoconf)
38
        if [ -f /proc/net/tcp -o -f /proc/net/tcp6 ] ; then
39
	    echo yes
40
	    exit 0
41
	else
42
	    echo no
43
	    exit 1
44
	fi
66
        if [ -f /proc/net/tcp -o -f /proc/net/tcp6 ]
67
		then
68
			echo yes
69
			exit 0
70
		else
71
			echo no
72
			exit 1
73
		fi
45 74
esac
46 75

  
47 76
# See #include <netinet/tcp.h>
48 77

  
49 78
cat /proc/net/tcp* | awk '
50
  BEGIN  { STATE["01"]=STATE["02"]=STATE["03"]=STATE["04"]=STATE["05"]=STATE["06"]=STATE["07"]=STATE["08"]=STATE["09"]=STATE["0A"]=STATE["0B"]=0; }
51
  match ($4, /0[0-9A-B]/) { STATE[$4]++; }
52
  END    { print "established.value " STATE["01"];
53
           print "syn_sent.value "    STATE["02"];
54
	   print "syn_recv.value "    STATE["03"];
55
	   print "fin_wait1.value "   STATE["04"];
56
	   print "fin_wait2.value "   STATE["05"];
57
	   print "time_wait.value "   STATE["06"];
58
	   print "close.value "       STATE["07"];
59
	   print "close_wait.value "  STATE["08"];
60
	   print "last_ack.value "    STATE["09"];
61
	   print "listen.value "      STATE["0A"];
62
	   print "closing.value "     STATE["0B"];
63
	 }'
79

  
80
  match ($4, /0[0-9A-B]/) {
81
      STATE[$4]++;
82
  }
83

  
84
  END {
85
      printf "established.value %d\n", STATE["01"];
86
      printf "syn_sent.value %d\n",    STATE["02"];
87
      printf "syn_recv.value %d\n",    STATE["03"];
88
      printf "fin_wait1.value %d\n",   STATE["04"];
89
      printf "fin_wait2.value %d\n",   STATE["05"];
90
      printf "time_wait.value %d\n",   STATE["06"];
91
      printf "close.value %d\n",       STATE["07"];
92
      printf "close_wait.value %d\n",  STATE["08"];
93
      printf "last_ack.value %d\n",    STATE["09"];
94
      printf "listen.value %d\n",      STATE["0A"];
95
      printf "closing.value %d\n",     STATE["0B"];
96
  }'

Formats disponibles : Unified diff