Projet

Général

Profil

Révision 52651cc4

ID52651cc471eb537102e5a68b02dda781be356aff
Parent 39714938
Enfant 7d58463d

Ajouté par Gergely Czuczy il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/pf
1
#!/bin/sh
2
#
3
# OpenBSD's pf(4) monitoring for FreeBSD
4
# 2007, Gergely Czuczy <phoemix@harmless.hu>
5
#
6
# Needs to run as root.
7
# Add "user root" for the [pf] into plugins.conf.
8
#
9
# Options:
10
#  - env.do_searches yes: to enable state table search monitoring`
11
#
12
# 0.1 - initial release:
13
# - state table usage
14
# - search rate
15
# - match rate
16
# - state mismatch rate
17
# - blocked packets
18
# - monitoring of labelled rules
19
#
20
# 0.2 - feature improvements:
21
#  - Labelled rules for packet count
22
#  - OpenBSD compatibility
23
#  - Warning and critical on state table
24
#
25
# 0.3 - feature improvements:
26
#  - Aggregate rules with the same label
27
#
28
# 0.4 - feature changes:
29
#  - State searches are optional. it can shrink others.
30
#  - Labelled targets are marked with a leading L
31
#
32
#
33
#%# family=auto
34
#%# capabilities=autoconf
35

  
36
pfctl='/sbin/pfctl'
37

  
38
case $1 in
39
    config)
40
    cat <<EOF
41
graph_title OpenBSD pf statistics
42
graph_vlabel Entries per second
43
graph_scale no
44
graph_category network
45
graph_args -l 0
46
graph_info OpenBSD's pf usage statistics
47
states.label States
48
states.type GAUGE
49
EOF
50
${pfctl} -sm 2> /dev/null | awk '
51
/states/ {print "states.warning "$4*0.9; print "states.critical "$4*0.95}
52
'
53
if [ "x${do_searches}" = "xyes" ]; then
54
    cat <<EOF
55
searches.label Searches
56
searches.min 0
57
searches.type DERIVE
58
EOF
59
fi
60
    cat <<EOF
61
matches.label Matches
62
matches.min 0
63
matches.type DERIVE
64
mismatches.label State mismatches
65
mismatches.min 0
66
mismatches.type DERIVE
67
blocks.label Blocked packets
68
blocks.type DERIVE
69
blocks.min 0
70
EOF
71
pfctl -sl | awk '
72
{
73
 l="";
74
 for (i=1; i<NF-2; i=i+1) l=l" "$i;
75
 sub(/^ /, "", l);
76
 f=l;
77
 gsub(/[^a-z0-9A-Z]/, "_", f);
78
 print f".label L: "l;
79
 print f".type DERIVE"
80
 print f".min 0"}'
81

  
82
    exit 0
83
    ;;
84
    autoconf)
85
	# FreeBSD
86
	ostype=`uname -s`
87
	if [ ${ostype} = "FreeBSD" ]; then
88
	    # enabled?
89
	    if [ `pfctl -si 2>/dev/null | awk '/^Status:/{print $2}'` != "Enabled" ]; then
90
		echo "no (pf(4) is not enabled, consult pfctl(8)"
91
		exit 1
92
	    fi
93
	# OpenBSD
94
	elif [ ${ostype} = "OpenBSD" ]; then
95
	    # pf(4) module loaded?
96
	    if [ `kldstat -v | grep pf | wc -l` -eq 0 ]; then
97
		echo "no (pf(4) is not loaded)"
98
		exit 1
99
	    fi
100
            # enabled?
101
	    if [ `pfctl -si 2>/dev/null | awk '/^Status:/{print $2}'` != "Enabled" ]; then
102
		echo "no (pf(4) is not enabled, consult pfctl(8)"
103
		exit 1
104
	    fi
105
	# Other OSes
106
	else
107
	    echo "no (this plugin is not supported on your OS)"
108
	    exit 1
109
	fi
110
	echo "yes"
111
	exit 0
112
	;;
113
    suggest)
114
	exit 0;
115
	;;
116
esac
117

  
118
#
119
${pfctl} -si 2>/dev/null | awk '
120
/current entries/{print "states.value",$3}
121
/searches/{if ( "'${do_searches}'" == "yes" ) print "searches.value",$2}
122
$1~/^match$/{print "matches.value",$2}
123
/state-mismatch/{print "mismatches.value",$2}'
124
${pfctl} -vsr 2> /dev/null| grep -A 1 ^block | awk 'BEGIN {sum=0}/^[ \t]*\[/{sum=sum+$5} END {print "blocks.value",sum}'
125

  
126
# the labeled ones
127
pfctl -sl | awk '
128
BEGIN {
129
 total=0
130
}
131
{
132
 l="";
133
 for (i=1; i<NF-2; i=i+1) l=l" "$i;
134
 sub(/^ /, "", l);
135
 f=l;
136
 gsub(/[^a-z0-9A-Z]/, "_", f);
137
 total=total+1;
138
 fields[f]=fields[f]+$(NF-i+2);
139
}
140
END {
141
 if ( total == 0 ) exit 0;
142
 for ( k in fields ) print k".value "fields[k]
143
}'

Formats disponibles : Unified diff