line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::Parallels; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
58314370
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
98
|
|
4
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
103
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
675
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1733
|
|
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
|
|
16
|
my $handle = getFileHandle(@_); |
60
|
|
|
|
|
|
|
|
61
|
1
|
50
|
|
|
|
4
|
return unless $handle; |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
9
|
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
|
|
|
|
|
10
|
my $line = <$handle>; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
3
|
my @machines; |
78
|
1
|
|
|
|
|
6
|
while (my $line = <$handle>) { |
79
|
1
|
|
|
|
|
2
|
chomp $line; |
80
|
1
|
|
|
|
|
8
|
my @info = split(/\s+/, $line, 4); |
81
|
1
|
|
|
|
|
2
|
my $uuid = $info[0]; |
82
|
1
|
|
|
|
|
3
|
my $status = $status_list{$info[1]}; |
83
|
1
|
|
|
|
|
2
|
my $name = $info[3]; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
6
|
$uuid =~s/{(.*)}/$1/; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Avoid security risk. Should never appends |
89
|
1
|
50
|
|
|
|
6
|
next if $uuid =~ /(;\||&)/; |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
12
|
push @machines, { |
92
|
|
|
|
|
|
|
NAME => $name, |
93
|
|
|
|
|
|
|
UUID => $uuid, |
94
|
|
|
|
|
|
|
STATUS => $status, |
95
|
|
|
|
|
|
|
SUBSYSTEM => "Parallels", |
96
|
|
|
|
|
|
|
VMTYPE => "Parallels", |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
7
|
close $handle; |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
7
|
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; |