#!/bin/sh
# Author:	Gary Baluha
# Created On:	12-05-2007
# Description:	Removes all bogus data from the RRD graphs.
#		Specifically, this script looks for values that look like
#		nnn.nnne+1nn (it looks for a number that has e+1NNN).  This
#		script doesn't care about the length of the number.  These
#		bogus values are changed to NaN, so there will be gaps in the
#		trend graphs, but at least it scales correctly.
#
# NOTE:		If there are trend graphs where values DO get to be large
#		enough for NNNe+1NN to be valid, this script will have
#		unexpected results.

if [ $# -lt 1 ] || [ "$1" != "yes" ]
then
	echo "Are you in the directory with the RRD files to fix?"
	echo -n " [ yes ] or [ no ] :"
	read answer
	if [ "$answer" != "yes" ]
	then
		echo "Please cd to the directory with the RRD files to fix"
	fi
fi

for n in `ls -1 *.rrd`; do
	/usr/local/rrdtool/bin/rrdtool dump $n > $n.xml
	cat $n.xml | sed 's/[0-9]*\.[0-9]*e+1[0-9]*/NaN/g' > $n.xml0
	rm -f $n
	/usr/local/rrdtool/bin/rrdtool restore $n.xml0 $n
	rm -f $n.xml $n.xml0
done
chown hobbit:hobbit *
