LoginHelp/GuideAbout TracPreferences
WikiTimelineRoadmapBrowse SourceView TicketsNew TicketSearchDownloads

source: check_afs_rpc/check_afs_rpc @ 987

Revision 987, 6.8 KB checked in by corti, 6 years ago (diff)

usage

  • Property svn:executable set to *
Line 
1#!perl
2
3# check_afs_rpc is a Nagios plugin to check for the RPC status of an AFS
4# server by using rxdebug
5#
6# See  the INSTALL file for installation instructions
7#
8# Copyright (c) 2007, ETH Zurich.
9#
10# based on check_rxdebug by Quanah Gibson-Mount, Neil Crellin, and Russ Allbery
11#
12# This module is free software; you can redistribute it and/or modify it
13# under the terms of GNU general public license (gpl) version 3.
14# See the LICENSE file for details.
15#
16# RCS information
17# enable substitution with:
18#   $ svn propset svn:keywords "Id Revision HeadURL Source Date"
19#
20#   $Id$
21#   $Revision$
22#   $HeadURL$
23#   $Date$
24
25use 5.008;
26use strict;
27use warnings;
28use Carp;
29
30use version; our $VERSION = '1.0.2';
31
32use English qw(-no_match_vars);
33use Getopt::Long;
34use Nagios::Plugin::Threshold;
35use Nagios::Plugin;
36use POSIX qw(uname);
37
38# IMPORTANT: Nagios plugins could be executed using embedded perl in this case
39#            the main routine would be executed as a subroutine and all the
40#            declared subroutines would therefore be inner subroutines
41#            This will cause all the global lexical variables not to stay shared
42#            in the subroutines!
43#
44# All variables are therefore declared as package variables...
45#
46use vars qw(
47  $blocked
48  $command
49  $critical
50  $hostname
51  $output
52  $plugin
53  $port
54  $verbosity
55  $result
56  $rxdebug_bin
57  $threshold
58  $timeout
59  $warning
60);
61
62##############################################################################
63# Usage     : usage()
64# Purpose   : prints a usage message
65# Returns   : n/a
66# Arguments : -message : an optional error message
67# Throws    : n/a
68# Comments  : n/a
69# See also  : n/a
70sub usage {
71
72    my %args = @_;
73
74    my $exitval = 0;
75    if ($args{-exitval}) {
76        $exitval = $args{-exitval};
77    }
78   
79    if ($args{-message}) {
80        print $args{-message};
81    }
82
83    print<<'EOT';
84
85        check_rxdebug [OPTIONS] --hostname hostname
86
87        Mandatory arguments:
88         --hostname,-H   hostname   name of the AFS server
89
90        Options:
91         --critical,-c   critical   specify the critical number of blocked
92                                    connections (default 8)
93         --help,-h,-?               usage info
94         --port,p        port       connection port (default 7000)
95         --version,V                print version number
96         --warning,-w    warning    specify warning threshold for the number
97                                    blocked connections (default 2)
98
99EOT
100
101    exit $exitval;
102   
103}
104
105##############################################################################
106# Usage     : verbose("some message string", $optional_verbosity_level);
107# Purpose   : write a message if the verbosity level is high enough
108# Returns   : n/a
109# Arguments : message : message string
110#             level   : options verbosity level
111# Throws    : n/a
112# Comments  : n/a
113# See also  : n/a
114sub verbose {
115
116    # arguments
117    my $message   = shift;
118    my $level     = shift;
119
120    if ( !defined $message) {
121        $plugin->nagios_exit(UNKNOWN, q{Internal error: not enough parameters for 'verbose'});
122    }
123   
124    if ( !defined $level ) {
125        $level = 0;
126    }
127
128    if ( $level < $verbosity ) {
129        print $message;
130    }
131
132    return;
133
134}
135
136##############################################################################
137# Usage     : get_path('program_name');
138# Purpose   : retrieves the path of an executable file using the
139#             'which' utility
140# Returns   : the path of the program (if found)
141# Arguments : the program name
142# Throws    : n/a
143# Comments  : n/a
144# See also  : n/a
145sub get_path {
146
147    my $prog = shift;
148    my $path;
149
150    $command = "which $prog";
151
152    open $output, q{-|}, "$command 2>&1"
153      or $plugin->nagios_exit( UNKNOWN, "Cannot execute $command: $OS_ERROR" );
154
155    while (<$output>) {
156        chomp;
157        if ( !/^which:/mx ) {
158            $path = $_;
159        }
160    }
161
162    if ( !( close $output )
163        && ( $OS_ERROR != 0 ) )
164    {
165
166        # close to a piped open return false if the command with non-zero
167        # status. In this case $! is set to 0
168        $plugin->nagios_exit( UNKNOWN,
169            "Error while closing pipe to $command: $OS_ERROR\n" );
170    }
171
172    return $path;
173
174}
175
176################################################################################
177# Main
178
179################
180# Initialization
181
182# The default count of blocked connections at which to warn or send a
183# critical alert.  These can be overridden with the -w and -c
184# command-line options.
185$critical = 8;
186$warning  = 2;
187
188$verbosity = 0;
189
190# The default timeout in seconds (implemented by alarm) for rxdebug.
191$timeout = 60;
192
193$rxdebug_bin = get_path('rxdebug');
194$port        = 7_000;
195
196$plugin = Nagios::Plugin->new( shortname => 'CHECK_AFS_RPC' );
197
198##############################
199# Process command line options
200
201Getopt::Long::config( 'bundling', 'no_ignore_case' );
202$result = GetOptions(
203    'critical|c=i' => \$critical,
204    'hostname|H=s' => \$hostname,
205    'help|h|?'     => sub {
206        usage(
207            -exitval => UNKNOWN,
208        );
209        exit UNKNOWN, },
210    'port|p=i',    => \$port,
211    'timeout|t=i'  => \$timeout,
212    'verbose|v+'   => \$verbosity,
213    'version|V'    => sub { print "check_afs_rpc version $VERSION\n"; exit 3; },
214    'warning|w=i'  => \$warning
215);
216
217###############
218# sanity checks
219
220if ( !defined $hostname ) {
221    usage( -message =>
222          'Error: please specify an AFS server with the --hostname option'
223      );
224}
225if ( !defined $rxdebug_bin ) {
226    usage( -message =>
227'Cannot find the rxdebug binary: please specify it with the --rxdebug option'
228    );
229}
230if ( !-x $rxdebug_bin ) {
231    usage( -message => "$rxdebug_bin is not executable" );
232}
233
234$threshold = Nagios::Plugin::Threshold->set_thresholds(
235    warning  => $warning,
236    critical => $critical,
237);
238
239####################
240# Set up the timeout
241$SIG{ALRM} = sub {
242    $plugin->nagios_exit( UNKNOWN,
243        "AFS_RPC CRITICAL: network timeout after $timeout seconds\n",
244    );
245};
246alarm $timeout;
247
248##################################
249# Run rxdebug and parse the output
250
251$command = "$rxdebug_bin -noconn $hostname -port $port";
252
253verbose "Executing $command\n";
254
255open $output, q{-|}, "$command 2>&1"
256  or $plugin->nagios_exit( UNKNOWN, "Cannot execute $command: $OS_ERROR", );
257
258undef $blocked;
259while (<$output>) {
260    if (/^(\d+)\ calls\ waiting\ for\ a\ thread/mx) {
261        $blocked = $1;
262        last;
263    }
264}
265
266if ( !( close $output )
267    && ( $OS_ERROR != 0 ) )
268{
269
270    # close to a piped open return false if the command with non-zero
271    # status. In this case $! is set to 0
272    $plugin->nagios_exit( UNKNOWN,
273        "Error while closing pipe to $command: $OS_ERROR\n" );
274}
275
276if ( !defined $blocked ) {
277    $plugin->nagios_exit( UNKNOWN, 'Cannot parse rxdebug output', );
278}
279
280$plugin->add_perfdata(
281    label     => 'blocked',
282    value     => $blocked,
283    uom       => q{},
284    threshold => $threshold,
285);
286
287$plugin->nagios_exit( $threshold->get_status($blocked), "blocked = $blocked", );
288
2891;
Note: See TracBrowser for help on using the repository browser.
 

Wichtiger Hinweis:
Diese Website wird in älteren Versionen von Netscape ohne graphische Elemente dargestellt. Die Funktionalität der Website ist aber trotzdem gewährleistet. Wenn Sie diese Website regelmässig benutzen, empfehlen wir Ihnen, auf Ihrem Computer einen aktuellen Browser zu installieren. Weitere Informationen finden Sie auf
folgender Seite.

Important Note:
The content in this site is accessible to any browser or Internet device, however, some graphics will display correctly only in the newer versions of Netscape. To get the most out of our site we suggest you upgrade to the newer browser.
More information

 
© 2005 ETH Zürich | Imprint | 26.09.2007 | Version 0.12
top