summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2013-10-31 07:04:15 +0100
committerByron Jones <bjones@mozilla.com>2013-10-31 07:04:15 +0100
commit69d8d262406f29b742c61850cd1d4932909277b5 (patch)
tree3fd1f478c21da8eba9bf846b4770c393f803af26
parentc683bdfcff3e1ff69290a9cff5845692bbc27f71 (diff)
downloadbugzilla-69d8d262406f29b742c61850cd1d4932909277b5.tar.gz
bugzilla-69d8d262406f29b742c61850cd1d4932909277b5.tar.xz
Bug 886497: update the nagios check to allow severity selection
-rwxr-xr-xcontrib/nagios_blocker_checker.pl35
1 files changed, 24 insertions, 11 deletions
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 <name> filter bugs by product name
--unassigned <email> 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 <major|critical|blocker>[,..]
+
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 = <<EOF;
SELECT bug_id, bug_severity, UNIX_TIMESTAMP(bugs.creation_ts) AS ts
FROM bugs
WHERE $where
AND COALESCE(resolution, '') = ''
- AND bug_severity IN ('blocker', 'critical', 'major')
+ AND bug_severity IN $severity
EOF
my $bugs = {
@@ -117,32 +131,31 @@ my $bugs = {
my $current_state = NAGIOS_OK;
my $current_time = time;
-my $dbh = Bugzilla->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";