[tor.news] source to "scanlog"

dave@lsuc.UUCP (12/11/86)

Since people keep asking me for it, I might as well post it.

NOTES:
1. This was written as a quick hack by {lsuc,sq}!msb some time back.
   It doesn't pretend to be good code.
2. It's set up for v7-style UUCP SYSLOG files. For other flavours
   of UNIX, some mods will be needed because more information is kept
   in SYSLOG. Perhaps some of the people who have already received and
   modified it would care to post diffs for 4.2BSD or whatever.
3. It reads from SYSLOG.recent. We have an "earlymorn" script which
   runs every night; among other things, it does a mv SYSLOG SYSLOG.recent.
   scanlog runs later. You have to be careful with these things, and not
   to cp-then-truncate an existing file, or you can lose data from
   a currently-running uucico.
4. There are two files, scanlog and sca. We keep both in /usr/lib/news.
5. Our earlymorn entry to post the results looks like this:

/usr/lib/news/scanlog 2>&1 > /tmp/scanlog.out
date >> /usr/adm/newsxfr
sed '/local/q' /tmp/scanlog.out >> /usr/adm/newsxfr
mail -s "Nightly news report" dave keith < /tmp/scanlog.out
(echo -n "24-hour (approx.) period ended: ";date;cat /tmp/scanlog.out) |
	/usr/lib/news/inews -t "lsuc UUCP & news report" \
		-n tor.news -f dave@lsuc.UUCP

Note that you'll need to change the details here to suit your site.

6. Anyone who wants to revise this into a better tool for summarizing
   the information most relevant to Toronto news distribution, feel free to.

David Sherman


---------------------- /usr/lib/news/scanlog --------------------
stdin=${1-/usr/lib/news/log}
/usr/lib/news/sca $stdin ${2-/usr/spool/uucp/SYSLOG.recent} 
awk 'BEGIN {errors=0; badlinecounts=0; received=0; posted=0; dups=0;
	garbled=0; notinsys=0; notinstall=0; linkfailed=0;
	cancelled=0; cfail=0; csuccess=0; cgroups=0; ctlmsgs=0; old=0}
/Bad option/{next}
/Duplicate/{dups++; next}
/Ctl Msg/  {ctlmsgs++; next}
/Article too old/  {old++; next}
/posted/   {posted++; next}
# Sent to corresponds to posted, except for local group postings.
/sent to/     {next}
/subj.*cmsg cancel/{cancelled++; next}
/subj.*cancel/{cancelled++; next}
/Can.t cancel/{cfail++; next}
/Cancelling/{csuccess++; next}
/cancel article/{cgroups++; next}
/from/ {next}
/received/ {received++; next}
/linecount/{badlinecounts++; next}
/in active, but not sys/{notinsys++;next}
/Link into.*failed/ {linkfailed++;next}
/Cannot install article/ {notinstall++;next}
/Inbound news is garbled/ {garbled++;next}
/^  / {next}
	{if (length==0) next;
	if (errors++ == 0) {
		print "Miscellaneous errors:";
		}
	 print; next}
/cancel/ {next}
END {print "     SUMMARY OF MESSAGES"
     if (posted)
	print posted,"articles posted."
     if (ctlmsgs)
	print ctlmsgs,"control messages received."
     if (received)
	print received,"articles received."
     if (badlinecounts)
	print badlinecounts,"articles/duplicates had bad line counts."
     if (cancelled) {
	print cancelled " articles cancelled, " cfail " unsuccessfully,"
	print "   " csuccess " successfully in " cgroups " groups."
     }
     if (old)
	print old " old articles moved to junk."
     if (dups)
	print dups,"duplicate articles rejected."
     if (notinsys)
	print notinsys,"articles in groups not in sys file."
     if (notinstall)
	print notinstall,"articles could not be installed."
     if (linkfailed)
	print linkfailed,"links failed."
     if (garbled)
	print garbled,"inbound batches were garbled."
}
' $stdin
---------------------- /usr/lib/news/sca --------------------
cat <<EOF
		 UUCP Traffic (bytes)	   News Arts Rcv'd    Arts Que'd
		 Received	 Sent	   Accepted   Dups    to Send

EOF
(
	awk <${1-log.old} '
	$5 == "received"	{rec[$4]++; rec["Total"]++; all[$4]=0}
	$5 == "Duplicate"	{dup[$4]++; dup["Total"]++; all[$4]=0}
	$5 == "posted"		{pst++; rec["Total"]++}
	$6 == "sent"		{for (i = 8; i < NF; ++i) {snt[$i]++; all[$i]=0}
			 t = $NF ","; snt[t]++; snt["Total"] += NF-7; all[t]=0}
	END	{
		all["Total"]=0
		for (sys in all)
			print sys, 0, 0, 0, rec[sys]+0, dup[sys]+0, snt[sys]+0
		print "Local", 0, 0, 0, 0, 0, 0, pst
		}' |
	sed		's/[.][Uu][Uu][Cc][Pp]//
			s/,//'
	awk <${2-/usr/spool/uucp/SYSLOG.recent} '
		/ sent /  {snt[$2] += $6; snt["Total"] += $6; total[$2] += $6}
		/ received /  {rec[$2]+=$6; rec["Total"]+=$6; total[$2]+=$6}
		END	{ total["Total"] = snt["Total"] + rec["Total"]
			  for (sys in total)
				print sys, total[sys], rec[sys]+0, snt[sys]+0}
	'
) | awk '
		{ sys = substr($1,0,6)
		  if (length($1) > length(n[sys])) n[sys] = $1
		  t[sys] += $2; r[sys] += $3; s[sys] += $4
		  a[sys] += $5; d[sys] += $6; q[sys] += $7; local += $8 }
	END	{ for (sys in t) if (sys != "Local")
			printf "%12d:%-13s%12d%12d%12d%9d%10d \n", t[sys], \
				n[sys], r[sys], s[sys], a[sys], d[sys], q[sys]
          if (local>0) printf "%12d:%49d originated locally\n", 0, local }
' | sort -r | sed	's/.*://
			 s/ \([^ ]*[0-9]\)\([0-9][0-9][0-9][^0-9]\)/\1,\2/g
			 s/ \([^ ]*[0-9]\)\([0-9][0-9][0-9][^0-9]\)/\1,\2/g
		/Total/ !s/ 0 /   /g
		/locally/s/  orig/0 orig/
			 s/ *$//
			1s/$/\
/'
-- 
{ ihnp4!utzoo  seismo!mnetor  utai  watmath  decvax!utcsri  } !lsuc!dave

msb@dciem.UUCP (12/11/86)

David Sherman (lsuc!dave) writes:

> NOTES:
> 1. This was written as a quick hack by {lsuc,sq}!msb some time back.
>    It doesn't pretend to be good code.

Part of the quick hack was to jam in some code written by someone else
and posted to the net.  I didn't keep any indication of the original
author.  In fact, while "sca" is by me, "scanlog" mostly isn't.

Mark Brader
Any replies to utzoo!sq!msb, please.