58 |
rodolico |
1 |
#!/usr/bin/env perl
|
|
|
2 |
use warnings;
|
|
|
3 |
use strict;
|
|
|
4 |
|
|
|
5 |
# Description: get information on md (RAID)
|
|
|
6 |
|
|
|
7 |
our $VERSION = '1.0';
|
|
|
8 |
|
|
|
9 |
# Linux MD (RAID)
|
|
|
10 |
# Author: R. W. Rodolico
|
|
|
11 |
# Date: 2017-11-24
|
|
|
12 |
|
|
|
13 |
# get some information on RAID arrays covered by mdadm
|
|
|
14 |
|
|
|
15 |
BEGIN {
|
|
|
16 |
push @INC, shift;
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
use library;
|
|
|
20 |
|
|
|
21 |
# category we will use for all values found
|
|
|
22 |
# see sysinfo for a list of valid categories
|
|
|
23 |
my $CATEGORY = 'diskinfo';
|
|
|
24 |
|
|
|
25 |
# run the commands necessary to do whatever you want to do
|
|
|
26 |
# The library entered above has some helper routines
|
|
|
27 |
# validCommandOnSystem -- passed a name, returns the fully qualified path or '' if it does not exist
|
|
|
28 |
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
|
|
|
29 |
# chomps the string (removes trailing newlines)
|
|
|
30 |
# removes all text BEFORE the delimiter, the delimiter, and any whitespace
|
|
|
31 |
# thus, the string 'xxI Am x a weird string' with a newline will become
|
|
|
32 |
# 'a weird string' with no newline
|
|
|
33 |
|
|
|
34 |
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
|
|
|
35 |
# item, name as recognized by sysinfo is the second and the value is
|
|
|
36 |
# the last one. For multiple entries, place on separate lines (ie, newline separated)
|
|
|
37 |
|
|
|
38 |
# check for commands we want to run
|
|
|
39 |
my %commands = (
|
|
|
40 |
'mdadm' => '',
|
|
|
41 |
'fdisk' => ''
|
|
|
42 |
);
|
|
|
43 |
|
|
|
44 |
# check the commands for validity
|
|
|
45 |
foreach my $command ( keys %commands ) {
|
|
|
46 |
$commands{$command} = &validCommandOnSystem( $command );
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
# bail if we don't have the commands we need
|
|
|
50 |
exit 1 unless $commands{'mdadm'};
|
|
|
51 |
|
|
|
52 |
exit 1 unless -e '/proc/mdstat';
|
|
|
53 |
|
|
|
54 |
open MD,'</proc/mdstat' or exit 1;
|
|
|
55 |
my @temp = <MD>;
|
|
|
56 |
close MD;
|
|
|
57 |
|
|
|
58 |
my @results;
|
|
|
59 |
|
|
|
60 |
while ( my $line = shift @temp ) {
|
|
|
61 |
chomp $line;
|
|
|
62 |
if ( $line =~ m/^(md\d+)\s+:\s+(.*)$/ ) {
|
|
|
63 |
my $device = $1;
|
|
|
64 |
my @components = split( /\s+/, $2 );
|
|
|
65 |
shift @components;
|
|
|
66 |
push @results, "$CATEGORY\t$device\tlevel\t" . shift(@components);
|
|
|
67 |
push @results, "$CATEGORY\t$device\tcomponents\t" . join( " ", @components );
|
|
|
68 |
my $temp = qx( $commands{mdadm} --detail /dev/$device | grep 'Array Size' | cut -d':' -f2 | cut -d' ' -f2 );
|
|
|
69 |
chomp $temp;
|
|
|
70 |
push @results, "$CATEGORY\t$device\tsize\t$temp";
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
print join( "\n", @results ) . "\n";
|
|
|
75 |
|
|
|
76 |
exit 0;
|
|
|
77 |
|