mirror of
https://github.com/stylersnico/librenms.git
synced 2026-08-03 08:01:38 +02:00
add xen support to libvirt vm discovery
git-svn-id: http://www.observium.org/svn/observer/trunk@2111 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -20,9 +20,9 @@ else if ($vm['vmwVmGuestOS'] == "")
|
||||
|
||||
if ($vm['vmwVmMemSize'] >= 1024)
|
||||
{
|
||||
echo("<td class=list>" . $vm['vmwVmMemSize']/1024 . " GB</td>");
|
||||
echo("<td class=list>" . sprintf("%.2f",$vm['vmwVmMemSize']/1024) . " GB</td>");
|
||||
} else {
|
||||
echo("<td class=list>" . $vm['vmwVmMemSize'] . " MB</td>");
|
||||
echo("<td class=list>" . sprintf("%.2f",$vm['vmwVmMemSize']) . " MB</td>");
|
||||
}
|
||||
|
||||
echo('<td class="list">' . $vm['vmwVmCpus'] . " CPU</td>");
|
||||
|
||||
@@ -54,7 +54,7 @@ foreach ($datas as $type)
|
||||
echo('<span class="pagemenu-selected">');
|
||||
}
|
||||
|
||||
echo("<a href='".$config['base_url']."/device/".$device['device_id']."/health/" . $type . ($_GET['optb'] ? "/" . $_GET['optb'] : ''). "/'> " . $type_text[$type] ."</a>");
|
||||
echo("<a href='device/".$device['device_id']."/health/" . $type . ($_GET['optb'] ? "/" . $_GET['optb'] : ''). "/'> " . $type_text[$type] ."</a>");
|
||||
if ($_GET['opta'] == $type) { echo("</span>"); }
|
||||
$sep = " | ";
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -10,10 +10,19 @@ 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';
|
||||
foreach ($config['libvirt_protocols'] as $method)
|
||||
{
|
||||
if (strstr($method,'qemu'))
|
||||
{
|
||||
$uri = $method.'://' . $device['hostname'] . '/system';
|
||||
}
|
||||
else
|
||||
{
|
||||
$uri = $method.'://' . $device['hostname'];
|
||||
}
|
||||
|
||||
$ok = 0;
|
||||
|
||||
if (strstr($method,'ssh'))
|
||||
{
|
||||
# Check if we are using SSH if we can log in without password - without blocking the discovery
|
||||
@@ -30,7 +39,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
|
||||
{
|
||||
# Fetch virtual machine list
|
||||
unset($domlist);
|
||||
exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system list',$domlist);
|
||||
exec($config['virsh'] . ' -c '.$uri.' list',$domlist);
|
||||
|
||||
foreach ($domlist as $dom)
|
||||
{
|
||||
@@ -40,7 +49,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
|
||||
{
|
||||
# Fetch the Virtual Machine information.
|
||||
unset($vm_info_array);
|
||||
exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system dumpxml ' . $dom_id,$vm_info_array);
|
||||
exec($config['virsh'] . ' -c '.$uri.' dumpxml ' . $dom_id,$vm_info_array);
|
||||
|
||||
# <domain type='kvm' id='3'>
|
||||
# <name>moo.example.com</name>
|
||||
@@ -66,7 +75,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
|
||||
$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);
|
||||
exec($config['virsh'] . ' -c '.$uri.' domstate ' . $dom_id,$vm_state);
|
||||
$vmwVmState = ucfirst($vm_state[0]);
|
||||
$vmwVmCpus = $xml->vcpu;
|
||||
|
||||
@@ -103,6 +112,10 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
|
||||
}
|
||||
}
|
||||
|
||||
# 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.
|
||||
$db_vm_list = mysql_query("SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='libvirt'");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user