From cfd9dce620f7205357e96cf22d65d6ad26759d69 Mon Sep 17 00:00:00 2001 From: Jellyfrog Date: Wed, 11 Nov 2020 01:15:20 +0100 Subject: [PATCH] Convert Virtual Machine pages to Laravel (#12287) * Convert Virtual Machine pages to Laravel * wip * wip * wip * wip * wip * wip * delete * wip * wip * move powerStateLabel --- LibreNMS/Enum/PowerState.php | 39 ++++++++ .../Snmptrap/Handlers/VmwVmPoweredOff.php | 3 +- LibreNMS/Snmptrap/Handlers/VmwVmPoweredOn.php | 3 +- LibreNMS/Snmptrap/Handlers/VmwVmSuspended.php | 3 +- LibreNMS/Util/Html.php | 20 ++++ LibreNMS/Util/Rewrite.php | 30 ++++++ .../Device/Tabs/VmInfoController.php | 13 ++- app/Http/Controllers/DeviceController.php | 2 +- .../Controllers/Table/VminfoController.php | 79 ++++++++++++++++ app/Models/Vminfo.php | 45 +++++++++ database/factories/VminfoFactory.php | 3 +- ...2_164331_add_powerstate_enum_to_vminfo.php | 45 +++++++++ includes/common.php | 21 +---- includes/discovery/libvirt-vminfo.inc.php | 3 +- includes/discovery/vmware-vminfo.inc.php | 4 +- includes/html/forms/get-vmlist.inc.php | 68 -------------- includes/html/pages/device/vm.inc.php | 12 --- includes/html/pages/vminfo.inc.php | 92 ------------------- includes/html/print-vm.inc.php | 36 -------- includes/polling/os/vmware-esxi.inc.php | 4 +- misc/db_schema.yaml | 2 +- resources/views/device/tabs/vminfo.blade.php | 37 ++++++++ resources/views/vminfo.blade.php | 34 +++++++ routes/web.php | 2 + 24 files changed, 363 insertions(+), 237 deletions(-) create mode 100644 LibreNMS/Enum/PowerState.php create mode 100644 app/Http/Controllers/Table/VminfoController.php create mode 100644 database/migrations/2020_11_02_164331_add_powerstate_enum_to_vminfo.php delete mode 100644 includes/html/forms/get-vmlist.inc.php delete mode 100644 includes/html/pages/device/vm.inc.php delete mode 100644 includes/html/pages/vminfo.inc.php create mode 100644 resources/views/device/tabs/vminfo.blade.php create mode 100644 resources/views/vminfo.blade.php diff --git a/LibreNMS/Enum/PowerState.php b/LibreNMS/Enum/PowerState.php new file mode 100644 index 0000000000..666bef7733 --- /dev/null +++ b/LibreNMS/Enum/PowerState.php @@ -0,0 +1,39 @@ +. + */ + +namespace LibreNMS\Enum; + +abstract class PowerState +{ + const OFF = 0; + const ON = 1; + const SUSPENDED = 2; + const UNKNOWN = 3; + + const STATES = [ + 'powered off' => self::OFF, + 'shut off' => self::OFF, + + 'powered on' => self::ON, + 'running' => self::ON, + + 'suspended' => self::SUSPENDED, + 'paused' => self::SUSPENDED, + ]; +} diff --git a/LibreNMS/Snmptrap/Handlers/VmwVmPoweredOff.php b/LibreNMS/Snmptrap/Handlers/VmwVmPoweredOff.php index b8312d3660..0529fe11d9 100644 --- a/LibreNMS/Snmptrap/Handlers/VmwVmPoweredOff.php +++ b/LibreNMS/Snmptrap/Handlers/VmwVmPoweredOff.php @@ -27,6 +27,7 @@ namespace LibreNMS\Snmptrap\Handlers; use App\Models\Device; +use LibreNMS\Enum\PowerState; use LibreNMS\Interfaces\SnmptrapHandler; use LibreNMS\Snmptrap\Trap; use Log; @@ -46,7 +47,7 @@ class VmwVmPoweredOff implements SnmptrapHandler $vmGuestName = VmwTrapUtil::getGuestName($trap); $vminfo = $device->vminfo()->where('vmwVmDisplayName', $vmGuestName)->first(); - $vminfo->vmwVmState = 'powered off'; + $vminfo->vmwVmState = PowerState::OFF; Log::event("Guest $vmGuestName was powered off", $device->device_id, 'trap', 2); diff --git a/LibreNMS/Snmptrap/Handlers/VmwVmPoweredOn.php b/LibreNMS/Snmptrap/Handlers/VmwVmPoweredOn.php index 413747bfc5..2bcb6f6c98 100644 --- a/LibreNMS/Snmptrap/Handlers/VmwVmPoweredOn.php +++ b/LibreNMS/Snmptrap/Handlers/VmwVmPoweredOn.php @@ -27,6 +27,7 @@ namespace LibreNMS\Snmptrap\Handlers; use App\Models\Device; +use LibreNMS\Enum\PowerState; use LibreNMS\Interfaces\SnmptrapHandler; use LibreNMS\Snmptrap\Trap; use Log; @@ -46,7 +47,7 @@ class VmwVmPoweredOn implements SnmptrapHandler $vmGuestName = VmwTrapUtil::getGuestName($trap); $vminfo = $device->vminfo()->where('vmwVmDisplayName', $vmGuestName)->first(); - $vminfo->vmwVmState = 'powered on'; + $vminfo->vmwVmState = PowerState::ON; Log::event("Guest $vmGuestName was powered on", $device->device_id, 'trap', 2); diff --git a/LibreNMS/Snmptrap/Handlers/VmwVmSuspended.php b/LibreNMS/Snmptrap/Handlers/VmwVmSuspended.php index ccfa0c54b6..9aa3e1c540 100644 --- a/LibreNMS/Snmptrap/Handlers/VmwVmSuspended.php +++ b/LibreNMS/Snmptrap/Handlers/VmwVmSuspended.php @@ -27,6 +27,7 @@ namespace LibreNMS\Snmptrap\Handlers; use App\Models\Device; +use LibreNMS\Enum\PowerState; use LibreNMS\Interfaces\SnmptrapHandler; use LibreNMS\Snmptrap\Trap; use Log; @@ -46,7 +47,7 @@ class VmwVmSuspended implements SnmptrapHandler $vmGuestName = VmwTrapUtil::getGuestName($trap); $vminfo = $device->vminfo()->where('vmwVmDisplayName', $vmGuestName)->first(); - $vminfo->vmwVmState = 'suspended'; + $vminfo->vmwVmState = PowerState::SUSPENDED; Log::event("Guest $vmGuestName has been suspended", $device->device_id, 'trap', 2); diff --git a/LibreNMS/Util/Html.php b/LibreNMS/Util/Html.php index df7719d1d8..72ba5e0403 100644 --- a/LibreNMS/Util/Html.php +++ b/LibreNMS/Util/Html.php @@ -25,6 +25,7 @@ namespace LibreNMS\Util; use LibreNMS\Config; +use LibreNMS\Enum\PowerState; class Html { @@ -154,4 +155,23 @@ class Html return $output; } + + /** + * @param int|string $state + */ + public static function powerStateLabel($state): array + { + $state = is_string($state) ? PowerState::STATES[$state] : $state; + + switch ($state) { + case PowerState::OFF: + return ['OFF', 'label-default']; + case PowerState::ON: + return ['ON', 'label-success']; + case PowerState::SUSPENDED: + return ['SUSPENDED', 'label-warning']; + default: + return ['UNKNOWN', 'label-default']; + } + } } diff --git a/LibreNMS/Util/Rewrite.php b/LibreNMS/Util/Rewrite.php index 6eb251b852..ad8064a00f 100644 --- a/LibreNMS/Util/Rewrite.php +++ b/LibreNMS/Util/Rewrite.php @@ -410,4 +410,34 @@ class Rewrite { return str_pad($num, $length, '0', STR_PAD_LEFT); } + + public static function formatStorage($value, int $round = 2, int $sf = 3): string + { + $value = self::format_bi($value, $round, $sf) . 'B'; + + return $value; + } + + public static function format_bi($value, int $round = 2, int $sf = 3): string + { + $neg = false; + $sizes = ['', 'k', 'M', 'G', 'T', 'P', 'E']; + $ext = $sizes[0]; + + if ($value < 0) { + $neg = true; + $value = $value * -1; + } + + for ($i = 1; (($i < count($sizes)) && ($value >= 1024)); $i++) { + $value = $value / 1024; + $ext = $sizes[$i]; + } + + if ($neg) { + $value = $value * -1; + } + + return (number_format(round($value, $round), $sf, '.', '') + 0) . ' ' . $ext; + } } diff --git a/app/Http/Controllers/Device/Tabs/VmInfoController.php b/app/Http/Controllers/Device/Tabs/VmInfoController.php index 9d6b6533e9..6d151dd68b 100644 --- a/app/Http/Controllers/Device/Tabs/VmInfoController.php +++ b/app/Http/Controllers/Device/Tabs/VmInfoController.php @@ -51,6 +51,17 @@ class VmInfoController implements DeviceTab public function data(Device $device): array { - return []; + return [ + 'vms' => self::getVms($device), + ]; + } + + private static function getVms(Device $device) + { + return $device->vmInfo() + ->select('vmwVmDisplayName', 'vmwVmState', 'vmwVmGuestOS', 'vmwVmMemSize', 'vmwVmCpus') + ->with('parentDevice') + ->orderBy('vmwVmDisplayName') + ->get(); } } diff --git a/app/Http/Controllers/DeviceController.php b/app/Http/Controllers/DeviceController.php index d962ff1e43..0a5e66d9e7 100644 --- a/app/Http/Controllers/DeviceController.php +++ b/app/Http/Controllers/DeviceController.php @@ -79,7 +79,7 @@ class DeviceController extends Controller } $alert_class = $device->disabled ? 'alert-info' : ($device->status ? '' : 'alert-danger'); - $parent_id = Vminfo::query()->whereIn('vmwVmDisplayName', [$device->hostname, $device->hostname . '.' . Config::get('mydomain')])->value('device_id'); + $parent_id = Vminfo::guessFromDevice($device)->value('device_id'); $overview_graphs = $this->buildDeviceGraphArrays($device); $tabs = array_map(function ($class) { diff --git a/app/Http/Controllers/Table/VminfoController.php b/app/Http/Controllers/Table/VminfoController.php new file mode 100644 index 0000000000..5d4af69bd3 --- /dev/null +++ b/app/Http/Controllers/Table/VminfoController.php @@ -0,0 +1,79 @@ +. + * + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +namespace App\Http\Controllers\Table; + +use App\Models\Device; +use App\Models\Vminfo; +use LibreNMS\Util\Url; + +class VminfoController extends TableController +{ + public function searchFields($request) + { + return ['vmwVmDisplayName', 'vmwVmGuestOS', 'devices.hostname', 'devices.sysname']; + } + + public function sortFields($request) + { + return ['vmwVmDisplayName', 'vmwVmGuestOS', 'vmwVmMemSize', 'vmwVmCpus', 'vmwVmState', 'hostname']; + } + + /** + * Defines the base query for this resource + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder + */ + public function baseQuery($request) + { + return Vminfo::hasAccess($request->user()) + ->select('vminfo.*') + ->with('device') + ->with('parentDevice') + ->when($request->get('searchPhrase') || in_array('hostname', array_keys($request->get('sort', []))), function ($query) { + $query->leftJoin('devices', 'devices.device_id', 'vminfo.device_id'); + }); + } + + public function formatItem($vm) + { + return [ + 'vmwVmState' => '' . $vm->stateLabel[0] . '', + 'vmwVmDisplayName' => is_null($vm->parentDevice) ? $vm->vmwVmDisplayName : self::getHostname($vm->parentDevice), + 'vmwVmGuestOS' => $vm->operatingSystem, + 'vmwVmMemSize' => $vm->memoryFormatted, + 'vmwVmCpus' => $vm->vmwVmCpus, + 'hostname' => self::getHostname($vm->device), + 'deviceid' => $vm->device_id, + 'sysname' => $vm->device->sysName, + + ]; + } + + private static function getHostname(Device $device): string + { + return '' . $device->hostname . '
' . $device->sysName; + } +} diff --git a/app/Models/Vminfo.php b/app/Models/Vminfo.php index 367467ba1b..14c91843a5 100644 --- a/app/Models/Vminfo.php +++ b/app/Models/Vminfo.php @@ -2,7 +2,13 @@ namespace App\Models; +use Config; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Support\Str; +use LibreNMS\Util\Html; +use LibreNMS\Util\Rewrite; class Vminfo extends DeviceRelatedModel { @@ -10,4 +16,43 @@ class Vminfo extends DeviceRelatedModel protected $table = 'vminfo'; public $timestamps = false; + + public function getStateLabelAttribute(): string + { + return Html::powerStateLabel($this->vmwVmState); + } + + public function getMemoryFormattedAttribute(): string + { + return Rewrite::formatStorage($this->vmwVmMemSize * 1024 * 1024); + } + + public function getOperatingSystemAttribute(): string + { + if (Str::contains($this->vmwVmGuestOS, 'tools not installed')) { + return 'Unknown (VMware Tools not installed)'; + } elseif (Str::contains($this->vmwVmGuestOS, 'tools not running')) { + return 'Unknown (VMware Tools not running)'; + } elseif (empty($this->vmwVmGuestOS)) { + return '(Unknown)'; + } else { + return Rewrite::vmwareGuest($this->vmwVmGuestOS); + } + } + + public function scopeGuessFromDevice(Builder $query, Device $device): Builder + { + $where = [$device->hostname]; + + if (Config::get('mydomain')) { + $where[] = $device->hostname . '.' . Config::get('mydomain'); + } + + return $query->whereIn('vmwVmDisplayName', $where); + } + + public function parentDevice(): HasOne + { + return $this->hasOne('App\Models\Device', 'hostname', 'vmwVmDisplayName'); + } } diff --git a/database/factories/VminfoFactory.php b/database/factories/VminfoFactory.php index d7fd19ad5c..a0753589f9 100644 --- a/database/factories/VminfoFactory.php +++ b/database/factories/VminfoFactory.php @@ -4,6 +4,7 @@ namespace Database\Factories; use App\Models\Vminfo; use Illuminate\Database\Eloquent\Factories\Factory; +use LibreNMS\Enum\PowerState; class VminfoFactory extends Factory { @@ -28,7 +29,7 @@ class VminfoFactory extends Factory 'vmwVmGuestOS' => $this->faker->text(128), 'vmwVmMemSize' => $this->faker->randomDigit, 'vmwVmCpus' => $this->faker->randomDigit, - 'vmwVmState' => $this->faker->randomElement(['powered on', 'powered off', 'suspended']), + 'vmwVmState' => $this->faker->randomElement([PowerState::OFF, PowerState::ON, PowerState::SUSPENDED, PowerState::UNKNOWN]), ]; } } diff --git a/database/migrations/2020_11_02_164331_add_powerstate_enum_to_vminfo.php b/database/migrations/2020_11_02_164331_add_powerstate_enum_to_vminfo.php new file mode 100644 index 0000000000..0fd4c133da --- /dev/null +++ b/database/migrations/2020_11_02_164331_add_powerstate_enum_to_vminfo.php @@ -0,0 +1,45 @@ +chunk(100, function ($vms) { + foreach ($vms as $vm) { + if (is_numeric($vm->vmwVmState)) { + continue; + } + + $vm->vmwVmState = PowerState::STATES[strtolower($vm->vmwVmState)]; + $vm->update(); + } + }); + + Schema::table('vminfo', function (Blueprint $table) { + $table->smallInteger('vmwVmState')->unsigned()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('vminfo', function (Blueprint $table) { + $table->string('vmwVmState', 128)->change(); + }); + } +} diff --git a/includes/common.php b/includes/common.php index 95a0fcf692..56531ad18e 100644 --- a/includes/common.php +++ b/includes/common.php @@ -489,9 +489,7 @@ function formatRates($value, $round = '2', $sf = '3') function formatStorage($value, $round = '2', $sf = '3') { - $value = format_bi($value, $round) . 'B'; - - return $value; + return \LibreNMS\Util\Rewrite::formatStorage($value, $round, $sf); } function format_si($value, $round = '2', $sf = '3') @@ -527,22 +525,7 @@ function format_si($value, $round = '2', $sf = '3') function format_bi($value, $round = '2', $sf = '3') { - if ($value < '0') { - $neg = 1; - $value = $value * -1; - } - $sizes = ['', 'k', 'M', 'G', 'T', 'P', 'E']; - $ext = $sizes[0]; - for ($i = 1; (($i < count($sizes)) && ($value >= 1024)); $i++) { - $value = $value / 1024; - $ext = $sizes[$i]; - } - - if ($neg) { - $value = $value * -1; - } - - return (number_format(round($value, $round), $sf, '.', '') + 0) . ' ' . $ext; + return \LibreNMS\Util\Rewrite::format_bi($value, $round, $sf); } function format_number($value, $base = '1000', $round = 2, $sf = 3) diff --git a/includes/discovery/libvirt-vminfo.inc.php b/includes/discovery/libvirt-vminfo.inc.php index 356bb80438..b3e8744799 100644 --- a/includes/discovery/libvirt-vminfo.inc.php +++ b/includes/discovery/libvirt-vminfo.inc.php @@ -2,6 +2,7 @@ use Illuminate\Support\Str; use LibreNMS\Config; +use LibreNMS\Enum\PowerState; // FIXME should do the deletion etc in a common file perhaps? like for the sensors // Try to discover Libvirt Virtual Machines. @@ -73,7 +74,7 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') { $vmwVmGuestOS = ''; // libvirt does not supply this exec(Config::get('virsh') . ' -rc ' . $uri . ' domstate ' . $dom_id, $vm_state); - $vmwVmState = ucfirst($vm_state[0]); + $vmwVmState = PowerState::STATES[strtolower($vm_state[0])] ?? PowerState::UNKNOWN; unset($vm_state); $vmwVmCpus = $xml->vcpu['current']; diff --git a/includes/discovery/vmware-vminfo.inc.php b/includes/discovery/vmware-vminfo.inc.php index 9e9719c2ec..dfea282ad6 100644 --- a/includes/discovery/vmware-vminfo.inc.php +++ b/includes/discovery/vmware-vminfo.inc.php @@ -1,5 +1,7 @@ - * - * 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. Please see LICENSE.txt at the top level of - * the source code distribution for details. - * @package LibreNMS - * @subpackage webui - * @link http://librenms.org - * @copyright 2018 Aldemir Akpinar - * @author Aldemir Akpinar - */ - -$vm_query = 'SELECT v.vmwVmDisplayName AS vmname, v.vmwVmState AS powerstat, v.device_id AS deviceid, d.hostname AS physicalsrv, d.sysname AS sysname, v.vmwVmGuestOS AS os, v.vmwVmMemSize AS memory, v.vmwVmCpus AS cpu FROM vminfo AS v LEFT JOIN devices AS d ON v.device_id = d.device_id'; - -$param = []; -if (! Auth::user()->hasGlobalRead()) { - $vm_query .= ' LEFT JOIN devices_perms AS DP ON d.device_id = DP.device_id'; - $uidwhere = ' AND DP.user_id = ?'; - $uid = [Auth::id()]; -} else { - $uidwhere = ''; - $uid = []; -} - -if (isset($vars['searchPhrase']) && ! empty($vars['searchPhrase'])) { - $vm_query .= ' WHERE v.vmwVmDisplayName LIKE ? OR d.hostname LIKE ? OR v.vmwVmGuestOS LIKE ? OR d.sysname LIKE ?' . $uidwhere; - $count_query = 'SELECT COUNT(v.vmwVmDisplayName) FROM vminfo AS v LEFT JOIN devices AS d ON v.device_id = d.device_id WHERE v.vmwVmDisplayName LIKE ? OR d.hostname LIKE ? OR v.vmwVmGuestOS LIKE ? OR d.sysname LIKE ?' . $uidwhere; - $searchphrase = '%' . $vars['searchPhrase'] . '%'; - array_push($param, $searchphrase, $searchphrase, $searchphrase, $searchphrase, $uid); -} else { - $count_query = 'SELECT COUNT(*) FROM vminfo '; -} - -$order_by = ''; -if (isset($vars['sort']) && is_array($vars['sort'])) { - foreach ($vars['sort'] as $key => $value) { - $order_by .= " $key $value"; - } -} else { - $order_by = ' vmname'; -} - -$vm_query .= ' ORDER BY ' . $order_by; - -if (is_numeric($vars['rowCount']) && is_numeric($vars['current'])) { - $rowcount = $vars['rowCount']; - $current = $vars['current']; - $vm_query .= ' LIMIT ' . $rowcount * ($current - 1) . ', ' . $rowcount; -} - -if (isset($vars['searchPhrase']) && ! empty($vars['searchPhrase'])) { - $vm_arr = dbFetchRows($vm_query, $param); - $rec_count = dbFetchCell($count_query, $param); -} else { - $vm_arr = dbFetchRows($vm_query); - $rec_count = dbFetchCell($count_query); -} - -$status = ['current' => $current, 'rowCount' => $rowcount, 'rows' => $vm_arr, 'total' => $rec_count]; - -header('Content-Type: application/json'); -echo _json_encode($status); diff --git a/includes/html/pages/device/vm.inc.php b/includes/html/pages/device/vm.inc.php deleted file mode 100644 index 0f5c124a0d..0000000000 --- a/includes/html/pages/device/vm.inc.php +++ /dev/null @@ -1,12 +0,0 @@ -Server NamePower StatusOperating SystemMemoryCPU'; -$i = '1'; - -foreach (dbFetchRows('SELECT `vmwVmDisplayName`,`vmwVmState`,`vmwVmGuestOS`,`vmwVmMemSize`,`vmwVmCpus` FROM `vminfo` WHERE `device_id` = ? ORDER BY `vmwVmDisplayName`', [$device['device_id']]) as $vm) { - include 'includes/html/print-vm.inc.php'; - $i++; -} - -echo ''; -$pagetitle[] = 'Virtual Machines'; diff --git a/includes/html/pages/vminfo.inc.php b/includes/html/pages/vminfo.inc.php deleted file mode 100644 index 2bdf96b01f..0000000000 --- a/includes/html/pages/vminfo.inc.php +++ /dev/null @@ -1,92 +0,0 @@ - - * - * 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. Please see LICENSE.txt at the top level of - * the source code distribution for details. - * @package LibreNMS - * @subpackage webui - * @link http://librenms.org - * @copyright 2018 Aldemir Akpinar - * @author Aldemir Akpinar - */ - -$pagetitle[] = 'Virtual Machines'; -?> -
- - - - - - - - - - - - - - - -
NoSysnameServer NamePower StatusPhysical ServerOperating SystemMemoryCPU
-
- diff --git a/includes/html/print-vm.inc.php b/includes/html/print-vm.inc.php index 7fe0da6c15..e69de29bb2 100644 --- a/includes/html/print-vm.inc.php +++ b/includes/html/print-vm.inc.php @@ -1,36 +0,0 @@ -'; -echo ''; - -if (getidbyname($vm['vmwVmDisplayName'])) { - echo generate_device_link(device_by_name($vm['vmwVmDisplayName'])); -} else { - echo $vm['vmwVmDisplayName']; -} - -echo ''; - -if ($vm['vmwVmState'] == 'powered off' || $vm['vmwVmState'] == 'Shut off') { - echo 'OFF'; -} elseif ($vm['vmwVmState'] == 'powered on' || $vm['vmwVmState'] == 'Running') { - echo 'ON'; -} elseif ($vm['vmwVmState'] == 'suspended' || $vm['vmwVmState'] == 'Paused') { - echo 'SUSPEND'; -} - -if ($vm['vmwVmGuestOS'] == 'E: tools not installed') { - echo 'Unknown (VMware Tools not installed)'; -} elseif ($vm['vmwVmGuestOS'] == '') { - echo '(Unknown)'; -} else { - echo '' . \LibreNMS\Util\Rewrite::vmwareGuest($vm['vmwVmGuestOS']) . ''; -} - -if ($vm['vmwVmMemSize'] >= 1024) { - echo '' . sprintf('%.2f', ($vm['vmwVmMemSize'] / 1024)) . ' GB'; -} else { - echo '' . sprintf('%.2f', $vm['vmwVmMemSize']) . ' MB'; -} - -echo '' . $vm['vmwVmCpus'] . ' CPU'; diff --git a/includes/polling/os/vmware-esxi.inc.php b/includes/polling/os/vmware-esxi.inc.php index 4c43ee4803..470ae61c50 100644 --- a/includes/polling/os/vmware-esxi.inc.php +++ b/includes/polling/os/vmware-esxi.inc.php @@ -1,5 +1,7 @@ + + + @lang('Server Name') + @lang('Power Status') + @lang('Operating System') + @lang('Memory') + @lang('CPU') + + + + @foreach($data['vms'] as $vm) + + + @if ($vm->parentDevice) + @deviceLink($vm->parentDevice) + @else + {{ $vm->vmwVmDisplayName }} + @endif + + + {{ $vm->stateLabel[0] }} + + {{ $vm->operatingSystem }} + {{ $vm->memoryFormatted }} + {{ $vm->vmwVmCpus }} + + @endforeach + + +@endsection + + + diff --git a/resources/views/vminfo.blade.php b/resources/views/vminfo.blade.php new file mode 100644 index 0000000000..51e474535e --- /dev/null +++ b/resources/views/vminfo.blade.php @@ -0,0 +1,34 @@ +@extends('layouts.librenmsv1') + +@section('title', __('Virtual Machines')) + +@section('content') +
+ + + + + + + + + + + + + + + +
NoSysname@lang('Device')@lang('Power Status')@lang('Host')@lang('Operating System')@lang('Memory')@lang('CPU')
+
+@endsection + +@section('scripts') + +@endsection diff --git a/routes/web.php b/routes/web.php index 5213ca774a..a74eda7131 100644 --- a/routes/web.php +++ b/routes/web.php @@ -34,6 +34,7 @@ Route::group(['middleware' => ['auth'], 'guard' => 'auth'], function () { Route::get('authlog', 'UserController@authlog'); Route::get('overview', 'OverviewController@index')->name('overview'); Route::get('/', 'OverviewController@index')->name('home'); + Route::view('vminfo', 'vminfo'); // Device Tabs Route::group(['prefix' => 'device/{device}', 'namespace' => 'Device\Tabs', 'as' => 'device.'], function () { @@ -124,6 +125,7 @@ Route::group(['middleware' => ['auth'], 'guard' => 'auth'], function () { Route::post('location', 'LocationController'); Route::post('port-nac', 'PortNacController'); Route::post('syslog', 'SyslogController'); + Route::post('vminfo', 'VminfoController'); }); // dashboard widgets