mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
libvirt VM listing support (qemu/kvm over ssh only for now), renamed vmware table to something a little more generic
git-svn-id: http://www.observium.org/svn/observer/trunk@2030 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
parent
f55a30f744
commit
e3f4361e15
@ -30,3 +30,5 @@ ALTER TABLE `vrfs` MODIFY `vrf_name` VARCHAR(128);
|
||||
ALTER TABLE `ports` MODIFY `ifDescr` VARCHAR(255);
|
||||
CREATE TABLE IF NOT EXISTS `vmware_vminfo` (`id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `vmwVmVMID` int(11) NOT NULL, `vmwVmDisplayName` varchar(128) NOT NULL, `vmwVmGuestOS` varchar(128) NOT NULL, `vmwVmMemSize` int(11) NOT NULL, `vmwVmCpus` int(11) NOT NULL, `vmwVmState` varchar(128) NOT NULL, PRIMARY KEY (`id`), KEY `device_id` (`device_id`), KEY `vmwVmVMID` (`vmwVmVMID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
ALTER TABLE `ports` MODIFY `port_descr_type` VARCHAR(255);
|
||||
RENAME TABLE `vmware_vminfo` TO `vminfo` ;
|
||||
ALTER TABLE `vminfo` ADD `vm_type` VARCHAR(16) NOT NULL DEFAULT 'vmware' AFTER `device_id`;
|
||||
|
@ -194,6 +194,7 @@ while ($device = mysql_fetch_assoc($device_query))
|
||||
include("includes/discovery/cisco-pw.inc.php");
|
||||
include("includes/discovery/cisco-vrf.inc.php");
|
||||
include("includes/discovery/vmware-vminfo.inc.php");
|
||||
include("includes/discovery/libvirt-vminfo.inc.php");
|
||||
include("includes/discovery/toner.inc.php");
|
||||
include("includes/discovery/ucd-diskio.inc.php");
|
||||
include("includes/discovery/services.inc.php");
|
||||
|
@ -2,23 +2,29 @@
|
||||
|
||||
if (!is_integer($i/2)) { $bg_colour = $list_colour_a; } else { $bg_colour = $list_colour_b; }
|
||||
|
||||
echo("<tr bgcolor='$bg_colour'>");
|
||||
echo('<tr bgcolor="' . $bg_colour . '">');
|
||||
|
||||
echo("<td class=list>" . $vm['vmwVmDisplayName'] . "</td>");
|
||||
echo("<td class=list>" . $vm['vmwVmState'] . "</td>");
|
||||
echo('<td class="list">' . $vm['vmwVmDisplayName'] . "</td>");
|
||||
echo('<td class="list">' . $vm['vmwVmState'] . "</td>");
|
||||
|
||||
if ($vm['vmwVmGuestOS'] == "E: tools not installed") {
|
||||
echo("<td class=box-desc>Unknown (VMware Tools not installed)</td>");
|
||||
if ($vm['vmwVmGuestOS'] == "E: tools not installed")
|
||||
{
|
||||
echo('<td class="box-desc">Unknown (VMware Tools not installed)</td>');
|
||||
}
|
||||
else if ($vm['vmwVmGuestOS'] == "")
|
||||
{
|
||||
echo('<td class="box-desc"><i>(Unknown)</i></td>');
|
||||
} else {
|
||||
echo("<td class=list>" . $config['vmware_guestid'][$vm['vmwVmGuestOS']] . "</td>");
|
||||
echo('<td class="list">' . $config['vmware_guestid'][$vm['vmwVmGuestOS']] . "</td>");
|
||||
}
|
||||
|
||||
if ($vm['vmwVmMemSize'] >= 1024) {
|
||||
if ($vm['vmwVmMemSize'] >= 1024)
|
||||
{
|
||||
echo("<td class=list>" . $vm['vmwVmMemSize']/1024 . " GB</td>");
|
||||
} else {
|
||||
echo("<td class=list>" . $vm['vmwVmMemSize'] . " MB</td>");
|
||||
}
|
||||
|
||||
echo("<td class=list>" . $vm['vmwVmCpus'] . " CPU</td>");
|
||||
echo('<td class="list">' . $vm['vmwVmCpus'] . " CPU</td>");
|
||||
|
||||
?>
|
||||
|
@ -104,7 +104,7 @@ if (device_permitted($_GET['id']) || $check_device == $_GET['id'])
|
||||
</li>');
|
||||
}
|
||||
|
||||
if (@mysql_result(mysql_query("SELECT COUNT(id) FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'"), 0) > '0')
|
||||
if (@mysql_result(mysql_query("SELECT COUNT(id) FROM vminfo WHERE device_id = '" . $device["device_id"] . "'"), 0) > '0')
|
||||
{
|
||||
echo('<li class="' . $select['vm'] . '">
|
||||
<a href="'.$config['base_url'].'/device/' . $device['device_id'] . '/vm/">
|
||||
|
@ -3,7 +3,7 @@
|
||||
echo('<table border="0" cellspacing="0" cellpadding="5" width="100%" class="sortable"><tr class="tablehead"><th>Server Name</th><th>Power Status</th><th>Operating System</th><th>Memory</th><th>CPU</th></tr>');
|
||||
|
||||
$i = "1";
|
||||
$vm_query = mysql_query("SELECT id, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState FROM vmware_vminfo WHERE device_id = '".$device['device_id']."' ORDER BY vmwVmDisplayName");
|
||||
$vm_query = mysql_query("SELECT id, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState FROM vminfo WHERE device_id = '".$device['device_id']."' ORDER BY vmwVmDisplayName");
|
||||
|
||||
while ($vm = mysql_fetch_assoc($vm_query))
|
||||
{
|
||||
|
@ -22,6 +22,7 @@ $config['mtr'] = "/usr/bin/mtr";
|
||||
$config['nmap'] = "/usr/bin/nmap";
|
||||
$config['nagios_plugins'] = "/usr/lib/nagios/plugins";
|
||||
$config['ipmitool'] = "/usr/bin/ipmitool";
|
||||
$config['virsh'] = "/usr/bin/virsh";
|
||||
|
||||
### RRDCacheD - Make sure it can write to your RRD dir!
|
||||
|
||||
@ -128,6 +129,7 @@ $config['enable_syslog'] = 0; # Enable Syslog
|
||||
$config['enable_inventory'] = 1; # Enable Inventory
|
||||
$config['enable_pseudowires'] = 1; # Enable Pseudowires
|
||||
$config['enable_printers'] = 0; # Enable Printer support
|
||||
$config['enable_libvirt'] = 0; # Enable Libvirt VM support
|
||||
|
||||
### Ports extension modules
|
||||
|
||||
|
108
includes/discovery/libvirt-vminfo.inc.php
Executable file
108
includes/discovery/libvirt-vminfo.inc.php
Executable file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
# FIXME should do the deletion etc in a common file perhaps? like for the sensors
|
||||
|
||||
# Try to discover Libvirt Virtual Machines.
|
||||
|
||||
if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
|
||||
{
|
||||
$libvirt_vmlist = array();
|
||||
|
||||
echo("Libvirt VM: ");
|
||||
|
||||
# FIXME should support other methods here too (tls etc), and other hypervisors, like xen, too!
|
||||
$method = 'qemu+ssh';
|
||||
|
||||
# Fetch virtual machine list
|
||||
unset($domlist);
|
||||
exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system list',$domlist);
|
||||
|
||||
foreach ($domlist as $dom)
|
||||
{
|
||||
list($dom_id,) = explode(' ',trim($dom),2);
|
||||
|
||||
if (is_numeric($dom_id))
|
||||
{
|
||||
# Fetch the Virtual Machine information.
|
||||
unset($vm_info_array);
|
||||
exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system dumpxml ' . $dom_id,$vm_info_array);
|
||||
|
||||
# <domain type='kvm' id='3'>
|
||||
# <name>moo.example.com</name>
|
||||
# <uuid>48cf6378-6fd5-4610-0611-63dd4b31cfd6</uuid>
|
||||
# <memory>1048576</memory>
|
||||
# <currentMemory>1048576</currentMemory>
|
||||
# <vcpu>8</vcpu>
|
||||
# <os>
|
||||
# <type arch='x86_64' machine='pc-0.12'>hvm</type>
|
||||
# <boot dev='hd'/>
|
||||
# </os>
|
||||
# <features>
|
||||
# <acpi/>
|
||||
# (...)
|
||||
|
||||
# Convert array to string
|
||||
unset($vm_info_xml);
|
||||
foreach ($vm_info_array as $line) { $vm_info_xml .= $line; }
|
||||
|
||||
$xml = simplexml_load_string('<?xml version="1.0"?> ' . $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)
|
||||
{
|
||||
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("+");
|
||||
# FIXME eventlog
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
# Get a list of all the known Virtual Machines for this host.
|
||||
$db_vm_list = mysql_query("SELECT id, vmwVmVMID FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='libvirt'");
|
||||
|
||||
while ($db_vm = mysql_fetch_assoc($db_vm_list))
|
||||
{
|
||||
# Delete the Virtual Machines that are removed from the host.
|
||||
|
||||
if (!in_array($db_vm["vmwVmVMID"], $libvirt_vmlist))
|
||||
{
|
||||
mysql_query("DELETE FROM vminfo WHERE id = '" . $db_vm["id"] . "'");
|
||||
echo("-");
|
||||
# FIXME eventlog
|
||||
}
|
||||
}
|
||||
|
||||
echo("\n");
|
||||
}
|
||||
|
||||
?>
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
# FIXME should do the deletion etc in a common file perhaps? like for the sensors
|
||||
|
||||
/*
|
||||
* Try to discover any Virtual Machines.
|
||||
*/
|
||||
@ -56,7 +58,7 @@ if ($device['os'] == "vmware")
|
||||
|
||||
/*
|
||||
* VMware does not return an INTEGER but a STRING of the vmwVmMemSize. This bug
|
||||
* might be resolved by VMware in the future making this code absolete.
|
||||
* might be resolved by VMware in the future making this code obsolete.
|
||||
*/
|
||||
|
||||
if (preg_match("/^([0-9]+) .*$/", $vmwVmMemSize, $matches))
|
||||
@ -68,13 +70,15 @@ if ($device['os'] == "vmware")
|
||||
* Check whether the Virtual Machine is already known for this host.
|
||||
*/
|
||||
|
||||
if (mysql_result(mysql_query("SELECT COUNT(id) FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $oid . "'"), 0) == 0)
|
||||
if (mysql_result(mysql_query("SELECT COUNT(id) FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vmwVmVMID = '" . $oid . "' AND vm_type='vmware'"), 0) == 0)
|
||||
{
|
||||
mysql_query("INSERT INTO vmware_vminfo (device_id, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState) VALUES (" . $device["device_id"] . ", " . $oid . ", '" . mres($vmwVmDisplayName) . "', '" . mres($vmwVmGuestOS) . "', " . $vmwVmMemSize . ", " . $vmwVmCpus . ", '" . mres($vmwVmState) . "')");
|
||||
mysql_query("INSERT INTO vminfo (device_id, vm_type, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState) VALUES (" . $device["device_id"] . ",'vmware', " . $oid . ", '" . mres($vmwVmDisplayName) . "', '" . mres($vmwVmGuestOS) . "', " . $vmwVmMemSize . ", " . $vmwVmCpus . ", '" . mres($vmwVmState) . "')");
|
||||
echo("+");
|
||||
# FIXME eventlog
|
||||
} else {
|
||||
echo(".");
|
||||
}
|
||||
# FIXME update code!
|
||||
|
||||
/*
|
||||
* Save the discovered Virtual Machine.
|
||||
@ -87,7 +91,7 @@ if ($device['os'] == "vmware")
|
||||
* Get a list of all the known Virtual Machines for this host.
|
||||
*/
|
||||
|
||||
$db_vm_list = mysql_query("SELECT id, vmwVmVMID FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'");
|
||||
$db_vm_list = mysql_query("SELECT id, vmwVmVMID FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='vmware'");
|
||||
|
||||
while ($db_vm = mysql_fetch_assoc($db_vm_list))
|
||||
{
|
||||
@ -95,9 +99,11 @@ if ($device['os'] == "vmware")
|
||||
* Delete the Virtual Machines that are removed from the host.
|
||||
*/
|
||||
|
||||
if (!in_array($db_vm["vmwVmVMID"], $vmw_vmlist)) {
|
||||
mysql_query("DELETE FROM vmware_vminfo WHERE id = '" . $db_vm["id"] . "'");
|
||||
if (!in_array($db_vm["vmwVmVMID"], $vmw_vmlist))
|
||||
{
|
||||
mysql_query("DELETE FROM vminfo WHERE id = '" . $db_vm["id"] . "'");
|
||||
echo("-");
|
||||
# FIXME eventlog
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ echo("VMware VM: ");
|
||||
* Get a list of all the known Virtual Machines for this host.
|
||||
*/
|
||||
|
||||
$db_info_list = mysql_query("SELECT id, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState FROM vmware_vminfo WHERE device_id = '" . $device["device_id"] . "'");
|
||||
$db_info_list = mysql_query("SELECT id, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState FROM vminfo WHERE device_id = '" . $device["device_id"] . "'");
|
||||
|
||||
while ($db_info = mysql_fetch_assoc($db_info_list))
|
||||
{
|
||||
@ -84,7 +84,7 @@ while ($db_info = mysql_fetch_assoc($db_info_list))
|
||||
|
||||
if ($vm_info[$property] != $db_info[$property])
|
||||
{
|
||||
mysql_query("UPDATE vmware_vminfo SET " . $property ." = '" . mres($vm_info[$property]) ."' WHERE id = '" . $db_info["id"] . "'");
|
||||
mysql_query("UPDATE vminfo SET " . $property ." = '" . mres($vm_info[$property]) ."' WHERE id = '" . $db_info["id"] . "'");
|
||||
log_event($db_info["vmwVmDisplayName"] . " (" . preg_replace("/^vmwVm/", "", $property) . ") -> " . $vm_info[$property], $device);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user