????

Your IP : 216.73.216.174


Current Path : /lib/raider/Raider/Jobs/
Upload File :
Current File : //lib/raider/Raider/Jobs/FusionMPTSAS2.pm

use strict;
use warnings;

package Raider::Jobs::FusionMPTSAS2;
use base qw( Raider::Jobs );

use Raider::Notification::API;
use Raider::Notification::Email;

=head1 NAME

Raider::Jobs::FusionMPTSAS2 - FusionMPTSAS2 specific tasks for checking raid health

=head1 DESCRIPTION

Checks raid health for FusionMPTSAS2 cards.

=head1 USAGE

use Raider::Jobs::FusionMPTSAS2;
my jobsFusionMPTSAS2 = Raider::Jobs::FusionMPTSAS2->new();

=head1 METHODS

=head2 run_job

Takes all needed actions for checking raid health.

=head2 get_controller_list()

Returns a list of controllers.

=head2 get_array_list(\%args)

Returns a list of arrays.

=head2 array_is_ok(\%args)

Returns true if array is healthy.

=cut

# The FusionMPT SAS2 is a low-end card from LSI. It replaces the Fusion MPT
# cards. It only supports RAID0 and RAID1 and can usually be found in many 1U
# rackmount servers which have only two disks drives.

my $icmd = '/usr/bin/sas2ircu';

sub run_job {
  my $self = shift;
  $self->icmd_in_path({ icmd => $icmd });

  my $controller_list_ref = $self->get_controller_list();
  my @controller_list = @$controller_list_ref;

  my $output;
  my $raid_bad = 0;
  for my $controller ( @controller_list ) {

    my $cntrl_disp = `$icmd $controller display`;

    my $array_list_ref = $self->get_array_list({ c => $controller, cntrl_disp => $cntrl_disp });
    my @array_list = @$array_list_ref;
     for my $u ( @array_list ) {
      
      unless ( $self->array_is_ok({ cntrl_disp => $cntrl_disp, u => $u }) ) {
        $output .= "root ~ # $icmd $controller display\n";
        $output .= $cntrl_disp;
        $output .= "root ~ #\n";
        $raid_bad = 1;
      }
    };
  };

  my $notifEmail = Raider::Notification::Email->new();
  my $notifAPI = Raider::Notification::API->new();

  if ( $raid_bad ) {
    if ( $notifAPI->can_alert({ notify_type => 'FusionMPTSAS2' }) ) {
      $self->logger({ cat => 'w', msg => 'FusionMPTSAS2 Hardware RAID Alarm Detected' });
      my $notify_msg = "FusionMPTSAS2 Hardware RAID Alarm Detected on [$Raider::Base::base_conf{'hostname'}] at [$self->{uniq_id}]\nDetails:\n $output";
      if ( $notifAPI->can_api() ) {
        $notifAPI->send_notification({ 
          message => $notify_msg
        });
      }
      else {
        $notifEmail->send_notification({ 
            subject => "RAID Controller Alarm on $Raider::Base::base_conf{'hostname'}", 
            message => $notify_msg
          });
      }
      $notifAPI->place_alert({notify_type => 'FusionMPTSAS2'});
    }
    else {
      $self->logger({ cat => 'w', msg => 'Notification for FusionMPTSAS2 suppressed, alert file for today already exists.' });
    }
  }
  else {
    # health is ok, clear alerts for device
    $notifAPI->clear_alerts_for_device('FusionMPTSAS2');
  }

}  

sub get_controller_list {
  my $self = shift;

  my @controller_list;
  for my $line ( split /^/, `$icmd list` ) {

    ## START SAMPLE OUTPUT ##
    # Index  Adapter Type  Vendor  DevID    Pci Address       VenID  DevID 
    # -----  ------------  ------  ------  -----------------  -----  -----
    #   0     SAS2008       1000h    72h   00h:01h:00h:00h    1028h  1f1dh
    #   1f1dh 
    #SAS2IRCU: Utility Completed Successfully.
    #
    ## END SAMPLE OUTPUT ##

    if ( $line =~ /^\s+(\d+)\s+SAS\S+\s+/i ) {
      push(@controller_list, $1);
    }
  }

  return \@controller_list;
}

sub get_array_list {
  my $self = shift;
  my $opts = shift;
  
  my @array_list;

  # It's common for these types of cards to not support RAID. Weed these out.
  if ( $opts->{cntrl_disp} =~ /RAID\s+Support(\s+)?:\s+No/ ) {
    $self->logger({ cat => 'i', msg => "FusionMPTSAS2 controller #[$opts->{c}] does not support RAID. Skipping jobs health check routine..." });
  }
  else {

    ## START SAMPLE OUTPUT ##
    #
    #------------------------------------------------------------------------
    #IR Volume information
    #------------------------------------------------------------------------
    #IR volume 1
    #  Volume ID                               : 79
    #  Status of volume                        : Okay (OKY)
    #  RAID level                              : RAID1
    #  Size (in MB)                            : 1800000
    #  Boot                                    : Primary
    #  Physical hard disks                     :
    #  PHY[0] Enclosure#/Slot#                 : 1:0
    #  PHY[1] Enclosure#/Slot#                 : 1:1
    #
    ## END SAMPLE OUTPUT ##

    for my $line ( split /^/, $opts->{cntrl_disp} ) {
      if ( $line =~ /IR\s+volume\s+(\d+)/i ) {
        push(@array_list, $1);
      } 
    }
  }
  
  return \@array_list;
}

sub array_is_ok {
  my $self = shift;
  my $opts = shift;
  
  my $the_array_to_check = 0;
  for my $line ( split /^/, $opts->{cntrl_disp} ) {

    if ( $line =~ /IR\s+volume\s+$opts->{u}/i ) {
      $the_array_to_check = 1;
    }

    if ( $line =~ /IR\s+volume\s+(\d+)/i ) {
      if ( $1 != $opts->{u} ) {
        $the_array_to_check = 0;
      }
    }

    if ( $the_array_to_check ) {
      if ( $line =~ /Status\s+of\s+volume(\s+)?:(\.+)/i ) {
        if ( $2 =~ /Okay/i ) {
          return 1;
        }
      }
    }

  }

  return 0;
}


1;