line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::MacOS::Storages; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
88525985
|
use strict; |
|
2
|
|
|
|
|
23
|
|
|
2
|
|
|
|
|
194
|
|
4
|
2
|
|
|
2
|
|
17
|
use warnings; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
129
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
852
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
405
|
|
7
|
2
|
|
|
2
|
|
1215
|
use FusionInventory::Agent::Tools::MacOS; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1594
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub isEnabled { |
10
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
11
|
0
|
0
|
|
|
|
0
|
return 0 if $params{no_category}->{storage}; |
12
|
0
|
|
|
|
|
0
|
return 1; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub doInventory { |
16
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
19
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
foreach my $storage (_getStorages(logger => $logger)) { |
22
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
23
|
|
|
|
|
|
|
section => 'STORAGES', |
24
|
|
|
|
|
|
|
entry => $storage |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _getStorages { |
30
|
5
|
|
|
5
|
|
1224
|
my (%params) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $infos = getSystemProfilerInfos( |
33
|
|
|
|
|
|
|
type => 'SPStorageDataType', |
34
|
|
|
|
|
|
|
logger => $params{logger}, |
35
|
|
|
|
|
|
|
file => $params{file} |
36
|
5
|
|
|
|
|
145
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# system profiler data structure: |
39
|
|
|
|
|
|
|
# bus |
40
|
|
|
|
|
|
|
# └── controller |
41
|
|
|
|
|
|
|
# ├── device |
42
|
|
|
|
|
|
|
# │ ├── subdevice |
43
|
|
|
|
|
|
|
# │ │ └── key:value |
44
|
|
|
|
|
|
|
# │ └── key:value |
45
|
|
|
|
|
|
|
# └── key:value |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
56
|
my @storages; |
48
|
5
|
|
|
|
|
19
|
my @busNames = ('ATA', 'SERIAL-ATA', 'USB', 'FireWire', 'Fibre Channel'); |
49
|
5
|
|
|
|
|
16
|
foreach my $busName (@busNames) { |
50
|
25
|
|
|
|
|
42
|
my $bus = $infos->{$busName}; |
51
|
25
|
100
|
|
|
|
62
|
next unless $bus; |
52
|
14
|
|
|
|
|
18
|
foreach my $controllerName (keys %{$bus}) { |
|
14
|
|
|
|
|
39
|
|
53
|
31
|
|
|
|
|
45
|
my $controller = $bus->{$controllerName}; |
54
|
31
|
|
|
|
|
34
|
foreach my $deviceName (keys %{$controller}) { |
|
31
|
|
|
|
|
89
|
|
55
|
181
|
|
|
|
|
291
|
my $device = $controller->{$deviceName}; |
56
|
181
|
100
|
|
|
|
409
|
next unless ref $device eq 'HASH'; |
57
|
23
|
100
|
|
|
|
48
|
if (_isStorage($device)) { |
58
|
6
|
|
|
|
|
17
|
push @storages, |
59
|
|
|
|
|
|
|
_getStorage($device, $deviceName, $busName); |
60
|
|
|
|
|
|
|
} else { |
61
|
17
|
|
|
|
|
22
|
foreach my $subdeviceName (keys %{$device}) { |
|
17
|
|
|
|
|
58
|
|
62
|
131
|
|
|
|
|
168
|
my $subdevice = $device->{$subdeviceName}; |
63
|
131
|
100
|
|
|
|
302
|
next unless ref $subdevice eq 'HASH'; |
64
|
7
|
100
|
|
|
|
21
|
push @storages, |
65
|
|
|
|
|
|
|
_getStorage($subdevice, $subdeviceName, $busName) |
66
|
|
|
|
|
|
|
if _isStorage($subdevice); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
5
|
|
|
|
|
23
|
return @storages; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _isStorage { |
78
|
30
|
|
|
30
|
|
36
|
my ($device) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return |
81
|
|
|
|
|
|
|
($device->{'BSD Name'} && $device->{'BSD Name'} =~ /^disk\d+$/) || |
82
|
30
|
|
66
|
|
|
195
|
($device->{'Protocol'} && $device->{'Socket Type'}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _getStorage { |
86
|
9
|
|
|
9
|
|
18
|
my ($device, $device_name, $bus_name) = @_; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $storage = { |
89
|
|
|
|
|
|
|
NAME => $device_name, |
90
|
|
|
|
|
|
|
MANUFACTURER => getCanonicalManufacturer($device_name), |
91
|
|
|
|
|
|
|
TYPE => $bus_name eq 'FireWire' ? '1394' : $bus_name, |
92
|
|
|
|
|
|
|
SERIAL => $device->{'Serial Number'}, |
93
|
|
|
|
|
|
|
FIRMWARE => $device->{'Revision'}, |
94
|
|
|
|
|
|
|
MODEL => $device->{'Model'}, |
95
|
9
|
50
|
|
|
|
37
|
DISKSIZE => $device->{'Capacity'} |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
9
|
100
|
33
|
|
|
36
|
if (!$device->{'Protocol'}) { |
|
|
50
|
|
|
|
|
|
99
|
5
|
|
|
|
|
15
|
$storage->{DESCRIPTION} = 'Disk drive'; |
100
|
|
|
|
|
|
|
} elsif ($device->{'Protocol'} eq 'ATAPI' || $device->{'Drive Type'}) { |
101
|
4
|
|
|
|
|
13
|
$storage->{DESCRIPTION} = 'CD-ROM Drive'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
9
|
100
|
|
|
|
21
|
if ($storage->{DISKSIZE}) { |
105
|
|
|
|
|
|
|
#e.g: Capacity: 320,07 GB (320 072 933 376 bytes) |
106
|
5
|
|
|
|
|
13
|
$storage->{DISKSIZE} =~ s/\s*\(.*//; |
107
|
5
|
|
|
|
|
15
|
$storage->{DISKSIZE} =~ s/,/./; |
108
|
|
|
|
|
|
|
|
109
|
5
|
100
|
|
|
|
33
|
if ($storage->{DISKSIZE} =~ s/\s*TB//) { |
|
|
50
|
|
|
|
|
|
110
|
2
|
|
|
|
|
11
|
$storage->{DISKSIZE} = int($storage->{DISKSIZE} * 1000 * 1000); |
111
|
|
|
|
|
|
|
} elsif ($storage->{DISKSIZE} =~ s/\s+GB$//) { |
112
|
3
|
|
|
|
|
15
|
$storage->{DISKSIZE} = int($storage->{DISKSIZE} * 1000 * 1000); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
9
|
100
|
|
|
|
22
|
if ($storage->{MODEL}) { |
117
|
6
|
|
|
|
|
160
|
$storage->{MODEL} =~ s/\s*$storage->{MANUFACTURER}\s*//i; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
9
|
|
|
|
|
41
|
return $storage; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |