#!/usr/bin/perl -X
#
# Complaints, praise, money to: sven@unit0.net
#
# Crontab:
# 0 0 * * * feedinfo.pl | sort | uniq -c | sort -rg | mail -s "[Servername] Feedinfo" news 2>&1
# 0 0 * * * feedinfo.pl | sort | uniq -c | sort -rg | egrep -v -E "  [ 0-9]{1,2}" | mail -s "[Servername] Feedinfo" news 2>&1
#
########################################

use strict; # ... oder Sie werden erschossen!
require "/news/lib/innshellvars.pl";

my $log=$inn::pathlog.'/news.notice';
my @exceptios=(
	'^last message repeated \d+ times',
	'^nnrpd: ',
	'^controlchan: ',
	'^nocem: ',
	'^cnfsstat: ',
	'^innd: rejecting\[perl\]',
	'^innd: CNFS-sm: ',
	'^innd: SERVER paused',
	'^innd: SERVER running',
	'^innd: SERVER reload',
	'^innd: SERVER servermode',
	'^innd: SERVER flushlogs',
	'^innd: SERVER newgroup',
	'^innd: SERVER rmgroup',
	'^innd: ME (HISstats|time)',
	'^innd: \S+ NCmode \"mode stream\" received',
	'^innd: \S+ connected \d+ streaming allowed',
	'^innd: \S+ inactive \d+',
	'^innd: \S+ timeout',
	'^innd: \S+ checkpoint seconds',
	'^innd: \S+ closed seconds',
	'^innd: \S+ readclose',
	'^innd: \S+ bad_messageid',
	'^innd: filter: Saved EMP database',
	'^innd: localhost connected',
	'^innd: inflow',
	'^innfeed: ME starting innfeed',
	'^innfeed: \S+ remote MODE STREAM',
	'^innfeed: \S+ connected',
	'^innfeed: \S+ hostChkCxns - maxConnections was \d+ now \d+',
	'^innfeed: \S+ (checkpoint|final|global) seconds',
	'^innfeed: \S+ idle tearing down connection',
	'^innfeed: \S+ periodic close',
	'^innfeed: \S+ mode no-CHECK',
	'^innfeed: ME time',
	'^innfeed: ME articles',
	'^innfeed: ME finishing',
);
my $unwanted;

# Merge exceptions to regexstring
for my $ex (@exceptios) {
	if (!$unwanted) { $unwanted=$ex } else { $unwanted=join('|',$unwanted,$ex) }
}

open(LOG, "<$log");
while (<LOG>) {
	# Strip Timestamp and host "Aug 24 11:51:46 news"
	s/^\w+\s+\d+\s+\d+:\d+:\d+\s+\S+\s+//;
	# Strip PID from innfeed entry "innfeed[51858]"
	s/\[\d+\]//;
	# Strip channel from host "unit0-out.nntp.cambrium.nl:18"
	s/:\d+ / /;
	# Unifing  "rejecting huge article" entrys
	s/(rejecting huge article) \(\d+ > 300000\)/$1/;
	# No lines we have definied within @exceptios
	next if (/$unwanted/);
	# print (hopefully interessting) leftovers to STDOUT
	print;
}

