Skip to content

Instantly share code, notes, and snippets.

@afresh1
Forked from dlangille/queue-status.pl
Last active July 22, 2017 22:12
Show Gist options
  • Save afresh1/f56f8d09437e3ed4f1c6a28e0ab73f28 to your computer and use it in GitHub Desktop.
Save afresh1/f56f8d09437e3ed4f1c6a28e0ab73f28 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.
#!/usr/bin/perl
#
# $Id: queue-status.pl,v 1.3 2012/10/17 18:10:22 dan Exp $
#
# Copyright (c) 2001-2006 DVL Software
#
use strict;
use warnings;
use config;
use database;
use utilities;
use status;
use Sys::Hostname 'hostname';
sub SendNotice($) {
my $Msg = shift;
my $Body = 'At ' . hostname() . " $Msg\n";
print $Body;
}
sub debug ($) {
print localtime . " @_\n"
}
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;
debug("Starting sites loop");
foreach my $site (@FreshPorts::Status::sites) {
debug("> SITE: $site");
$msg .= "SITE: $site ";
foreach my $queue (sort keys %queues) {
debug("-> QUEUE: $queue");
my $pattern = $queues{$queue} || '*';
my $Count = glob( "$base/$site/msgs/FreeBSD/$queue/$pattern" );
$msg .= " $queue: $Count ";
debug("-> COUNT: $count");
if ($Count && defined($report_non_zero{$queue})) {
debug("-> Checking report");
if (!defined($CountRecent)) {
debug("-> Getting dbh");
my $dbh = FreshPorts::Database::GetDBHandle();
debug("-> Getting CountRecent");
$CountRecent = FreshPorts::Utilities::CommitCountPeriod($dbh, $Interval);
debug("-> CountRecent: $CountRecent");
$dbh->disconnect();
}
if ($Count > $CountRecent) {
debug("-> Enabling Report");
$send_report = 1;
}
}
debug("-> Done: $queue");
}
$msg .= " ";
debug("> DONE: $site");
}
debug($msg);
if ($send_report) {
# Sys::Syslog::syslog('notice', 'There is a problem with the FreshPorts queues');
SendNotice($msg);
} else {
print 'Queues are OK';
}
exit($send_report)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment