<commit_before>#!/usr/bin/perl
#
# check_engenio_raid.pl
# Author: <NAME> <<EMAIL>>
# Checks the status of any LSI/Engenio/NetApp E-Series disk arrays
# Requires SMcli to be installed
#

# sudo hostsdo -el6 'yum -q -y install perl-Nagios-Plugin'
# http://www.raidinc.com/assets/Manual/Xanadu%20LSI/linux/Documentation/SANtricity%20Documentation/SANtricity%20CLI%20Guide%2010.70_RevA.pdf

use strict;
use Nagios::Plugin;
use Data::Dumper;
use IPC::Run qw(run timeout);

# paths to SMcli, we are going to try them all in order until we find one
my @sm_cli = qw(/opt/SMgr/client/SMcli /opt/dell/mdstoragesoftware/mdstoragemanager/client/SMcli /opt/dell/mdstoragemanager/client/SMcli);

my $n = Nagios::Plugin->new(
    shortname   => 'engenio_raid',
    usage       => 'Usage: %s --hostname HOSTNAME',
);

$n->add_arg(
    spec => 'hostname|H=s',
    help => '--hostname=HOSTNAME - hostname of the RAID controller',
);

$n->getopts;
$n->nagios_die("no hostname specified") unless $n->opts->hostname;

check_health();

$n->nagios_exit($n->check_messages(join_all => "\n"));

# Storage array health status = optimal.

# Storage array health status = fixing.                                     
# The following failures have been found:
# Failed physical disk
# Storage array: nfs5raid1
# Component reporting problem: Physical Disk in slot 1
#   Status: Failed
#   Location: RAID enclosure 0, Drawer 1
# Component requiring service: Physical Disk in slot 1
#   Service action (removal) allowed: Yes
#   Service action LED on component: Yes
# 
# Degraded Virtual Disk
# Storage array: nfs5raid1
#   Disk group: 1
#     RAID level: 6
#     Status: Degraded
#       Enclosure: RAID enclosure 0, Drawer 1
#         Affected physical disk slot(s): 1
#           Service action (removal) allowed: Yes
#           Service action LED on component: Yes
#     Virtual Disks: 1

