LogwatchNetvaultScript

From Devwiki
Revision as of 14:47, 12 September 2006 by Phb (talk | contribs) (Logwatch Netvault Script)
(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Logwatch Netvault Script

Back

#!/usr/bin/perl  
# Ffeil er mwn ddal pob peth o netvault
#

my ($client,$class,$warnLevel,$message);
my %msg;
my %JobNames;

$JobName{55}="Some Job Name";
$JobName{202}="Some Other Job NAme";



while(defined($line=<STDIN>))
{
	chomp $line;
	next if ($line eq '');
	
	$client = " ";
	$class = " ";
	$warnLevel=" ";
	$message=" ";
	$tempLine=$line;	
	
	if ( $tempLine =~ /[Nn]et[Vv]ault/ )
	{
		 $tempLine=$line;
		 $line =~ m/Job:\s'([0-9]+)'/ ;
		 $job=$1;
		($class) = ( $tempLine =~ /Class:\s'([\w\s]+)'/ );
		 $tempLine=$line;
		($client) = ( $tempLine =~ /Client:\s'([\w\d]+)'/ );
		$tempLine = $line;
		($warnLevel) = ( $tempLine =~ /Warnlevel:\s'([\w\s]+)'/ );
		$tempLine=$line;
		($message) = ( $tempLine =~ /Msg:\s'([\w\s:\\\W]*)'/ ); 
		if ($msg{$job}{$warnLevel}{$class}{$client}{$message} eq $message)
		{
			$msg{$job}{$warnLevel}{$class}{$client}{$message}{$count}++;
		}
		$msg{$job}{$warnLevel}{$class}{$client}{$message}=$message;
	}
}

if (keys %msg)
{
	foreach $jobNumber(keys %msg)
	{
		print "---";
		if ($JobNames{$jobNumber}) 
		{
			print "$JobNames{$jobNumber} ";
			print "($jobNumber)\n\n";
		}
		else
		{
			print "$jobNumber\n";
		}

	foreach $warnType(keys %{$msg{$jobNumber}})
	{
		print "**$warnType**\n\n";
		foreach $class(keys %{$msg{$jobNumber}{$warnType}})
		{
			print "\t==$class==\n";
			foreach $client(keys %{$msg{$jobNumber}{$warnType}{$class}})
			{
				$dataPlugin=0;
				print "\t\t-".$client."- \n";
				foreach $message(keys %{$msg{$jobNumber}{$warnType}{$class}{$client}})
				{
					if ($class eq "Data Plugin")
					{
						if($warnType eq "Severe Error")
						{
							print "\t\t\t".$message."\n";
						}
						else
						{
							$dataPlugin++;
						}
					}
					else
					{
						print "\t\t\t";
						if ($msg{$jobNumber}{$warnType}{$class}{$client}{$message}{$count}>0)
						{
							print "Repeated ".($msg{$jobNumber}{$warnType}{$class}{$client}{$message}{$count}+1)." times -";

						}
						print $message."\n";
					}
				}
				if($class eq "Data Plugin")
				{
					print "\t\t\t Data Plugin Skipped ".$dataPlugin." times\n";
				}
				print "\n";
			}
		}
	}
	}
}