line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::MacOS::Storages; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
71403713
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
87
|
|
4
|
2
|
|
|
2
|
|
22
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
105
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
590
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
249
|
|
7
|
2
|
|
|
2
|
|
695
|
use FusionInventory::Agent::Tools::MacOS; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1006
|
|
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
|
|
767
|
my (%params) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $infos = getSystemProfilerInfos( |
33
|
|
|
|
|
|
|
type => 'SPStorageDataType', |
34
|
|
|
|
|
|
|
logger => $params{logger}, |
35
|
|
|
|
|
|
|
file => $params{file} |
36
|
5
|
|
|
|
|
111
|
); |
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
|
|
|
|
|
43
|
my @storages; |
48
|
5
|
|
|
|
|
14
|
my @busNames = ('ATA', 'SERIAL-ATA', 'USB', 'FireWire', 'Fibre Channel'); |
49
|
5
|
|
|
|
|
9
|
foreach my $busName (@busNames) { |
50
|
25
|
|
|
|
|
21
|
my $bus = $infos->{$busName}; |
51
|
25
|
100
|
|
|
|
38
|
next unless $bus; |
52
|
14
|
|
|
|
|
11
|
foreach my $controllerName (keys %{$bus}) { |
|
14
|
|
|
|
|
24
|
|
53
|
31
|
|
|
|
|
24
|
my $controller = $bus->{$controllerName}; |
54
|
31
|
|
|
|
|
21
|
foreach my $deviceName (keys %{$controller}) { |
|
31
|
|
|
|
|
46
|
|
55
|
181
|
|
|
|
|
132
|
my $device = $controller->{$deviceName}; |
56
|
181
|
100
|
|
|
|
236
|
next unless ref $device eq 'HASH'; |
57
|
23
|
100
|
|
|
|
27
|
if (_isStorage($device)) { |
58
|
6
|
|
|
|
|
10
|
push @storages, |
59
|
|
|
|
|
|
|
_getStorage($device, $deviceName, $busName); |
60
|
|
|
|
|
|
|
} else { |
61
|
17
|
|
|
|
|
10
|
foreach my $subdeviceName (keys %{$device}) { |
|
17
|
|
|
|
|
39
|
|
62
|
131
|
|
|
|
|
92
|
my $subdevice = $device->{$subdeviceName}; |
63
|
131
|
100
|
|
|
|
175
|
next unless ref $subdevice eq 'HASH'; |
64
|
7
|
100
|
|
|
|
10
|
push @storages, |
65
|
|
|
|
|
|
|
_getStorage($subdevice, $subdeviceName, $busName) |
66
|
|
|
|
|
|
|
if _isStorage($subdevice); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
5
|
|
|
|
|
21
|
return @storages; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _isStorage { |
78
|
30
|
|
|
30
|
|
21
|
my ($device) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return |
81
|
|
|
|
|
|
|
($device->{'BSD Name'} && $device->{'BSD Name'} =~ /^disk\d+$/) || |
82
|
30
|
|
66
|
|
|
146
|
($device->{'Protocol'} && $device->{'Socket Type'}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _getStorage { |
86
|
9
|
|
|
9
|
|
10
|
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
|
|
|
|
30
|
DISKSIZE => $device->{'Capacity'} |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
9
|
100
|
33
|
|
|
22
|
if (!$device->{'Protocol'}) { |
|
|
50
|
|
|
|
|
|
99
|
5
|
|
|
|
|
8
|
$storage->{DESCRIPTION} = 'Disk drive'; |
100
|
|
|
|
|
|
|
} elsif ($device->{'Protocol'} eq 'ATAPI' || $device->{'Drive Type'}) { |
101
|
4
|
|
|
|
|
6
|
$storage->{DESCRIPTION} = 'CD-ROM Drive'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
9
|
100
|
|
|
|
16
|
if ($storage->{DISKSIZE}) { |
105
|
|
|
|
|
|
|
#e.g: Capacity: 320,07 GB (320 072 933 376 bytes) |
106
|
5
|
|
|
|
|
8
|
$storage->{DISKSIZE} =~ s/\s*\(.*//; |
107
|
5
|
|
|
|
|
9
|
$storage->{DISKSIZE} =~ s/,/./; |
108
|
|
|
|
|
|
|
|
109
|
5
|
100
|
|
|
|
23
|
if ($storage->{DISKSIZE} =~ s/\s*TB//) { |
|
|
50
|
|
|
|
|
|
110
|
2
|
|
|
|
|
7
|
$storage->{DISKSIZE} = int($storage->{DISKSIZE} * 1000 * 1000); |
111
|
|
|
|
|
|
|
} elsif ($storage->{DISKSIZE} =~ s/\s+GB$//) { |
112
|
3
|
|
|
|
|
10
|
$storage->{DISKSIZE} = int($storage->{DISKSIZE} * 1000 * 1000); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
9
|
100
|
|
|
|
14
|
if ($storage->{MODEL}) { |
117
|
6
|
|
|
|
|
117
|
$storage->{MODEL} =~ s/\s*$storage->{MANUFACTURER}\s*//i; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
9
|
|
|
|
|
45
|
return $storage; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |