diff --git a/html/includes/print-vm.inc.php b/html/includes/print-vm.inc.php
index 559e6d5e4f..bc9b3e1cb7 100644
--- a/html/includes/print-vm.inc.php
+++ b/html/includes/print-vm.inc.php
@@ -20,9 +20,9 @@ else if ($vm['vmwVmGuestOS'] == "")
if ($vm['vmwVmMemSize'] >= 1024)
{
- echo("
" . $vm['vmwVmMemSize']/1024 . " GB | ");
+ echo("" . sprintf("%.2f",$vm['vmwVmMemSize']/1024) . " GB | ");
} else {
- echo("" . $vm['vmwVmMemSize'] . " MB | ");
+ echo("" . sprintf("%.2f",$vm['vmwVmMemSize']) . " MB | ");
}
echo('' . $vm['vmwVmCpus'] . " CPU | ");
diff --git a/html/pages/device/health.inc.php b/html/pages/device/health.inc.php
index 39da2fb41f..b2bc605042 100644
--- a/html/pages/device/health.inc.php
+++ b/html/pages/device/health.inc.php
@@ -54,7 +54,7 @@ foreach ($datas as $type)
echo('"); }
$sep = " | ";
}
diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php
index cdca9e6ff0..8bc5ac20c7 100644
--- a/includes/defaults.inc.php
+++ b/includes/defaults.inc.php
@@ -131,7 +131,6 @@ $config['enable_inventory'] = 1; # Enable Inventory
$config['enable_pseudowires'] = 1; # Enable Pseudowires
$config['enable_vrfs'] = 1; # Enable VRFs
$config['enable_printers'] = 0; # Enable Printer support
-$config['enable_libvirt'] = 0; # Enable Libvirt VM support
### Ports extension modules
@@ -218,6 +217,11 @@ $config['syslog_filter'] = array("last message repeated", "Connection from UDP:
"ipSystemStatsTable node ipSystemStatsOutFragOKs not implemented",
"diskio.c: don't know how to handle"); ## Ignore some crappy stuff from SNMP daemon
+### Virtualization
+
+$config['enable_libvirt'] = 0; # Enable Libvirt VM support
+$config['libvirt_protocols'] = array("qemu+ssh","xen+ssh"); # Mechanisms used, add or remove if not using this on any of your machines.
+
### LDAP Authentication
$config['auth_ldap_version'] = 3; # v2 or v3
diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php
index 0e56979fe6..de5803fade 100755
--- a/includes/discovery/discovery-protocols.inc.php
+++ b/includes/discovery/discovery-protocols.inc.php
@@ -53,7 +53,6 @@ if ($cdp_array)
$remote_interface_id = @mysql_result(mysql_query("SELECT interface_id FROM `ports` WHERE (`ifDescr` = '$if' OR `ifName`='$if') AND `device_id` = '".$remote_device_id."'"),0);
} else { $remote_interface_id = "0"; }
-
if ($interface['interface_id'] && $cdp['cdpCacheDeviceId'] && $cdp['cdpCacheDevicePort'])
{
discover_link($interface['interface_id'], 'cdp', $remote_interface_id, $cdp['cdpCacheDeviceId'], $cdp['cdpCacheDevicePort'], $cdp['cdpCachePlatform'], $cdp['cdpCacheVersion']);
diff --git a/includes/discovery/libvirt-vminfo.inc.php b/includes/discovery/libvirt-vminfo.inc.php
index 380c5f643f..8c74c16727 100755
--- a/includes/discovery/libvirt-vminfo.inc.php
+++ b/includes/discovery/libvirt-vminfo.inc.php
@@ -10,97 +10,110 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
echo("Libvirt VM: ");
- # FIXME should support other methods here too (tls etc), and other hypervisors, like xen, too!
- $method = 'qemu+ssh';
-
- $ok = 0;
- if (strstr($method,'ssh'))
+ foreach ($config['libvirt_protocols'] as $method)
{
- # Check if we are using SSH if we can log in without password - without blocking the discovery
- # Also automatically add the host key so discovery doesn't block on the yes/no question, and run echo so we don't get stuck in a remote shell ;-)
- exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" ' . $device['hostname'] . ' echo', $out, $ret);
- if ($ret != 255) { $ok = 1; }
- }
- else
- {
- $ok = 1;
- }
-
- if ($ok)
- {
- # Fetch virtual machine list
- unset($domlist);
- exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system list',$domlist);
-
- foreach ($domlist as $dom)
+ if (strstr($method,'qemu'))
{
- list($dom_id,) = explode(' ',trim($dom),2);
+ $uri = $method.'://' . $device['hostname'] . '/system';
+ }
+ else
+ {
+ $uri = $method.'://' . $device['hostname'];
+ }
+
+ $ok = 0;
- if (is_numeric($dom_id))
+ if (strstr($method,'ssh'))
+ {
+ # Check if we are using SSH if we can log in without password - without blocking the discovery
+ # Also automatically add the host key so discovery doesn't block on the yes/no question, and run echo so we don't get stuck in a remote shell ;-)
+ exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" ' . $device['hostname'] . ' echo', $out, $ret);
+ if ($ret != 255) { $ok = 1; }
+ }
+ else
+ {
+ $ok = 1;
+ }
+
+ if ($ok)
+ {
+ # Fetch virtual machine list
+ unset($domlist);
+ exec($config['virsh'] . ' -c '.$uri.' list',$domlist);
+
+ foreach ($domlist as $dom)
{
- # Fetch the Virtual Machine information.
- unset($vm_info_array);
- exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system dumpxml ' . $dom_id,$vm_info_array);
+ list($dom_id,) = explode(' ',trim($dom),2);
- #
- # moo.example.com
- # 48cf6378-6fd5-4610-0611-63dd4b31cfd6
- # 1048576
- # 1048576
- # 8
- #
- # hvm
- #
- #
- #
- #
- # (...)
-
- # Convert array to string
- unset($vm_info_xml);
- foreach ($vm_info_array as $line) { $vm_info_xml .= $line; }
-
- $xml = simplexml_load_string(' ' . $vm_info_xml);
- if ($debug) { print_r($xml); }
-
- $vmwVmDisplayName = $xml->name;
- $vmwVmGuestOS = ''; # libvirt does not supply this
- $vmwVmMemSize = $xml->currentMemory / 1024;
- exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system domstate ' . $dom_id,$vm_state);
- $vmwVmState = ucfirst($vm_state[0]);
- $vmwVmCpus = $xml->vcpu;
-
- # Check whether the Virtual Machine is already known for this host.
- $result = mysql_query("SELECT * FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $dom_id . "' AND vm_type='libvirt'");
- if (mysql_num_rows($result) == 0)
+ if (is_numeric($dom_id))
{
- mysql_query("INSERT INTO vminfo (device_id, vm_type, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState) VALUES (" . $device["device_id"] . ", 'libvirt',
- '" . $dom_id . "', '" . mres($vmwVmDisplayName) . "', '" . mres($vmwVmGuestOS) . "', '" . $vmwVmMemSize . "', '" . $vmwVmCpus . "', '" . mres($vmwVmState) . "')");
- echo("+");
- log_event("Virtual Machine added: $vmwVmDisplayName ($vmwVmMemSize MB)", $device, 'vm', mysql_insert_id());
- } else {
- $row = mysql_fetch_assoc($result);
- if ($row['vmwVmState'] != $vmwVmState
- || $row['vmwVmDisplayName'] != $vmwVmDisplayName
- || $row['vmwVmCpus'] != $vmwVmCpus
- || $row['vmwVmGuestOS'] != $vmwVmGuestOS
- || $row['vmwVmMemSize'] != $vmwVmMemSize)
- {
- mysql_query("UPDATE vminfo SET vmwVmState='" . mres($vmwVmState) . "', vmwVmGuestOS='" . mres($vmwVmGuestOS) . "', vmwVmDisplayName='". mres($vmwVmDisplayName) . "',
- vmwVmMemSize='" . mres($vmwVmMemSize) . "', vmwVmCpus='" . mres($vmwVmCpus) . "' WHERE device_id='" . $device["device_id"] . "' AND vm_type='libvirt' AND vmwVmVMID='" . $dom_id . "'");
- echo("U");
- # FIXME eventlog
- }
- else
- {
- echo(".");
- }
- }
+ # Fetch the Virtual Machine information.
+ unset($vm_info_array);
+ exec($config['virsh'] . ' -c '.$uri.' dumpxml ' . $dom_id,$vm_info_array);
- # Save the discovered Virtual Machine.
- $libvirt_vmlist[] = $dom_id;
+ #
+ # moo.example.com
+ # 48cf6378-6fd5-4610-0611-63dd4b31cfd6
+ # 1048576
+ # 1048576
+ # 8
+ #
+ # hvm
+ #
+ #
+ #
+ #
+ # (...)
+
+ # Convert array to string
+ unset($vm_info_xml);
+ foreach ($vm_info_array as $line) { $vm_info_xml .= $line; }
+
+ $xml = simplexml_load_string(' ' . $vm_info_xml);
+ if ($debug) { print_r($xml); }
+
+ $vmwVmDisplayName = $xml->name;
+ $vmwVmGuestOS = ''; # libvirt does not supply this
+ $vmwVmMemSize = $xml->currentMemory / 1024;
+ exec($config['virsh'] . ' -c '.$uri.' domstate ' . $dom_id,$vm_state);
+ $vmwVmState = ucfirst($vm_state[0]);
+ $vmwVmCpus = $xml->vcpu;
+
+ # Check whether the Virtual Machine is already known for this host.
+ $result = mysql_query("SELECT * FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $dom_id . "' AND vm_type='libvirt'");
+ if (mysql_num_rows($result) == 0)
+ {
+ mysql_query("INSERT INTO vminfo (device_id, vm_type, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState) VALUES (" . $device["device_id"] . ", 'libvirt',
+ '" . $dom_id . "', '" . mres($vmwVmDisplayName) . "', '" . mres($vmwVmGuestOS) . "', '" . $vmwVmMemSize . "', '" . $vmwVmCpus . "', '" . mres($vmwVmState) . "')");
+ echo("+");
+ log_event("Virtual Machine added: $vmwVmDisplayName ($vmwVmMemSize MB)", $device, 'vm', mysql_insert_id());
+ } else {
+ $row = mysql_fetch_assoc($result);
+ if ($row['vmwVmState'] != $vmwVmState
+ || $row['vmwVmDisplayName'] != $vmwVmDisplayName
+ || $row['vmwVmCpus'] != $vmwVmCpus
+ || $row['vmwVmGuestOS'] != $vmwVmGuestOS
+ || $row['vmwVmMemSize'] != $vmwVmMemSize)
+ {
+ mysql_query("UPDATE vminfo SET vmwVmState='" . mres($vmwVmState) . "', vmwVmGuestOS='" . mres($vmwVmGuestOS) . "', vmwVmDisplayName='". mres($vmwVmDisplayName) . "',
+ vmwVmMemSize='" . mres($vmwVmMemSize) . "', vmwVmCpus='" . mres($vmwVmCpus) . "' WHERE device_id='" . $device["device_id"] . "' AND vm_type='libvirt' AND vmwVmVMID='" . $dom_id . "'");
+ echo("U");
+ # FIXME eventlog
+ }
+ else
+ {
+ echo(".");
+ }
+ }
+
+ # Save the discovered Virtual Machine.
+ $libvirt_vmlist[] = $dom_id;
+ }
}
}
+
+ # If we found VMs, don't cycle the other protocols anymore.
+ if (count($libvirt_vmlist)) { break; }
}
# Get a list of all the known Virtual Machines for this host.