From 159341cde7e94ad4f4062438da50f4fb275e9d98 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 30 Oct 2013 16:25:04 +0800 Subject: Bug 886497: mdn: set up bug paging --- contrib/nagios_blocker_checker.pl | 94 ++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 17 deletions(-) (limited to 'contrib') diff --git a/contrib/nagios_blocker_checker.pl b/contrib/nagios_blocker_checker.pl index bbc08b629..0e292c8c9 100755 --- a/contrib/nagios_blocker_checker.pl +++ b/contrib/nagios_blocker_checker.pl @@ -16,35 +16,95 @@ use lib "$Bin/../lib"; use Bugzilla; use Bugzilla::Constants; -use Bugzilla::User qw(login_to_id); +use Bugzilla::Product; +use Bugzilla::User; +use Getopt::Long; Bugzilla->usage_mode(USAGE_MODE_CMDLINE); -# Time in hours to wait before paging/warning -use constant ALERT_TIMES => { - 'major.alarm' => 24, - 'major.warn' => 20, - 'critical.alarm' => 8, - 'critical.warn' => 5, - 'blocker.alarm' => 0, - 'blocker.warn' => 0, +my $config = { + # Filter by assignee or product + assignee => '', + product => '', + unassigned => 'nobody@mozilla.org', + # Time in hours to wait before paging/warning + major_alarm => 24, + major_warn => 20, + critical_alarm => 8, + critical_warn => 5, + blocker_alarm => 0, + blocker_warn => 0, }; +my $usage = < filter bugs by assignee + --product filter bugs by product name + --unassigned set the unassigned user (default: $config->{unassigned}) + +TIMING + + time in hours to wait before paging or warning + + --major_alarm (default: $config->{major_alarm}) + --major_warn (default: $config->{major_warn}) + --critical_alarm (default: $config->{critical_alarm}) + --critical_warn (default: $config->{critical_warn}) + --blocker_alarm (default: $config->{blocker_alarm}) + --blocker_warn (default: $config->{blocker_warn}) + +EXAMPLES + + nagios_blocker_checker.pl --assignee server-ops\@mozilla-org.bugs + nagios_blocker_checker.pl server-ops\@mozilla-org.bugs + nagios_blocker_checker.pl --product 'mozilla developer network' +EOF + +die($usage) unless GetOptions( + 'assignee=s' => \$config->{assignee}, + 'product=s' => \$config->{product}, + 'major_alarm=i' => \$config->{major_alarm}, + 'major_warn=i' => \$config->{major_warn}, + 'critical_alarm=i' => \$config->{critical_alarm}, + 'critical_warn=i' => \$config->{critical_warn}, + 'blocker_alarm=i' => \$config->{blocker_alarm}, + 'blocker_warn=i' => \$config->{blocker_warn}, + 'help|?' => \$config->{help}, +); +$config->{assignee} = $ARGV[0] if !$config->{assignee} && @ARGV; +die $usage if + $config->{help} + || !($config->{assignee} || $config->{product}) + || ($config->{assignee} && $config->{product}); + +# + use constant NAGIOS_OK => 0; use constant NAGIOS_WARNING => 1; use constant NAGIOS_CRITICAL => 2; use constant NAGIOS_NAMES => [qw( OK WARNING CRITICAL )]; -my $assignee = shift - || die "Syntax: $0 assignee\neg. $0 server-ops\@mozilla-org.bugs\n"; -login_to_id($assignee, 1); +my($where, @values); + +if ($config->{assignee}) { + $where = 'bugs.assigned_to = ?'; + push @values, Bugzilla::User->check({ name => $config->{assignee} })->id; +} else { + $where = 'bugs.product_id = ? AND bugs.assigned_to = ?'; + push @values, Bugzilla::Product->check({ name => $config->{product} })->id; + push @values, Bugzilla::User->check({ name => $config->{unassigned} })->id; +} my $sql = <switch_to_shadow_db; -foreach my $bug (@{ $dbh->selectall_arrayref($sql, { Slice => {} }, $assignee) }) { +foreach my $bug (@{ $dbh->selectall_arrayref($sql, { Slice => {} }, @values) }) { my $severity = $bug->{bug_severity}; my $age = ($current_time - $bug->{ts}) / 3600; - if ($age > ALERT_TIMES->{"$severity.alarm"}) { + if ($age > $config->{"${severity}_alarm"}) { $current_state = NAGIOS_CRITICAL; push @{$bugs->{$severity}}, "https://bugzil.la/" . $bug->{bug_id}; - } elsif ($age > ALERT_TIMES->{"$severity.warn"}) { + } elsif ($age > $config->{"${severity}_warn"}) { if ($current_state < NAGIOS_WARNING) { $current_state = NAGIOS_WARNING; } -- cgit v1.2.3-24-g4f1b