/
Drives.pm
98 lines (74 loc) · 2.2 KB
/
Drives.pm
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
package FusionInventory::Agent::Task::Inventory::Input::Solaris::Drives;
use strict;
use warnings;
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Unix;
sub isEnabled {
return canRun('df');
}
sub _getDfCmd {
my $line = getFirstLine(
command => "df --version"
);
# df --help is on STDERR on some system
# so $line is undef
return ($line && $line =~ /GNU/) ?
"df -P -k" :
"df -k";
}
sub _getFsTypeFromMount {
my %mountInfo;
my $handle = getFileHandle(
command => 'mount -v',
@_
);
while (my $line = <$handle>) {
next unless $line =~ /^(\S+)\son\s\S+\stype\s(\S+)/;
$mountInfo{$1} = $2;
}
return %mountInfo;
}
sub doInventory {
my (%params) = @_;
my $inventory = $params{inventory};
my $logger = $params{logger};
# get filesystems list
my @filesystems =
# exclude solaris 10 specific devices
grep { $_->{VOLUMN} !~ /^\/(devices|platform)/ }
# keep physical devices or swap
grep { $_->{VOLUMN} =~ /^(\/|swap)/ }
# exclude cdrom mount
grep { $_->{TYPE} !~ /cdrom/ }
# get all file systems
getFilesystemsFromDf(logger => $logger, command => _getDfCmd());
my %fsTypeFromMount = _getFsTypeFromMount();
# get additional informations
foreach my $filesystem (@filesystems) {
if ($filesystem->{VOLUMN} eq 'swap') {
$filesystem->{FILESYSTEM} = 'swap';
next;
}
my $line = getFirstLine(
command => "zfs get creation $filesystem->{VOLUMN}"
);
if ($line && $line =~ /creation\s+(\S.*\S+)\s-/) {
$filesystem->{FILESYSTEM} = 'zfs';
next;
}
if ($fsTypeFromMount{$filesystem->{VOLUMN}}) {
$filesystem->{FILESYSTEM} = $fsTypeFromMount{$filesystem->{VOLUMN}};
next;
}
$filesystem->{FILESYSTEM} =
getFirstLine(command => "fstyp $filesystem->{VOLUMN}");
}
# add filesystems to the inventory
foreach my $filesystem (@filesystems) {
$inventory->addEntry(
section => 'DRIVES',
entry => $filesystem
);
}
}
1;