From 69d8d262406f29b742c61850cd1d4932909277b5 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Thu, 31 Oct 2013 14:04:15 +0800 Subject: Bug 886497: update the nagios check to allow severity selection --- contrib/nagios_blocker_checker.pl | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'contrib') diff --git a/contrib/nagios_blocker_checker.pl b/contrib/nagios_blocker_checker.pl index 0e292c8c9..a67d72b6e 100755 --- a/contrib/nagios_blocker_checker.pl +++ b/contrib/nagios_blocker_checker.pl @@ -24,11 +24,13 @@ Bugzilla->usage_mode(USAGE_MODE_CMDLINE); my $config = { - # Filter by assignee or product + # filter by assignee or product assignee => '', product => '', unassigned => 'nobody@mozilla.org', - # Time in hours to wait before paging/warning + # severities + severity => 'major,critical,blocker', + # time in hours to wait before paging/warning major_alarm => 24, major_warn => 20, critical_alarm => 8, @@ -48,6 +50,13 @@ FILTERS --product filter bugs by product name --unassigned set the unassigned user (default: $config->{unassigned}) +SEVERITIES + + by default alerts and warnings will be generated for 'major', 'critical', and + 'blocker' bugs. you can alter this list with the 'severity' switch. + + --severity [,..] + TIMING time in hours to wait before paging or warning @@ -63,12 +72,13 @@ 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' + nagios_blocker_checker.pl --product 'mozilla developer network' --severity blocker EOF die($usage) unless GetOptions( 'assignee=s' => \$config->{assignee}, 'product=s' => \$config->{product}, + 'severity=s' => \$config->{severity}, 'major_alarm=i' => \$config->{major_alarm}, 'major_warn=i' => \$config->{major_warn}, 'critical_alarm=i' => \$config->{critical_alarm}, @@ -81,7 +91,8 @@ $config->{assignee} = $ARGV[0] if !$config->{assignee} && @ARGV; die $usage if $config->{help} || !($config->{assignee} || $config->{product}) - || ($config->{assignee} && $config->{product}); + || ($config->{assignee} && $config->{product}) + || !$config->{severity}; # @@ -90,7 +101,8 @@ use constant NAGIOS_WARNING => 1; use constant NAGIOS_CRITICAL => 2; use constant NAGIOS_NAMES => [qw( OK WARNING CRITICAL )]; -my($where, @values); +my $dbh = Bugzilla->switch_to_shadow_db; +my($where, @values, $severity); if ($config->{assignee}) { $where = 'bugs.assigned_to = ?'; @@ -101,12 +113,14 @@ if ($config->{assignee}) { push @values, Bugzilla::User->check({ name => $config->{unassigned} })->id; } +$severity = '(' . join(',', map { $dbh->quote($_) } split(/,/, $config->{severity})) . ')'; + my $sql = <switch_to_shadow_db; foreach my $bug (@{ $dbh->selectall_arrayref($sql, { Slice => {} }, @values) }) { my $severity = $bug->{bug_severity}; my $age = ($current_time - $bug->{ts}) / 3600; if ($age > $config->{"${severity}_alarm"}) { $current_state = NAGIOS_CRITICAL; - push @{$bugs->{$severity}}, "https://bugzil.la/" . $bug->{bug_id}; + push @{$bugs->{$severity}}, $bug->{bug_id}; } elsif ($age > $config->{"${severity}_warn"}) { if ($current_state < NAGIOS_WARNING) { $current_state = NAGIOS_WARNING; } - push @{$bugs->{$severity}}, "https://bugzil.la/" . $bug->{bug_id}; + push @{$bugs->{$severity}}, $bug->{bug_id}; } } print "bugs " . NAGIOS_NAMES->[$current_state] . ": "; if ($current_state == NAGIOS_OK) { - print "No blocker, critical, or major bugs found." + print "No $config->{severity} bugs found." } foreach my $severity (qw( blocker critical major )) { my $list = $bugs->{$severity}; if (@$list) { - printf "%s %s bug(s) found " . join(' , ', @$list) . " ", scalar(@$list), $severity; + printf "%s %s bug(s) found https://bugzil.la/" . join(',', @$list) . " ", scalar(@$list), $severity; } } print "\n"; -- cgit v1.2.3-24-g4f1b