/usr/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Virtualization/Parallels.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 | package FusionInventory::Agent::Task::Inventory::Virtualization::Parallels;
use strict;
use warnings;
use FusionInventory::Agent::Tools;
sub isEnabled {
my (%params) = @_;
# We don't want to scan user directories unless --scan-homedirs is used
return
canRun('prlctl') &&
$params{scan_homedirs};
}
sub doInventory {
my (%params) = @_;
my $inventory = $params{inventory};
my $logger = $params{logger};
foreach my $user ( glob("/Users/*") ) {
$user =~ s/.*\///; # Just keep the login
next if $user =~ /Shared/i;
next if $user =~ /^\./i; # skip hidden directory
next if $user =~ /\ /; # skip directory containing space
next if $user =~ /'/; # skip directory containing quote
foreach my $machine (_parsePrlctlA(
logger => $logger,
command => "su '$user' -c 'prlctl list -a'"
)) {
my $uuid = $machine->{UUID};
# Avoid security risk. Should never appends
$uuid =~ s/[^A-Za-z0-9\.\s_-]//g;
($machine->{MEMORY}, $machine->{VCPU}) =
_parsePrlctlI(
logger => $logger,
command => "su '$user' -c 'prlctl list -i $uuid'"
);
$inventory->addEntry(
section => 'VIRTUALMACHINES', entry => $machine
);
}
}
}
sub _parsePrlctlA {
my $handle = getFileHandle(@_);
return unless $handle;
my %status_list = (
'running' => 'running',
'blocked' => 'blocked',
'paused' => 'paused',
'suspended' => 'suspended',
'crashed' => 'crashed',
'dying' => 'dying',
'stopped' => 'off',
);
# get headers line first
my $line = <$handle>;
my @machines;
while (my $line = <$handle>) {
chomp $line;
my @info = split(/\s+/, $line, 4);
my $uuid = $info[0];
my $status = $status_list{$info[1]};
my $name = $info[3];
$uuid =~s/{(.*)}/$1/;
# Avoid security risk. Should never appends
next if $uuid =~ /(;\||&)/;
push @machines, {
NAME => $name,
UUID => $uuid,
STATUS => $status,
SUBSYSTEM => "Parallels",
VMTYPE => "Parallels",
};
}
close $handle;
return @machines;
}
sub _parsePrlctlI {
my $handle = getFileHandle(@_);
my ($mem, $cpus);
while (my $line = <$handle>) {
if ($line =~ m/^\s\smemory\s(.*)Mb/) {
$mem = $1;
}
if ($line =~ m/^\s\scpu\s(\d{1,2})/) {
$cpus = $1;
}
}
close $handle;
return ($mem, $cpus);
}
1;
|