Last active
April 21, 2020 13:19
-
-
Save lazyfrosch/8bce6c794ab2830c93e868a486188928 to your computer and use it in GitHub Desktop.
check_logfiles for the slightly magical usage, when files are named with the current date, but we can't expect a static filename
This file contains hidden or 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
## Config | |
$seekfilesdir = '/var/tmp'; | |
my $logdir = '/var/log/app'; | |
my $search_defaults = { | |
tag => 'prefix', | |
criticalpatterns => 'someerror', | |
options => 'sticky=3600,allyoucaneat', | |
}; | |
## Internal | |
use POSIX qw(strftime); | |
@searches = (); | |
my $date = strftime "%y%m%d", localtime; | |
my $tag = $search_defaults->{'tag'}; | |
my $prefix = "${tag}${date}"; | |
my $dh; | |
if (! opendir($dh, $logdir)) { | |
print("Could not open ${logdir} - $!"); | |
exit(3); | |
} | |
while (my $file = readdir($dh)) { | |
if (! -f $file || $file !~ /^${prefix}/) { | |
next; | |
} | |
my $search = { %$search_defaults }; | |
$search->{'tag'} .= $date; | |
$search->{'logfile'} = "${logdir}\\$file"; | |
push @searches, $search; | |
} | |
if (@searches == 0) { | |
print("OK - No files found for ${tag}${date}*"); | |
exit(0); | |
} | |
# Debugging | |
#use Data::Dumper; | |
#print Dumper(\@searches); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment