line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Linux::Storages; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
46166717
|
use strict; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
134
|
|
4
|
4
|
|
|
4
|
|
26
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
180
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
26
|
use English qw(-no_match_vars); |
|
4
|
|
|
|
|
84
|
|
|
4
|
|
|
|
|
41
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
3138
|
use FusionInventory::Agent::Tools; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
846
|
|
9
|
4
|
|
|
4
|
|
2565
|
use FusionInventory::Agent::Tools::Generic; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
406
|
|
10
|
4
|
|
|
4
|
|
2525
|
use FusionInventory::Agent::Tools::Linux; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
435
|
|
11
|
4
|
|
|
4
|
|
28
|
use FusionInventory::Agent::Tools::Unix; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
3774
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub isEnabled { |
14
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
15
|
0
|
0
|
|
|
|
|
return 0 if $params{no_category}->{storage}; |
16
|
0
|
|
|
|
|
|
return 1; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub doInventory { |
20
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
23
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
foreach my $device (_getDevices(logger => $logger)) { |
26
|
0
|
|
|
|
|
|
$inventory->addEntry(section => 'STORAGES', entry => $device); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _getDevices { |
31
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my @devices = _getDevicesBase(logger => $logger); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# complete with udev for missing bits, if available |
38
|
0
|
0
|
|
|
|
|
if (-d '/dev/.udev/db/') { |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my %udev_devices = map { $_->{NAME} => $_ } |
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
getDevicesFromUdev(logger => $logger); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
foreach my $device (@devices) { |
44
|
|
|
|
|
|
|
# find corresponding udev entry |
45
|
0
|
|
|
|
|
|
my $udev_device = $udev_devices{$device->{NAME}}; |
46
|
0
|
0
|
|
|
|
|
next unless $udev_device; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
foreach my $key (keys %$udev_device) { |
49
|
0
|
0
|
|
|
|
|
next if $device->{$key}; |
50
|
0
|
|
|
|
|
|
$device->{$key} = $udev_device->{$key}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# get serial & firmware numbers from hdparm, if available |
56
|
0
|
0
|
|
|
|
|
if (_correctHdparmAvailable()) { |
57
|
0
|
|
|
|
|
|
foreach my $device (@devices) { |
58
|
0
|
0
|
0
|
|
|
|
next if $device->{SERIALNUMBER} && $device->{FIRMWARE}; |
59
|
|
|
|
|
|
|
my $info = getHdparmInfo( |
60
|
|
|
|
|
|
|
device => "/dev/" . $device->{NAME}, |
61
|
0
|
|
|
|
|
|
logger => $logger |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$device->{SERIALNUMBER} = $info->{serial} |
65
|
0
|
0
|
0
|
|
|
|
if $info->{serial} && !$device->{SERIALNUMBER}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$device->{FIRMWARE} = $info->{firmware} |
68
|
0
|
0
|
0
|
|
|
|
if $info->{firmware} && !$device->{FIRMWARE}; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
$device->{DESCRIPTION} = $info->{transport} if $info->{transport}; |
71
|
0
|
0
|
|
|
|
|
$device->{MODEL} = $info->{model} if $info->{model}; |
72
|
0
|
0
|
|
|
|
|
$device->{WWN} = $info->{wwn} if $info->{wwn}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
foreach my $device (@devices) { |
77
|
0
|
0
|
|
|
|
|
if (!$device->{DESCRIPTION}) { |
78
|
|
|
|
|
|
|
$device->{DESCRIPTION} = _getDescription( |
79
|
|
|
|
|
|
|
$device->{NAME}, |
80
|
|
|
|
|
|
|
$device->{MANUFACTURER}, |
81
|
|
|
|
|
|
|
$device->{DESCRIPTION}, |
82
|
|
|
|
|
|
|
$device->{SERIALNUMBER} |
83
|
0
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
0
|
|
|
|
if (!$device->{MANUFACTURER} or $device->{MANUFACTURER} eq 'ATA') { |
87
|
|
|
|
|
|
|
$device->{MANUFACTURER} = getCanonicalManufacturer( |
88
|
|
|
|
|
|
|
$device->{MODEL} |
89
|
0
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
0
|
|
|
|
if (!$device->{DISKSIZE} && $device->{TYPE} !~ /^cd/) { |
93
|
0
|
|
|
|
|
|
$device->{DISKSIZE} = getDeviceCapacity(device => '/dev/' . $device->{NAME}); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
return @devices; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _getDevicesBase { |
101
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
104
|
0
|
|
|
|
|
|
$logger->debug("retrieving devices list:"); |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
if (-d '/sys/block') { |
107
|
0
|
|
|
|
|
|
my @devices = getDevicesFromProc(logger => $logger); |
108
|
0
|
|
|
|
|
|
$logger->debug_result( |
109
|
|
|
|
|
|
|
action => 'reading /sys/block content', |
110
|
|
|
|
|
|
|
data => scalar @devices |
111
|
|
|
|
|
|
|
); |
112
|
0
|
0
|
|
|
|
|
return @devices if @devices; |
113
|
|
|
|
|
|
|
} else { |
114
|
0
|
|
|
|
|
|
$logger->debug_result( |
115
|
|
|
|
|
|
|
action => 'reading /sys/block content', |
116
|
|
|
|
|
|
|
status => 'directory not available' |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
if (canRun('/usr/bin/lshal')) { |
121
|
0
|
|
|
|
|
|
my @devices = getDevicesFromHal(logger => $logger); |
122
|
0
|
|
|
|
|
|
$logger->debug_result( |
123
|
|
|
|
|
|
|
action => 'running lshal command', |
124
|
|
|
|
|
|
|
data => scalar @devices |
125
|
|
|
|
|
|
|
); |
126
|
0
|
0
|
|
|
|
|
return @devices if @devices; |
127
|
|
|
|
|
|
|
} else { |
128
|
0
|
|
|
|
|
|
$logger->debug_result( |
129
|
|
|
|
|
|
|
action => 'running lshal command', |
130
|
|
|
|
|
|
|
status => 'command not available' |
131
|
|
|
|
|
|
|
); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
return; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _getDescription { |
138
|
0
|
|
|
0
|
|
|
my ($name, $manufacturer, $description, $serialnumber) = @_; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# detected as USB by udev |
141
|
|
|
|
|
|
|
# TODO maybe we should trust udev detection by default? |
142
|
0
|
0
|
0
|
|
|
|
return "USB" if ($description && $description =~ /usb/i); |
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
if ($name =~ /^s/) { # /dev/sd* are SCSI _OR_ SATA |
|
|
0
|
|
|
|
|
|
145
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
146
|
|
|
|
|
|
|
($manufacturer && $manufacturer =~ /ATA/) || |
147
|
|
|
|
|
|
|
($serialnumber && $serialnumber =~ /ATA/) || |
148
|
|
|
|
|
|
|
($description && $description =~ /ATA/) |
149
|
|
|
|
|
|
|
) { |
150
|
0
|
|
|
|
|
|
return "SATA"; |
151
|
|
|
|
|
|
|
} else { |
152
|
0
|
|
|
|
|
|
return "SCSI"; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} elsif ($name =~ /^vd/) { |
155
|
0
|
|
|
|
|
|
return "Virtual"; |
156
|
|
|
|
|
|
|
} else { |
157
|
0
|
|
|
|
|
|
return "IDE"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# some hdparm release generated kernel error if they are |
162
|
|
|
|
|
|
|
# run on CDROM device |
163
|
|
|
|
|
|
|
# http://forums.ocsinventory-ng.org/viewtopic.php?pid=20810 |
164
|
|
|
|
|
|
|
sub _correctHdparmAvailable { |
165
|
0
|
0
|
|
0
|
|
|
return unless canRun('hdparm'); |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my ($major, $minor) = getFirstMatch( |
168
|
|
|
|
|
|
|
command => 'hdparm -V', |
169
|
|
|
|
|
|
|
pattern => qr/^hdparm v(\d+)\.(\d+)/ |
170
|
|
|
|
|
|
|
); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# we need at least version 9.15 |
173
|
0
|
|
|
|
|
|
return compareVersion($major, $minor, 9, 15); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |