-
Notifications
You must be signed in to change notification settings - Fork 0
/
idrac-raid.pl
134 lines (110 loc) · 3.81 KB
/
idrac-raid.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/perl
# Simple demo script to check the basic RAID health of idrac7/idrac8 PERC RAID
$AUTHOR = 'Phil Doroff <[email protected]>';
$VERSION = '0.01';
use v5.18;
use Data::Dumper;
use Format::Human::Bytes;
use Getopt::Long qw(:config gnu_getopt);
use Pod::Usage;
my $racadm = '/usr/local/hannibal/bmc-edge-api/bin/idracadm7';
# Defaults
my %opt = (
'user' => 'root',
'pass' => 'yomamafat',
);
GetOptions (
\%opt, 'host|h=s', 'user|u=s', 'pass|p=s', 'help|?'
);
pod2usage(1) if ( ( defined( $opt{'help'} ) ) );
my @out = `$racadm -r $opt{host} -u $opt{user} -p $opt{pass} hwinventory`;
my $instanceid;
my %inv;
for (@out) {
chomp();
# Delete spurious DOS newlines
s/[\r\n]+//;
next if /^\s*$/;
next if /^-+$/; # Skip seperator lines
if (/\[InstanceID:\s+([^]]*)/) {
$instanceid = $1;
} else {
# Whitespace is important
my ($key,$value) = split(' = ');
# Whitespace is also a PITA... try to remove forward/trailing
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$inv{$instanceid}{$key} = $value;
}
}
# We care about:
# 1) What type of RAID card is installed/firmware
# 2) What logical volumes are present/status
# 3) What physical drives (type, size, make, model, serial, status)
#
## Disk.Bay.6:Enclosure.Internal.0-1:RAID.Integrated.1-1
# Build list of RAID controllers
my @PERC;
for my $node (keys %inv) {
if ($node =~ /^RAID\.Integrated\.(\d{1,}-\d{1,})/) {
# Found a RAID card, add to array
push (@PERC,$inv{$node}{'FQDD'});
}
}
sub PrintOutput {
# Putting in subroutine so we can rip out later...
for my $perc (@PERC) {
say "$inv{$perc}{ProductName} ($perc)";
say "|--FW Rev:\t\t$inv{$perc}{'ControllerFirmwareVersion'}";
say "|--Primary Status:\t\t$inv{$perc}{'PrimaryStatus'}";
say "|--Rollup Status:\t\t$inv{$perc}{'RollupStatus'}";
say "|";
# Now find any logical volumes for this controller
# Disk.Virtual.0:RAID.Integrated.1-1
for my $lv (grep { /Disk.Virtual.\d{1,}:$perc/ } keys %inv) {
say "|--$inv{$lv}{'Name'}";
say "| |--RAID Type:\t\t$inv{$lv}{'RAIDTypes'}";
say "| |--RAID Status:\t\t$inv{$lv}{'RAIDStatus'}";
say "| |--Primary Status:\t\t$inv{$lv}{'PrimaryStatus'}";
say "| |--Rollup Status:\t\t$inv{$lv}{'RollupStatus'}";
say "| |--Media Type:\t\t$inv{$lv}{'MediaType'}";
say "| |--Disk Cache:\t\t$inv{$lv}{'DiskCachePolicy'}";
}
say "|";
# Now find disks that belong to this controller
# unfortunately there is no way to associate a disk to a logical volume
# that I've found so far
# Disk.Bay.7:Enclosure.Internal.0-1:RAID.Integrated.1-1
for my $disk (grep { /Disk.Bay.\d{1,}:[^:](.+)$/} keys %inv) {
$inv{$disk}{'SizeInBytes'} =~ m/^(\d+)/;
my $size = Format::Human::Bytes::base2($1);
say "|--$size $inv{$disk}{'Manufacturer'} $inv{$disk}{'MediaType'}";
say "| |--Type:\t\t$inv{$disk}{'MediaType'}";
say "| |--Protocol:\t\t$inv{$disk}{'BusProtocol'}";
say "| |--Model:\t\t$inv{$disk}{'Model'}";
say "| |--FW Rev:\t\t$inv{$disk}{'Revision'}";
say "| |--Serial:\t\t$inv{$disk}{'SerialNumber'}";
say "| |--Phy Slot:\t\t$inv{$disk}{'Slot'}";
say "| |--RAID Status:\t$inv{$disk}{'RaidStatus'}";
say "| |--Primary Status:\t$inv{$disk}{'PrimaryStatus'}";
say "| |--Rollup Status:\t$inv{$disk}{'RollupStatus'}";
say "| |--Remaining Endur.:\t$inv{$disk}{'RemainingRatedWriteEndurance'}";
say "|";
}
}
}
&PrintOutput;
exit 0;
__END__
=head1 NAME
B<idrac_raid.pl> - Demo tool/wrapper around racadm to get quick raid/hdd status
=head1 SYNOPSIS
B<idrac_raid.pl> -u <username> -p <password> -h <hostname>
=head1 OPTIONS
=over 8
=item B<--pass|-p>
The password of the remote iDrac
=item B<--user|-u>
The user of the remote iDrac
=item B<--host|-h>
The remote hostname or IP of the idrac