#! /bin/sh
# PCP QA Test No. 1049 (formerly 552)
# make sure that installed pmie rule files are syntactically OK.
#
# Copyright (c) 2015 Red Hat.
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

which pmieconf >/dev/null 2>&1 || _notrun "No pmieconf binary installed"

status=1	# failure is the default!
username=`id -u -n`
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

# Some metrics unavailable by default, so skip the associated rules
#
echo "modify all enabled yes" >$tmp.cmd
for group in shping cisco dmthin mssql openvswitch
do
    # most have group == dir, but some do not
    #
    case $group
    in
	dmthin)
	    dir=dm
	    ;;
	*)
	    dir=$group
	    ;;
    esac
    [ -d $PCP_ETC_DIR/pcp/pmieconf/$dir ] && echo "modify $group enabled no" >>$tmp.cmd
done

# Some rules need special cusomization
#
disks=`pmprobe -I disk.dev.total | sed -e 's/" "/ /g' -e 's/^[^ ]* [0-9][0-9]* //'`
if [ -z "$disks" ]
then
    # Arrgh ...
    #
    echo "Empty list of disks from ..."
    pmprobe -I disk.dev.total
    exit
fi
echo "modify per_disk.bandwidth disks $disks" >>$tmp.cmd
echo "modify per_disk.iops disks $disks" >>$tmp.cmd


# real QA test starts here
echo "running pmieconf with default rules..."
( cat $tmp.cmd; echo quit ) | pmieconf -f $tmp.eek
echo "status=$?"

echo "running pmie..."
pmieargs="-C"
id pcp >/dev/null 2>&1 && pmieargs="$pmieargs -U $username"
pmie $pmieargs -c $tmp.eek -l $tmp.pmielog
echo "status=$?"
echo "pmie log file..."
cat $tmp.pmielog | _filter_pmie_log

echo "--- pmieconf input ---" >$seq.full
cat $tmp.cmd >>$seq.full
echo "--- pmie input ---" >>$seq.full
cat $tmp.eek >>$seq.full
echo "--- pmie output ---" >>$seq.full
cat $tmp.pmielog >>$seq.full

# success, all done
status=0
exit
