retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-afs-udebug
1 #!/usr/bin/perl -w
2 $ID = q$Id: check_udebug,v 1.3 2006/03/17 23:06:54 quanah Exp $;
3 #
4 # check_udebug -- Check AFS database servers using udebug for Nagios.
5 #
6 # Written by Russ Allbery <rra@stanford.edu>
7 # Copyright 2004 Board of Trustees, Leland Stanford Jr. University
8 #
9 # This program is free software; you may redistribute it and/or modify it
10 # under the same terms as Perl itself.
11 #
12 # Takes a hostname and a port number and checks the udebug output for that
13 # host and port.  Reports an error if the recovery state is not 1f on the sync
14 # site (ensuring that it considers all of the other servers up-to-date) or if
15 # any of the servers don't believe there is a sync site.
16
17 ##############################################################################
18 # Site configuration
19 ##############################################################################
20
21 # The default timeout in seconds (implemented by alarm) for udebug.
22 $TIMEOUT = 10;
23
24 # The full path to udebug.  Make sure that this is on local disk so that
25 # monitoring doesn't have an AFS dependency.
26 ($UDEBUG) = grep { -x $_ } qw(/usr/bin/udebug /usr/local/bin/udebug);
27 $UDEBUG ||= '/usr/bin/udebug';
28
29 ##############################################################################
30 # Modules and declarations
31 ##############################################################################
32
33 require 5.003;
34
35 use strict;
36 use vars qw($ID $TIMEOUT $UDEBUG);
37
38 use Getopt::Long qw(GetOptions);
39
40 ##############################################################################
41 # Implementation
42 ##############################################################################
43
44 # Parse command line options.
45 my ($help, $host, $port, $version);
46 Getopt::Long::config ('bundling', 'no_ignore_case');
47 GetOptions ('hostname|H=s' => \$host,
48             'help|h'       => \$help,
49             'port|p=i'     => \$port,
50             'timeout|t=i'  => \$TIMEOUT,
51             'version|V'    => \$version) or exit 3;
52 if ($help) {
53     print "Feeding myself to perldoc, please wait....\n";
54     exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n";
55 } elsif ($version) {
56     my $version = join (' ', (split (' ', $ID))[1..3]);
57     $version =~ s/,v\b//;
58     $version =~ s/(\S+)$/($1)/;
59     $version =~ tr%/%-%;
60     print $version, "\n";
61     exit 0;
62 }
63 if (@ARGV || !(defined ($host) && defined ($port))) {
64     warn "Usage: $0 [-hv] [-t <timeout>] -H <host> -p <port>\n";
65     exit 3;
66 }
67
68 # Set up the alarm.
69 $SIG{ALRM} = sub {
70     print "UBIK CRITICAL - network timeout after $TIMEOUT seconds\n";
71     exit 2;
72 };
73 alarm ($TIMEOUT);
74
75 # Run udebug and parse the output.  We're looking for three things:  first,
76 # we're looking to see if this host claims to be the sync site.  If so, check
77 # that recovery state is 1f.  Otherwise, make sure that there's a defined sync
78 # host.
79 unless (open (UDEBUG, "$UDEBUG $host $port |")) {
80     warn "$0: cannot run udebug\n";
81     exit 3;
82 }
83 my ($issync, $recovery, $synchost);
84 while (<UDEBUG>) {
85     $issync = 1 if /^I am sync site /;
86     $recovery = 1 if /^Recovery state 1f/;
87     $synchost = 1 if /^Sync host \d+(\.\d+){3} was set /;
88 }
89 close UDEBUG;
90 if ($? != 0) {
91     print "UBIK CRITICAL - udebug failed\n";
92     exit 2;
93 }
94
95 # Check the results.
96 if ($issync && !$recovery) {
97     print "UBIK CRITICAL - recovery state not 1f\n";
98     exit 2;
99 } elsif (!$issync && !$synchost) {
100     print "UBIK CRITICAL - no sync site\n";
101     exit 2;
102 } else {
103     print "UBIK OK\n";
104     exit 0;
105 }
106
107 ##############################################################################
108 # Documentation
109 ##############################################################################
110
111 =head1 NAME
112
113 check_udebug - Check AFS servers for blocked connections in Nagios
114
115 =head1 SYNOPSIS
116
117 check_udebug [B<-hV>] [B<-t> I<timeout>] B<-H> I<host> B<-p> I<port>
118
119 =head1 DESCRIPTION
120
121 B<check_udebug> is a Nagios plugin for checking AFS database servers to make
122 sure the Ubik replication between the database servers is running correctly.
123 B<udebug> is used to connect to the specified port, which should generally
124 be one of 7002 (ptserver), 7003 (vlserver), or 7004 (kaserver), on the
125 specified server.  The resulting output is checked to make sure that the
126 recovery state is 1f if that server is the sync site, or that a sync site is
127 known if that server doesn't claim to be the sync site.
128
129 B<check_udebug> will always print out a single line of output.  That line
130 will be C<UBIK OK> if everything is fine, or C<UBIK CRITICAL - > followed by
131 an error message otherwise.
132
133 =head1 OPTIONS
134
135 =over 4
136
137 =item B<-H> I<host>, B<--hostname>=I<host>
138
139 The AFS database server whose Ubik status B<check_udebug> should check.
140 This option is required.
141
142 =item B<-h>, B<--help>
143
144 Print out this documentation (which is done simply by feeding the script
145 to C<perldoc -t>).
146
147 =item B<-p> I<port>, B<--port>=I<port>
148
149 The port to connect to on the AFS database server.  This should generally be
150 one of 7002 (ptserver), 7003 (vlserver), or 7004 (kaserver).  This option is
151 required.
152
153 =item B<-t> I<timeout>, B<--timeout>=I<timeout>
154
155 Change the timeout for the B<udebug> command.  The default timeout is 60
156 seconds.
157
158 =item B<-V>, B<--version>
159
160 Print out the version of B<check_udebug> and quit.
161
162 =back
163
164 =head1 EXIT STATUS
165
166 B<check_udebug> follows the standard Nagios exit status requirements.  This
167 means that it will exit with status 0 if there are no problems or with
168 status 2 if there are critical problems.  For other errors, such as invalid
169 syntax, B<check_udebug> will exit with status 3.
170
171 =head1 BUGS
172
173 The standard B<-v> verbose Nagios plugin option is not supported.  It should
174 print out the full B<udebug> output.
175
176 The usage message for invalid options and for the B<-h> option doesn't
177 conform to Nagios standards.
178
179 =head1 CAVEATS
180
181 This script does not use the Nagios util library or any of the defaults that
182 it provides, which makes it somewhat deficient as a Nagios plugin.  This is
183 intentional, though, since this script can be used with other monitoring
184 systems as well.  It's not clear what a good solution to this would be.
185
186 =head1 SEE ALSO
187
188 The current version of this and other AFS monitoring plugins for Nagios are
189 available from the AFS monitoring tools page at
190 L<http://www.eyrie.org/~eagle/software/afs-monitor/>.
191
192 =head1 AUTHORS
193
194 Russ Allbery <rra@stanford.edu>
195
196 =head1 COPYRIGHT AND LICENSE
197
198 Copyright 2004 Board of Trustees, Leland Stanford Jr. University.
199
200 This program is free software; you may redistribute it and/or modify it
201 under the same terms as Perl itself.
202
203 =cut