-
Notifications
You must be signed in to change notification settings - Fork 5
/
pf_
executable file
·153 lines (129 loc) · 4.43 KB
/
pf_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
#
# Copyright (c) 2016 Babak Farrokhi. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# 04-Aug-2015 @farrokhi
# This script extracts pf firewall statistics from from "pfctl -vsi"
# on FreeBSD and feeds to munin
#
# Magic markers:
#%# family=auto
#%# capabilities=autoconf suggest
SCRIPT_NAME=$(basename $0)
STAT_TYPE=`echo $SCRIPT_NAME | sed -n s/pf_//p`
PFCTL="/sbin/pfctl"
STATFILE=`mktemp -t pf`
${PFCTL} -vsi > ${STATFILE} 2>/dev/null
print_config()
{
local fname=$1; shift;
local fdesc=$1; shift;
echo "${fname}.label ${fdesc}"
echo "${fname}.draw LINE1"
echo "${fname}.type DERIVE"
echo "${fname}.min 0"
}
if [ $# -lt 1 ]; then
case ${STAT_TYPE} in
state)
cat ${STATFILE} | grep "^State Table" -A4 | grep "current" | awk '{print "state.value "$3}'
;;
state_act)
cat ${STATFILE} | grep "^State Table" -A4 | tail -3 | awk '{print "state_"$1".value",$2}'
;;
source)
cat ${STATFILE} | grep "^Source Tracking Table" -A4 | grep "current" | awk '{print "source.value "$3}'
;;
source_act)
cat ${STATFILE} | grep "^Source Tracking Table" -A4 | tail -3 | awk '{print "source_"$1".value",$2}'
;;
counters)
cat ${STATFILE} | grep "^Counters" -A15 | tail -15 | awk '{print "counter_"$1".value",$2}'
;;
esac
elif [ "$1" == "suggest" ]; then
echo "state"
echo "state_act"
echo "source"
echo "source_act"
echo "counters"
elif [ "$1" == "autoconf" ]; then
${PFCTL} -si >/dev/null 2>&1 && echo yes || echo no
exit 0
elif [ "$1" == "config" ]; then
LIMITFILE=`mktemp -t pf`
${PFCTL} -vsm > ${LIMITFILE} 2>/dev/null
MAX_STATES=`cat ${LIMITFILE} | grep "^states" | awk '{print $4}'`
MAX_SRC=`cat ${LIMITFILE} | grep "^src-nodes" | awk '{print $4}'`
rm ${LIMITFILE}
case ${STAT_TYPE} in
state)
echo "graph_title State Table Entries"
echo "graph_args --lower-limit 0 --base 1000"
echo "graph_vlabel states"
echo "graph_category firewall"
echo "state.label current"
echo "state.critical ${MAX_STATES}"
;;
state_act)
echo "graph_title State Table Activity"
echo "graph_args --lower-limit 0 --base 1000"
echo "graph_vlabel actions / second"
echo "graph_category firewall"
print_config "state_searches" "search"
print_config "state_inserts" "insert"
print_config "state_removals" "removal"
;;
source)
echo "graph_title Source Tracking Table Entries"
echo "graph_args --lower-limit 0 --base 1000"
echo "graph_vlabel sources"
echo "graph_category firewall"
echo "source.label current"
echo "source.min 0"
echo "source.critical ${MAX_SRC}"
;;
source_act)
echo "graph_title Source Tracking Table Activity"
echo "graph_args --lower-limit 0 --base 1000"
echo "graph_vlabel actions / second"
echo "graph_category firewall"
print_config "source_searches" "search"
print_config "source_inserts" "insert"
print_config "source_removals" "removal"
;;
counters)
echo "graph_title Misc Counters"
echo "graph_args --lower-limit 0 --base 1000"
echo "graph_vlabel actions / second"
echo "graph_category firewall"
for i in `cat ${STATFILE} | grep "^Counters" -A15 | tail -15 | awk '{print $1}' `; do
print_config "counter_${i}" ${i}
done
;;
esac
fi
rm ${STATFILE}