Rev 87 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#!/usr/bin/env perl
use warnings;
use strict;
# Description: get information on md (RAID)
our $VERSION = '1.0';
# Linux MD (RAID)
# Author: R. W. Rodolico
# Date: 2017-11-24
# get some information on RAID arrays covered by mdadm
BEGIN {
push @INC, shift;
}
use library;
# category we will use for all values found
# see sysinfo for a list of valid categories
my $CATEGORY = 'diskinfo';
# run the commands necessary to do whatever you want to do
# The library entered above has some helper routines
# validCommandOnSystem -- passed a name, returns the fully qualified path or '' if it does not exist
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
# chomps the string (removes trailing newlines)
# removes all text BEFORE the delimiter, the delimiter, and any whitespace
# thus, the string 'xxI Am x a weird string' with a newline will become
# 'a weird string' with no newline
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
# item, name as recognized by sysinfo is the second and the value is
# the last one. For multiple entries, place on separate lines (ie, newline separated)
# check for commands we want to run
my %commands = (
'mdadm' => '',
'fdisk' => ''
);
# check the commands for validity
foreach my $command ( keys %commands ) {
$commands{$command} = &validCommandOnSystem( $command );
}
# bail if we don't have the commands we need
exit 1 unless $commands{'mdadm'};
exit 1 unless -e '/proc/mdstat';
open MD,'</proc/mdstat' or exit 1;
my @temp = <MD>;
close MD;
my @results;
while ( my $line = shift @temp ) {
chomp $line;
if ( $line =~ m/^(md\d+)\s+:\s+(.*)$/ ) {
my $device = $1;
my @components = split( /\s+/, $2 );
shift @components;
push @results, "$CATEGORY\t$device\tlevel\t" . shift(@components);
push @results, "$CATEGORY\t$device\tcomponents\t" . join( " ", @components );
my $temp = qx( $commands{mdadm} --detail /dev/$device | grep 'Array Size' | cut -d':' -f2 | cut -d' ' -f2 );
chomp $temp;
push @results, "$CATEGORY\t$device\tsize\t$temp";
}
}
print join( "\n", @results ) . "\n";
exit 0;