<commit_before>package Resmon::Module::MDSTAT;
use strict;
use Resmon::ExtComm qw/cache_command/;
use vars qw/@ISA/;
@ISA = qw/Resmon::Module/;

my $statfile = '/proc/mdstat';

sub handler {
    my $arg = shift;
    open FH, "<$statfile";
    my $getnext = 0;
    my $status = "OK";
    my @message = ();
    while (<FH>) {
        chomp;
        if (/^(md[0-9]+)\s*:\s+/) {
            my $array = $1;
            my $messageline = "$array ";
            my @baddevs = ();
            foreach my $part (split(/ /,$')) {
                if ($part eq "active") {
                    $messageline .= "active ";
                } elsif ($part eq "inactive") {
                    $status = "BAD";
                    $messageline .= "inactive ";
                } elsif ($part =~ /^([a-z0-9]+)\[(\d+)\](?:\((\S+)\))?$/) {
                    if ($3 eq "F") {
                        $status = "BAD";
                        push @baddevs, $1;
                    }
                }
            }
            chop $messageline;
            if (@baddevs) {
                $messageline = "$messageline - " . join(', ', @baddevs) .
                    " faulted";
            }
            push @message, $messageline;
        }
    }<commit_msg>Make MDSTAT check go bad if devices show as down in addition to faulted devices/inactive arrays<commit_after>package Resmon::Module::MDSTAT;
use strict;
use Resmon::ExtComm qw/cache_command/;
use vars qw/@ISA/;
@ISA = qw/Resmon::Module/;

my $statfile = '/proc/mdstat';

sub handler {
    my $arg = shift;
    open FH, "<$statfile";
    my $getnext = 0;
    my $status = "OK";
    my @message = ();
    my $array = "";
    while (<FH>) {
        chomp;
        if (/^(md[0-9]+)\s*:\s+/) {
            $array = $1;
            my $messageline = "$array ";
            my @baddevs = ();
            foreach my $part (split(/ /,"$'")) {
                if ($part eq "active") {
                    $messageline .= "active ";
                } elsif ($part eq "inactive") {
                    $status = "BAD";
                    $messageline .= "inactive ";
                } elsif ($part =~ /^([a-z0-9]+)\[(\d+)\](?:\((\S+)\))?$/) {
                    if ($3 eq "F") {
                        $status = "BAD";
                        push @baddevs, $1;
                    }
                }
            }
            chop $messageline;
            if (@baddevs) {
                $messageline = "$messageline - " . join(', ', @baddevs) .
                    " faulted";
            }
            push @message, $messageline;
        } elsif (/\[([U_]+)\]/) {
            my $devices = $1;
            my $count = ($devices =~ tr/_//);
            if ($count > 0) {
                $status = "BAD";
                # Plural if required
                my $s = '';
                if ($count > 1) {
                    $s = 's';
                }
                push @message, "$array - $count device$s down";
            }
        }
    }
{'fraction_non_alphanumeric': 0.17410265011741027, 'fraction_numerical': 0.00637370010063737, 'mean_word_length': 1.1468682505399568, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3799911', 'n_tokens_mistral': 979, 'n_tokens_neox': 912, 'n_words': 218}