line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::Parallels; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
59265187
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
57
|
|
4
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
78
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
412
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1188
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub isEnabled { |
9
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
0
|
return canRun('prlctl'); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub doInventory { |
15
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
18
|
0
|
|
|
|
|
0
|
my $logger = $params{logger}; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
0
|
if (!$params{scan_homedirs}) { |
21
|
0
|
|
|
|
|
0
|
$logger->warning( |
22
|
|
|
|
|
|
|
"'scan-homedirs' configuration parameter disabled, " . |
23
|
|
|
|
|
|
|
"ignoring parallels virtual machines in user directories" |
24
|
|
|
|
|
|
|
); |
25
|
0
|
|
|
|
|
0
|
return; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
foreach my $user ( glob("/Users/*") ) { |
29
|
0
|
|
|
|
|
0
|
$user =~ s/.*\///; # Just keep the login |
30
|
0
|
0
|
|
|
|
0
|
next if $user =~ /Shared/i; |
31
|
0
|
0
|
|
|
|
0
|
next if $user =~ /^\./i; # skip hidden directory |
32
|
0
|
0
|
|
|
|
0
|
next if $user =~ /\ /; # skip directory containing space |
33
|
0
|
0
|
|
|
|
0
|
next if $user =~ /'/; # skip directory containing quote |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
foreach my $machine (_parsePrlctlA( |
36
|
|
|
|
|
|
|
logger => $logger, |
37
|
|
|
|
|
|
|
command => "su '$user' -c 'prlctl list -a'" |
38
|
|
|
|
|
|
|
)) { |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
my $uuid = $machine->{UUID}; |
41
|
|
|
|
|
|
|
# Avoid security risk. Should never appends |
42
|
0
|
|
|
|
|
0
|
$uuid =~ s/[^A-Za-z0-9\.\s_-]//g; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
($machine->{MEMORY}, $machine->{VCPU}) = |
46
|
|
|
|
|
|
|
_parsePrlctlI( |
47
|
|
|
|
|
|
|
logger => $logger, |
48
|
|
|
|
|
|
|
command => "su '$user' -c 'prlctl list -i $uuid'" |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
52
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', entry => $machine |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _parsePrlctlA { |
59
|
1
|
|
|
1
|
|
10
|
my $handle = getFileHandle(@_); |
60
|
|
|
|
|
|
|
|
61
|
1
|
50
|
|
|
|
3
|
return unless $handle; |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
4
|
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
|
1
|
|
|
|
|
7
|
my $line = <$handle>; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
1
|
my @machines; |
78
|
1
|
|
|
|
|
4
|
while (my $line = <$handle>) { |
79
|
1
|
|
|
|
|
1
|
chomp $line; |
80
|
1
|
|
|
|
|
6
|
my @info = split(/\s+/, $line, 4); |
81
|
1
|
|
|
|
|
1
|
my $uuid = $info[0]; |
82
|
1
|
|
|
|
|
2
|
my $status = $status_list{$info[1]}; |
83
|
1
|
|
|
|
|
1
|
my $name = $info[3]; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
5
|
$uuid =~s/{(.*)}/$1/; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Avoid security risk. Should never appends |
89
|
1
|
50
|
|
|
|
3
|
next if $uuid =~ /(;\||&)/; |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
8
|
push @machines, { |
92
|
|
|
|
|
|
|
NAME => $name, |
93
|
|
|
|
|
|
|
UUID => $uuid, |
94
|
|
|
|
|
|
|
STATUS => $status, |
95
|
|
|
|
|
|
|
SUBSYSTEM => "Parallels", |
96
|
|
|
|
|
|
|
VMTYPE => "Parallels", |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
5
|
close $handle; |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
5
|
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; |