File: Parallels.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.0.5-1.2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 4,120 kB
  • ctags: 899
  • sloc: perl: 20,687; sh: 576; objc: 468; ansic: 333; makefile: 55
file content (78 lines) | stat: -rw-r--r-- 2,091 bytes parent folder | download | duplicates (2)
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
package Ocsinventory::Agent::Backend::Virtualization::Parallels;

use strict;

sub check { return can_run('prlctl') }

sub run {
    my $params = shift;
    my $common = $params->{common};
    my $config = $params->{config};

    my %status_list = (
        'running' => 'running',
        'blocked' => 'blocked',
        'paused' => 'paused',
        'suspended' => 'suspended',
        'crashed' => 'crashed',
        'dying' => 'dying',
    );

    my $uuid="";
    my $mem="";
    my $status="";
    my $name="";
    my $cpus = 1;
    my @users = ();

    # We don't want to scan user directories unless --scan-homedirs is used
    return unless $config->{scanhomedirs};

    foreach my $lsuser ( glob("/Users/*") ) {
        $lsuser =~ s/.*\///; # Just keep the login
        next if /Shared/i;
        next if /^\./i; # Ignore hidden directory
        next if /\ /; # Ignore directory with space in the name
        next if /'/; # Ignore directory with space in the name

        push(@users,$lsuser);
    }

    foreach my $user (@users) {
        my @command = `su '$user' -c "prlctl list -a"`;
        shift (@command);

        foreach my $line ( @command ) {
            chomp $line; 
            my @params = split(/  /, $line);
            $uuid = $params[0];
            #$status = $params[1];
            $status = $status_list{$params[1]};
            $name = $params[4];

            # Avoid security risk. Should never appends
            next if $uuid =~ /(;\||&)/;

            foreach my $infos ( `sudo -u '$user' prlctl list -i $uuid`) {
            if ($infos =~ m/^\s\smemory\s(.*)Mb/) {
                $mem = $1;
            }
            elsif ($infos =~ m/^\s\scpu\s([0-9]{1,2})/) {
                $cpus= $1;
            }
        }

        $common->addVirtualMachine ({
                NAME      => $name,
                VCPU      => $cpus,
                UUID      => $uuid,
                MEMORY    => $mem,
                STATUS    => $status,
                SUBSYSTEM => "",
                VMTYPE    => "Parallels",
            });
    }
}
}

1;