librenms/includes/discovery/vmware-vminfo.inc.php
Tony Murray eeb3d58f5b Improved Logging and Debugging (#8870)
Use Log facility when Laravel is booted.
Update init.php so we can easily boot Laravel for CLI scripts. (and just Eloquent, but that may go away)
Move all debug setup into set_debug() function and use that across all scripts.
Log Laravel database queries.
Send debug output to librenms log file when enabling debug in the webui.
Allow for colorized Log CLI output. (currently will leave % tags in log file output)

** Needs testing and perhaps tweaking still.

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
2018-07-13 23:08:00 +01:00

84 lines
2.8 KiB
PHP

<?php
// FIXME should do the deletion etc in a common file perhaps? like for the sensors
/*
* Try to discover any Virtual Machines.
*/
if (($device['os'] == 'vmware') || ($device['os'] == 'linux')) {
/*
* Variable to hold the discovered Virtual Machines.
*/
$vmw_vmlist = array();
/*
* CONSOLE: Start the VMware discovery process.
*/
/*
* Fetch information about Virtual Machines.
*/
$oids = snmpwalk_cache_multi_oid($device, 'vmwVmTable', [], '+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB', 'vmware');
foreach ($oids as $index => $entry) {
$vmwVmDisplayName = $entry['vmwVmDisplayName'];
$vmwVmGuestOS = $entry['vmwVmGuestOS'];
$vmwVmMemSize = $entry['vmwVmMemSize'];
$vmwVmState = $entry['vmwVmState'];
$vmwVmCpus = $entry['vmwVmCpus'];
/*
* 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 obsolete.
*/
if (preg_match('/^([0-9]+) .*$/', $vmwVmMemSize, $matches)) {
$vmwVmMemSize = $matches[1];
}
/*
* Check whether the Virtual Machine is already known for this host.
*/
if (dbFetchCell("SELECT COUNT(id) FROM `vminfo` WHERE `device_id` = ? AND `vmwVmVMID` = ? AND vm_type='vmware'", array($device['device_id'], $index)) == 0) {
$vmid = dbInsert(array('device_id' => $device['device_id'], 'vm_type' => 'vmware', 'vmwVmVMID' => $index, 'vmwVmDisplayName' => mres($vmwVmDisplayName), 'vmwVmGuestOS' => mres($vmwVmGuestOS), 'vmwVmMemSize' => mres($vmwVmMemSize), 'vmwVmCpus' => mres($vmwVmCpus), 'vmwVmState' => mres($vmwVmState)), 'vminfo');
log_event(mres($vmwVmDisplayName) . " ($vmwVmMemSize GB / $vmwVmCpus vCPU) Discovered", $device, 'system', 3, $vmid);
echo '+';
// FIXME eventlog
} else {
echo '.';
}
/*
* Save the discovered Virtual Machine.
*/
$vmw_vmlist[] = $index;
}
/*
* Get a list of all the known Virtual Machines for this host.
*/
$sql = "SELECT id, vmwVmVMID, vmwVmDisplayName FROM vminfo WHERE device_id = '".$device['device_id']."' AND vm_type='vmware'";
foreach (dbFetchRows($sql) as $db_vm) {
/*
* Delete the Virtual Machines that are removed from the host.
*/
if (!in_array($db_vm['vmwVmVMID'], $vmw_vmlist)) {
dbDelete('vminfo', '`id` = ?', array($db_vm['id']));
log_event(mres($db_vm['vmwVmDisplayName']) . ' Removed', $device, 'system', 4, $db_vm['vmwVmVMID']);
echo '-';
// FIXME eventlog
}
}
/*
* Finished discovering VMware information.
*/
echo "\n";
}//end if