#!/bin/csh
#	$Header: makeawk,v 4.300 91/06/09 00:59:57 root Rel41 $
#
#	Auto-configuration script for SNMP plot.1.awk
#	This produces an awk script which extracts I/O thruput/errors
#	information from an snmppoll output file, whose format is:
#	<Unix Date Stamp><Object Name><Hex Value><Value Decimal>
#	Items are seperated by tabs.
#
#	Loosely based on an awk script by Wengyik Yeong for NYSERNet 4/18/88
#	Further modifications on data reduction and auto-configuration
#	by Bill Caloccia, NYSERNet Feb, 1989
#
#	Copyright 1990, Performance Systems International Inc.
#	Copyright 1988,1989 NYSERNet, Inc.
#	Copyright 1990, Sony Corp.
#	All Rights Reserved.
#

set InFile=Var00
set InEFile=Err00
set OutFile=plot.1.awk.NEW
set Begin=Begin00
set End=End00

set MAXPERIODS=97	# 24 hours * 4 + 1

#	Variables monitored

set VARS=( InOctets  OutOctets InUcastPkts OutUcastPkts )

#	Errors monitored (which happen to all be proteon specific at this time.

set ERRS=(xmit-framing xmit-underruns xmit-no-dcd xmit-no-cts xmit-no-dsr \
	recv-framing recv-overruns recv-aborts recv-crc	\
	selftest-failed maint-failed )

#	Single character equivalent for graphing of errors
set ERRA=( F U C T S f o a c s m) 
#XMIT:	Framing Underruns no-dCd no-cTs no-dSr
#       ^       ^             ^      ^      ^
#recv:	framing overruns aborts crc
#       ^       ^        ^      ^
#other:	selftest-failed maint-failed 
#	^               ^

#	prepare names of variables sans strokes '-', these will be used
#	as constants in the awk script, to reference data arrays

set VARSnb=(`echo $VARS | sed 's/-//g'`)
set ERRSnb=(`echo $ERRS | sed 's/-//g'`)


#	'canned' section of awk file...

cat	$Begin >! $OutFile

echo	'#  The following lines are added automatically.'	>> $OutFile

@ c = $#VARS + $#ERRS + 1
echo	"  MaxVars = $c"';'	>> $OutFile	# define the limit

##	Set-Up each var as a constant, ...

echo	"  # for each variable, define it's offset into an array "	>> $OutFile
echo	'  # (used with first, last & val )'	>> $OutFile

set	vars=($VARSnb $ERRSnb)
foreach v ( $vars )
@ c --
  echo	"  $v	= $c"';'	>> $OutFile
end 

##	Set-up array of one character abbreviations for errors...

set	vars=($ERRSnb)
foreach v ( $vars )
  echo	"  abbrev[$v]	= "'"'$ERRA[1]'";'	>> $OutFile
  shift	ERRA
end 

##	Set-up For loop to intialise arrays

echo	'  for(i = 0; i < MaxVars; i++)'	>> $OutFile
echo	'  {'	>> $OutFile
echo	'    last[i]	= 0;'	>> $OutFile
echo	'    val[i]	= 0;'	>> $OutFile
echo	'    max[i]	= 0;'	>> $OutFile
echo	'    ypt[i]	= 0;'	>> $OutFile
echo	'  }'	>> $OutFile		# end the for

##	End of the awk scripts ''BEGIN'' section

echo '}'	>> $OutFile		# end the begin
echo '# BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN # BEGIN'	>> $OutFile

##	Set up a section for each Variable

set	NB=($VARSnb )
foreach v ( $VARS )
	sed "s/VARIABLE/$v/" $InFile | sed "s/VARNAME/$NB[1]/" >> $OutFile
	shift	NB
end

##	Set up a section for each Error

set	NB=($ERRSnb)
foreach v ( $ERRS)
	sed "s/VARIABLE/$v/" $InEFile | sed "s/VARNAME/$NB[1]/" >> $OutFile
	shift	NB
end

##	Copy the 'canned' section for the ''END'' section of the awk script
##	(currently null)

cat	$End >> $OutFile
