summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2013-02-15 06:40:43 +0100
committerByron Jones <bjones@mozilla.com>2013-02-15 06:40:43 +0100
commit2f0f5e515f6b94aa802fe1bc8bf8604a748f19e7 (patch)
tree94e01e9c3bf93c7a7e71eaa4d681912f2ac99e8a
parentcaa591c679e58bbb92802b0ff8a685f0f9d010f9 (diff)
downloadbugzilla-2f0f5e515f6b94aa802fe1bc8bf8604a748f19e7.tar.gz
bugzilla-2f0f5e515f6b94aa802fe1bc8bf8604a748f19e7.tar.xz
Bug 841287: add nagios_blocker_check.pl
-rwxr-xr-xcontrib/nagios_blocker_checker.pl90
1 files changed, 90 insertions, 0 deletions
diff --git a/contrib/nagios_blocker_checker.pl b/contrib/nagios_blocker_checker.pl
new file mode 100755
index 000000000..bbc08b629
--- /dev/null
+++ b/contrib/nagios_blocker_checker.pl
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+
+use strict;
+use warnings;
+
+use FindBin qw($Bin);
+use lib "$Bin/..";
+use lib "$Bin/../lib";
+
+use Bugzilla;
+use Bugzilla::Constants;
+use Bugzilla::User qw(login_to_id);
+
+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,
+};
+
+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 $sql = <<EOF;
+ SELECT bug_id, bug_severity, UNIX_TIMESTAMP(bugs.creation_ts) AS ts
+ FROM bugs
+ INNER JOIN profiles map_assigned_to ON bugs.assigned_to = map_assigned_to.userid
+ WHERE map_assigned_to.login_name = ?
+ AND COALESCE(resolution, '') = ''
+ AND bug_severity IN ('blocker', 'critical', 'major')
+EOF
+
+my $bugs = {
+ 'major' => [],
+ 'critical' => [],
+ 'blocker' => [],
+};
+my $current_state = NAGIOS_OK;
+my $current_time = time;
+
+my $dbh = Bugzilla->switch_to_shadow_db;
+foreach my $bug (@{ $dbh->selectall_arrayref($sql, { Slice => {} }, $assignee) }) {
+ my $severity = $bug->{bug_severity};
+ my $age = ($current_time - $bug->{ts}) / 3600;
+
+ if ($age > ALERT_TIMES->{"$severity.alarm"}) {
+ $current_state = NAGIOS_CRITICAL;
+ push @{$bugs->{$severity}}, "https://bugzil.la/" . $bug->{bug_id};
+
+ } elsif ($age > ALERT_TIMES->{"$severity.warn"}) {
+ if ($current_state < NAGIOS_WARNING) {
+ $current_state = NAGIOS_WARNING;
+ }
+ push @{$bugs->{$severity}}, "https://bugzil.la/" . $bug->{bug_id};
+
+ }
+}
+
+print "bugs " . NAGIOS_NAMES->[$current_state] . ": ";
+if ($current_state == NAGIOS_OK) {
+ print "No blocker, critical, or major 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;
+ }
+}
+print "\n";
+
+exit $current_state;