line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Generic::Storages::3ware; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
125855220
|
use strict; |
|
1
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
115
|
|
4
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
94
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
560
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
139
|
|
7
|
1
|
|
|
1
|
|
426
|
use FusionInventory::Agent::Tools::Linux; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
81
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Tested on 2.6.* kernels |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Cards tested : |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# 8006-2LP |
16
|
|
|
|
|
|
|
# 9500S-4LP |
17
|
|
|
|
|
|
|
# 9550SXU-4LP |
18
|
|
|
|
|
|
|
# 9550SXU-8LP |
19
|
|
|
|
|
|
|
# 9650SE-2LP |
20
|
|
|
|
|
|
|
# 9650SE-4LPML |
21
|
|
|
|
|
|
|
# 9650SE-8LPML |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# AMCC/3ware CLI (version 2.00.0X.XXX) |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub isEnabled { |
26
|
0
|
|
|
0
|
0
|
|
return canRun('tw_cli'); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub doInventory { |
30
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
33
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my @devices; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
foreach my $card (_getCards()) { |
38
|
0
|
|
|
|
|
|
foreach my $unit (_getUnits($card)) { |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Try do get unit's serial in order to compare it to what was found |
41
|
|
|
|
|
|
|
# in udev db. |
42
|
|
|
|
|
|
|
# Works only on newer cards. |
43
|
|
|
|
|
|
|
# Allow us to associate a node to a drive : sda -> WD-WMANS1648590 |
44
|
0
|
|
|
|
|
|
my $sn = getFirstMatch( |
45
|
|
|
|
|
|
|
logger => $logger, |
46
|
|
|
|
|
|
|
command => "tw_cli info $card->{id} $unit->{id} serial", |
47
|
|
|
|
|
|
|
pattern => qr/serial number\s=\s(\w+)/ |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
foreach my $port (_getPorts($card, $unit)) { |
51
|
|
|
|
|
|
|
# Finally, getting drives' values. |
52
|
0
|
|
|
|
|
|
my $storage = _getStorage($card, $port); |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ($OSNAME eq 'Linux') { |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
@devices = getDevicesFromUdev(logger => $logger) unless @devices; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
foreach my $device (@devices) { |
59
|
|
|
|
|
|
|
# How does this work with multiple older cards |
60
|
|
|
|
|
|
|
# where serial for units is not implemented ? |
61
|
|
|
|
|
|
|
# Need to be tested on a system with multiple |
62
|
|
|
|
|
|
|
# 3ware cards. |
63
|
0
|
0
|
0
|
|
|
|
if ( |
64
|
|
|
|
|
|
|
$device->{SERIALNUMBER} eq 'AMCC_' . $sn || |
65
|
|
|
|
|
|
|
$device->{MODEL} eq 'Logical_Disk_' . $unit->{index} |
66
|
|
|
|
|
|
|
) { |
67
|
0
|
|
|
|
|
|
$storage->{NAME} = $device->{NAME}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'STORAGES', entry => $storage); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _getCards { |
80
|
0
|
|
|
0
|
|
|
my ($file) = @_; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
83
|
|
|
|
|
|
|
file => $file, |
84
|
|
|
|
|
|
|
command => "tw_cli info" |
85
|
|
|
|
|
|
|
); |
86
|
0
|
0
|
|
|
|
|
return unless $handle; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my @cards; |
89
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
90
|
0
|
0
|
|
|
|
|
next unless $line =~ /^(c\d+)\s+([\w-]+)/; |
91
|
0
|
|
|
|
|
|
push @cards, { id => $1, model => $2 }; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
close $handle; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return @cards; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _getUnits { |
99
|
0
|
|
|
0
|
|
|
my ($card, $file) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
102
|
|
|
|
|
|
|
file => $file, |
103
|
|
|
|
|
|
|
command => "tw_cli info $card->{id}" |
104
|
|
|
|
|
|
|
); |
105
|
0
|
0
|
|
|
|
|
return unless $handle; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my @units; |
108
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
109
|
0
|
0
|
|
|
|
|
next unless $line =~ /^(u(\d+))/; |
110
|
0
|
|
|
|
|
|
push @units, { id => $1, index => $2 }; |
111
|
|
|
|
|
|
|
} |
112
|
0
|
|
|
|
|
|
close $handle; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return @units; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _getPorts { |
118
|
0
|
|
|
0
|
|
|
my ($card, $unit, $file) = @_; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
121
|
|
|
|
|
|
|
file => $file, |
122
|
|
|
|
|
|
|
command => "tw_cli info $card->{id} $unit->{id}" |
123
|
|
|
|
|
|
|
); |
124
|
0
|
0
|
|
|
|
|
return unless $handle; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my @ports; |
127
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
128
|
0
|
0
|
|
|
|
|
next unless $line =~ /(p\d+)/; |
129
|
0
|
|
|
|
|
|
push @ports, { id => $1 }; |
130
|
|
|
|
|
|
|
} |
131
|
0
|
|
|
|
|
|
close $handle; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return @ports; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _getStorage { |
137
|
0
|
|
|
0
|
|
|
my ($card, $port, $file) = @_; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $handle = getFileHandle( |
140
|
|
|
|
|
|
|
file => $file, |
141
|
|
|
|
|
|
|
command => |
142
|
|
|
|
|
|
|
"tw_cli info $card->{id} $port->{id} model serial capacity firmware" |
143
|
|
|
|
|
|
|
); |
144
|
0
|
0
|
|
|
|
|
return unless $handle; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $storage; |
147
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
148
|
0
|
0
|
|
|
|
|
if ($line =~ /Model\s=\s(.*)/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$storage->{MODEL} = $1; |
150
|
|
|
|
|
|
|
} elsif ($line =~ /Serial\s=\s(.*)/) { |
151
|
0
|
|
|
|
|
|
$storage->{SERIALNUMBER} = $1; |
152
|
|
|
|
|
|
|
} elsif ($line =~ /Capacity\s=\s(\S+)\sGB.*/) { |
153
|
0
|
|
|
|
|
|
$storage->{DISKSIZE} = 1024 * $1; |
154
|
|
|
|
|
|
|
} elsif ($line =~ /Firmware Version\s=\s(.*)/) { |
155
|
0
|
|
|
|
|
|
$storage->{FIRMWARE} = $1 |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
0
|
|
|
|
|
|
close $handle; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
$storage->{MANUFACTURER} = getCanonicalManufacturer( |
161
|
|
|
|
|
|
|
$storage->{MODEL} |
162
|
|
|
|
|
|
|
); |
163
|
0
|
|
|
|
|
|
$storage->{TYPE} = 'disk'; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# Getting description from card model, very basic |
166
|
|
|
|
|
|
|
# and unreliable |
167
|
|
|
|
|
|
|
# Assuming only IDE drives can be plugged in |
168
|
|
|
|
|
|
|
# 5xxx/6xxx cards and |
169
|
|
|
|
|
|
|
# SATA drives only to 7xxx/8xxx/9xxxx cards |
170
|
0
|
0
|
|
|
|
|
$storage->{DESCRIPTION} = |
|
|
0
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$card->{model} =~ /^[56]/ ? 'IDE' : |
172
|
|
|
|
|
|
|
$card->{model} =~ /^[789]/ ? 'SATA' : |
173
|
|
|
|
|
|
|
undef; |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
return $storage; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |