#!/bin/sh
#################################################################
#                      parse-stats 1.0                       4/02
#
#                     by Orange-Admin   
#                  <http://www.arancio.net>
#
# Here's a little script that will parse a remailer-stats
# request for an hourly mrtg graph (mix/punk messages)
#
# Requirements: Mixmaster, an MTA, procmail, MRTG.
#
# To generate these requests hourly, add this to your crontab:
# 1 * * * * echo "ping" | /usr/bin/mail -s "remailer-stats" mix@localhost > /dev/null 2>&1 
#
# And add this recipe to your .procmailrc:
# :0
# * ^From: Orange Remailer <mix@arancio.net>
# * ^Subject: Statistics for the orange remailer
# {
#        :0c
#        /home/mix/tmp/stats-tmp
#        :0
#         | /home/mix/scripts/parse-stats
# }
#
# mrtg.cfg suggestion:
#
# Target[remailer-stats]: `cat /home/users/anon/tmp/remailer-stats.txt`
# Title[remailer-stats]: Remailer Statistics
# PageTop[remailer-stats]:<H1>Remailer Statistics: Mix/Cpunk Messages</H1>
# AbsMax[remailer-stats]: 2000
# WithPeak[remailer-stats]: dwmy
# Options[remailer-stats]: growright, gauge, nopercent
# Colours[remailer-stats]: Orange#FF9900,Red#FF0000,Yellow#E8E11E,DarkRed#9D0C0C
# MaxBytes[remailer-stats]: 200
# Unscaled[remailer-stats]: dwmy
# YLegend[remailer-stats]:  messages
# ShortLegend[remailer-stats]: messages
# LegendI[remailer-stats]: &nbsp; mixmaster:
# LegendO[remailer-stats]: &nbsp; cpunk:
# Legend1[remailer-stats]: mixmaster messages
# Legend2[remailer-stats]: cpunk messages
# Legend3[remailer-stats]: Maximal mixmaster messages
# Legend4[remailer-stats]: Maximal cpunk messages
#
#################################################################

# raw remailer-stats (snagged from procmail)
RAWSTATS=/home/users/anon/tmp/stats-tmp

# sanitized stats for www use
WWWSTATS=/home/users/anon/stats/remailer-stats.txt

#MRTG file for hourly remailer stats
MRTGSTATFILE=/home/users/anon/tmp/remailer-stats.txt

HOSTUPT=`uptime` 
HOSTN=`uname -n`

if [ -e $RAWSTATS ]; then

# sanitize and copy to www.
echo "" > $WWWSTATS
cp $RAWSTATS $WWWSTATS
rm -f $RAWSTATS

# make MRTG remailer-stats file
echo "" > $MRTGSTATFILE

#hourly mix - remove 0h as its a total # of msgs
cat $WWWSTATS | grep -v 0h | grep Pool | head -1 | awk '{ print $3 }' > $MRTGSTATFILE

#hourly pgp - remove 0h as its a total # of msgs
cat $WWWSTATS | grep -v 0h | grep Pool | head -1 | awk '{ print $5 }' >> $MRTGSTATFILE

echo $HOSTUPT >> $MRTGSTATFILE
echo $HOSTN >> $MRTGSTATFILE

else
 echo "!!!WARNING!!! This script should only be run by procmail: $RAWSTATS does not exist."
fi

