line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Virtualization::VmWareESX; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
43934582
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
98
|
|
4
|
1
|
|
|
1
|
|
15
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
91
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
596
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
738
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub isEnabled { |
9
|
0
|
|
|
0
|
0
|
|
return canRun('vmware-cmd'); |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub doInventory { |
13
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
16
|
0
|
|
|
|
|
|
my $logger = $params{logger}; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
foreach my $machine (_getMachines( |
19
|
|
|
|
|
|
|
command => 'vmware-cmd -l', logger => $logger |
20
|
|
|
|
|
|
|
)) { |
21
|
0
|
|
|
|
|
|
$inventory->addEntry( |
22
|
|
|
|
|
|
|
section => 'VIRTUALMACHINES', entry => $machine |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _getMachines { |
28
|
0
|
|
|
0
|
|
|
my (%params) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $handle = getFileHandle(%params); |
31
|
0
|
0
|
|
|
|
|
return unless $handle; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my @machines; |
34
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
35
|
0
|
|
|
|
|
|
chomp $line; |
36
|
0
|
0
|
|
|
|
|
next unless -f $line; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my %info = _getMachineInfo(file => $line, logger => $params{logger}); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $machine = { |
41
|
|
|
|
|
|
|
MEMORY => $info{'memsize'}, |
42
|
|
|
|
|
|
|
NAME => $info{'displayName'}, |
43
|
|
|
|
|
|
|
UUID => $info{'uuid.bios'}, |
44
|
|
|
|
|
|
|
SUBSYSTEM => "VmWareESX", |
45
|
|
|
|
|
|
|
VMTYPE => "VmWare", |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
0
|
|
|
|
$machine->{STATUS} = getFirstMatch( |
49
|
|
|
|
|
|
|
command => "vmware-cmd '$line' getstate", |
50
|
|
|
|
|
|
|
logger => $params{logger}, |
51
|
|
|
|
|
|
|
pattern => qr/= (\w+)/ |
52
|
|
|
|
|
|
|
) || 'unknown'; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# correct uuid format |
55
|
0
|
|
|
|
|
|
$machine->{UUID} =~ s/\s+//g; # delete space |
56
|
0
|
|
|
|
|
|
$machine->{UUID} =~ s/^(........)(....)(....)-(....)(.+)$/$1-$2-$3-$4-$5/; # add dashs |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
push @machines, $machine; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
close $handle; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return @machines; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _getMachineInfo { |
67
|
0
|
|
|
0
|
|
|
my $handle = getFileHandle(@_); |
68
|
0
|
0
|
|
|
|
|
return unless $handle; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my %info; |
71
|
0
|
|
|
|
|
|
while (my $line = <$handle>) { |
72
|
0
|
0
|
|
|
|
|
next unless $line = /^(\S+)\s*=\s*(\S+.*)/; |
73
|
0
|
|
|
|
|
|
my $key = $1; |
74
|
0
|
|
|
|
|
|
my $value = $2; |
75
|
0
|
|
|
|
|
|
$value =~ s/(^"|"$)//g; |
76
|
0
|
|
|
|
|
|
$info{$key} = $value; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
close $handle; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return %info; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |