diff --git a/html/includes/forms/get-vmlist.inc.php b/html/includes/forms/get-vmlist.inc.php new file mode 100644 index 0000000000..c3e51a9f49 --- /dev/null +++ b/html/includes/forms/get-vmlist.inc.php @@ -0,0 +1,71 @@ + + * + * 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 + */ + +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); diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 481a52a05b..11c3399a63 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -215,6 +215,11 @@ if (Auth::user()->hasGlobalAdmin()) { echo '
  • Device Dependencies
  • '; + $vm_count = dbFetchCell('SELECT COUNT(id) from `vminfo`'); + if ($vm_count > 0) { + echo '
  • Virtual Machines
  • '; + } + echo '
  • Add Device
  • diff --git a/html/pages/vminfo.inc.php b/html/pages/vminfo.inc.php new file mode 100644 index 0000000000..428f980bd2 --- /dev/null +++ b/html/pages/vminfo.inc.php @@ -0,0 +1,93 @@ + + * + * 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 + */ + + +use LibreNMS\Authentication\Auth; + +$pagetitle[] = 'Virtual Machines'; +?> +
    + + + + + + + + + + + + + + + +
    NoSysnameServer NamePower StatusPhysical ServerOperating SystemMemoryCPU
    +
    +