# The following failures have been found:
# Volume - Hot Spare In Use
# Storage array: Lead_R2_0637018811
# Volume group: 4
#   Failed drive at: tray 1, slot 1
#     Service action (removal) allowed: No
#     Service action LED on component: No
#   Replaced by drive at: tray 1, slot 16
#   Volumes: FIBRE_61_E7_A3
#     RAID level: 5
#     Status: Optimal
# 
# Impending Drive Failure - Medium Data Availability Risk
# Storage array: Lead_R2_0637018811
# Volume group: 5
#   RAID level: 5
#   Tray: Drive tray 1
#     Affected drive slot(s): 6
#     Service action (removal) allowed: No
#     Service action LED on component: Yes
#   Volumes: FIBRE_61_E9_B2
#     Status: Optimal
# 
# Bypassed Drive
# Storage array: Lead_R2_0637018811
# Component reporting problem: Drive in slot 1
#   Status: Unknown
#   Location: Drive tray 1
# Component requiring service: Drive in slot 1
#   Bypassed by: Drive in tray 1, slot 1
#   Service action (removal) allowed: No
#   Service action LED on component: Yes
sub check_health {

    my @output = run_sm_cli($n->opts->hostname, "show storageArray healthStatus;");

    # expecting exactly one line which contains
    # Storage array health status = optimal.
    #
    if (grep { /^Storage array health status = optimal.$/ } @output) {
        $n->add_message(OK, 'storage array is optimal');

        # now make sure we have exactly one line
        if (scalar @output != 1) {
            $n->add_message(WARNING, 'storage array is optimal but we also got a message');
            $n->add_message(WARNING, @output);
        }
    }

    # otherwise we are fixing
    elsif (grep { /^Storage array health status = fixing.$/ } @output) {
        $n->add_message(OK, 'storage array is repairing - ');

        if (grep { /^Failed physical disk$/ } @output) {
            $n->add_message(CRITICAL, 'failed disk');
        }
        if (grep { /^(Degraded Virtual Disk|Degraded volume)$/ } @output ) {
            $n->add_message(CRITICAL, 'degraded volume');
        }

#         } else {
#             $n->add_message(WARNING, 'unknown component');
#         }
    }

    # fall through to failures - doesn't appear to be a health status = failed. line
    elsif (grep { /^The following failures have been found/ } @output) {<commit_msg>Disable volume checks by default - only interested in failed disks. Add command line flag to enable volume checks.<commit_after>#!/usr/bin/perl
#
# check_engenio_raid.pl
# Author: <NAME> <<EMAIL>>
# Checks the status of any LSI/Engenio/NetApp E-Series disk arrays
# Requires SMcli to be installed
#

# sudo hostsdo -el6 'yum -q -y install perl-Nagios-Plugin'
# http://www.raidinc.com/assets/Manual/Xanadu%20LSI/linux/Documentation/SANtricity%20Documentation/SANtricity%20CLI%20Guide%2010.70_RevA.pdf

use strict;
use Nagios::Plugin;
use Data::Dumper;
use IPC::Run qw(run timeout);

# paths to SMcli, we are going to try them all in order until we find one
my @sm_cli = qw(/opt/SMgr/client/SMcli /opt/dell/mdstoragesoftware/mdstoragemanager/client/SMcli /opt/dell/mdstoragemanager/client/SMcli);

my $n = Nagios::Plugin->new(
    shortname   => 'engenio_raid',
    usage       => 'Usage: %s --hostname HOSTNAME [--volume]',
);

$n->add_arg(
    spec => 'hostname|H=s',
    help => '--hostname=HOSTNAME - hostname of the RAID controller',
);

$n->add_arg(
    spec => 'volume|v',
    help => '--volume - Enable volume checks',
);

$n->getopts;
$n->nagios_die("no hostname specified") unless $n->opts->hostname;

check_health();

$n->nagios_exit($n->check_messages(join_all => "\n"));

# Storage array health status = optimal.

# Storage array health status = fixing.                                     
# The following failures have been found:
# Failed physical disk
# Storage array: nfs5raid1
# Component reporting problem: Physical Disk in slot 1
#   Status: Failed
#   Location: RAID enclosure 0, Drawer 1
# Component requiring service: Physical Disk in slot 1
#   Service action (removal) allowed: Yes
#   Service action LED on component: Yes
# 
# Degraded Virtual Disk
# Storage array: nfs5raid1
#   Disk group: 1
#     RAID level: 6
#     Status: Degraded
#       Enclosure: RAID enclosure 0, Drawer 1
#         Affected physical disk slot(s): 1
#           Service action (removal) allowed: Yes
#           Service action LED on component: Yes
#     Virtual Disks: 1

# The following failures have been found:
# Volume - Hot Spare In Use
# Storage array: Lead_R2_0637018811
# Volume group: 4
#   Failed drive at: tray 1, slot 1
#     Service action (removal) allowed: No
#     Service action LED on component: No
#   Replaced by drive at: tray 1, slot 16
#   Volumes: FIBRE_61_E7_A3
#     RAID level: 5
#     Status: Optimal
# 
# Impending Drive Failure - Medium Data Availability Risk
# Storage array: Lead_R2_0637018811
# Volume group: 5
#   RAID level: 5
#   Tray: Drive tray 1
#     Affected drive slot(s): 6
#     Service action (removal) allowed: No
#     Service action LED on component: Yes
#   Volumes: FIBRE_61_E9_B2
#     Status: Optimal
# 
# Bypassed Drive
# Storage array: Lead_R2_0637018811
# Component reporting problem: Drive in slot 1
#   Status: Unknown
#   Location: Drive tray 1
# Component requiring service: Drive in slot 1
#   Bypassed by: Drive in tray 1, slot 1
#   Service action (removal) allowed: No
#   Service action LED on component: Yes
sub check_health {

    my @output = run_sm_cli($n->opts->hostname, "show storageArray healthStatus;");

    # expecting exactly one line which contains
    # Storage array health status = optimal.
    #
    if (grep { /^Storage array health status = optimal.$/ } @output) {
        $n->add_message(OK, 'storage array is optimal');

        # now make sure we have exactly one line
        if (scalar @output != 1) {
            $n->add_message(WARNING, 'storage array is optimal but we also got a message');
            $n->add_message(WARNING, @output);
        }
    }

    # otherwise we are fixing
    elsif (grep { /^Storage array health status = fixing.$/ } @output) {
        $n->add_message(OK, 'storage array is repairing - ');

        if (grep { /^Failed physical disk$/ } @output) {
            $n->add_message(CRITICAL, 'failed disk');
        }
        if (grep { /^(Degraded Virtual Disk|Degraded volume)$/ } @output ) {
            $n->add_message(CRITICAL, 'degraded volume') if $n->opts->volume;
        }

#         } else {
#             $n->add_message(WARNING, 'unknown component');
#         }
    }

    # fall through to failures - doesn't appear to be a health status = failed. line
    elsif (grep { /^The following failures have been found/ } @output) {
{'fraction_non_alphanumeric': 0.11064030131826742, 'fraction_numerical': 0.020480225988700564, 'mean_word_length': 3.046190476190476, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '196019', 'n_tokens_mistral': 2877, 'n_tokens_neox': 2693, 'n_words': 900}