Created
January 13, 2020 20:15
-
-
Save jdgoettsch/c8987205bd1b6c554266e2a1ab403250 to your computer and use it in GitHub Desktop.
Sample logwatch service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
my $Debug = $ENV{'LOGWATCH_DEBUG'}; | |
my $Detail = $ENV{'LOGWATCH_DETAIL_LEVEL'}; | |
my $Error = 0; | |
my @ErrorLines = (); | |
my $Success = 0; | |
my @SuccessLines = (); | |
my @Warning = 0; | |
my @WarningLines = (); | |
while (defined($ThisLine = <STDIN>)) { | |
if ($ThisLine =~ /ERROR: /) { | |
@ErrorLines[$Error] = $ThisLine; | |
$Error++; | |
} | |
if ($ThisLine =~ /WARNING: /) { | |
@WarningLines[$Warning] = $ThisLine; | |
$Warning++; | |
} | |
if ($ThisLine =~ /successfully/ and not $ThisLine =~ /logger/) { | |
@SuccessLines[$Success] = $ThisLine; | |
$Success++; | |
} | |
} | |
if ($Detail >= 0 and scalar(@ErrorLines) > 0) { | |
print "Errors:\n"; | |
for ($count = 0; $count <= scalar(@ErrorLines); $count++) { | |
print "@ErrorLines[$count]"; | |
} | |
print "\n"; | |
} | |
if ($Detail >= 0 and scalar(@WarningLines) > 0) { | |
print "Warnings:\n"; | |
for ($count = 0; $count <= scalar(@WarningLines); $count++) { | |
print "@WarningLines[$count]"; | |
} | |
print "\n"; | |
} | |
if ($Detail > 0 and scalar(@SuccessLines) > 0) { | |
print "Successes:\n"; | |
for ($count = 0; $count <= scalar(@SuccessLines); $count++) { | |
print "@SuccessLines[$count]"; | |
} | |
} | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment