Convert Virtual Machine pages to Laravel (#12287)

* Convert Virtual Machine pages to Laravel

* wip

* wip

* wip

* wip

* wip

* wip

* delete

* wip

* wip

* move powerStateLabel
This commit is contained in:
Jellyfrog
2020-11-11 01:15:20 +01:00
committed by GitHub
parent ac5920f45c
commit cfd9dce620
24 changed files with 363 additions and 237 deletions

View File

@@ -0,0 +1,39 @@
<?php
/**
* PowerState.php
*
*
* 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 <http://www.gnu.org/licenses/>.
*/
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,
];
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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'];
}
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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) {

View File

@@ -0,0 +1,79 @@
<?php
/**
* SyslogController.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 <http://www.gnu.org/licenses/>.
*
* @link http://librenms.org
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
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' => '<span class="label ' . $vm->stateLabel[1] . '">' . $vm->stateLabel[0] . '</span>',
'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 '<a class="list-device" href="' . Url::deviceUrl($device) . '">' . $device->hostname . '</a><br>' . $device->sysName;
}
}

View File

@@ -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');
}
}

View File

@@ -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]),
];
}
}

View File

@@ -0,0 +1,45 @@
<?php
use App\Models\Vminfo;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use LibreNMS\Enum\PowerState;
class AddPowerstateEnumToVminfo extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Vminfo::select('id', 'vmwVmState')->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();
});
}
}

View File

@@ -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)

View File

@@ -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'];

View File

@@ -1,5 +1,7 @@
<?php
use LibreNMS\Enum\PowerState;
// FIXME should do the deletion etc in a common file perhaps? like for the sensors
/*
* Try to discover any Virtual Machines.
@@ -26,7 +28,7 @@ if (($device['os'] == 'vmware-esxi') || ($device['os'] == 'linux')) {
$vmwVmDisplayName = $entry['vmwVmDisplayName'];
$vmwVmGuestOS = $entry['vmwVmGuestOS'];
$vmwVmMemSize = $entry['vmwVmMemSize'];
$vmwVmState = $entry['vmwVmState'];
$vmwVmState = PowerState::STATES[strtolower($entry['vmwVmState'])] ?? PowerState::UNKNOWN;
$vmwVmCpus = $entry['vmwVmCpus'];
/*

View File

@@ -1,68 +0,0 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Aldemir Akpinar <https://github.com/aldemira>
*
* 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 <aldemir.akpinar@gmail.com>
*/
$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);

View File

@@ -1,12 +0,0 @@
<?php
echo '<table border="0" cellspacing="0" cellpadding="5" width="100%" class="table table-condensed"><tr class="tablehead"><th>Server Name</th><th>Power Status</th><th>Operating System</th><th>Memory</th><th>CPU</th></tr>';
$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 '</table>';
$pagetitle[] = 'Virtual Machines';

View File

@@ -1,92 +0,0 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Aldemir Akpinar <https://github.com/aldemira>
*
* 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 <aldemir.akpinar@gmail.com>
*/
$pagetitle[] = 'Virtual Machines';
?>
<div class="table-responsive">
<table id="vminfo" class="table table-hover table-condensed table-striped">
<thead>
<tr>
<th data-column-id="deviceid" data-visible="false" data-css-class="deviceid">No</th>
<th data-column-id="sysname" data-visible="false">Sysname</th>
<th data-column-id="vmname" data-type="string">Server Name</th>
<th data-column-id="powerstat" data-type="string" data-formatter="powerstatus">Power Status</th>
<th data-column-id="physicalsrv" data-type="string" data-formatter="hostdev">Physical Server</th>
<th data-column-id="os" data-type="string" data-searchable="false" data-formatter="osname">Operating System</th>
<th data-column-id="memory" data-type="string" data-searchable="false" data-formatter="mem">Memory</th>
<th data-column-id="cpu" data-type="string" data-formatter="cpu" data-searchable="false">CPU</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script>
var grid = $("#vminfo").bootgrid({
rowCount: [50, 100, 250, -1],
ajax: true,
post: function() {
return {
type: "get-vmlist",
};
},
url: "ajax_form.php",
templates: {
header: '<div id="{{ctx.id}}" class="{{css.header}}"> \
<div class="row"> \
<div class="actionBar"><p class="{{css.search}}"></p><p class="{{css.actions}}"></p></div></div></div>'
},
formatters: {
"osname": function(column, row) {
if (row.os == 'E: tools not installed') {
return 'Unknown (VMware tools not installed)';
} else if (row.os == 'E: tools not running') {
return 'Unknown (VMware tools not running)';
} else if (row.os == '') {
return 'Uknown';
} else {
return row.os;
}
},
"powerstatus": function(column, row) {
if (row.powerstat == "powered on") {
var response = '<span class="label label-success">ON</span>';
} else if (row.powerstat == "powered off") {
var response = '<span class="label label-default">OFF</span>';
} else if (row.powerstat == "suspended") {
var response = '<span class="label label-warning">SUSPEND</span>';
}
return response;
},
"mem": function(column, row) {
if (row.memory >= 1024) {
tmpNumber = row.memory / 1024;
return tmpNumber.toFixed(2) + ' GB';
} else {
return row.memory + ' MB';
}
},
"cpu": function(column, row) {
return row.cpu + ' CPU';
},
"hostdev": function(column, row) {
return '<a href="device/device='+row.deviceid+'/" class="list-device">'+row.physicalsrv+'</a><br />'+row.sysname;
},
},
});
</script>

