#!/bin/sh
#
# $OpenBSD: pf_searches,v 1.1 2010/02/25 17:07:17 sthen Exp $
#
# (c) 2010 Kim Højgaard-Hansen <kimrhh@gmail.com>
#
# Script to monitor number of pf state lookups from "pfctl -si".
# 
#    ln -s /usr/local/libexec/munin/plugins/pf_states \
#	/etc/munin/plugins/pf_states
#
# ...will monitor number of pf state lookups.
#
# Parameters:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
# 	suggest  (optional - used by munin-config)
#
# Magic markers (optional):
#%# family=manual
#%# capabilities=autoconf

if [ "$1" = "autoconf" ]; then
	if [ "$(uname -s)" = "OpenBSD" ]; then
		echo yes
		exit 0
	else
		echo no
		exit 1
	fi
fi

if [ "$1" = "suggest" ]; then
	exit 0
fi

if [ "$1" = "config" ]; then

	echo 'graph_title number of pf state lookups'
	echo 'graph_args --base 1000'
	echo 'graph_category pf'
	echo 'graph_vlabel state lookups'
	echo 'lookup.label Lookups'
	echo 'lookup.info State table lookups'
	echo 'lookup.type DERIVE'
	echo 'lookup.min 0'
	exit 0
fi

pfctl -si | awk '$1 == "searches" { print "lookup.value " $2 }'
