File Coverage

blib/lib/FusionInventory/Agent/Task/Inventory/Win32/AntiVirus.pm
Criterion Covered Total %
statement 9 26 34.6
branch 0 12 0.0
condition 0 5 0.0
subroutine 3 5 60.0
pod 0 2 0.0
total 12 50 24.0


line stmt bran cond sub pod time code
1             package FusionInventory::Agent::Task::Inventory::Win32::AntiVirus;
2              
3 1     1   52008341 use strict;
  1         8  
  1         73  
4 1     1   9 use warnings;
  1         1  
  1         63  
5              
6 1     1   518 use FusionInventory::Agent::Tools::Win32;
  1         3  
  1         353  
7              
8             my $seen;
9              
10             sub isEnabled {
11 0     0 0   my (%params) = @_;
12 0 0         return 0 if $params{no_category}->{antivirus};
13 0           return 1;
14             }
15              
16             sub doInventory {
17 0     0 0   my (%params) = @_;
18              
19 0           my $inventory = $params{inventory};
20              
21             # Doesn't works on Win2003 Server
22             # On Win7, we need to use SecurityCenter2
23 0           foreach my $instance (qw/SecurityCenter SecurityCenter2/) {
24 0           my $moniker = "winmgmts:{impersonationLevel=impersonate,(security)}!//./root/$instance";
25              
26 0           foreach my $object (getWMIObjects(
27             moniker => $moniker,
28             class => "AntiVirusProduct",
29             properties => [ qw/
30             companyName displayName instanceGuid onAccessScanningEnabled
31             productUptoDate versionNumber productState
32             / ]
33             )) {
34 0 0         next unless $object;
35              
36 0           my $antivirus = {
37             COMPANY => $object->{companyName},
38             NAME => $object->{displayName},
39             GUID => $object->{instanceGuid},
40             VERSION => $object->{versionNumber},
41             ENABLED => $object->{onAccessScanningEnabled},
42             UPTODATE => $object->{productUptoDate}
43             };
44              
45 0 0         if ($object->{productState}) {
46 0           my $bin = sprintf( "%b\n", $object->{productState});
47             # http://blogs.msdn.com/b/alejacma/archive/2008/05/12/how-to-get-antivirus-information-with-wmi-vbscript.aspx?PageIndex=2#comments
48 0 0         if ($bin =~ /(\d)\d{5}(\d)\d{6}(\d)\d{5}$/) {
49 0   0       $antivirus->{UPTODATE} = $1 || $2;
50 0 0         $antivirus->{ENABLED} = $3 ? 0 : 1;
51             }
52             }
53              
54             # avoid duplicates
55 0 0 0       next if $seen->{$antivirus->{NAME}}->{$antivirus->{VERSION}||'_undef_'}++;
56              
57 0           $inventory->addEntry(
58             section => 'ANTIVIRUS',
59             entry => $antivirus
60             );
61             }
62             }
63             }
64              
65             1;