forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove legacy file and migrate to OS discovery
- Loading branch information
Showing
8 changed files
with
170 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
/** | ||
* VmwareEsxi.php | ||
* | ||
* -Description- | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* @link https://www.librenms.org | ||
* | ||
* @copyright 2023 Tony Murray | ||
* @author Tony Murray <murraytony@gmail.com> | ||
*/ | ||
|
||
namespace LibreNMS\OS; | ||
|
||
use App\Models\Device; | ||
use App\Models\Vminfo; | ||
use App\Observers\ModuleModelObserver; | ||
use LibreNMS\DB\SyncsModels; | ||
use LibreNMS\Enum\PowerState; | ||
|
||
class VmwareEsxi extends \LibreNMS\OS | ||
{ | ||
use SyncsModels; | ||
|
||
public function discoverOS(Device $device): void | ||
{ | ||
echo 'VMware VM: '; | ||
|
||
/* | ||
* 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 | ||
*/ | ||
|
||
$vm_info = \SnmpQuery::hideMib()->walk('VMWARE-VMINFO-MIB::vmwVmTable'); | ||
|
||
$vms = $vm_info->mapTable(function ($data, $vmwVmVMID) { | ||
$vm_data = [ | ||
'vm_type' => 'vmware', | ||
'vmwVmVMID' => $vmwVmVMID, | ||
'vmwVmDisplayName' => $data['vmwVmDisplayName'], | ||
'vmwVmGuestOS' => $data['vmwVmGuestOS'], | ||
'vmwVmMemSize' => $data['vmwVmMemSize'], | ||
'vmwVmCpus' => $data['vmwVmCpus'], | ||
'vmwVmState' => PowerState::STATES[$data['vmwVmState']] ?? PowerState::UNKNOWN, | ||
]; | ||
|
||
/* | ||
* If VMware Tools is not running then don't overwrite the GuestOS with the error | ||
* message, but just leave it as it currently is. | ||
*/ | ||
if (str_contains($vm_data['vmwVmGuestOS'], 'tools not ')) { | ||
unset($vm_data['vmwVmGuestOS']); | ||
} | ||
|
||
return new Vminfo($vm_data); | ||
}); | ||
|
||
ModuleModelObserver::observe(Vminfo::class); | ||
$this->syncModels($device, 'vminfo', $vms); | ||
|
||
echo "\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\Observers; | ||
|
||
use App\Models\Eventlog; | ||
use App\Models\Vminfo; | ||
|
||
class VminfoObserver | ||
{ | ||
/** | ||
* Handle the Vminfo "created" event. | ||
* | ||
* @param \App\Models\Vminfo $vminfo | ||
* @return void | ||
*/ | ||
public function created(Vminfo $vminfo) | ||
{ | ||
Eventlog::log($vminfo->vmwVmDisplayName . " ($vminfo->vmwVmMemSize GB / $vminfo->vmwVmCpus vCPU) Discovered", $vminfo->device_id, 'system', 3, $vminfo->vmwVmVMID); | ||
} | ||
|
||
/** | ||
* Handle the Vminfo "updated" event. | ||
* | ||
* @param \App\Models\Vminfo $vminfo | ||
* @return void | ||
*/ | ||
public function updating(Vminfo $vminfo) | ||
{ | ||
foreach ($vminfo->getDirty() as $field => $value) { | ||
Eventlog::log($vminfo->vmwVmDisplayName . ' (' . preg_replace('/^vmwVm/', '', $field) . ') -> ' . $value, $vminfo->device_id); | ||
} | ||
} | ||
|
||
/** | ||
* Handle the Vminfo "deleted" event. | ||
* | ||
* @param \App\Models\Vminfo $vminfo | ||
* @return void | ||
*/ | ||
public function deleted(Vminfo $vminfo) | ||
{ | ||
Eventlog::log($vminfo->vmwVmDisplayName . ' Removed', $vminfo->device_id, 'system', 4, $vminfo->vmwVmVMID); | ||
} | ||
|
||
/** | ||
* Handle the Vminfo "restored" event. | ||
* | ||
* @param \App\Models\Vminfo $vminfo | ||
* @return void | ||
*/ | ||
public function restored(Vminfo $vminfo) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Handle the Vminfo "force deleted" event. | ||
* | ||
* @param \App\Models\Vminfo $vminfo | ||
* @return void | ||
*/ | ||
public function forceDeleted(Vminfo $vminfo) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.