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

if [ ! "$GRAPH_STATSFILE" ] ; then
	GRAPH_STATSFILE=/var/munin/munin-graph.stats
fi

if [ "$1" = "autoconf" ]; then
	if [ -f $GRAPH_STATSFILE ]; then
	    echo "yes"
	    exit 0
	fi
	echo "no (statefile not found)"
	exit 1
fi

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

	echo 'graph_title Munin-graph'
	echo 'graph_vlabel seconds'
	[ -f $GRAPH_STATSFILE ] || exit 0
	cat $GRAPH_STATSFILE | grep "GD" | while read i; do
		name=`echo $i | cut -d"|" -f2 |tr  '.-' '__'`
		printf "$name.label "
		echo $i | cut -d"|" -f2
		echo "$name.warning 100"
		echo "$name.critical 179"
	done
	exit 0
fi

[ -f $GRAPH_STATSFILE ] || exit 0
cat $GRAPH_STATSFILE | grep "GD" | while read i; do
        name=`echo $i | cut -d"|" -f2 | tr  '.-' '__'`
	printf "$name.value "
	echo $i | cut -d"|" -f3
done
