#!/bin/sh
# Input parameters: Hostname, testname (column), and messagefile
#
# Messagefile contains this:
# Thu Jan 12 06:33:28 CST 2006 compaq_cpu
# 
# This checkout shows CPU utilization as a percentage of the
# theoretical maximum over 1min, 5min, 30min & 60min periods.
# 
# 
# 
#        CPU	1 min	5 min	30 min	60min
# &green  0	7%	7%	6%	7%
# &green  1	7%	9%	8%	10%
# 
# 
TMPLOG="/tmp/$1.$2.out"
echo "$1, $2, $3" > $TMPLOG
cat $3 >> $TMPLOG

HOSTNAME="$1"
TESTNAME="$2"
FNAME="$3"

if [ "$TESTNAME" = "cpqcpu" ]
then
  # The RRD dataset definitions
  echo "DS:1min:GAUGE:600:0:100"
  echo "DS:5min:GAUGE:600:0:100"
  echo "DS:30min:GAUGE:600:0:100"
  echo "DS:60min:GAUGE:600:0:100"

  # Analyze the message we got
  cat $FNAME | while read line
  do
    if [ "$line" ]; then
      line=`echo $line | sed -e 's/&//g' -e 's/%//g'`
      set $line
      case $1 in
        green)
          echo "cpqcpu.$2.rrd"
          echo "$3:$4:$5:$6"
          echo "cpqcpu.$2.rrd" >> $TMPLOG
          echo "$3:$4:$5:$6" >> $TMPLOG
          ;;
        yellow)
          echo "cpqcpu.$2.rrd"
          echo "$3:$4:$5:$6"
          echo "cpqcpu.$2.rrd" >> $TMPLOG
          echo "$3:$4:$5:$6" >> $TMPLOG
          ;;
        red)
          echo "cpqcpu.$2.rrd"
          echo "$3:$4:$5:$6"
          echo "cpqcpu.$2.rrd" >> $TMPLOG
          echo "$3:$4:$5:$6" >> $TMPLOG
          ;;
        *)
          ;;
      esac
    fi
  done
fi
exit 0
