Last active
July 22, 2017 22:29
-
-
Save dlangille/6a7c81ff17cf1f446581660d96a33a14 to your computer and use it in GitHub Desktop.
Would someone convert this to use File::Find for me please? I wrote this a loooong time ago. Thank you.
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
#!/usr/bin/perl -w | |
# | |
# $Id: queue-status.pl,v 1.3 2012/10/17 18:10:22 dan Exp $ | |
# | |
# Copyright (c) 2001-2006 DVL Software | |
##!/usr/bin/perl -w | |
# | |
# $Id: queue-status.pl,v 1.3 2012/10/17 18:10:22 dan Exp $ | |
# | |
# Copyright (c) 2001-2006 DVL Software | |
# | |
use strict; | |
use config; | |
use database; | |
use utilities; | |
use status; | |
use POSIX qw( strftime ); | |
use File::Find; | |
sub SendNotice($) { | |
my $Msg = shift; | |
my $hostname = `hostname`; | |
chomp $hostname; | |
my $Body = 'At ' . $hostname . ' ' . $Msg . "\n"; | |
print $Body; | |
} | |
print strftime("%Y-%m-%d %H:%M:%S\n", localtime); | |
my $base=$FreshPorts::Config::QueueBaseDir; | |
my %queues = ('incoming' => '*.txt', 'retry' => '*.txt', 'recent' => '*.xml'); | |
my %queue_names = ('incoming' => 'incoming', 'retry' => 'retry', 'recent' => 'processed'); | |
my %report_non_zero = ('retry' => 1, 'incoming' => 1); | |
my $Interval = '10 minutes'; | |
my $send_report = 0; | |
my $msg = ''; | |
my $CountRecent; | |
undef($CountRecent); | |
print strftime("%Y-%m-%d %H:%M:%S\n", localtime); | |
my $dbh = FreshPorts::Database::GetDBHandle(); | |
print strftime("%Y-%m-%d %H:%M:%S\n", localtime); | |
foreach my $site (@FreshPorts::Status::sites) { | |
print strftime("%Y-%m-%d %H:%M:%S\n", localtime); | |
$msg .= "SITE: $site "; | |
foreach my $queue (keys %queues) { | |
my $pattern = $queues{$queue} || '*'; | |
my $glob = "$base/$site/msgs/FreeBSD/$queue/$pattern"; | |
my @files = glob( $glob ); | |
print strftime("%Y-%m-%d %H:%M:%S\n", localtime); | |
print "working on '$glob'\n"; | |
my $Count = scalar @files; | |
$msg .= " $queue: $Count "; | |
if ($Count && defined($report_non_zero{$queue})) { | |
if (!defined($CountRecent)) { | |
$CountRecent = FreshPorts::Utilities::CommitCountPeriod($dbh, $Interval); | |
} | |
if ($Count > $CountRecent) { | |
$send_report = 1; | |
} | |
} | |
print "done foreach my queue\n"; | |
} | |
$msg .= " "; | |
print "done foreach my site\n"; | |
} | |
print strftime("%Y-%m-%d %H:%M:%S\n", localtime); | |
print "done\n"; | |
if ($send_report) { | |
# Sys::Syslog::syslog('notice', 'There is a problem with the FreshPorts queues'); | |
SendNotice($msg); | |
$dbh->disconnect(); | |
exit(1) | |
} else { | |
print 'Queues are OK'; | |
$dbh->disconnect(); | |
} | |
print strftime("%Y-%m-%d %H:%M:%S\n", localtime); | |
use strict; | |
use config; | |
use database; | |
use utilities; | |
use status; | |
sub SendNotice($) { | |
my $Msg = shift; | |
my $hostname = `hostname`; | |
chomp $hostname; | |
my $Body = 'At ' . $hostname . ' ' . $Msg . "\n"; | |
print $Body; | |
} | |
my $base=$FreshPorts::Config::QueueBaseDir; | |
my %queues = ('incoming' => '*.txt', 'retry' => '*.txt', 'recent' => '*.xml'); | |
my %queue_names = ('incoming' => 'incoming', 'retry' => 'retry', 'recent' => 'processed'); | |
my %report_non_zero = ('retry' => 1, 'incoming' => 1); | |
my $Interval = '10 minutes'; | |
my $send_report = 0; | |
my $msg = ''; | |
my $CountRecent; | |
undef($CountRecent); | |
my $dbh = FreshPorts::Database::GetDBHandle(); | |
foreach my $site (@FreshPorts::Status::sites) { | |
$msg .= "SITE: $site "; | |
while (my ($queue, $pattern) = each %queues) { | |
my $Command = "find $base/$site/msgs/FreeBSD/$queue/"; | |
# print $Command . "\n"; | |
if ($pattern ne '') { | |
$Command .= " -name \"$pattern\""; | |
} | |
$Command .= ' -maxdepth 1 | wc -l'; | |
# print $Command . "\n"; | |
my $Count = `$Command`; | |
chomp $Count; | |
$Count = FreshPorts::Utilities::trim($Count); | |
$msg .= " $queue: $Count "; | |
if ($Count && defined($report_non_zero{$queue})) { | |
if (!defined($CountRecent)) { | |
$CountRecent = FreshPorts::Utilities::CommitCountPeriod($dbh, $Interval); | |
} | |
if ($Count > $CountRecent) { | |
$send_report = 1; | |
} | |
} | |
} | |
$msg .= " "; | |
} | |
if ($send_report) { | |
# Sys::Syslog::syslog('notice', 'There is a problem with the FreshPorts queues'); | |
SendNotice($msg); | |
$dbh->disconnect(); | |
exit(1) | |
} else { | |
print 'Queues are OK'; | |
$dbh->disconnect(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now we get: