4
# 2010-11-05 First release (v1)
6
# Comment: Please send bug fixes and enhancements to <rmichel@devnu11.net>
8
# check_ajp - nagios plugin for jboss monitoring
9
# Copyright (C) 2010 Michel Rode <rmichel@devnu11.net>
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation, either version 3 of the License, or
14
# (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
21
# You should have received a copy of the GNU General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
25
# Usage: ./check_ajp --app ip.of.the.app [--port 8009 --warn 1 --crit 2 --timeout 5]
32
use Time::HiRes 'time';
40
my ($iaddr, $paddr, $proto, $sock, $time1, $time2);
45
printf STDERR "Usage: check_ajp --app ip.of.the.app [--port 8009 --warn 1 --crit 2 --timeout 5]\n\n";
46
printf STDERR "ERROR: $msg\n";
50
GetOptions("app=s" => \$app, "port=s" => \$port, "warn=f" => \$warntime, "crit=f" => \$crittime, "timeout=f" => \$timeout);
52
my $ping = pack 'C5' # Format template.
53
, 0x12, 0x34 # Magic number for server->container packets.
54
, 0x00, 0x01 # 2 byte int length of payload.
55
, 0x0A # Type of packet. 10 = CPing.
58
my $expected = pack 'C5' # Format template.
59
, 0x41, 0x42 # Magic number for container->server packets.
60
, 0x00, 0x01 # 2 byte int length of payload.
61
, 0x09 # Type of packet. 9 = CPong reply.
64
$iaddr = inet_aton($app) || xdie("No host given !");
65
$paddr = sockaddr_in($port, $iaddr) || xdie("Wrong port !");
66
$proto = getprotobyname 'tcp';
71
local $SIG{ALRM} = sub { die "alarm\n" };
73
socket $sock, PF_INET, SOCK_STREAM, $proto || xdie("socket !");
74
connect $sock, $paddr || xdie("connect !");
75
syswrite $sock, $ping || xdie("syswrite !");
76
sysread $sock, $pong, 5 || xdie("sysread !");
81
die unless $@ eq "alarm\n";
82
$time2 = (time() - $time1);
83
printf "CRITICAL - AJP - Timeout after %1.0fs\n",$time2;
86
$time2 = (time() - $time1);
88
if ($pong eq $expected) {
89
if ($time2 >= $crittime) {
90
printf "CRITICAL - AJP - %3.5f seconds response time|time=%3.6fs;;;0.000000;%2.6f\n",$time2,$time2,$timeout;
92
} elsif ($time2 >= $warntime) {
93
printf "WARNING - AJP - %3.5f seconds response time|time=%3.6fs;;;0.000000;%2.6f\n",$time2,$time2,$timeout;
96
printf "OK - AJP - %3.5f seconds response time|time=%3.6fs;;;0.000000;%2.6f\n",$time2,$time2,$timeout;
100
printf "UNKNOWN - AJP - %3.5f seconds response time|time=%3.6fs;;;0.000000;%2.6f\n",$time2,$time2,$timeout;