/usr/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Win32/Storages.pm is in fusioninventory-agent 1:2.3.10.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | package FusionInventory::Agent::Task::Inventory::Win32::Storages;
use strict;
use warnings;
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Win32;
sub isEnabled {
return canRun('hdparm');
}
sub doInventory {
my (%params) = @_;
my $inventory = $params{inventory};
foreach my $object (getWMIObjects(
class => 'Win32_DiskDrive',
properties => [ qw/
Name Manufacturer Model MediaType InterfaceType FirmwareRevision
SerialNumber Size SCSIPort SCSILogicalUnit SCSITargetId
/ ]
)) {
my $info = {};
if ($object->{Name} =~ /(\d+)$/) {
$info = _getInfo("hd", $1);
}
$object->{Size} = int($object->{Size} / (1024 * 1024))
if $object->{Size};
$inventory->addEntry(
section => 'STORAGES',
entry => {
MANUFACTURER => $object->{Manufacturer},
MODEL => $info->{model} || $object->{Model},
DESCRIPTION => $object->{Description},
NAME => $object->{Name},
TYPE => $object->{MediaType},
INTERFACE => $object->{InterfaceType},
FIRMWARE => $info->{firmware} || $object->{FirmwareRevision},
SERIAL => $info->{serial} || $object->{SerialNumber},
DISKSIZE => $info->{size} || $object->{Size},
SCSI_COID => $object->{SCSIPort},
SCSI_LUN => $object->{SCSILogicalUnit},
SCSI_UNID => $object->{SCSITargetId},
}
);
}
foreach my $object (getWMIObjects(
class => 'Win32_CDROMDrive',
properties => [ qw/
Manufacturer Caption Description Name MediaType InterfaceType
FirmwareRevision SerialNumber Size SCSIPort
SCSILogicalUnit SCSITargetId
/ ]
)) {
my $info = {};
if ($object->{Name} =~ /(\d+)$/) {
$info = _getInfo("cdrom", $1);
}
$object->{Size} = int($object->{Size} / (1024 * 1024))
if $object->{Size};
$inventory->addEntry(
section => 'STORAGES',
entry => {
MANUFACTURER => $object->{Manufacturer},
MODEL => $info->{model} || $object->{Caption},
DESCRIPTION => $object->{Description},
NAME => $object->{Name},
TYPE => $object->{MediaType},
INTERFACE => $object->{InterfaceType},
FIRMWARE => $info->{firmware} || $object->{FirmwareRevision},
SERIAL => $info->{serial} || $object->{SerialNumber},
DISKSIZE => $info->{size} || $object->{Size},
SCSI_COID => $object->{SCSIPort},
SCSI_LUN => $object->{SCSILogicalUnit},
SCSI_UNID => $object->{SCSITargetId},
}
);
}
foreach my $object (getWMIObjects(
class => 'Win32_TapeDrive',
properties => [ qw/
Manufacturer Caption Description Name MediaType InterfaceType
FirmwareRevision SerialNumber Size SCSIPort
SCSILogicalUnit SCSITargetId
/ ]
)) {
$object->{Size} = int($object->{Size} / (1024 * 1024))
if $object->{Size};
$inventory->addEntry(
section => 'STORAGES',
entry => {
MANUFACTURER => $object->{Manufacturer},
MODEL => $object->{Caption},
DESCRIPTION => $object->{Description},
NAME => $object->{Name},
TYPE => $object->{MediaType},
INTERFACE => $object->{InterfaceType},
FIRMWARE => $object->{FirmwareRevision},
SERIAL => $object->{SerialNumber},
DISKSIZE => $object->{Size},
SCSI_COID => $object->{SCSIPort},
SCSI_LUN => $object->{SCSILogicalUnit},
SCSI_UNID => $object->{SCSITargetId},
}
);
}
}
sub _getInfo {
my ($type, $nbr) = @_;
my $device = "/dev/";
$device .= $type eq 'hd'?'hd':'scd';
$device .= chr(ord('a')+$nbr);
my $handle = getFileHandle(
command => "hdparm -I $device",
);
return unless $handle;
my $info;
while (my $line = <$handle>) {
$info->{model} = $1 if $line =~ /Model Number:\s+(.*?)\s*$/;
$info->{firmware} = $1 if $line =~ /Firmware Revision:\s+(\S*)/;
$info->{serial} = $1 if $line =~ /Serial Number:\s+(\S*)/;
$info->{size} = $1 if $line =~ /1000:\s+(\d*)\sMBytes\s\(/;
}
close $handle;
return $info;
}
1;
|