#! /bin/sh
# PCP QA Test No. 116
# Check hyphen in host name
#
# Copyright (c) 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

. ./common.config

[ -z "$PCPQA_HYPHEN_HOST" ] && _notrun 'PCPQA_HYPHEN_HOST is not set in ./common.config'

status=0	# success is the default!
$sudo rm -rf $tmp.*
rm -f $seq.full
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15

# real QA test starts here

host=$PCPQA_HYPHEN_HOST
eval realhost=`pmprobe -v -h $PCPQA_HYPHEN_HOST pmcd.hostname | \
	$PCP_AWK_PROG '{ print $3 }'`
if [ -z "$realhost" ]
then
    _notrun "cannot connect to pmcd on $PCPQA_HYPHEN_HOST"
fi
[ "$realhost" = Unknown ] && realhost=`pmhostname $PCPQA_HYPHEN_HOST`

_filter_pmlc()
{
    sed \
	-e '/primary/d' \
	-e "s/$host/HYPHEN-HOST/" \
	-e "s/$realhost/HYPHEN-HOST/" \
	-e 's/HYPHEN-HOST\.localdomain/HYPHEN-HOST/' \
	-e 's/   *.*/	.../'
}

_filter()
{
    sed \
	-e "s/$host/HYPHEN-HOST/" \
	-e "s/$realhost/HYPHEN-HOST/" \
	-e 's/HYPHEN-HOST\.localdomain/HYPHEN-HOST/' \
	-e 's/[A-Z][a-z][a-z] [A-Z][a-z][a-z]  *[0-9][0-9]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9]/DATE/'
}

# real QA test starts here

echo "pmie [hostname in config]"
cat <<End-of-File >$tmp.config
delta = 1;
// note have to quote hostname
2 * pmcd.control.sighup :'$host' - pmcd.control.sighup :'$host';
End-of-File
cat $tmp.config >$seq.full
pmie -T 2sec -v <$tmp.config >$tmp.out 2>$tmp.err
cat $tmp.out $tmp.err \
| tee -a $seq.full \
| sed -e 's/expr_1:  */expr_1: /' \
| _show_pmie_errors

echo
echo "pmval [metric spec on command line]"
pmval -t0.5 -s 1 $host:pmcd.control.sighup \
| tee -a $seq.full \
| _filter

echo
echo "pmlc [several uses]"
( echo "show loggers"; \
  echo "show loggers@$host";  \
  echo "connect primary@$host"; \
  echo "status" \
) \
| pmlc -h $host -P \
| tee -a $seq.full \
| _filter_pmlc

# success, all done
status=0
exit
