~ubuntu-branches/ubuntu/wily/nagios-plugins-contrib/wily-proposed

« back to all changes in this revision

Viewing changes to check_ajp/check_ajp

  • Committer: Package Import Robot
  • Author(s): Bernd Zeimetz, Jan Wagner, Bernd Zeimetz
  • Date: 2013-08-24 00:06:27 UTC
  • Revision ID: package-import@ubuntu.com-20130824000627-0q2ws6d93fs4nafx
Tags: 8.20130824
[ Jan Wagner ]
* [3bce1c4b] Merge remote-tracking branch 'debian/master'
* [bcf6f1d9] Merge remote-tracking branch 'bzed/master'
* [d436ca0e] Fixing check_raid for 3ware controllers when reporting "NOT-PRESENT" (Closes: #692598)
* [8f55cc69] add patch check_raid/3ware_fix_notpresent
* [506000a8] Merge remote-tracking branch 'bzed/master'
* [62bbdd2f] disable epn
* [6c73c15b] Auto update of debian/control
* [5e43a9ae] update check_ssl_cert
* [ad1c463d] update check_ssl_cert
* [4975ff97] Revert "Fixing check_raid for 3ware controllers when reporting "NOT-PRESENT""
  This reverts commit d436ca0e6a4e3147265627afd256856c9fab3836.
* [f6c71f97] drop removed patch
* [4e52a4ad] Merge remote-tracking branch 'bzed/master'
* [c01cd192] fix typo in patches/check_rbl/epn

[ Bernd Zeimetz ]
* [a61aefc4] Add syslog output to check_checksums
* [62d55e7e] New plugin: check_ajp
* [5a00818c] Auto update of debian/control
* [eb29e6c6] Auto update of debian/copyright
* [cf6c7f44] Delete unused patch file check_raid/cciss_bugfix
* [a3e036b7] Fix an error message in check_raid if not using cciss_vol_status.
  Use of uninitialized value in -x at /usr/lib/nagios/plugins/check_raid
  line 2495.
  Thanks to Stefan Kaltenbrunner
* [6dddc838] Updating changelog.
* [192396b7] Fix check_ajp to return CRITICAL on connection errors.
* [d8d41faf] Add config file for check_ajp.
* [4e092c04] Read 5 bytes only - thats all an AJP pong needs.
* [26cb156f] Be nice and close the AJP connection socket.
* [ccc8f7d6] check_ajp: print an error message if --app is not specified.
* [915d3708] Add -epn to check_packages.
  Thanks to Salvatore Bonaccorso (Closes: #691012)
* [240ca0fc] Updating date/version in changelog.
* [8534630e] Update DSA nagios checks/scripts
* [5078ff97] Refresh patches for new dsa plugin versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
#
 
3
# History:
 
4
#       2010-11-05      First release (v1)
 
5
#
 
6
# Comment: Please send bug fixes and enhancements to <rmichel@devnu11.net>
 
7
#
 
8
# check_ajp - nagios plugin for jboss monitoring
 
9
# Copyright (C) 2010  Michel Rode <rmichel@devnu11.net>
 
10
#
 
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.
 
15
#
 
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.
 
20
#
 
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/>.
 
23
#
 
24
#
 
25
# Usage: ./check_ajp --app ip.of.the.app [--port 8009 --warn 1 --crit 2 --timeout 5]
 
26
 
27
 
 
28
use warnings;
 
29
use strict;
 
30
use Getopt::Long;
 
31
use Socket;
 
32
use Time::HiRes 'time';
 
33
 
 
34
my $app = '';
 
35
my $port = '8009';
 
36
my $warntime = '1.5';
 
37
my $crittime = '3';
 
38
my $timeout = '10';
 
39
 
 
40
my ($iaddr, $paddr, $proto, $sock, $time1, $time2);
 
41
my $pong = 'null';
 
42
 
 
43
sub xdie{
 
44
        my $msg = shift;
 
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";
 
47
        exit 3;
 
48
}
 
49
 
 
50
GetOptions("app=s" => \$app, "port=s" => \$port, "warn=f" => \$warntime, "crit=f" => \$crittime, "timeout=f" => \$timeout);
 
51
 
 
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.
 
56
;
 
57
 
 
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.
 
62
;
 
63
 
 
64
$iaddr = inet_aton($app) || xdie("No host given !");
 
65
$paddr = sockaddr_in($port, $iaddr) || xdie("Wrong port !");
 
66
$proto = getprotobyname 'tcp';
 
67
 
 
68
$time1 = time();
 
69
 
 
70
eval {
 
71
        local $SIG{ALRM} = sub { die "alarm\n" };
 
72
        alarm($timeout);
 
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 !");
 
77
        alarm(0);
 
78
}; 
 
79
 
 
80
if ($@) {
 
81
        die unless $@ eq "alarm\n";
 
82
        $time2 = (time() - $time1);
 
83
        printf "CRITICAL - AJP - Timeout after %1.0fs\n",$time2;
 
84
        exit 2;
 
85
} else {
 
86
        $time2 = (time() - $time1);
 
87
 
 
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;
 
91
                        exit 2;
 
92
                } elsif ($time2 >= $warntime) {
 
93
                        printf "WARNING - AJP - %3.5f seconds response time|time=%3.6fs;;;0.000000;%2.6f\n",$time2,$time2,$timeout;
 
94
                        exit 1;
 
95
                } else {
 
96
                        printf "OK - AJP - %3.5f seconds response time|time=%3.6fs;;;0.000000;%2.6f\n",$time2,$time2,$timeout;
 
97
                        exit 0;
 
98
                }
 
99
        } else {
 
100
                printf "UNKNOWN - AJP - %3.5f seconds response time|time=%3.6fs;;;0.000000;%2.6f\n",$time2,$time2,$timeout;
 
101
                exit 3;
 
102
        }
 
103
}