@@ -0,0 +1,456 @@
+#!/usr/bin/perl -w
+
+####################################################
+# check_drbd v0.5.3 #
+# by Brandon Lee Poyner bpoyner / CCAC.edu #
+####################################################
+
+use strict;
+use File::Basename;
+use Getopt::Long;
+
+my $drbd_proc='/proc/drbd';
+my $drbd_devices=0;
+my ($drbd_expect, $drbd_role, $drbd_version, $debug_mode);
+my (%options, %cs, %st, %ld, %ds, %check, %warning, %critical);
+
+my $prog_name=basename($0);
+my $prog_revision='0.5.3';
+
+my %errorcodes = (
+ 'OK' => { 'retvalue' => 0 },
+ 'WARNING' => { 'retvalue' => 1 },
+ 'CRITICAL' => { 'retvalue' => 2 },
+ 'UNKNOWN' => { 'retvalue' => 3 }
+);
+
+#
+# Define various states and default alarm values
+#
+my %state = (
+ 'Primary' => { 'value' => 'OK', 'type' => 'st' },
+ 'Secondary' => { 'value' => 'OK', 'type' => 'st' },
+ 'Unknown' => { 'value' => 'CRITICAL', 'type' => 'st' },
+ 'StandAlone' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'Unconnected' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'Timeout' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'BrokenPipe' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'WFConnection' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'WFReportParams' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'Connected' => { 'value' => 'OK', 'type' => 'cs' },
+ 'Unconfigured' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ # DRBD 0.6
+ 'SyncingAll' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'SyncingQuick' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'SyncPaused' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ # DRBD 0.7
+ 'WFBitMapS' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'WFBitMapT' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'SyncSource' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'SyncTarget' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'PausedSyncS' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'PausedSyncT' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'NetworkFailure' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'SkippedSyncS' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'SkippedSyncT' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'Consistent' => { 'value' => 'OK', 'type' => 'ld' },
+ 'Inconsistent' => { 'value' => 'CRITICAL', 'type' => 'ld' },
+ # DRBD 8.0
+ 'UpToDate' => { 'value' => 'OK', 'type' => 'ds' },
+ 'Consistent' => { 'value' => 'OK', 'type' => 'ds' },
+ 'Negotiating' => { 'value' => 'WARNING', 'type' => 'ds' },
+ 'Attaching' => { 'value' => 'WARNING', 'type' => 'ds' },
+ 'Diskless' => { 'value' => 'CRITICAL', 'type' => 'ds' },
+ 'Failed' => { 'value' => 'CRITICAL', 'type' => 'ds' },
+ 'Outdated' => { 'value' => 'CRITICAL', 'type' => 'ds' },
+ 'Inconsistent' => { 'value' => 'CRITICAL', 'type' => 'ds' },
+ 'DUnknown' => { 'value' => 'CRITICAL', 'type' => 'ds' },
+ # DRBD 8.2
+ 'VerifyS' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'VerifyT' => { 'value' => 'WARNING', 'type' => 'cs' },
+ # DRBD 8.3
+ 'Disconnecting' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'ProtocolError' => { 'value' => 'CRITICAL', 'type' => 'cs' },
+ 'TearDown' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'StartingSyncS' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'StartingSyncT' => { 'value' => 'WARNING', 'type' => 'cs' },
+ 'WFSyncUUID' => { 'value' => 'WARNING', 'type' => 'cs' }
+);
+
+&parse_options;
+&parse_proc;
+&parse_drbd_devices;
+&check_drbd_state;
+&report_status;
+&myexit('UNKNOWN',"$prog_name should never reach here");
+
+sub print_usage {
+ print <<EOF
+Usage: $prog_name [-d <All|Configured|...>] [-e expect] [-p proc] [-r role] [-o states] [-w states] [-c states] [--debug]
+ Options:
+ -d STRING [default: $drbd_devices. Example: 0,1,2 ]
+ -p STRING [default: $drbd_proc. Use '-' for stdin]
+ -e STRING [Must be this connected state. Example: Connected]
+ -r STRING [Must be this node state. Example: Primary]
+ -o STRING [Change value to OK. Example: StandAlone]
+ -w STRING [Change value to WARNING. Example: SyncingAll]
+ -c STRING [Change value to CRITICAL. Example: Inconsistent,WFConnection]
+EOF
+}
+
+sub print_revision {
+ print <<EOF;
+$prog_name $prog_revision
+
+The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute
+copies of the plugins under the terms of the GNU General Public License.
+For more information about these matters, see the file named COPYING.
+EOF
+
+}
+
+sub print_help {
+ &print_revision;
+ print "\n";
+ &print_usage;
+ print <<EOF;
+
+Send email to nagios-users\@lists.sourceforge.net if you have questions
+regarding use of this software. To submit patches or suggest improvements,
+send email to bpoyner\@ccac.edu
+EOF
+ exit $errorcodes{'UNKNOWN'}->{'retvalue'};
+}
+
+sub parse_options {
+ my ($help, $version, $debug, $ok_string, $warning_string,
+ $critical_string);
+ #
+ # Get command line options
+ #
+ GetOptions("h|help" => \$help,
+ "V|version" => \$version,
+ "d|device|devices=s" => \$drbd_devices,
+ "e|expect=s" => \$drbd_expect,
+ "p|proc=s" => \$drbd_proc,
+ "r|role=s" => \$drbd_role,
+ "o|ok=s" => \$ok_string,
+ "w|warning=s" => \$warning_string,
+ "c|critical=s" => \$critical_string,
+ "debug" => \$debug);
+ if (defined($help) && ($help ne "")) {
+ &print_help;
+ exit $errorcodes{'UNKNOWN'}->{'retvalue'};
+ }
+ if (defined($version) && ($version ne "")) {
+ &print_revision;
+ exit $errorcodes{'UNKNOWN'}->{'retvalue'};
+ }
+ if (defined($drbd_expect) && ($drbd_expect ne "")) {
+ # User requested the connected state to be very specific
+ &change_values($drbd_expect,'cs','expect','connected state');
+ }
+ if (defined($drbd_role) && ($drbd_role ne "")) {
+ # User requested the node state to be very specific
+ &change_values($drbd_role,'st','role','node state');
+ }
+ if (defined($ok_string) && ($ok_string ne "")) {
+ # User requested certain values to be OK
+ &set_values($ok_string,'OK');
+ }
+ if (defined($warning_string) && ($warning_string ne "")) {
+ # User requested certain values to be WARNING
+ &set_values($warning_string,'WARNING');
+ }
+ if (defined($critical_string) && ($critical_string ne "")) {
+ # User requested certain values to be CRITICAL
+ &set_values($critical_string,'CRITICAL');
+ }
+ if (defined($debug) && ($debug ne "")) {
+ #
+ # Debugging information
+ #
+ $debug_mode=1;
+ print STDERR "<$prog_name settings>\n";
+ print STDERR "DRBD Devices: $drbd_devices\n";
+ printf STDERR "DRBD Proc: %s\n", defined($drbd_proc)?$drbd_proc:"";
+ printf STDERR "DRBD Expect: %s\n", defined($drbd_expect)?$drbd_expect:"";
+ printf STDERR "DRBD Role: %s\n", defined($drbd_role)?$drbd_role:"";
+ my (@ok, @critical, @warning);
+ for my $key ( keys %state ) {
+ if ($state{$key}->{'value'} eq 'OK') {
+ push(@ok,$key);
+ }
+ if ($state{$key}->{'value'} eq 'WARNING') {
+ push(@warning,$key);
+ }
+ if ($state{$key}->{'value'} eq 'CRITICAL') {
+ push(@critical,$key);
+ }
+ }
+ printf STDERR "DRBD OK: %s\n", join(" ",sort(@ok));
+ printf STDERR "DRBD WARNING: %s\n", join(" ",sort(@warning));
+ printf STDERR "DRBD CRITICAL: %s\n", join(" ",sort(@critical));
+ print STDERR "</$prog_name settings>\n";
+ }
+}
+
+sub parse_proc {
+ #
|