-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_afs_udebug
executable file
·218 lines (168 loc) · 6.93 KB
/
check_afs_udebug
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/perl -w
our $VERSION = '@VERSION@ @DATE@';
#
# check_afs_udebug -- Check AFS database servers using udebug for Nagios.
#
# Takes a hostname and a port number and checks the udebug output for that
# host and port. Reports an error if the recovery state is not 1f or 17 on the
# sync site (ensuring that it considers all of the other servers up-to-date) or
# if any of the servers don't believe there is a sync site.
#
# Written by Russ Allbery <[email protected]>
# Copyright 2004, 2010, 2013
# The Board of Trustees of the Leland Stanford Junior University
#
# This program is free software; you may redistribute it and/or modify it
# under the same terms as Perl itself.
##############################################################################
# Modules and declarations
##############################################################################
require 5.006;
use strict;
use Getopt::Long qw(GetOptions);
##############################################################################
# Site configuration
##############################################################################
# The default timeout in seconds (implemented by alarm) for udebug.
our $TIMEOUT = 10;
# The full path to udebug. Make sure that this is on local disk so that
# monitoring doesn't have an AFS dependency.
our ($UDEBUG) = grep { -x $_ } qw(/usr/bin/udebug /usr/local/bin/udebug);
$UDEBUG ||= 'udebug';
##############################################################################
# Implementation
##############################################################################
# Report a syntax error and exit. We do this via stdout in order to satisfy
# the Nagios plugin output requirements, but also report a more conventional
# error via stderr in case people are calling this outside of Nagios.
sub syntax {
print "UBIK UNKNOWN - ", join ('', @_), "\n";
warn "$0: ", join ('', @_), "\n";
exit 3;
}
# Parse command line options.
my ($help, $host, $port, $version);
Getopt::Long::config ('bundling', 'no_ignore_case');
GetOptions ('H|hostname=s' => \$host,
'h|help' => \$help,
'p|port=i' => \$port,
't|timeout=i' => \$TIMEOUT,
'V|version' => \$version)
or syntax ("invalid option");
if ($help) {
print "Feeding myself to perldoc, please wait....\n";
exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n";
} elsif ($version) {
my $version = $VERSION;
print "check_afs_udebug $version\n";
exit 0;
}
syntax ("extra arguments on command line") if @ARGV;
syntax ("host to check not specified") unless (defined $host);
syntax ("port to check not specified") unless (defined $port);
# Set up the alarm.
$SIG{ALRM} = sub {
print "UBIK CRITICAL - network timeout after $TIMEOUT seconds\n";
exit 2;
};
alarm ($TIMEOUT);
# Run udebug and parse the output. We're looking for three things: first,
# we're looking to see if this host claims to be the sync site. If so, check
# that recovery state is 1f. Otherwise, make sure that there's a defined sync
# host.
unless (open (UDEBUG, "$UDEBUG $host $port |")) {
warn "$0: cannot run udebug\n";
exit 3;
}
my ($issync, $recovery, $synchost, $db);
while (<UDEBUG>) {
$issync = 1 if /^I am sync site /;
$recovery = $1 if /^Recovery state (.*)$/;
$synchost = 1 if /^Sync host \d+(\.\d+){3} was set /;
if (/Local db version is (\d+\.\d+)/) {
$db = "db version $1";
}
}
close UDEBUG;
if ($? != 0) {
print "UBIK CRITICAL - udebug failed\n";
exit 2;
}
# Check the results.
if ($issync && ($recovery // "") !~ /1[7f]/) {
print "UBIK CRITICAL - recovery state not 1f or 17\n";
exit 2;
} elsif (!$issync && !$synchost) {
print "UBIK CRITICAL - no sync site\n";
exit 2;
} else {
print "UBIK OK - $db; state $recovery\n";
exit 0;
}
##############################################################################
# Documentation
##############################################################################
=for stopwords
AFS Nagios Ubik afs-monitor -hV kaserver ptserver udebug util vlserver
=head1 NAME
check_afs_udebug - Check AFS servers for blocked connections in Nagios
=head1 SYNOPSIS
B<check_afs_udebug> [B<-hV>] [B<-t> I<timeout>] B<-H> I<host> B<-p> I<port>
=head1 DESCRIPTION
B<check_afs_udebug> is a Nagios plugin for checking AFS database servers
to make sure the Ubik replication between the database servers is running
correctly. B<udebug> is used to connect to the specified port on the
specified server. The port should generally be one of 7002 (ptserver),
7003 (vlserver), or 7004 (kaserver). The resulting output is checked to
make sure that the recovery state is 1f if that server is the sync site,
or that a sync site is known if that server doesn't claim to be the sync
site.
B<check_afs_udebug> will always print out a single line of output. That
line will be C<UBIK OK> if everything is fine, or C<UBIK CRITICAL - >
followed by an error message otherwise.
=head1 OPTIONS
=over 4
=item B<-H> I<host>, B<--hostname>=I<host>
The AFS database server whose Ubik status B<check_afs_udebug> should
check. This option is required.
=item B<-h>, B<--help>
Print out this documentation (which is done simply by feeding the script
to C<perldoc -t>).
=item B<-p> I<port>, B<--port>=I<port>
The port to connect to on the AFS database server. This should generally
be one of 7002 (ptserver), 7003 (vlserver), or 7004 (kaserver). This
option is required.
=item B<-t> I<timeout>, B<--timeout>=I<timeout>
Change the timeout for the B<udebug> command. The default timeout is 60
seconds.
=item B<-V>, B<--version>
Print out the version of B<check_afs_udebug> and quit.
=back
=head1 EXIT STATUS
B<check_afs_udebug> follows the standard Nagios exit status requirements.
This means that it will exit with status 0 if there are no problems or
with status 2 if there are critical problems. For other errors, such as
invalid syntax, B<check_afs_udebug> will exit with status 3.
=head1 BUGS
The standard B<-v> verbose Nagios plugin option is not supported. It
should print out the full B<udebug> output.
The usage message for invalid options and for the B<-h> option doesn't
conform to Nagios standards.
=head1 CAVEATS
This script does not use the Nagios util library or any of the defaults
that it provides, which makes it somewhat deficient as a Nagios plugin.
This is intentional, though, since this script can be used with other
monitoring systems as well. It's not clear what a good solution to this
would be.
=head1 SEE ALSO
This script is part of the afs-monitor package, which includes various AFS
monitoring plugins for Nagios. It is available from the AFS monitoring
tools page at L<http://www.eyrie.org/~eagle/software/afs-monitor/>.
=head1 AUTHORS
Russ Allbery <[email protected]>
=head1 COPYRIGHT AND LICENSE
Copyright 2004, 2010, 2013 The Board of Trustees of the Leland Stanford
Junior University
This program is free software; you may redistribute it and/or modify it
under the same terms as Perl itself.
=cut