diff options
author | Byron Jones <glob@mozilla.com> | 2016-02-01 17:14:41 +0100 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2016-02-01 17:14:41 +0100 |
commit | 939604e747a383cb03f15a1144bb5c9e89dab606 (patch) | |
tree | 4f84d9de7f74ded96713ac8327079524a6a67112 /scripts | |
parent | 6a9eda8c1a7f6bc5d1e3d399d19f5d56f060ba7f (diff) | |
download | bugzilla-939604e747a383cb03f15a1144bb5c9e89dab606.tar.gz bugzilla-939604e747a383cb03f15a1144bb5c9e89dab606.tar.xz |
Bug 1244604 - configure nagios alerting for the bmo/reviewboard connector
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/nagios_push_checker.pl | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/scripts/nagios_push_checker.pl b/scripts/nagios_push_checker.pl new file mode 100755 index 000000000..109f794d7 --- /dev/null +++ b/scripts/nagios_push_checker.pl @@ -0,0 +1,83 @@ +#!/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($RealBin); +use lib ("$RealBin/..", "$RealBin/../lib"); + +use Bugzilla; +use Bugzilla::Constants; +use Bugzilla::Product; +use Bugzilla::User; +use Getopt::Long; + +Bugzilla->usage_mode(USAGE_MODE_CMDLINE); + +my $config = { + connector => '', + warn => 5, + alarm => 10, +}; + +my $usage = <<EOF; +DESCRIPTION + + this script is called by nagios to warn/alarm when a push connector is + backlogged. + +SYNTAX + + --connector (required) connector's name (eg. ReviewBoard) + --warn (optional) number of messages that trigger a warning (def: 5) + --alarm (optional) number of messages that trigger an alarm (def: 10) + +EXAMPLES + + nagios_push_checker.pl --connector ReviewBoard + nagios_push_checker.pl --connector TCL --warn 25 --alarm 50 +EOF + +die($usage) unless GetOptions( + 'connector=s' => \$config->{connector}, + 'warn=i' => \$config->{warn}, + 'alarm=i' => \$config->{alarm}, + 'help|?' => \$config->{help}, +); +die $usage if $config->{help} || !$config->{connector}; + +# + +use constant NAGIOS_OK => 0; +use constant NAGIOS_WARNING => 1; +use constant NAGIOS_CRITICAL => 2; +use constant NAGIOS_NAMES => [qw( OK WARNING CRITICAL )]; + +my $dbh = Bugzilla->switch_to_shadow_db; + +my ($count) = $dbh->selectrow_array( + "SELECT COUNT(*) FROM push_backlog WHERE connector=?", + undef, + $config->{connector}, +); + +my $state; +if ($count >= $config->{alarm}) { + $state = NAGIOS_CRITICAL; +} elsif ($count >= $config->{warn}) { + $state = NAGIOS_WARNING; +} else { + $state = NAGIOS_OK; +} + +print "push ", NAGIOS_NAMES->[$state], ": ", $count, " ", + "push.", $config->{connector}, " message", + ($count == 1 ? '' : 's'), " in backlog\n"; +exit $state; |