#! /bin/sh

BCNUHOME="/usr/local/bcnu/docs/sample"

# host names to build
HOSTS="host1 host2 host3 host4 host5"
AGENTS=`ls $BCNUHOME/data/agents`

NTHOSTS="nthost1 nthost2"
NTAGENTS="net-ping net-http net-ftp net-smtp"

W95HOSTS="95host1 95host2"
W95AGENTS="net-ping net-bcnu"

ROUTERS="router1 router2"
ROUTAGENTS="net-ping"

NOW=`date "+%Y-%m-%d %H.%M.%S"`
NOWLOG=`date "+%Y%m%d.log"`

prochost() {

host=$1
agents=$2
	echo "processing $host"
	mkdir $host 2>/dev/null
	cd $host
	for agent in $agents
	do
		procagent $agent
	done
	cd ..
}

procagent() {

agent=$1
	echo "   $agent"
	statusmsg=`cat $BCNUHOME/data/agents/$agent`
	status=0
		
	if [ -s $BCNUHOME/data/files/$agent ]
	then
		msg="status_file:$status:$host:$host:$agent:$NOW:$statusmsg:$host:$NOW:1:$BCNUHOME/data/files/$agent:$type"
	else
		msg="status_log:$status:$host:$host:$agent:$NOW:$statusmsg:$host:$NOW:0::$type"
	fi
	echo $msg >$agent
	echo $msg >>$BCNUHOME/data/$NOWLOG
}

procgroup () {

hostgroup=$1
aggroup=$2
type=$3

for host in $hostgroup
do
	prochost $host "$aggroup" 
done

}
>$BCNUHOME/data/$NOWLOG

echo "Building sample data"

cd $BCNUHOME/data/hosts

procgroup "$HOSTS" "$AGENTS" 1
procgroup "$NTHOSTS" "$NTAGENTS" 3
procgroup "$W95HOSTS" "$W95AGENTS" 4
procgroup "$ROUTERS" "$ROUTAGENTS" 20

# errors
host="host1"
agent="vmgt"
status=9
statusmsg="error - disk volume requires maintenance"
msg="status_file:$status:$host:$host:$agent:$NOW:$statusmsg:$host:$NOW:1:$BCNUHOME/data/files/$agent.error:1"
echo $msg >>$BCNUHOME/data/$NOWLOG
echo $msg >$BCNUHOME/data/hosts/$host/$agent
# warning
host="host3"
agent="logs"
status=5
statusmsg="warning - pattern found in /var/adm/messages"
msg="status_file:$status:$host:$host:$agent:$NOW:$statusmsg:$host:$NOW:1:$BCNUHOME/data/files/$agent.error:1"
echo $msg >>$BCNUHOME/data/$NOWLOG
echo $msg >$BCNUHOME/data/hosts/$host/$agent

echo "Sample data complete"

rm -f $BCNUHOME/* 2>/dev/null
cp $BCNUHOME/../images/* $BCNUHOME

echo "Building sample pages"
$BCNUHOME/../../cgi-bin/buildanon

echo "Sample pages complete"
