diff -r 818e48975f3c -r f0871534a792 check_drbd.pl --- a/check_drbd.pl Mon Jan 09 15:33:15 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,188 +0,0 @@ -#! /usr/bin/perl -w - -# Copyright (C) 2011-2014 Christian Arnold -# Copyright (C) 2014-2017 Matthias Förste -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Christian Arnold -# Matthias Förste - -use strict; -use File::Basename; -use Getopt::Long; -use Pod::Usage; - -my %ERRORS = ( - OK => 0, - WARNING => 1, - CRITICAL => 2, - UNKNOWN => 3, - DEPENDENT => 4 -); - -sub check_status($); -sub version($$); - -my $ME = basename $0; -my $NAME = 'DRBD'; -my $VERSION = "2.0"; - -my %opt = ( file => "/proc/drbd" ); - -MAIN: { - Getopt::Long::Configure('bundling'); - GetOptions( - "f|file=s" => \$opt{file}, - "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) }, - "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) }, - "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; } - ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); - - check_status( $opt{file} ); -} - -sub check_status($) { - my $file = shift; - my ( %drbd, @warning, @critical, @ok ) = (); - - unless ( -r $file ) { - print "$NAME CRITICAL: $file $!\n"; - exit $ERRORS{CRITICAL}; - } - - open( FH, $file ) - or print "$NAME CRITICAL: $file $!\n" and exit $ERRORS{CRITICAL}; - my $r; - while () { - chomp; - if (/^\s*(?(?\d+):\s+cs:(?\S+)\s+(?:st|ro):(?\S+)\s+(?:ds|ld):(?\S+))/) { - $r = $+{resource}; - $drbd{$r} = { - line => $+{line}, - connection_state => $+{connection_state}, - roles => $+{roles}, - disk_states => $+{disk_states} - }; - } elsif (defined $r and /oos:(?\d+)/) { - $drbd{$r}->{out_of_sync} = $+{out_of_sync}; - $drbd{$r}->{line} .= " oos: $+{out_of_sync}"; - } - } - close(FH); - - unless (%drbd) { - print "$NAME CRITICAL: $file found, but no entries\n"; - exit $ERRORS{CRITICAL}; - } - - foreach my $dev ( map { $drbd{$_} } sort keys %drbd ) { - $dev->{state} = "CRITICAL", next - if ( $dev->{roles} ne "Primary/Secondary" ) - and ( $dev->{roles} ne "Secondary/Primary" ); - - $dev->{state} = "CRITICAL", next - if ( $dev->{disk_states} ne "UpToDate/UpToDate" ) - and ( $dev->{disk_states} ne "Consistent" ); - - $dev->{state} = "CRITICAL", next - if ( $dev->{out_of_sync} != 0 ); - - $dev->{state} = "WARNING", next - if $dev->{connection_state} ne "Connected"; - - $dev->{state} = "OK"; - } - - foreach my $dev ( map { $drbd{$_} } sort keys %drbd ) { - $dev->{state} eq "WARNING" and push( @warning, $dev->{line} ), next; - $dev->{state} eq "CRITICAL" and push( @critical, $dev->{line} ), next; - $dev->{state} eq "OK" and push( @ok, $dev->{line} ), next; - } - - print("$NAME CRITICAL: @critical\n"), exit $ERRORS{CRITICAL} if @critical; - print("$NAME WARNING: @warning\n"), exit $ERRORS{WARNING} if @warning; - print("$NAME OK: @ok\n"), exit $ERRORS{OK}; -} - -sub version($$) { - my $progname = shift; - my $version = shift; - - print <<_VERSION; -$progname version $version -Copyright (C) 2011-2014 by Christian Arnold and Schlittermann internet & unix support. -Copyright (C) 2014-2017 by Matthias Förste and Schlittermann internet & unix support. - -$ME comes with ABSOLUTELY NO WARRANTY. This is free software, -and you are welcome to redistribute it under certain conditions. -See the GNU General Public Licence for details. -_VERSION -} - -__END__ - -=head1 NAME - -check_drbd - nagios plugin to check drbd status - -=head1 SYNOPSIS - -check_drbd [-f|--file path] - [-h|--help] - [-m|--man] - [-V|--version] - -=head1 OPTIONS - -=over - -=item B<-f>|B<--file> I - -Absolute path of drbd status file. (default: /proc/drbd) - -=item B<-h>|B<--help> - -Print detailed help screen. - -=item B<-m>|B<--man> - -Print manual page. - -=item B<-V>|B<--version> - -Print version information. - -=back - -=head1 DESCRIPTION - -This plugin check drbd status. - -=head1 VERSION - -This man page is current for version 2.0 of check_drbd. - -=head1 AUTHOR - -Written by Christian Arnold L. Currently maintained by Matthias Förste L - -=head1 COPYRIGHT - -Copyright (C) 2011-2014 by Christian Arnold and Schlittermann internet & unix support. -Copyright (C) 2014-2017 by Matthias Förste and Schlittermann internet & unix support. -This is free software, and you are welcome to redistribute it under certain conditions. -See the GNU General Public Licence for details. - -=cut