mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Added VM overview page in devices menu (#8640)
I've created single page which shows all VMs known to LibreNMS. Also I thought not everyone would like to enable this option so it requires $config['show_allvm_list'] = true; in config.php to be enabled as a menu item (under devices) DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
committed by
Neil Lathwood
parent
82d01eb1a1
commit
f389500f65
71
html/includes/forms/get-vmlist.inc.php
Normal file
71
html/includes/forms/get-vmlist.inc.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?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>
|
||||
*/
|
||||
|
||||
use LibreNMS\Authentication\Auth;
|
||||
|
||||
$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);
|
||||
@@ -215,6 +215,11 @@ if (Auth::user()->hasGlobalAdmin()) {
|
||||
|
||||
echo '<li><a href="'.generate_url(array('page'=>'device-dependencies')).'"><i class="fa fa-group fa-fw fa-lg"></i> Device Dependencies</a></li>';
|
||||
|
||||
$vm_count = dbFetchCell('SELECT COUNT(id) from `vminfo`');
|
||||
if ($vm_count > 0) {
|
||||
echo '<li><a href="'.generate_url(array('page'=>'vminfo')).'"><i class="fa fa-cog fa-fw fa-lg"></i> Virtual Machines</a></li>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<li role="presentation" class="divider"></li>
|
||||
<li><a href="addhost/"><i class="fa fa-plus fa-fw fa-lg" aria-hidden="true"></i> Add Device</a></li>
|
||||
|
||||
93
html/pages/vminfo.inc.php
Normal file
93
html/pages/vminfo.inc.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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>
|
||||
*/
|
||||
|
||||
|
||||
use LibreNMS\Authentication\Auth;
|
||||
|
||||
$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>';
|
||||
}
|
||||
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>
|
||||
Reference in New Issue
Block a user