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
|
package FusionInventory::Agent::Task::Inventory::Win32::OS;
use strict;
use warnings;
use integer;
use English qw(-no_match_vars);
use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Hostname;
use FusionInventory::Agent::Tools::Win32;
sub isEnabled {
return 1;
}
sub doInventory {
my (%params) = @_;
my $inventory = $params{inventory};
my ($operatingSystem) = getWMIObjects(
class => 'Win32_OperatingSystem',
properties => [ qw/
OSLanguage Caption Version SerialNumber Organization RegisteredUser
CSDVersion TotalSwapSpaceSize LastBootUpTime
/ ]
);
my ($computerSystem) = getWMIObjects(
class => 'Win32_ComputerSystem',
properties => [ qw/
Name Domain Workgroup PrimaryOwnerName TotalPhysicalMemory
/ ]
);
my ($computerSystemProduct) = getWMIObjects(
class => 'Win32_ComputerSystemProduct',
properties => [ qw/UUID/ ]
);
my $key =
parseProductKey(getRegistryValue(path => 'HKEY_LOCAL_MACHINE/Software/Microsoft/Windows NT/CurrentVersion/DigitalProductId')) ||
parseProductKey(getRegistryValue(path => 'HKEY_LOCAL_MACHINE/Software/Microsoft/Windows NT/CurrentVersion/DigitalProductId4'));
my $description =
encodeFromRegistry(getRegistryValue(path => 'HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/lanmanserver/Parameters/srvcomment'));
my $arch = is64bit() ? '64-bit' : '32-bit';
my $swap = $operatingSystem->{TotalSwapSpaceSize} ?
int($operatingSystem->{TotalSwapSpaceSize} / (1024 * 1024)) : undef;
my $memory = $computerSystem->{TotalPhysicalMemory} ?
int($computerSystem->{TotalPhysicalMemory} / (1024 * 1024)) : undef;
my $uuid = $computerSystemProduct->{UUID} !~ /^[0-]+$/ ?
$computerSystemProduct->{UUID} : undef;
my $boottime;
if ($operatingSystem->{LastBootUpTime} =~
/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/) {
$boottime = getFormatedDate($1, $2, $3, $4, $5, $6);
}
# get the name through native Win32::API, as WMI DB is sometimes broken
my $name = FusionInventory::Agent::Tools::Hostname::getHostname() ||
$ENV{COMPUTERNAME};
$name =~ s/\..*$//; # use short host name
$inventory->setOperatingSystem({
NAME => "Windows",
ARCH => $arch,
INSTALL_DATE => _getInstallDate(),
BOOT_TIME => $boottime,
KERNEL_VERSION => $operatingSystem->{Version},
FULL_NAME => $operatingSystem->{Caption},
SERVICE_PACK => $operatingSystem->{CSDVersion},
});
$inventory->setHardware({
NAME => $name,
DESCRIPTION => $description,
UUID => $uuid,
WINPRODKEY => $key,
WINLANG => $operatingSystem->{OSLanguage},
OSNAME => $operatingSystem->{Caption},
OSVERSION => $operatingSystem->{Version},
WINPRODID => $operatingSystem->{SerialNumber},
WINCOMPANY => $operatingSystem->{Organization},
WINOWNER => $operatingSystem->{RegisteredUser} ||
$computerSystem->{PrimaryOwnerName},
OSCOMMENTS => $operatingSystem->{CSDVersion},
SWAP => $operatingSystem->{TotalSwapSpaceSize},
MEMORY => $computerSystem->{TotalPhysicalMemory},
WORKGROUP => $computerSystem->{Domain} ||
$computerSystem->{Workgroup},
});
}
sub _getInstallDate {
my $installDate = getRegistryValue(
path => 'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/InstallDate'
);
return unless $installDate;
my $dec = hex2dec($installDate);
return unless $dec;
return getFormatedLocalTime($dec);
}
1;
|