1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SyslogController.php |
4
|
|
|
* |
5
|
|
|
* -Description- |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
* @link https://www.librenms.org |
21
|
|
|
* |
22
|
|
|
* @copyright 2018 Tony Murray |
23
|
|
|
* @author Tony Murray <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace App\Http\Controllers\Table; |
27
|
|
|
|
28
|
|
|
use App\Models\Device; |
29
|
|
|
use App\Models\Vminfo; |
30
|
|
|
use LibreNMS\Util\Url; |
31
|
|
|
|
32
|
|
|
class VminfoController extends TableController |
33
|
|
|
{ |
34
|
|
|
public function searchFields($request) |
35
|
|
|
{ |
36
|
|
|
return ['vmwVmDisplayName', 'vmwVmGuestOS', 'devices.hostname', 'devices.sysname']; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function sortFields($request) |
40
|
|
|
{ |
41
|
|
|
return ['vmwVmDisplayName', 'vmwVmGuestOS', 'vmwVmMemSize', 'vmwVmCpus', 'vmwVmState', 'hostname']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Defines the base query for this resource |
46
|
|
|
* |
47
|
|
|
* @param \Illuminate\Http\Request $request |
48
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder |
49
|
|
|
*/ |
50
|
|
|
public function baseQuery($request) |
51
|
|
|
{ |
52
|
|
|
return Vminfo::hasAccess($request->user()) |
|
|
|
|
53
|
|
|
->select('vminfo.*') |
54
|
|
|
->with('device') |
55
|
|
|
->with('parentDevice') |
56
|
|
|
->when($request->get('searchPhrase') || in_array('hostname', array_keys($request->get('sort', []))), function ($query) { |
57
|
|
|
$query->leftJoin('devices', 'devices.device_id', 'vminfo.device_id'); |
58
|
|
|
}); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param Vminfo $vm |
63
|
|
|
*/ |
64
|
|
|
public function formatItem($vm) |
65
|
|
|
{ |
66
|
|
|
return [ |
67
|
|
|
'vmwVmState' => '<span class="label ' . $vm->stateLabel[1] . '">' . $vm->stateLabel[0] . '</span>', |
68
|
|
|
'vmwVmDisplayName' => is_null($vm->parentDevice) ? $vm->vmwVmDisplayName : self::getHostname($vm->parentDevice), |
69
|
|
|
'vmwVmGuestOS' => $vm->operatingSystem, |
70
|
|
|
'vmwVmMemSize' => $vm->memoryFormatted, |
71
|
|
|
'vmwVmCpus' => $vm->vmwVmCpus, |
72
|
|
|
'hostname' => self::getHostname($vm->device), |
|
|
|
|
73
|
|
|
'deviceid' => $vm->device_id, |
74
|
|
|
'sysname' => $vm->device->sysName, |
75
|
|
|
|
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private static function getHostname(Device $device): string |
80
|
|
|
{ |
81
|
|
|
return '<a class="list-device" href="' . Url::deviceUrl($device) . '">' . $device->hostname . '</a><br>' . $device->sysName; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|