line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::Parallels; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
43554048
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
75
|
|
4
|
1
|
|
|
1
|
|
11
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
422
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
627
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub isEnabled { |
9
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
|
return canRun('prlctl'); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub doInventory { |
15
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
18
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
if (!$params{scan_homedirs}) { |
21
|
0
|
|
|
|
|
|
$logger->warning( |
22
|
|
|
|
|
|
|
"'scan-homedirs' configuration parameter disabled, " . |
23
|
|
|
|
|
|
|
"ignoring parallels virtual machines in user directories" |
24
|
|
|
|
|
|
|
); |
25
|
0
|
|
|
|
|
|
return; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
foreach my $user ( glob("/Users/*") ) { |
29
|
0
|
|
|
|
|
|
$user =~ s/.*\///; # Just keep the login |
30
|
0
|
0
|
|
|
|
|
next if $user =~ /Shared/i; |
31
|
0
|
0
|
|
|
|
|
next if $user =~ /^\./i; # skip hidden directory |
32
|
0
|
0
|
|
|
|
|
next if $user =~ /\ /; # skip directory containing space |
33
|
0
|
0
|
|
|
|
|
next if $user =~ /'/; # skip directory containing quote |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
foreach my $machine (_parsePrlctlA( |
36
|
|
|
|
|
|
|
logger => $logger, |
37
|
|
|
|
|
|
|
command => "su '$user' -c 'prlctl list -a'" |
38
|
|
|
|
|
|
|
)) { |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $uuid = $machine->{UUID}; |
41
|
|
|
|
|
|
|
# Avoid security risk. Should never appends |
42
|
0
|
|
|
|
|
|
$uuid =~ s/[^A-Za-z0-9\.\s_-]//g; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
($machine->{MEMORY}, $machine->{VCPU}) = |
46
|
|
|
|
|
|
|
_parsePrlctlI( |
47
|
|
|
|
|
|
|
logger => $logger, |
48
|
|
|
|
|
|
|
command => "su '$user' -c 'prlctl list -i $uuid'" |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$inventory->addEntry( |
52
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', entry => $machine |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _parsePrlctlA { |
59
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
return unless $handle; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my %status_list = ( |
64
|
|
|
|
|
|
|
'running' => 'running', |
65
|
|
|
|
|
|
|
'blocked' => 'blocked', |
66
|
|
|
|
|
|
|
'paused' => 'paused', |
67
|
|
|
|
|
|
|
'suspended' => 'suspended', |
68
|
|
|
|
|
|
|
'crashed' => 'crashed', |
69
|
|
|
|
|
|
|
'dying' => 'dying', |
70
|
|
|
|
|
|
|
'stopped' => 'off', |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# get headers line first |
75
|
0
|
|
|
|
|
|
my $line = <$handle>; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my @machines; |
78
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
79
|
0
|
|
|
|
|
|
chomp $line; |
80
|
0
|
|
|
|
|
|
my @info = split(/\s+/, $line, 4); |
81
|
0
|
|
|
|
|
|
my $uuid = $info[0]; |
82
|
0
|
|
|
|
|
|
my $status = $status_list{$info[1]}; |
83
|
0
|
|
|
|
|
|
my $name = $info[3]; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$uuid =~s/{(.*)}/$1/; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Avoid security risk. Should never appends |
89
|
0
|
0
|
|
|
|
|
next if $uuid =~ /(;\||&)/; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
push @machines, { |
92
|
|
|
|
|
|
|
NAME => $name, |
93
|
|
|
|
|
|
|
UUID => $uuid, |
94
|
|
|
|
|
|
|
STATUS => $status, |
95
|
|
|
|
|
|
|
SUBSYSTEM => "Parallels", |
96
|
|
|
|
|
|
|
VMTYPE => "Parallels", |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
close $handle; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
return @machines; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _parsePrlctlI { |
106
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my ($mem, $cpus); |
109
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
110
|
0
|
0
|
|
|
|
|
if ($line =~ m/^\s\smemory\s(.*)Mb/) { |
111
|
0
|
|
|
|
|
|
$mem = $1; |
112
|
|
|
|
|
|
|
} |
113
|
0
|
0
|
|
|
|
|
if ($line =~ m/^\s\scpu\s(\d{1,2})/) { |
114
|
0
|
|
|
|
|
|
$cpus = $1; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
close $handle; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return ($mem, $cpus); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |