Add unified pf
plugin
This commit is contained in:
parent
fc9c61f0db
commit
fa65a7a365
97
pf
Executable file
97
pf
Executable file
@ -0,0 +1,97 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2018 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.
|
||||
#
|
||||
#
|
||||
# Magic markers:
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
|
||||
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;
|
||||
local ftype=$1; shift;
|
||||
|
||||
echo "${fname}.label ${fdesc}"
|
||||
echo "${fname}.draw LINE1"
|
||||
echo "${fname}.type ${ftype}"
|
||||
echo "${fname}.min 0"
|
||||
}
|
||||
|
||||
if [ "$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}
|
||||
|
||||
echo "graph_title Firewall State Counters"
|
||||
echo "graph_args --lower-limit 0 --base 1000"
|
||||
echo "graph_category firewall"
|
||||
|
||||
print_config "state" "current" "GAUGE"
|
||||
echo "state.critical ${MAX_STATES}"
|
||||
|
||||
print_config "state_searches" "search" "DERIVE"
|
||||
print_config "state_inserts" "insert" "DERIVE"
|
||||
print_config "state_removals" "removal" "DERIVE"
|
||||
|
||||
print_config "source" "current" "GAUGE"
|
||||
echo "source.critical ${MAX_SRC}"
|
||||
|
||||
print_config "source_searches" "search" "DERIVE"
|
||||
print_config "source_inserts" "insert" "DERIVE"
|
||||
print_config "source_removals" "removal" "DERIVE"
|
||||
|
||||
for i in `grep "^Counters" -A15 ${STATFILE} | tail -15 | awk '{print $1}' `; do
|
||||
print_config "counter_${i}" ${i} "DERIVE"
|
||||
done
|
||||
|
||||
else
|
||||
grep "^State Table" -A4 ${STATFILE} | grep "current" | awk '{print "state.value "$3}'
|
||||
grep "^State Table" -A4 ${STATFILE} | tail -3 | awk '{print "state_"$1".value",$2}'
|
||||
grep "^Source Tracking Table" -A4 ${STATFILE} | grep "current" | awk '{print "source.value "$3}'
|
||||
grep "^Source Tracking Table" -A4 ${STATFILE} | tail -3 | awk '{print "source_"$1".value",$2}'
|
||||
grep "^Counters" -A15 ${STATFILE} | tail -15 | awk '{print "counter_"$1".value",$2}'
|
||||
|
||||
fi
|
||||
|
||||
rm ${STATFILE}
|
||||
|
Loading…
x
Reference in New Issue
Block a user