#!/bin/csh
#	$Header: newerrs,v 4.300 91/06/09 00:59:32 root Rel41 $
#	SNMP
#	Copyright 1990 Sony Corp.
#	Copyright 1990 Performance Systems International Inc.
#       copyright 1988 NYSERNet, Inc.
#	All Rights Reserved.
#       wpc
#	on date
#	foreach ifc
#	  grep date | awk | sed > output file
#	end
#	separate out total lines > totalerrs.file	
#	separate out errs lines >  errslog.file

#name rxcrc  rxab  rxovr  txund  rxfr  txfr  txdsr  txcts  txdcd  self  maint
#

source ../../config/report-env
if (-e $ROOT/config/daily-env) then
  source $ROOT/config/daily-env
else
  echo "$0 : daily-env missing. Can't continue. Exit."
  exit(1)
endif

if ($#argv) then
        set ext=$argv[1]
        set ext2=$ext
else 
	echo "Usage : $0 mmddyy"
	exit(1)
endif

alias	echo $BIN/echo
set	awkfile=$SEDAWK/errs.awk
set	sedfile=$SEDAWK/newerrs.sed

if (! $?DAILYREPORTS) then
  set	ODIR=$DAILY/report/$ext
else
  set	ODIR=$DAILYREPORTS/$ext
endif

set	DDIR=$DATA/$ext
set	NEW=$ODIR/Errors.new
set	LIST=$ODIR/Errors.list

set	TMP=/tmp/snewerrs.$ext.tmp

cd	$DDIR ; /bin/rm -f $TMP ; touch	$TMP

#	sed pattern is "s/^/$f:t \t/"

set nonomatch
foreach	link (*-*)
	if ("$link" == '*-*') then
	  break
	endif
	awk -f $awkfile $link  >> $TMP
#	compress	$link &
end
unset nonomatch

#
set	edate=(`$BIN/prsdate $ext`)
echo	"SNMP  Error Report for $edate\n\nError counters were polled every 15 minutes." >! $NEW

echo	"For the 'upper' and the 'lower' lines, the counts indicate\nhow many times a preset threshold was exceeded.\nThe 'total' line is actually a count of errors." >> $NEW 

echo	"name\t\trxcrc\trxab\trxovr\ttxund\trxfr\ttxfr\ttxdsr\ttxcts\ttxdcd\tself\tmaint\n" >> $NEW 

echo	"lower-threshold\t100\t10\t10\t5\t0\t0\t0\t5\t5\t5\t0\n" >> $NEW 

echo	"upper-threshold\t1000\t100\t100\t50\t10\t10\t5\t10\t10\t10\t5\n" >> $NEW 
echo	"name\t\trxcrc\trxab\trxovr\ttxund\trxfr\ttxfr\ttxdsr\ttxcts\ttxdcd\tself\tmaint\n" >> $NEW 

#	get totals lines

grep	error	$TMP	| sed -f $sedfile | awk -f $SEDAWK/errs.page.awk>> $NEW


#	get excessive lines....

( echo "SNMP  Error List\n\nErrors which exceeded the upper limit during the polling period.\n\n" ;	\
  grep	from $TMP | awk -F\t '{printf "%s\t%s\t%s\t%s\n", $1,$2,$4,$3;}' | \
  sort +0 +4	 | awk -f $SEDAWK/errs.list.awk ; \
  echo "\f\nSNMP  List of Error Counter Resets\n\n"; grep	RESET $TMP ; \
  echo "\f\nSNMP  List of Data Anomalies\n\n\tnode\tin pkts\toutpkts\n";	\
  echo	"threshold\t150 K\t150 K\tdata > lower\n" ;	\
  echo	"threshold\t200 K\t200 K\tdata > upper\n" ;	\
  egrep "(data|start)" $TMP ; \
  echo "\f\nSNMP  List of NO Errors\n\n" ;	grep	"NO ERRORS" $TMP ) >! $LIST
/bin/rm -f $TMP
