Welcome to OCS Inventory NG community support, where you can ask questions and receive answers from other members of the community.

Please ask questions only in English or French.

Release 2.12.3 available

The official documentation can be found on https://wiki.ocsinventory-ng.org. Read it before asking your question.

client not collect machine virtual from de Xenserver [closed]

hi,

I need help in the client from xenserver, it collect information xenserver with client 2.0.1, but no collect the information de virtualmachine.

I am creating a script in shell that collect information from virtual machi, but do not know how to create an entry in ocs for the agent.

 

 

#!/bin/bash

echo "Create the csv for the vm-list"

xe vm-list params=dom-id,name-label,power-state,memory-actual,name-description,uuid,resident-on   |grep -i [a-z]|awk 'ORS=NR%7?":":"\n"' |awk -F': ' '{print $2";"$4";"$6";"$8";"$10";"$12";"$14}'|grep -v "Control domain on host" >> csv/vm-list.csv
 

echo "Create the csv for the host-list"

xe host-list |grep -i [a-z]|awk 'ORS=NR%3?":":"\n"' |awk -F': ' '{print $2";"$4}'|grep -v "^Control domain on host" >> csv/$CMD.csv
 

VirtualMachine ( )
{
cat csv/vm-list.csv |while read LINE
do
   ARQ1=$LINE
   echo $ARQ1 > arq2.txt
   maquinasvirtuais
done
}
maquinasvirtuais ()
{
    residenton=$(awk -F ";" '{print $6}' arq2.txt)
    l6=$(grep "$residenton" csv'\'host-list.csv|cut -d ";" -f2)
   l1=$(awk -F ";" '{print $1}' arq2.txt)
   l2=$(awk -F ";" '{print $2}' arq2.txt)
   l3=$(awk -F ";" '{print $3}' arq2.txt)
   l4=$(awk -F ";" '{print $4}' arq2.txt)
   l5=$(awk -F ";" '{print $5}' arq2.txt)
   l7=$(awk -F ";" '{print $7}' arq2.txt)
   echo "    <VIRTUALMACHINES>" >> $l6.ocs  
   echo "      <COMMENT></COMMENT>" >> $l6.ocs
   echo "      <MAC></MAC>" >> $l6.ocs
   echo "      <MEMORY>$l5</MEMORY>" >> $l6.ocs
   echo "      <NAME>$l2</NAME>" >> $l6.ocs
   echo "      <STATUS>$l4</STATUS>" >> $l6.ocs
   echo "      <UUID>$l1</UUID>" >> $l6.ocs
   echo "      <VCPU></VCPU>" >> $l6.ocs
   echo "      <VMID>vm-$l7</VMID>" >> $l6.ocs
   echo "      <VMTYPE>XEN</VMTYPE>" >> $l6.ocs
   echo "    </VIRTUALMACHINES>" >> $l6.ocs
   
}
rm *.ocs
head ()
{
cat csv/host-list.csv |while read LINE
do
 host=$LINE
 host=$(grep "$host" csv'\'host-list.csv|cut -d ";" -f2)
 echo '<?xml version="1.0" encoding="UTF-8"?>' >> $host.ocs
 echo " <REQUEST>" >> $host.ocs
 echo "   <CONTENT>" >> $host.ocs
done
}
tail ()
{
cat csv/host-list.csv |while read LINE
do
 host=$LINE
 host=$(grep "$host" csv'\'host-list.csv|cut -d ";" -f2)
 echo "   </CONTENT>" >> $host.ocs
 echo "   <DEVICEID>$host</DEVICEID>" >> $host.ocs
 echo "   <QUERY>INVENTORY</QUERY>" >> $host.ocs
 echo " </REQUEST>" >> $host.ocs
done
}

head

VirtualMachine

tail
closed with the note: scritp perl created by me.
in OCS Inventory NG server for Unix by (220 points)
closed by

2 Answers

–1 vote
Hi,

ocs unified agent can retrieve these informations. Install ocs unified agent on your server.
by (90.4k points)

Hi,

This up and running, no longer brings information which virtual machines are running on it.

plugins collection for virtual machine running virtualbox, XEN or KVM, XenServer does not have a more specific plugin.

+1 vote

creating XenServer.pm in the directory perl > Ocsinventory > Agent > Backend > Virtualization

 

package Ocsinventory::Agent::Backend::Virtualization::XenServer;

use strict;

use XML::Simple;

sub check { can_run('xe') }

sub run {
    my $params = shift;
    my $common = $params->{common};
    my $hostname = `hostname`;
    my $residenton;
    foreach (`xe host-list params=uuid hostname=$hostname`) {
         $residenton = $1 if /:\s+(.+)/;
    }
    foreach (`xe vm-list params=uuid resident-on=$residenton`) {
        if (/:\s+(.+)/) {
        my $uuid = $1 if /:\s+(.+)/;
        my $fname = `xe vm-list params=name-label uuid=$uuid`;
        my $name = $1 if $fname =~ /:\s+(.+)/;
        my $fstatus = `xe vm-list params=power-state uuid=$uuid`;
        my $status = $1 if $fstatus =~ /:\s+(.+)/;
        my $fvcpu = `xe vm-list params=VCPUs-max uuid=$uuid`;
        my $vcpu = $1 if $fvcpu =~ /:\s+(.+)/;
        my $fmemory = `xe vm-list params=memory-actual uuid=$uuid`;
        my $tmemory = $1 if $fmemory =~ /:\s+(.+)/;
        my $memory = $1 if $tmemory =~ /(\d+)\d{6}$/;
    
        my $machine = {
                MEMORY => $memory,
                NAME => $name,
                UUID => $uuid,
                STATUS => $status,
                SUBSYSTEM => "libvirt",
                VMTYPE => "XEN",
                VCPU   => $vcpu,

        };
            $common->addVirtualMachine($machine);
        }
    }
}

1;

 

Now running this beauty.

by (220 points)
Thank you for this.  It works beautifully on my XenServer 6.5 installations.
 
Powered by Question2Answer
...