#!/bin/sh
#
# Script to monitor disk usage.
#
# Parameters understood:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)
#
# Magic markers (optional - used by munin-config and installation
# scripts):
#
#%# family=auto
#%# capabilities=autoconf

MAXLABEL=20

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

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

	echo 'graph_title Filesystem usage (in %)'
	echo 'graph_args --upper-limit 100 -l 0'
	echo 'graph_vlabel %'
	df -P -l  | sed 1d | grep -v "//" | sort | while read i; do
		name=`echo $i | sed 's/[\/.-]/_/g'| awk '{ print $1 }'`
		printf "$name.label "
		echo $i | awk "{ 
			dir=\$6
			if (length(dir) <= $MAXLABEL)
				print dir
			else
				printf (\"...%s\n\", substr (dir, length(dir)-$MAXLABEL+4, $MAXLABEL-3)) 
		}"
		echo "$name.warning 92"
		echo "$name.critical 98"
	done
	exit 0
fi

df -P -l | sed 1d | grep -v "//" | while read i; do
	name=`echo $i | sed 's/[\/.-]/_/g'| awk '{ print $1 ".value " }'`
	printf "$name "
	echo $i | awk '{ print $5 }' | cut -f1 -d%
done
