File Coverage

blib/lib/FusionInventory/Agent/Task/Inventory/Win32/OS.pm
Criterion Covered Total %
statement 24 47 51.0
branch 0 14 0.0
condition 0 9 0.0
subroutine 8 11 72.7
pod 0 2 0.0
total 32 83 38.5


line stmt bran cond sub pod time code
1             package FusionInventory::Agent::Task::Inventory::Win32::OS;
2              
3 1     1   62994567 use strict;
  1         5  
  1         110  
4 1     1   19 use warnings;
  1         11  
  1         131  
5 1     1   1612 use integer;
  1         125  
  1         12  
6              
7 1     1   80 use English qw(-no_match_vars);
  1         13  
  1         45  
8              
9 1     1   2736 use FusionInventory::Agent::Tools;
  1         2  
  1         216  
10 1     1   602 use FusionInventory::Agent::Tools::Hostname;
  1         2  
  1         56  
11 1     1   681 use FusionInventory::Agent::Tools::License;
  1         3  
  1         71  
12 1     1   648 use FusionInventory::Agent::Tools::Win32;
  1         4  
  1         636  
13              
14             sub isEnabled {
15 0     0 0   return 1;
16             }
17              
18             sub doInventory {
19 0     0 0   my (%params) = @_;
20              
21 0           my $inventory = $params{inventory};
22              
23 0           my ($operatingSystem) = getWMIObjects(
24             class => 'Win32_OperatingSystem',
25             properties => [ qw/
26             OSLanguage Caption Version SerialNumber Organization RegisteredUser
27             CSDVersion TotalSwapSpaceSize LastBootUpTime
28             / ]
29             );
30              
31 0           my ($computerSystem) = getWMIObjects(
32             class => 'Win32_ComputerSystem',
33             properties => [ qw/
34             Name Domain Workgroup PrimaryOwnerName TotalPhysicalMemory
35             / ]
36             );
37              
38 0           my ($computerSystemProduct) = getWMIObjects(
39             class => 'Win32_ComputerSystemProduct',
40             properties => [ qw/UUID/ ]
41             );
42              
43 0   0       my $key =
44             decodeMicrosoftKey(getRegistryValue(path => 'HKEY_LOCAL_MACHINE/Software/Microsoft/Windows NT/CurrentVersion/DigitalProductId')) ||
45             decodeMicrosoftKey(getRegistryValue(path => 'HKEY_LOCAL_MACHINE/Software/Microsoft/Windows NT/CurrentVersion/DigitalProductId4'));
46              
47 0           my $description =
48             encodeFromRegistry(getRegistryValue(path => 'HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/lanmanserver/Parameters/srvcomment'));
49              
50 0 0         my $arch = is64bit() ? '64-bit' : '32-bit';
51              
52             my $swap = $operatingSystem->{TotalSwapSpaceSize} ?
53 0 0         int($operatingSystem->{TotalSwapSpaceSize} / (1024 * 1024)) : undef;
54              
55             my $memory = $computerSystem->{TotalPhysicalMemory} ?
56 0 0         int($computerSystem->{TotalPhysicalMemory} / (1024 * 1024)) : undef;
57              
58             my $uuid = $computerSystemProduct->{UUID} !~ /^[0-]+$/ ?
59 0 0         $computerSystemProduct->{UUID} : undef;
60              
61 0           my $boottime;
62 0 0         if ($operatingSystem->{LastBootUpTime} =~
63             /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/) {
64 0           $boottime = getFormatedDate($1, $2, $3, $4, $5, $6);
65             }
66              
67             # get the name through native Win32::API, as WMI DB is sometimes broken
68 0           my $hostname = getHostname(short => 1);
69              
70             $inventory->setOperatingSystem({
71             NAME => "Windows",
72             ARCH => $arch,
73             INSTALL_DATE => _getInstallDate(),
74             BOOT_TIME => $boottime,
75             KERNEL_VERSION => $operatingSystem->{Version},
76             FULL_NAME => $operatingSystem->{Caption},
77             SERVICE_PACK => $operatingSystem->{CSDVersion},
78 0           });
79              
80             $inventory->setHardware({
81             NAME => $hostname,
82             DESCRIPTION => $description,
83             UUID => $uuid,
84             WINPRODKEY => $key,
85             WINLANG => $operatingSystem->{OSLanguage},
86             OSNAME => $operatingSystem->{Caption},
87             OSVERSION => $operatingSystem->{Version},
88             WINPRODID => $operatingSystem->{SerialNumber},
89             WINCOMPANY => $operatingSystem->{Organization},
90             WINOWNER => $operatingSystem->{RegisteredUser} ||
91             $computerSystem->{PrimaryOwnerName},
92             OSCOMMENTS => $operatingSystem->{CSDVersion},
93             SWAP => $swap,
94             MEMORY => $memory,
95             WORKGROUP => $computerSystem->{Domain} ||
96             $computerSystem->{Workgroup},
97 0   0       });
      0        
98             }
99              
100             sub _getInstallDate {
101 0     0     my $installDate = getRegistryValue(
102             path => 'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/InstallDate'
103             );
104 0 0         return unless $installDate;
105              
106 0           my $dec = hex2dec($installDate);
107 0 0         return unless $dec;
108              
109 0           return getFormatedLocalTime($dec);
110             }
111              
112             1;