Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2011-03-26 17:16:09 +00:00
<?php
use LibreNMS\Enum\PowerState;
2011-03-26 17:16:09 +00:00
/*
* CONSOLE: Start the VMware discovery process.
*/
echo 'VMware VM: ';
/*
* Get a list of all the known Virtual Machines for this host.
*/
2020-09-21 15:43:38 +02:00
$db_info_list = dbFetchRows('SELECT id, vmwVmVMID, vmwVmDisplayName, vmwVmGuestOS, vmwVmMemSize, vmwVmCpus, vmwVmState FROM vminfo WHERE device_id = ?', [$device['device_id']]);
$current_vminfo = snmpwalk_cache_multi_oid($device, 'vmwVmTable', [], '+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB', 'vmware');
2015-07-13 20:10:26 +02:00
2011-05-17 21:14:28 +00:00
foreach ($db_info_list as $db_info) {
2011-03-26 19:12:24 +00:00
/*
* Fetch the Virtual Machine information.
*
* VMWARE-VMINFO-MIB::vmwVmDisplayName.224 = STRING: My First VM
* VMWARE-VMINFO-MIB::vmwVmGuestOS.224 = STRING: windows7Server64Guest
* VMWARE-VMINFO-MIB::vmwVmMemSize.224 = INTEGER: 8192 megabytes
* VMWARE-VMINFO-MIB::vmwVmState.224 = STRING: poweredOn
* VMWARE-VMINFO-MIB::vmwVmVMID.224 = INTEGER: 224
* VMWARE-VMINFO-MIB::vmwVmCpus.224 = INTEGER: 2
*/
2015-07-13 20:10:26 +02:00
2020-09-21 15:43:38 +02:00
$vm_info = [];
2015-07-13 20:10:26 +02:00
$vm_info['vmwVmDisplayName'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmDisplayName'];
2020-09-21 15:43:38 +02:00
$vm_info['vmwVmGuestOS'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmGuestOS'];
$vm_info['vmwVmMemSize'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmMemSize'];
$vm_info['vmwVmState'] = PowerState::STATES[$current_vminfo[$db_info['vmwVmVMID']]['vmwVmState']] ?? PowerState::UNKNOWN;
2020-09-21 15:43:38 +02:00
$vm_info['vmwVmCpus'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmCpus'];
2015-07-13 20:10:26 +02:00
2011-03-26 19:12:24 +00:00
/*
* 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.
*/
2015-07-13 20:10:26 +02:00
2011-03-26 19:12:24 +00:00
if (preg_match('/^([0-9]+) .*$/', $vm_info['vmwVmMemSize'], $matches)) {
$vm_info['vmwVmMemSize'] = $matches[1];
}
2015-07-13 20:10:26 +02:00
2011-03-26 19:12:24 +00:00
/*
* If VMware Tools is not running then don't overwrite the GuesOS with the error
* message, but just leave it as it currently is.
*/
if (stristr($vm_info['vmwVmGuestOS'], 'tools not running') !== false) {
$vm_info['vmwVmGuestOS'] = $db_info['vmwVmGuestOS'];
}
2015-07-13 20:10:26 +02:00
2011-03-26 17:16:09 +00:00
/*
2011-03-26 19:12:24 +00:00
* Process all the VMware Virtual Machine properties.
2011-03-26 17:16:09 +00:00
*/
2011-03-26 19:12:24 +00:00
foreach ($vm_info as $property => $value) {
2015-07-13 20:10:26 +02:00
/*
2011-03-26 19:12:24 +00:00
* Check the property for any modifications.
2015-07-13 20:10:26 +02:00
*/
2011-05-17 21:14:28 +00:00
2011-03-26 19:12:24 +00:00
if ($vm_info[$property] != $db_info[$property]) {
2012-05-25 12:24:34 +00:00
// FIXME - this should loop building a query and then run the query after the loop (bad geert!)
2020-09-21 15:43:38 +02:00
dbUpdate([$property => $vm_info[$property]], 'vminfo', '`id` = ?', [$db_info['id']]);
if ($db_info['vmwVmDisplayName'] != null) {
log_event($db_info['vmwVmDisplayName'] . ' (' . preg_replace('/^vmwVm/', '', $property) . ') -> ' . $vm_info[$property], $device, null, 3);
}
2015-07-13 20:10:26 +02:00
}
2011-03-26 17:16:09 +00:00
}
}//end foreach
/*
* Finished discovering VMware information.
*/
echo "\n";