#! /bin/sh

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

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

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

sub prochost {

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

sub procagent {

agent=$1
	echo "creating agent $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:1"
	else
		msg="status_log:$status:$host:$host:$agent:$NOW:$statusmsg:$host:$NOW:0::1"
	fi
	echo $msg >$agent
	echo $msg >>$BCNUHOME/data/$NOWLOG
}

>$BCNUHOME/data/$NOWLOG

echo "Building sample data"

cd $BCNUHOME/data/hosts

for host in $HOSTS
do
	echo "processing $host"
	mkdir $host 2>/dev/null
	cd $host
	for agent in $AGENTS
	do
		echo "creating agent $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:1"
		else
			msg="status_log:$status:$host:$host:$agent:$NOW:$statusmsg:$host:$NOW:0::1"
		fi
		echo $msg >$agent
		echo $msg >>$BCNUHOME/data/$NOWLOG
	done
	cd ..
done
echo "Sample data complete"

rm -f $BCNUHOME/*
cp $BCNUHOME/../images/* $BCNUHOME

exit

../cgi-bin/buildsample
