2011-03-26 17:16:09 +00:00
< ? php
2012-05-25 12:24:34 +00:00
// FIXME should do the deletion etc in a common file perhaps? like for the sensors
2011-03-26 17:16:09 +00:00
/*
* Try to discover any Virtual Machines .
*/
2015-07-13 20:10:26 +02:00
if (( $device [ 'os' ] == 'vmware' ) || ( $device [ 'os' ] == 'linux' )) {
/*
* Variable to hold the discovered Virtual Machines .
*/
2012-05-07 16:23:43 +00:00
2015-07-13 20:10:26 +02:00
$vmw_vmlist = array ();
2011-03-26 19:12:24 +00:00
2015-07-13 20:10:26 +02:00
/*
* CONSOLE : Start the VMware discovery process .
*/
echo 'VMware VM: ' ;
2011-03-26 19:12:24 +00:00
2011-03-26 17:16:09 +00:00
/*
2016-01-05 12:33:10 -08:00
* Fetch information about Virtual Machines .
2011-03-26 17:16:09 +00:00
*/
2011-03-26 19:12:24 +00:00
2016-01-05 12:33:10 -08:00
$oids = snmpwalk_cache_multi_oid ( $device , 'vmwVmTable' , $oids , '+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB' , '+' . $config [ 'mib_dir' ] . '/vmware:' . $config [ 'mib_dir' ]);
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' , $vmid );
echo '+' ;
// FIXME eventlog
}
else {
echo '.' ;
}
2011-03-26 19:12:24 +00:00
2016-01-05 12:33:10 -08:00
/*
* Save the discovered Virtual Machine .
*/
$vmw_vmlist [] = $index ;
}
2015-07-13 20:10:26 +02:00
/*
* 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 .
*/
2012-05-07 16:23:43 +00:00
2015-07-13 20:10:26 +02:00
if ( ! in_array ( $db_vm [ 'vmwVmVMID' ], $vmw_vmlist )) {
dbDelete ( 'vminfo' , '`id` = ?' , array ( $db_vm [ 'id' ]));
log_event ( mres ( $db_vm [ 'vmwVmDisplayName' ]) . ' Removed' , $device , 'system' , $db_vm [ 'vmwVmVMID' ]);
echo '-' ;
// FIXME eventlog
}
}
/*
* Finished discovering VMware information .
*/
2012-05-07 16:23:43 +00:00
2015-07-13 20:10:26 +02:00
echo " \n " ;
} //end if