🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.admin
Article #3984

update to C news report script

#3984
From: News Administrator
Date: Wed, 11 Mar 1992 19:33
334 lines
11305 bytes
Here's an upgrade to the C news log report script I posted
recently.


Most of the changes are upgrades of functionalty, plus I
added some comments to the awk script.  I found that
different implementations of awk have different syntax
problems with certain regular expressions - a comment in
the script will expain further if you have problems...


 --------- 8< --------- 8< --------- 8< --------- 8< --------- 8< ---------

# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by  on Wed Mar 11 14:27:26 EST 1992
# Contents:  news.repz news.repz.awk
 
echo x - news.repz
sed 's/^@//' > "news.repz" <<'@//E*O*F news.repz//'
#!/bin/sh
#
# Shell script for chewing up Cnews log files and spitting out
# summary news stats. Reads from standard input or give it a news log
# file as an argument. Bug fixes and enhancements welcome.
#
#
# Many changes & enhancements - Bruce Becker  04/Mar/92
#
# John A. Palkovic 1/31/91
#
# Keith Cantrell (kcantrel@digi.lonestar.org) added the ability to
# print the summary of files sent out. 1/30/90
#

@. ${NEWSCONFIG-/usr/lib/news/bin/config}

ME=`$NEWSBIN/newshostname`

FILE=$1; if [ -z "$FILE" ]; then FILE="-"; fi

awk -f $NEWSBIN/maint/news.repz.awk ME=$ME $FILE

@//E*O*F news.repz//
chmod u=rwx,g=rwx,o=rx news.repz
 
echo x - news.repz.awk
sed 's/^@//' > "news.repz.awk" <<'@//E*O*F news.repz.awk//'
# awk script for chewing up Cnews log files and spitting out
# summary news stats. Bug fixes and enhancements welcome.
#
#
# Many changes & enhancements - Bruce Becker  04/Mar/92
#
# If you don't run with the relaynews daemon patch change
# "SENT_FIELD = 8" just below to 'SENT_FIELD = 7'. Everything
# except the "control" and "failed" stuff should work the same.
#
# John A. Palkovic 1/31/91
#
# Keith Cantrell (kcantrel@digi.lonestar.org) added the ability to
# print the summary of files sent out. 1/30/90
#
BEGIN	{

	SENT_FIELD = 8	# change this to 7 for vanilla C news

	posted[""]  = 0; psent[""]   = 0
	control[""] = 0; cancel[""]  = 0; ihave[""]  = 0; sendme[""]  = 0
	chkgrp[""]  = 0; rmgroup[""] = 0; newgrp[""] = 0; sendsys[""] = 0
	version[""] = 0; uunames[""] = 0; cother[""] = 0; csent[""]   = 0
	junked[""]  = 0
	reject[""]  = 0
	dupl[""]    = 0;  nosub[""]  = 0; actx[""]   = 0; unapp[""]   = 0
	daterr[""]  = 0;  hdrerr[""] = 0; rother[""] = 0
	iwant[""]   = 0;  sendto[""] = 0
	failed[""]  = 0;  other[""]  = 0

	jng[""]     = 0; nsb[""]     = 0; xed[""]    = 0
}

