<commit_before>#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $megaraid = "/apps/Linux64/bin/megasasctl";

my @output = `$megaraid`;

foreach my $line (@output) {

  # Ensure volumes are optimal
  if ($line =~ /^a\dd/) {
    my @volume = split(/\s+/, $line);
    critical("volume $volume[0] is $volume[5]") unless ($volume[5] eq "optimal");
  }

  # Output physical disk errors
  if ($line =~ /^a\de/) {
    # skip online disk
    next if $line =~ /^a\de.*online/;
    my @disk = split(/\s+/, $line);
    critical("disk $disk[0] is $disk[2]") unless ($disk[2] eq "hotspare");
  }
}

print "Everything OK\n";
exit 0;

sub critical {
  my $message = shift;
  print "CRITICAL: $message\n";
  exit 2;
}<commit_msg>Return UNKNOWN if megaraid command doesn't succeed<commit_after>#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $megaraid = "bash -c /apps/Linux64/bin/megasasctl";

my @output = `$megaraid 2>&1`;

if ($? ne 0) {
  unknown($output[0]);
}

foreach my $line (@output) {

  # Ensure volumes are optimal
  if ($line =~ /^a\dd/) {
    my @volume = split(/\s+/, $line);
    critical("volume $volume[0] is $volume[5]") unless ($volume[5] eq "optimal");
  }

  # Output physical disk errors
  if ($line =~ /^a\de/) {
    # skip online disk
    next if $line =~ /^a\de.*online/;
    my @disk = split(/\s+/, $line);
    critical("disk $disk[0] is $disk[2]") unless ($disk[2] eq "hotspare");
  }
}

print "Everything OK\n";
exit 0;

sub critical {
  my $message = shift;
  print "CRITICAL: $message\n";
  exit 2;
}

sub unknown {
  my $message = shift;
  print "UNKNOWN: $message\n";
  exit 3;
}
{'fraction_non_alphanumeric': 0.1941031941031941, 'fraction_numerical': 0.015356265356265357, 'mean_word_length': 3.264397905759162, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4355528', 'n_tokens_mistral': 660, 'n_tokens_neox': 629, 'n_words': 177}