Skip to content

Commit e1740b4

Browse files
committed
fix: Add support for Trellix/McAfee agent as Antivirus on windows
1 parent c887d36 commit e1740b4

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ inventory:
3535
* Fix --partial option when used with glpi-agent script
3636
* Update getProcesses() API to permit filtering and report processes only in the same
3737
namespace to not list containers processes. Refacto inventory module using this API.
38+
* Add support for Trellix/McAfee agent as Antivirus on windows
3839

3940
remoteinventory:
4041
* Store remote inventory part checksums in dedicated state files and support maintenance

lib/GLPI/Agent/Task/Inventory/Win32/AntiVirus.pm

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use warnings;
66
use parent 'GLPI::Agent::Task::Inventory::Module';
77

88
use UNIVERSAL::require;
9+
use File::Spec;
10+
use File::Basename qw(dirname);
911

1012
use GLPI::Agent::Tools;
1113
use GLPI::Agent::Tools::Win32;
@@ -160,14 +162,26 @@ sub doInventory {
160162
# Cortex XDR support
161163
name => "Cortex XDR",
162164
service => "cyserver",
163-
command => "C:\\Program Files\\Palo Alto Networks\\Traps\\cytool.exe",
165+
path => "C:\\Program Files\\Palo Alto Networks\\Traps",
166+
command => "cytool.exe",
164167
func => \&_setCortexInfos,
165168
}, {
166169
# BitDefender support
167170
name => "Bitdefender Endpoint Security",
168171
service => "EPSecurityService",
169-
command => "C:\\Program Files\\Bitdefender\\Endpoint Security\\product.console.exe",
172+
path => "C:\\Program Files\\Bitdefender\\Endpoint Security",
173+
command => "product.console.exe",
170174
func => \&_setBitdefenderInfos,
175+
}, {
176+
# Trellix/McAfee support
177+
name => "Trellix",
178+
service => "masvc",
179+
path => [
180+
"C:\\Program Files\\McAfee\\Agent",
181+
"C:\\Program Files (x86)\\McAfee\\Commmon Framework",
182+
],
183+
command => "CmdAgent.exe",
184+
func => \&_setMcAfeeInfos,
171185
}) {
172186
my $antivirus;
173187
my $service = $services->{$support->{service}}
@@ -176,8 +190,26 @@ sub doInventory {
176190
$antivirus->{NAME} = $support->{name} || $service->{NAME};
177191
$antivirus->{ENABLED} = $service->{STATUS} =~ /running/i ? 1 : 0;
178192

179-
if (my $cmd = $support->{command}) {
180-
&{$support->{func}}($antivirus, $logger, $cmd) if canRun($cmd);
193+
if ($support->{command}) {
194+
my @path;
195+
if ($service->{PATHNAME}) {
196+
# First use pathname extracted from service PATHNAME
197+
my ($path) = $service->{PATHNAME} =~ /^"/ ?
198+
$service->{PATHNAME} =~ /^"([^"]+)\"/ :
199+
$service->{PATHNAME} =~ /^(\S+)/ ;
200+
push @path, $path if $path;
201+
}
202+
push @path, ref($support->{path}) ? @{$support->{path}} : $support->{path}
203+
if $support->{path};
204+
my %tried;
205+
foreach my $path (@path) {
206+
next if $tried{$path};
207+
$tried{$path} = 1;
208+
my $cmd = File::Spec->catfile($path, $support->{command});
209+
next unless canRun($cmd);
210+
&{$support->{func}}($antivirus, $logger, $cmd);
211+
last;
212+
}
181213
}
182214

183215
# avoid duplicates
@@ -219,7 +251,17 @@ sub _getAntivirusUninstall {
219251
}
220252

221253
sub _setMcAfeeInfos {
222-
my ($antivirus) = @_;
254+
my ($antivirus, $logger, $command) = @_;
255+
256+
if ($command) {
257+
my $version = getFirstMatch(
258+
command => "\"$command\" /i",
259+
pattern => qr/^Version: (.*)$/,
260+
logger => $logger
261+
);
262+
$antivirus->{VERSION} = $version if $version;
263+
$antivirus->{COMPANY} = "Trellix" unless $antivirus->{COMPANY};
264+
}
223265

224266
my %properties = (
225267
BASE_VERSION => [ qw(AVDatVersion AVDatVersionMinor) ],

lib/GLPI/Agent/Tools/Win32.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ sub getServices {
707707
foreach my $object (getWMIObjects(
708708
class => 'Win32_Service',
709709
properties => [ qw/
710-
Name DisplayName Description State
710+
Name DisplayName Description State PathName
711711
/
712712
],
713713
%params
@@ -718,6 +718,7 @@ sub getServices {
718718
NAME => $object->{DisplayName},
719719
DESCRIPTION => $object->{Description} // "",
720720
STATUS => $object->{State} // "n/a",
721+
PATHNAME => $object->{PathName} // "",
721722
};
722723
}
723724

0 commit comments

Comments
 (0)