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
  • Select an option

  • Save afresh1/f56f8d09437e3ed4f1c6a28e0ab73f28 to your computer and use it in GitHub Desktop.

Select an option

Save afresh1/f56f8d09437e3ed4f1c6a28e0ab73f28 to your computer and use it in GitHub Desktop.

Revisions

  1. afresh1 revised this gist Jul 22, 2017. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions queue-status.pl
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,9 @@ ($)
    my $Body = 'At ' . hostname() . " $Msg\n";
    print $Body;
    }
    sub debug ($) {
    print localtime . " @_\n"
    }

    my $base = $FreshPorts::Config::QueueBaseDir;

    @@ -33,28 +36,40 @@ ($)

    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');
  2. afresh1 revised this gist Jul 22, 2017. 1 changed file with 14 additions and 18 deletions.
    32 changes: 14 additions & 18 deletions queue-status.pl
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,26 @@
    #!/usr/bin/perl -w
    #!/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 $hostname = `hostname`;

    chomp $hostname;

    my $Body = 'At ' . $hostname . ' ' . $Msg . "\n";
    my $Msg = shift;
    my $Body = 'At ' . hostname() . " $Msg\n";
    print $Body;
    }

    my $base=$FreshPorts::Config::QueueBaseDir;
    my $base = $FreshPorts::Config::QueueBaseDir;

    my %queues = ('incoming' => '*.txt', 'retry' => '*.txt', 'recent' => '*.xml');
    my %queue_names = ('incoming' => 'incoming', 'retry' => 'retry', 'recent' => 'processed');
    @@ -35,20 +33,19 @@ ($)

    my $CountRecent;

    undef($CountRecent);

    my $dbh = FreshPorts::Database::GetDBHandle();

    foreach my $site (@FreshPorts::Status::sites) {
    $msg .= "SITE: $site ";
    foreach my $queue (keys %queues) {

    foreach my $queue (sort keys %queues) {
    my $pattern = $queues{$queue} || '*';
    my $Count = glob( "$base/$site/msgs/FreeBSD/$queue/$pattern" );
    $msg .= " $queue: $Count ";
    my $Count = glob( "$base/$site/msgs/FreeBSD/$queue/$pattern" );
    $msg .= " $queue: $Count ";

    if ($Count && defined($report_non_zero{$queue})) {
    if (!defined($CountRecent)) {
    my $dbh = FreshPorts::Database::GetDBHandle();
    $CountRecent = FreshPorts::Utilities::CommitCountPeriod($dbh, $Interval);
    $dbh->disconnect();
    }
    if ($Count > $CountRecent) {
    $send_report = 1;
    @@ -62,9 +59,8 @@ ($)
    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();
    }

    exit($send_report)
  3. afresh1 revised this gist Jul 22, 2017. 1 changed file with 3 additions and 14 deletions.
    17 changes: 3 additions & 14 deletions queue-status.pl
    Original file line number Diff line number Diff line change
    @@ -41,20 +41,9 @@ ($)

    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);
    foreach my $queue (keys %queues) {
    my $pattern = $queues{$queue} || '*';
    my $Count = glob( "$base/$site/msgs/FreeBSD/$queue/$pattern" );
    $msg .= " $queue: $Count ";

    if ($Count && defined($report_non_zero{$queue})) {
  4. @dlangille dlangille created this gist Jul 22, 2017.
    81 changes: 81 additions & 0 deletions queue-status.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    #!/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;

    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();
    }