#!/bin/sh
#
# Returns amount of traffic tinydns has handled 
# within the last 5 minutes
#
# Only requests where tinydns is authoritative is reported, requests
# where tinydns is not authoritative (NOTAUTH) is not reported.
#
# By Rasmus Skaarup <dlog@gal.dk> - Aug 2006
#
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=manual
#%# capabilities=autoconf

DLOG=/usr/local/dlog/bin/dodlog.pl
LOGDIR=/var/service/tinydns/log/main/

CMD="$DLOG tinydns raw $LOGDIR"

if [ "$1" = "autoconf" ]; then
        echo yes
        exit 0
fi

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

        echo 'graph_title tinydns traffic'
        echo 'graph_args --base 1000 -l 0 '
        echo 'graph_vlabel requests'
        echo 'graph_category DNS'
        echo 'graph_order dtin1 dtin2 dtin3 dtin4 dtin5 dtin6 dtin7 dtin8 dtin9 dtin10'
        echo 'dtin1.label A'
        echo 'dtin1.min 0'
        echo 'dtin1.draw LINE2'
        echo 'dtin2.label NS'
        echo 'dtin2.min 0'
        echo 'dtin2.draw LINE2'
        echo 'dtin3.label CNAME'
        echo 'dtin3.min 0'
        echo 'dtin3.draw LINE2'
        echo 'dtin4.label SOA'
        echo 'dtin4.min 0'
        echo 'dtin4.draw LINE2'
        echo 'dtin5.label PTR'
        echo 'dtin5.min 0'
        echo 'dtin5.draw LINE2'
        echo 'dtin6.label MX'
        echo 'dtin6.min 0'
        echo 'dtin6.draw LINE2'
        echo 'dtin7.label TXT'
        echo 'dtin7.min 0'
        echo 'dtin7.draw LINE2'
        echo 'dtin8.label AAAA'
        echo 'dtin8.min 0'
        echo 'dtin8.draw LINE2'
        echo 'dtin9.label AXFR'
        echo 'dtin9.min 0'
        echo 'dtin9.draw LINE2'
        echo 'dtin10.label 255'
        echo 'dtin10.min 0'
        echo 'dtin10.draw LINE2'
        exit 0

fi

OUTPUT=`$CMD`

ANSWER1=`echo "$OUTPUT" | grep ANSWER:1: | cut -f 3 -d:`
ANSWER2=`echo "$OUTPUT" | grep ANSWER:2: | cut -f 3 -d:`
ANSWER5=`echo "$OUTPUT" | grep ANSWER:5: | cut -f 3 -d:`
ANSWER6=`echo "$OUTPUT" | grep ANSWER:6: | cut -f 3 -d:`
ANSWER12=`echo "$OUTPUT" | grep ANSWER:12: | cut -f 3 -d:`
ANSWER15=`echo "$OUTPUT" | grep ANSWER:15: | cut -f 3 -d:`
ANSWER16=`echo "$OUTPUT" | grep ANSWER:16: | cut -f 3 -d:`
ANSWER28=`echo "$OUTPUT" | grep ANSWER:28: | cut -f 3 -d:`
ANSWER252=`echo "$OUTPUT" | grep ANSWER:252: | cut -f 3 -d:`
ANSWER255=`echo "$OUTPUT" | grep ANSWER:255: | cut -f 3 -d:`

if [ "$ANSWER1" = "" ]; then
  ANSWER1=0
fi
if [ "$ANSWER2" = "" ]; then
  ANSWER2=0
fi
if [ "$ANSWER5" = "" ]; then
  ANSWER5=0
fi
if [ "$ANSWER6" = "" ]; then
  ANSWER6=0
fi
if [ "$ANSWER12" = "" ]; then
  ANSWER12=0
fi
if [ "$ANSWER15" = "" ]; then
  ANSWER15=0
fi
if [ "$ANSWER16" = "" ]; then
  ANSWER16=0
fi
if [ "$ANSWER28" = "" ]; then
  ANSWER28=0
fi
if [ "$ANSWER252" = "" ]; then
  ANSWER252=0
fi
if [ "$ANSWER255" = "" ]; then
  ANSWER255=0
fi

echo "dtin1.value $ANSWER1"
echo "dtin2.value $ANSWER2"
echo "dtin3.value $ANSWER5"
echo "dtin4.value $ANSWER6"
echo "dtin5.value $ANSWER12"
echo "dtin6.value $ANSWER15"
echo "dtin7.value $ANSWER16"
echo "dtin8.value $ANSWER28"
echo "dtin9.value $ANSWER252"
echo "dtin10.value $ANSWER255"