View File

@@ -1,36 +0,0 @@
<?php
echo '<tr class="list">';
echo '<td class="list">';
if (getidbyname($vm['vmwVmDisplayName'])) {
echo generate_device_link(device_by_name($vm['vmwVmDisplayName']));
} else {
echo $vm['vmwVmDisplayName'];
}
echo '</td>';
if ($vm['vmwVmState'] == 'powered off' || $vm['vmwVmState'] == 'Shut off') {
echo '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-default">OFF</span></td>';
} elseif ($vm['vmwVmState'] == 'powered on' || $vm['vmwVmState'] == 'Running') {
echo '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-success">ON</span></td>';
} elseif ($vm['vmwVmState'] == 'suspended' || $vm['vmwVmState'] == 'Paused') {
echo '<td class="list"><span style="min-width:40px; display:inline-block;" class="label label-warning">SUSPEND</span></td>';
}
if ($vm['vmwVmGuestOS'] == 'E: tools not installed') {
echo '<td class="box-desc">Unknown (VMware Tools not installed)</td>';
} elseif ($vm['vmwVmGuestOS'] == '') {
echo '<td class="box-desc"><i>(Unknown)</i></td>';
} else {
echo '<td class="list">' . \LibreNMS\Util\Rewrite::vmwareGuest($vm['vmwVmGuestOS']) . '</td>';
}
if ($vm['vmwVmMemSize'] >= 1024) {
echo '<td class=list>' . sprintf('%.2f', ($vm['vmwVmMemSize'] / 1024)) . ' GB</td>';
} else {
echo '<td class=list>' . sprintf('%.2f', $vm['vmwVmMemSize']) . ' MB</td>';
}
echo '<td class="list">' . $vm['vmwVmCpus'] . ' CPU</td>';

View File

@@ -1,5 +1,7 @@
<?php
use LibreNMS\Enum\PowerState;
/*
* CONSOLE: Start the VMware discovery process.
*/
@@ -30,7 +32,7 @@ foreach ($db_info_list as $db_info) {
$vm_info['vmwVmDisplayName'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmDisplayName'];
$vm_info['vmwVmGuestOS'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmGuestOS'];
$vm_info['vmwVmMemSize'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmMemSize'];
$vm_info['vmwVmState'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmState'];
$vm_info['vmwVmState'] = PowerState::STATES[$current_vminfo[$db_info['vmwVmVMID']]['vmwVmState']] ?? PowerState::UNKNOWN;
$vm_info['vmwVmCpus'] = $current_vminfo[$db_info['vmwVmVMID']]['vmwVmCpus'];
/*

View File

@@ -1978,7 +1978,7 @@ vminfo:
- { Field: vmwVmGuestOS, Type: varchar(128), 'Null': false, Extra: '' }
- { Field: vmwVmMemSize, Type: int, 'Null': false, Extra: '' }
- { Field: vmwVmCpus, Type: int, 'Null': false, Extra: '' }
- { Field: vmwVmState, Type: varchar(128), 'Null': false, Extra: '' }
- { Field: vmwVmState, Type: 'smallint unsigned', 'Null': false, Extra: '' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
vminfo_device_id_index: { Name: vminfo_device_id_index, Columns: [device_id], Unique: false, Type: BTREE }

View File

@@ -0,0 +1,37 @@
@extends('device.submenu')
@section('tabcontent')
<table class="table table-hover table-condensed table-striped">
<thead>
<tr>
<th>@lang('Server Name')</th>
<th>@lang('Power Status')</th>
<th>@lang('Operating System')</th>
<th>@lang('Memory')</th>
<th>@lang('CPU')</th>
</tr>
</thead>
<tbody>
@foreach($data['vms'] as $vm)
<tr>
<td>
@if ($vm->parentDevice)
@deviceLink($vm->parentDevice)
@else
{{ $vm->vmwVmDisplayName }}
@endif
</td>
<td>
<span style="min-width:40px; display:inline-block;" class="label {{ $vm->stateLabel[1] }}">{{ $vm->stateLabel[0] }}</span>
</td>
<td>{{ $vm->operatingSystem }}</td>
<td>{{ $vm->memoryFormatted }}</td>
<td>{{ $vm->vmwVmCpus }}</td>
</tr>
@endforeach
</tbody>
</table>
@endsection

View File

@@ -0,0 +1,34 @@
@extends('layouts.librenmsv1')
@section('title', __('Virtual Machines'))
@section('content')
<div class="table-responsive">
<table id="vminfo" class="table table-hover table-condensed table-striped">
<thead>
<tr>
<th data-column-id="deviceid" data-visible="false" data-css-class="deviceid">No</th>
<th data-column-id="sysname" data-visible="false">Sysname</th>
<th data-column-id="vmwVmDisplayName">@lang('Device')</th>
<th data-column-id="vmwVmState">@lang('Power Status')</th>
<th data-column-id="hostname">@lang('Host')</th>
<th data-column-id="vmwVmGuestOS" data-searchable="false">@lang('Operating System')</th>
<th data-column-id="vmwVmMemSize" data-searchable="false">@lang('Memory')</th>
<th data-column-id="vmwVmCpus" data-searchable="false">@lang('CPU')</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
@endsection
@section('scripts')
<script>
$("#vminfo").bootgrid({
ajax: true,
rowCount: [50, 100, 250, -1],
url: "{{ url('/ajax/table/vminfo') }}"
});
</script>
@endsection

View File

@@ -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