forked from BillWeiss/MiscScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_activemq.pl
executable file
·80 lines (67 loc) · 1.72 KB
/
check_activemq.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
# Check_ActiveMQ
# Original author:
# © 2012 -- Sig-I/O Automatisering -- [email protected]
#
# I'm forking this thing to make it substantially less strange.
# The original author had some hardcoded values and a cron implementation,
# which I don't think we need to just check a queue. I'm adding some
# command-line arguments for everything we need.
# -- Bill Weiss <[email protected]>
use XML::Simple;
use Getopt::Std;
use strict;
my $verbose = 0;
my $warnlimit = 5;
my $criticallimit = 10;
my $targetqueue;
my $store;
my $memory;
my $temp;
my $url;
my $queue;
my $data;
my %options = ();
getopts("w:c:u:q:vh", \%options);
## trivial option parsing
if ($options{v}) {
$verbose++;
}
if ($options{w}) {
$warnlimit = $options{w};
}
if ($options{c}) {
$criticallimit = $options{c};
}
if ($options{u}) {
$url = $options{u};
} else {
print "UNKNOWN: Must pass in a url (-u)\n";
exit 3;
}
if ($options{q}) {
$targetqueue = $options{q};
} else {
print "UNKNOWN: Must pass in a queue to monitor (-q)\n";
exit 3;
}
## end trivial option parsing
my $dump = qx|/usr/bin/curl -s $url|;
my $xmldata = XMLin($dump);
while ( ($queue, $data) = each(%{$xmldata->{queue}}) ) {
next if $queue ne $targetqueue;
my $numinqueue = $data->{stats}->{size};
if ($numinqueue >= $criticallimit ) {
print "CRITICAL: ${numinqueue} items in queue ${targetqueue}!\n";
exit 2;
} elsif ($numinqueue >= $warnlimit) {
print "WARNING: ${numinqueue} items in queue ${targetqueue}!\n";
exit 1;
} else {
print "OK: ${numinqueue} items in queue ${targetqueue}\n";
exit 0;
}
}
## if we've gotten here, it means we haven't seen the queue. Dang.
print "UNKNOWN: Queue ${targetqueue} not found in ${url}\n";
exit 3;