check_drbd.pl
changeset 1 9542011381ce
parent 0 d2456e857a47
child 3 738d4b8f3a0f
equal deleted inserted replaced
0:d2456e857a47 1:9542011381ce
    60         exit $ERRORS{CRITICAL};
    60         exit $ERRORS{CRITICAL};
    61     }
    61     }
    62 
    62 
    63     open( FH, $file )
    63     open( FH, $file )
    64       or print "$NAME CRITICAL: $file $!\n" and exit $ERRORS{CRITICAL};
    64       or print "$NAME CRITICAL: $file $!\n" and exit $ERRORS{CRITICAL};
       
    65     my $r;
    65     while (<FH>) {
    66     while (<FH>) {
    66         chomp;
    67         chomp;
    67 /^.*(?<line>(?<resource>\d+):\s+cs:(?<connection_state>\S+)\s+(?:st|ro):(?<roles>\S+)\s+(?:ds|ld):(?<disk_states>\S+))/
    68         if (/^.*(?<line>(?<resource>\d+):\s+cs:(?<connection_state>\S+)\s+(?:st|ro):(?<roles>\S+)\s+(?:ds|ld):(?<disk_states>\S+))/) {
    68           or next;
    69             $r = $+{resource};
    69         $drbd{ $+{resource} } = {
    70             $drbd{$r} = {
    70             line             => $+{line},
    71                 line             => $+{line},
    71             connection_state => $+{connection_state},
    72                 connection_state => $+{connection_state},
    72             roles            => $+{roles},
    73                 roles            => $+{roles},
    73             disk_states      => $+{disk_states}
    74                 disk_states      => $+{disk_states}
    74         };
    75             };
       
    76         } elsif (defined $r and /oos:(?<out_of_sync>\d+)/) {
       
    77             $drbd{$r}->{out_of_sync} = $+{out_of_sync};
       
    78             $drbd{$r}->{line} .= " oos: $+{out_of_sync}";
       
    79         }
    75     }
    80     }
    76     close(FH);
    81     close(FH);
    77 
    82 
    78     unless (%drbd) {
    83     unless (%drbd) {
    79         print "$NAME CRITICAL: $file found, but no entries\n";
    84         print "$NAME CRITICAL: $file found, but no entries\n";
    86           and ( $dev->{roles} ne "Secondary/Primary" );
    91           and ( $dev->{roles} ne "Secondary/Primary" );
    87 
    92 
    88         $dev->{state} = "CRITICAL", next
    93         $dev->{state} = "CRITICAL", next
    89           if ( $dev->{disk_states} ne "UpToDate/UpToDate" )
    94           if ( $dev->{disk_states} ne "UpToDate/UpToDate" )
    90           and ( $dev->{disk_states} ne "Consistent" );
    95           and ( $dev->{disk_states} ne "Consistent" );
       
    96 
       
    97         $dev->{state} = "CRITICAL", next
       
    98           if ( $dev->{out_of_sync} != 0 );
    91 
    99 
    92         $dev->{state} = "WARNING", next
   100         $dev->{state} = "WARNING", next
    93           if $dev->{connection_state} ne "Connected";
   101           if $dev->{connection_state} ne "Connected";
    94 
   102 
    95         $dev->{state} = "OK";
   103         $dev->{state} = "OK";