This file is indexed.

/usr/share/fusioninventory/lib/FusionInventory/Agent/Task/Inventory/Virtualization/Qemu.pm is in fusioninventory-agent 1:2.3.10.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
79
80
81
82
83
84
85
86
87
package FusionInventory::Agent::Task::Inventory::Virtualization::Qemu;
# With Qemu 0.10.X, some option will be added to get more and easly information (UUID, memory, ...)

use strict;
use warnings;

use FusionInventory::Agent::Tools;
use FusionInventory::Agent::Tools::Unix;

sub isEnabled {
    # Avoid duplicated entry with libvirt
    return if canRun('virsh');

    return
        canRun('qemu') ||
        canRun('kvm')  ||
        canRun('qemu-kvm');
}

sub _parseProcessList {
    my ($process) = @_;


    my $values = {};

    my @options = split (/ -/, $process->{CMD});

    foreach my $option (@options) {
        if ($option =~ m/^(?:[fhsv]d[a-d]|cdrom) (\S+)/) {
            $values->{name} = $1 if !$values->{name};
        } elsif ($option =~ m/^name (\S+)/) {
            $values->{name} = $1;
        } elsif ($option =~ m/^m (\S+)/) {
            $values->{mem} = $1;
        } elsif ($option =~ m/^uuid (\S+)/) {
            $values->{uuid} = $1;
        }

        if ($option =~ /smbios/) {
            if ($option =~ m/smbios.*uuid=([a-zA-Z0-9-]+)/) {
                $values->{uuid} = $1;
            }
            if ($option =~ m/smbios.*serial=([a-zA-Z0-9-]+)/) {
                $values->{serial} = $1;
            }
        }
    }

    if ($values->{mem} == 0 ) {
        # Default value
        $values->{mem} = 128;
    }

    return $values;
}

sub doInventory {
    my (%params) = @_;

    my $inventory = $params{inventory};
    my $logger    = $params{logger};

    foreach my $process (getProcesses(logger => $logger)) {
        # match only if an qemu instance
        next if $process->{CMD} =~ /^\[/;
        next if $process->{CMD} !~ /(qemu|kvm|qemu-kvm|qemu-system\S+) .*\S/x;

        my $values = _parseProcessList($process);
        next unless $values;

        $inventory->addEntry(
            section => 'VIRTUALMACHINES',
            entry => {
                NAME      => $values->{name},
                UUID      => $values->{uuid},
                VCPU      => 1,
                MEMORY    => $values->{mem},
                STATUS    => "running",
                SUBSYSTEM => $values->{vmtype},
                VMTYPE    => $values->{vmtype},
                SERIAL    => $values->{serial},
            }
        );
    }
}

1;