{
	#	First see that we have a reasonable log entry -
	#	check for # of fields, syntax of message-id,
	#	character count of indicator, character set of systemname
	#
	#	Different awk's have different bugs -
	#	try one of these if you get errors in
	#	the expression below:
	#
	# 		$4 ~ /[ -,\057:-@[-`{-~]/) {
	#
	#		$4 ~ /[ -,\/:-@[-`{-~]/) {
	#
	if	(NF < 6 || $6 !~ /^<.+@.+>$/ || length($5) != 1 || \
			$4 ~ /[ -,/:-@[-`{-~]/) {

		if ($0 !~ /^[	 ]*$/) print
		next
	}

	#
	#	Get a reasonable-looking hostname
	#
	#	Note that the "ME" variable is passed
	#	on the command line as something like:
	#
	#		awk -f news.repz.awk ME=`newshostname` -
	#
	l = length($4)
	if	($4 ~ /\.uucp$/)	nm = substr($4, 1, l-5)
	else if	($4 ~ /\.UUCP$/)	nm = substr($4, 1, l-5)
	else if	($4 == ME)		nm = "<local>"
	else if	($4 == "local")		nm = "<local>"
	else if	($4 == "maps")		nm = "<maps>"
	else				nm = $4

	sys[nm]++; count++

	#
	#	Accepted article
	#
	if	($5 == "+")	{
		posted[nm]++
		for (i=SENT_FIELD; i <= NF; i++) { psent[$i]++; sys[$i]++ }
	}
	#
	#	Control article (only if Larry Blair's patch is installed)
	#
	else if	($5 == "c")	{
		control[nm]++
		if	($8 == "cancel") 	{ cancel[nm]++; S = 10
				if ($9 !~ /^<.+@.+>$/) { print; S = 0 } }
		else if	($8 == "ihave")		{ ihave[nm]++;	S = 10 }
		else if	($8 == "sendme")	{ sendme[nm]++;	S = 10 }
		else if	($8 == "checkgroups")	{ chkgrp[nm]++;	S =  9 }
		else if	($8 == "rmgroup")	{ print; rmgroup[nm]++;	S = 10 }
		else if	($8 == "newgroup")	{ print; newgrp[nm]++;	S = 10
						  if ($10 == "moderated") S++  }
		else if	($8 == "sendsys")	{ print; sendsys[nm]++;	S =  9 }
		else if	($8 == "version")	{ print; version[nm]++;	S =  9 }
		else if	($8 == "senduuname")	{ print; uunames[nm]++;	S =  9 }
		else				{ print; cother[nm]++;	S =  0 }
		if (S > 0) for (i=S; i <= NF; i++)	{
			l = length($i)
			if	($i ~ /\-ctl$/)		n = substr($i, 1, l-4)
			else				n = $i
			csent[n]++; sys[n]++
		}
	}
	#
	#	Junked article - note that it also has been counted as accepted
	#
	else if	($5 == "j")	{
		junked[nm]++
		l = length($NF); if (substr($NF, l, 1) == "'") l--
		s = 1; if (substr($NF, 1, 1) == "`") { s++; l-- }
		g = substr($NF, s, l); n = split(g, ng, ",")
		for (i=1; i <= n; i++) {
			g = ng[i]; if (g != "") jng[g]++
		}
	}
	#
	#	Articles rejected for various reasons
	#
	else if	($5 == "-")	{
		reject[nm]++
		if	($7 == "duplicate") 	dupl[nm]++
		else if	($7 == "no" && $8 == "subscribed")	{
			nosub[nm]++
			l = length($11); if (substr($11, l, 1) == "'") l--
			s = 1; if (substr($11, 1, 1) == "`") { s++; l-- }
			g = substr($11, s, l); n = split(g, ng, ",")
			for (i=1; i <= n; i++) {
				g = ng[i]; if (g != "") nsb[g]++
			}
		}
		else if	($7 == "all" && $8 == "groups")	{
			actx[nm]++
			l = length($9); if (substr($9, l, 1) == "'") l--
			s = 1; if (substr($9, 1, 1) == "`") { s++; l-- }
			g = substr($9, s, l); n = split(g, ng, ",")
			for (i=1; i <= n; i++) {
				g= ng[i]; if (g != "") xed[g]++
			}
		}
		else if	($0 ~ /unapproved/)	unapp[nm]++
		else if	($0 ~ /ancient|too far in the future|unparsable Date/) 
						daterr[nm]++
		else if	($0 ~ / (no|empty) .* header|contains non-|Message-ID|space in/)
						{ print; hdrerr[nm]++ }
		else				{ print; rother[nm]++ }
	}
	#
	#	Message-id of article requested in response to remote "ihave"
	#
	else if	($5 == "i")	{
		l = length($7)
		if	($7 ~ /\-send\-ids$/)	n = substr($7, 1, l-9)
		else				n = $7
		iwant[n]++; sys[n]++
	}
	#
	#	Message-id of article sent in response to remote "sendme"
	#
	else if	($5 == "s")	{
		l = length($7)
		if	($7 ~ /\-real$/)	n = substr($7, 1, l-5)
		else				n = $7
		sendto[n]++; sys[n]++
	}
	#
	#	Failed cancel (only if Larry Blair's patch is installed)
	#
	else if	($5 == "f")	failed[nm]++
	#
	#	Something quite odd, no doubt
	#
	else			{ print; other[nm]++ }
}

END	{
	printf	"\n\n\t\t\t   Articles Incoming\t\t |  Articles Outgoing\n"
	printf	"Hosts          Posted Contrl Junked Duplic Reject  Total | Queued Contrl  Total\n"
	printf	"-------------  ------ ------ ------ ------ ------ ------ | ------ ------ ------\n"
	if (count > 0) for (host in sys) {
		rp = posted[host]; rc = control[host]
		rj = junked[host]; rd = dupl[host]; rr = reject[host]
		rec = rp + rc + rr
		sp = psent[host]; sc = csent[host]
		snt = sp + sc
		if (rec <= 0 && snt <= 0) continue

		rp -= rj; rr -= rd

		printf	"%-14.14s %6d %6d %6d %6d %6d %6d   %6d %6d %6d\n", \
			host, rp, rc, rj, rd, rr, rec, sp, sc, snt
		totalpost   += rp; totalcontrol += rc; totaljunked += rj
		totaldupl   += rd; totalreject  += rr; totalrec    += rec
		totalpsent  += sp; totalcsent   += sc; totalsent   += snt

		totalnosub +=	nosub[host]
		totalactx  +=	actx[host]
		totalmisc  +=	reject[host] + \
				iwant[host]  + sendto[host] + \
				failed[host] + other[host]
	}
	printf	"-------------  ------ ------ ------ ------ ------ ------   ------ ------ ------\n"
	printf	"%-14.14s %6d %6d %6d %6d %6d %6d   %6d %6d %6d\n", \
		"Totals", totalpost,  totalcontrol, totaljunked, \
			  totaldupl,  totalreject,  totalrec, \
			  totalpsent, totalcsent,   totalsent
	printf	"\n"

	printf	"\n\t\t\t\tControl Messages\n"
	printf	"Hosts          Cancl Ihave Sndme Ckgrp Rmgrp Nwgrp Sdsys Versn Uunme Other\n"
	printf	"-------------  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----\n"
	if (totalcontrol > 0) for (host in control)
		if (host != "" && control[host] > 0) {

		ca = cancel[host];  ih = ihave[host];   sm = sendme[host]
		ck = chkgrp[host];  rm = rmgroup[host]; nw = newgrp[host]
		ss = sendsys[host]; vr = version[host]; uu = uunames[host]
		co = cother[host]
		printf	"%-14.14s %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n", \
			host, ca, ih, sm, ck, rm, nw, ss, vr, uu, co
		totalca += ca; totalih += ih; totalsm += sm
		totalck += ck; totalrm += rm; totalnw += nw
		totalss += ss; totalvr += vr; totaluu += uu
		totalco += co
	}
	printf	"-------------  ----- ----- ----- ----- ----- ----- ----- ----- ----- -----\n"
	printf	"%-14.14s %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n", \
			"Totals", totalca, totalih, totalsm, totalck, \
			totalrm, totalnw, totalss, totalvr, totaluu, totalco
	printf	"\n"

	printf	"\n\t\t\t\tRejects and Miscellany\n"
	printf	"Hosts          Dupli Unsub Unapp DatNG HdrNG Rmisc    Iwant Sndto Cfail Other\n"
	printf	"-------------  ----- ----- ----- ----- ----- -----    ----- ----- ----- -----\n"
	if (totalmisc > 0) for (host in sys) {
		iw = iwant[host];  sn = sendto[host]
		fa = failed[host]; ot = other[host]
		if (reject[host] > 0 || \
		    iw > 0 || sn > 0 || fa > 0 || ot > 0) {
			du = dupl[host];   ns = nosub[host] + actx[host];
			un = unapp[host];  dt = daterr[host]
			hd = hdrerr[host]; ro = rother[host]
			printf	"%-14.14s %5d %5d %5d %5d %5d %5d    %5d %5d %5d %5d\n", \
				host, du, ns, un, dt, hd, ro, iw, sn, fa, ot
			totaldu += du; totalns += ns; totalun += un
			totaldt += dt; totalhd += hd; totalro += ro
			totaliw += iw; totalsn += sn
			totalfa += fa; totalot += ot
		}
	}
	printf	"-------------  ----- ----- ----- ----- ----- -----    ----- ----- ----- -----\n"
	printf	"%-14.14s %5d %5d %5d %5d %5d %5d    %5d %5d %5d %5d\n", \
			"Totals", totaldu, totalns, totalun, \
				  totaldt, totalhd, totalro, \
				  totaliw, totalsn, totalfa, totalot
	printf	"\n"
	
	if (totaljunked > 0) {
		print "\nCount of Junked Newsgroups - Accepted, not found in \"active\""
		for (g in jng) if (g != "") printf "%5d\t %s\n", jng[g], g
		printf "\n"
	}
	
	if (totalnosub > 0) {
		print "\nCount of Rejected Newsgroups - Unsubscribed in \"sys\""
		for (g in nsb) if (g != "") printf "%5d\t %s\n", nsb[g], g
		printf "\n"
	}
	
	if (totalactx > 0) {
		print "\nCount of Rejected Newsgroups - \"x\"ed in \"active\""
		for (g in xed) if (g != "") printf "%5d\t %s\n", xed[g], g
		printf "\n"
	}
}

@//E*O*F news.repz.awk//
chmod u=rw,g=rw,o=r news.repz.awk
 
exit 0

 --------- 8< --------- 8< --------- 8< --------- 8< --------- 8< ---------

-- 
Bruce Becker
Usenet Administration	news@hybrid.gts.org
Technical Details
Message-ID: <1992Mar11.193331.20389@hybrid.gts.org>
Path: arc1-ca.pugleaf.net!wupost!usc!rpi!news-server.csri.toronto.edu!torsqnt!hybrid!news

Show Full Headers
Complete Article Headers
Newsgroups: news.admin,news.software.b,alt.sources,tor.news
Path: arc1-ca.pugleaf.net!wupost!usc!rpi!news-server.csri.toronto.edu!torsqnt!hybrid!news
From: news@hybrid.gts.org (News Administrator)
Subject: update to C news report script
Message-ID: <1992Mar11.193331.20389@hybrid.gts.org>
Followup-To: news.admin,news.software.b,alt.sources.d
Reply-To: news@hybrid.gts.org
Organization: The Home for Undeployed Basselopes, Toronto, Ontario, Canada
Date: Wed, 11 Mar 1992 19:33:31 GMT
Lines: 334