From Devwiki
Jump to: navigation, search


# Ffeil er mwn ddal pob peth o servers NT
# Ar hyn o bryd, just rhester o services NT mae hwn yn ddal, ac yna 
# gyrru yr output i logwatch 

my ($client,$class,$warnLevel,$message);
my %msg;
my %services;
my $debug=0;
$services{"em library"}="em library";
$services{"service control manager"}="service control manager";
$services{"windows server update services"}="windows server update services";

#Things to do:
# Split the line properly
# Remove date
# Allow checking on host and message (ignoring time)
# Format the output nicely.
# Figure out why other hosts aren't showing up in logwatch!

	chomp $line;
	next if ($line eq '');
	foreach $name(keys %services)
		if($line=~ m/$name/)
			#The interesting match to see if I can do it
			$line=~ m/^... .. ..:..:.. ([a-z,A-Z,0-9,\.]+) ([\s\S]+)\[([\S]+)\](?:\:)?(?:[\s]+)?([\s\S]*)/;
#			$line=~ m/^... .. ..:..:.. [a-z,A-Z,0-9,\.]+ ([\s\S]*)/;
			$message = $4;
			if($msg{$service}{$message} eq $message)
			if($debug) {
				print "\n";
			#	print "$line";
				print "$hostname\n";
				#oprint "Message: $msg{$line}\n";
				print "$service\n";
				print "Message: $msg{$service}{$message}\n";
				print "Count:$count\n\n";

foreach $name(keys %msg)
	print "----------$name---------\n\n";
	foreach $notice(keys %{$msg{$name}})
		print "$notice\n";
		if ($count> 0)
			print "Message Repeated:$count times";