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
|
package FusionInventory::Agent::Task::Inventory::Win32::Drives;
use strict;
use warnings;
use FusionInventory::Agent::Tools::Win32;
my @type = (
'Unknown',
'No Root Directory',
'Removable Disk',
'Local Disk',
'Network Drive',
'Compact Disc',
'RAM Disk'
);
sub isEnabled {
return 1;
}
sub doInventory {
my (%params) = @_;
my $inventory = $params{inventory};
foreach my $drive (_getDrives(
logger => $params{logger},
)) {
$inventory->addEntry(
section => 'DRIVES',
entry => $drive
);
}
}
sub _getDrives {
my (%params) = @_;
my $systemDrive;
foreach my $object (getWMIObjects(
class => 'Win32_OperatingSystem',
properties => [ qw/SystemDrive/ ]
)) {
$systemDrive = lc($object->{SystemDrive});
}
my @drives;
foreach my $object (getWMIObjects(
class => 'Win32_LogicalDisk',
properties => [ qw/
InstallDate Description FreeSpace FileSystem VolumeName Caption
VolumeSerialNumber DeviceID Size DriveType VolumeName ProviderName
/ ]
)) {
$object->{FreeSpace} = int($object->{FreeSpace} / (1024 * 1024))
if $object->{FreeSpace};
$object->{Size} = int($object->{Size} / (1024 * 1024))
if $object->{Size};
my $filesystem = $object->{FileSystem};
if ($object->{DriveType} == 4 && $object->{ProviderName}) {
if ($object->{ProviderName} =~ /\\DavWWWRoot\\/) {
$filesystem = "WebDav";
} elsif ($object->{ProviderName} =~ /^\\\\vmware-host\\/) {
$filesystem = "HGFS";
} elsif (!$object->{FileSystem} || $object->{FileSystem} ne 'NFS') {
$filesystem = "CIFS";
}
}
push @drives, {
CREATEDATE => $object->{InstallDate},
DESCRIPTION => $object->{Description},
FREE => $object->{FreeSpace},
FILESYSTEM => $filesystem,
LABEL => $object->{VolumeName},
LETTER => $object->{DeviceID} || $object->{Caption},
SERIAL => $object->{VolumeSerialNumber},
SYSTEMDRIVE => (lc($object->{DeviceID}) eq $systemDrive),
TOTAL => $object->{Size},
TYPE => $type[$object->{DriveType}],
VOLUMN => $object->{VolumeName},
};
}
return @drives;
}
1;
|