mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
libvirt discovery now should no longer block discovery runs
git-svn-id: http://www.observium.org/svn/observer/trunk@2050 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -129,7 +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 - DO NOT ENABLE (!BREAKAGE!)
|
||||
$config['enable_libvirt'] = 0; # Enable Libvirt VM support
|
||||
|
||||
### Ports extension modules
|
||||
|
||||
|
||||
@@ -13,82 +13,98 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
|
||||
# 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)
|
||||
$ok = 0;
|
||||
if (strstr($method,'ssh'))
|
||||
{
|
||||
list($dom_id,) = explode(' ',trim($dom),2);
|
||||
# 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 (is_numeric($dom_id))
|
||||
if ($ok)
|
||||
{
|
||||
# Fetch virtual machine list
|
||||
unset($domlist);
|
||||
exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system 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);
|
||||
|
||||
# <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)
|
||||
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("+");
|
||||
# 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(".");
|
||||
}
|
||||
}
|
||||
# Fetch the Virtual Machine information.
|
||||
unset($vm_info_array);
|
||||
exec($config['virsh'] . ' -c '.$method.'://' . $device['hostname'] . '/system dumpxml ' . $dom_id,$vm_info_array);
|
||||
|
||||
# Save the discovered Virtual Machine.
|
||||
$libvirt_vmlist[] = $dom_id;
|
||||
# <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("+");
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 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'");
|
||||
$db_vm_list = mysql_query("SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '" . $device["device_id"] . "' AND vm_type='libvirt'");
|
||||
|
||||
while ($db_vm = mysql_fetch_assoc($db_vm_list))
|
||||
{
|
||||
@@ -98,7 +114,7 @@ if ($config['enable_libvirt'] == '1' && $device['os'] == "linux" )
|
||||
{
|
||||
mysql_query("DELETE FROM vminfo WHERE id = '" . $db_vm["id"] . "'");
|
||||
echo("-");
|
||||
# FIXME eventlog
|
||||
log_event("Virtual Machine removed: " . $db_vm['vmwVmDisplayName'], $device, 'vm', $db_vm['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ if ($vlanversion == 'version1')
|
||||
{
|
||||
echo("VLAN $vlanversion ");
|
||||
|
||||
$vlans = snmp_walk($device, "dot1qVlanFdbId", $snmpoptions = "-Oqn", $mib = "Q-BRIDGE-MIB");
|
||||
$vlans = snmp_walk($device, "dot1qVlanFdbId", "-Oqn", "Q-BRIDGE-MIB");
|
||||
|
||||
foreach (explode("\n", $vlans) as $vlan_oid)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user