From 2f0f5e515f6b94aa802fe1bc8bf8604a748f19e7 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Fri, 15 Feb 2013 13:40:43 +0800 Subject: Bug 841287: add nagios_blocker_check.pl --- contrib/nagios_blocker_checker.pl | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 contrib/nagios_blocker_checker.pl (limited to 'contrib') 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 = < [], + '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; -- cgit v1.2.3-24-g4f1b