#!/usr/bin/perl -s

# httpsumm - add a summary atop a personalized http notifications mailbox
# Steve Kinzler, steve@kinzler.com, Apr 09
# https://kinzler.com/me/home.html#webadm

$usage = "usage: $0 [ file ... ]\n";
die $usage if $h;

print 'From httpsumm@localhost ' . localtime(time), "\n\n";

while (<>) {
	push(@in, $_);

	# hmmm, dev/sby not really working right now with postfix ...
	$prot = '', $dev = ! /\@alamode\d?\./,
		    $sby =   /\@alamoff\./, next if /^From /;
	$prot = /HTTPS/ ? 'S' : '-',	    next if /^Subject:/;
					    next if /^\s*$/;

	# from Apache 1.3 messages
	s/^\[(\S+ +)\S+ +\S+ +(\S+) +\S+\]/$1$2/;
	s/\[error\]( \[client [\d\.]*\])?/$prot/i;
	s/File does not exist:/!/i;
	s/script not found or unable to stat:/!x/i;
	s/authentication failure for/authfail/i;
	s/Invalid URI in request/badURI/i;
	s/OpenSSL:.*\[Hint: (.*)\].*/$1/i;
	s/OpenSSL: error:[\da-f]*://i;
	s/ certificate/ cert/gi;
	s/ character/ char/gi;
	s/ directory/ dir/gi;
	s/ request/ req/gi;
	s/([ "])\/(opt|l)\/wwws?/$1/g;

	# Oracle messages
	s/.*(cannot connect to \S+) \(ORA-12541:.*/$1/;

	$sby ? s/^/]]/ : $dev ? s/^/>>/ : '';

	print;
}

print "\n", '>' x 72, "\n\n", @in;
