Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/self/root/usr/share/perl5/vendor_perl/Ocsinventory/Agent/Backend/Virtualization/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/usr/share/perl5/vendor_perl/Ocsinventory/Agent/Backend/Virtualization/Libvirt.pm
package Ocsinventory::Agent::Backend::Virtualization::Libvirt;

use strict;

use XML::Simple;

sub check { 
    my $params = shift;
    my $common = $params->{common};
    $common->can_run('virsh') 
}

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

    foreach (`virsh --readonly list --all`) {
        if (/^\s*(\d+|\s+\-)\s+(\S+)\s+(\S.+)/){
            my $memory;
            my $vcpu;
            my $name = $2;
            my $status = $3;

            $status =~ s/^shut off/off/;
            my $xml = `virsh --readonly dumpxml $name`;
            my $data = XMLin($xml);

            my $vcpu = $data->{vcpu};
            my $uuid = $data->{uuid};
            my $vmtype = $data->{type};

            if ($data->{currentMemory}->{unit}) {
                $memory = $1 if $data->{currentMemory}->{content} =~ /(\d+)\d{3}$/;
                $vcpu = $data->{vcpu}->{content};
            } else {
                $memory = $1 if $data->{currentMemory} =~ /(\d+)\d{3}$/;
                $vcpu = $data->{vcpu};
            }

            my %machine = (
                MEMORY => $memory,
                NAME => $name,
                UUID => $uuid,
                STATUS => $status,
                SUBSYSTEM => "Libvirt",
                VMTYPE => $vmtype,
                VCPU   => $vcpu,
            );

            $common->addVirtualMachine(\%machine);

        }
    }
}

1;

Hry