Remove proxmox as a page and add is as an app. Also, this introduces actual working app_instance stuff into LibreNMS

This commit is contained in:
Mark Schouten
2015-08-28 17:01:51 +02:00
parent 45dd02d301
commit 34abb859df
5 changed files with 102 additions and 149 deletions

View File

@@ -360,21 +360,32 @@ foreach (array_keys($menu_sensors) as $item) {
</li> </li>
<?php <?php
$app_count = dbFetchCell("SELECT COUNT(`app_id`) FROM `applications`"); $app_list = dbFetchRows("SELECT DISTINCT(`app_type`) AS `app_type` FROM `applications` ORDER BY `app_type`");
if ($_SESSION['userlevel'] >= '5' && ($app_count) > "0") { if ($_SESSION['userlevel'] >= '5' && count($app_list) > "0") {
?> ?>
<li class="dropdown"> <li class="dropdown">
<a href="apps/" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown"><i class="fa fa-tasks fa-fw fa-lg fa-nav-icons"></i> Apps</a> <a href="apps/" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown"><i class="fa fa-tasks fa-fw fa-lg fa-nav-icons"></i> Apps</a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<?php <?php
$app_list = dbFetchRows("SELECT `app_type` FROM `applications` GROUP BY `app_type` ORDER BY `app_type`");
foreach ($app_list as $app) { foreach ($app_list as $app) {
if (isset($app['app_type'])) { if (isset($app['app_type'])) {
$app_i_list = dbFetchRows("SELECT DISTINCT(`app_instance`) FROM `applications` WHERE `app_type` = ? ORDER BY `app_instance`", array($app['app_type']));
$image = $config['html_dir']."/images/icons/".$app['app_type'].".png"; $image = $config['html_dir']."/images/icons/".$app['app_type'].".png";
$icon = (file_exists($image) ? $app['app_type'] : "apps"); $icon = (file_exists($image) ? $app['app_type'] : "apps");
echo('<li><a href="apps/app='.$app['app_type'].'/"><i class="fa fa-angle-double-right fa-fw fa-lg"></i> '.nicecase($app['app_type']).' </a></li>'); if (count($app_i_list) > 1) {
echo '<li class="dropdown-submenu">';
echo '<a href="apps/app='.$app['app_type'].'/"><i class="fa fa-server fa-fw fa-lg"></i> '.nicecase($app['app_type']).' </a>';
echo '<ul class="dropdown-menu scrollable-menu">';
foreach ($app_i_list as $instance) {
echo ' <li><a href="apps/app='.$app['app_type'].'/instance='.$instance['app_instance'].'/"><i class="fa fa-angle-double-right fa-fw fa-lg"></i> ' . nicecase($instance['app_instance']) . '</a></li>';
}
echo '</ul></li>';
}
else {
echo('<li><a href="apps/app='.$app['app_type'].'/"><i class="fa fa-angle-double-right fa-fw fa-lg"></i> '.nicecase($app['app_type']).' </a></li>');
}
} }
} }
?> ?>
@@ -383,26 +394,6 @@ if ($_SESSION['userlevel'] >= '5' && ($app_count) > "0") {
<?php <?php
} }
if (isset($config['enable_proxmox']) && $config['enable_proxmox']) {
$pmxcl = dbFetchRows("SELECT DISTINCT(`app_instance`) FROM `applications` WHERE `app_type` = ?", array('proxmox'));
if(count($pmxcl) > 0) {
?>
<li class="dropdown">
<a href="proxmox/" class="dropdown-toggle" data-hover="dropdown" data-toggle="dropdown"><i class="fa fa-tasks fa-fw fa-lg fa-nav-icons"></i> Proxmox</a>
<ul class="dropdown-menu">
<?php
foreach ($pmxcl as $pmxc) {
echo('<li><a href="/proxmox/cluster='.$pmxc['app_instance'].'/"><i class="fa fa-angle-double-right fa-fw fa-lg"></i> '.nicecase($pmxc['app_instance']).' </a></li>');
}
?>
</ul>
</li>
<?php
}
}
$routing_count['bgp'] = dbFetchCell("SELECT COUNT(bgpPeer_id) from `bgpPeers` LEFT JOIN devices AS D ON bgpPeers.device_id=D.device_id WHERE D.device_id IS NOT NULL"); $routing_count['bgp'] = dbFetchCell("SELECT COUNT(bgpPeer_id) from `bgpPeers` LEFT JOIN devices AS D ON bgpPeers.device_id=D.device_id WHERE D.device_id IS NOT NULL");
$routing_count['ospf'] = dbFetchCell("SELECT COUNT(ospf_instance_id) FROM `ospf_instances` WHERE `ospfAdminStat` = 'enabled'"); $routing_count['ospf'] = dbFetchCell("SELECT COUNT(ospf_instance_id) FROM `ospf_instances` WHERE `ospfAdminStat` = 'enabled'");
$routing_count['cef'] = dbFetchCell("SELECT COUNT(cef_switching_id) from `cef_switching`"); $routing_count['cef'] = dbFetchCell("SELECT COUNT(cef_switching_id) from `cef_switching`");

View File

@@ -0,0 +1,52 @@
<?php
include('includes/application/proxmox.inc.php');
$graphs['proxmox'] = array(
'netif'
);
$pmxcl = dbFetchRows("SELECT DISTINCT(`app_instance`) FROM `applications` WHERE `app_type` = ?", array('proxmox'));
print_optionbar_start();
echo "<span style='font-weight: bold;'>Proxmox</span> &#187; ";
unset($sep);
foreach ($pmxcl as $pmxc) {
if (isset($sep)) { echo $sep; };
if (var_eq('instance', $pmxc['app_instance'])) {
echo "<span class='pagemenu-selected'>";
}
echo generate_link(nicecase($pmxc['app_instance']), array('page' => 'apps', 'app' => 'proxmox', 'instance' => $pmxc['app_instance']));
if (var_eq('instance', $pmxc['app_instance'])) {
echo '</span>';
}
$sep = ' | ';
}
print_optionbar_end();
if (!var_isset('instance')) {
echo 'Select a cluster:';
echo '<ul>';
foreach ($pmxcl as $pmxc) {
echo '<li>'.generate_link(nicecase($pmxc['app_instance']), array('page' => 'apps', 'app' => 'proxmox', 'instance' => $pmxc['app_instance'])).'</li>';
}
echo '</ul>';
} elseif (!var_isset('vmid')) {
echo '<ul>';
foreach (proxmox_cluster_vms(var_get('instance')) as $pmxvm) {
echo '<li>'.generate_link($pmxvm['vmid']." (".$pmxvm['description'].")", array('page' => 'apps', 'app' => 'proxmox', 'instance' => var_get('instance'), 'vmid' => $pmxvm['vmid'])).'</li>';
}
echo '</ul>';
} else {
include("pages/apps/proxmox/vm.inc.php");
}
$pagetitle[] = 'Proxmox';

View File

@@ -0,0 +1,35 @@
<?php
global $vars;
$vm = proxmox_vm_info(var_get('vmid'), var_get('instance'));
$graphs = array(
'proxmox_traffic' => 'Traffic',
);
foreach ($vm['ports'] as $port) {
foreach ($graphs as $key => $text) {
$graph_type = 'proxmox_traffic';
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $vm['app_id'];
$graph_array['device_id'] = $vm['device_id'];
$graph_array['type'] = 'application_'.$key;
$graph_array['port'] = $port['port'];
$graph_array['vmid'] = $vm['vmid'];
$graph_array['cluster'] = $vm['cluster'];
$graph_array['hostname'] = $vm['description'];
echo '<h3>'.$text.' '.$port['port'].'@'.$vm['description'].'</h3>';
echo "<tr bgcolor='$row_colour'><td colspan=5>";
include 'includes/print-graphrow.inc.php';
echo '</td></tr>';
}
}

View File

@@ -1,65 +0,0 @@
<?php
/*
* Copyright (C) 2015 Mark Schouten <mark@tuxis.nl>
*
* 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; version 2 dated June,
* 1991.
*
* 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.
*
* See http://www.gnu.org/licenses/gpl.txt for the full license
*/
include('includes/application/proxmox.inc.php');
$graphs['proxmox'] = array(
'netif'
);
print_optionbar_start();
echo "<span style='font-weight: bold;'>Proxmox</span> &#187; ";
unset($sep);
foreach ($pmxcl as $pmxc) {
if (isset($sep)) { echo $sep; };
if (var_eq('cluster', $pmxc['app_instance'])) {
echo "<span class='pagemenu-selected'>";
}
echo generate_link(nicecase($pmxc['app_instance']), array('page' => 'proxmox', 'cluster' => $pmxc['app_instance']));
if (var_eq('cluster', $pmxc['app_instance'])) {
echo '</span>';
}
$sep = ' | ';
}
print_optionbar_end();
if (!var_isset('cluster')) {
echo 'Select a cluster:';
echo '<ul>';
foreach ($pmxcl as $pmxc) {
echo '<li>'.generate_link(nicecase($pmxc['app_instance']), array('page' => 'proxmox', 'cluster' => $pmxc['app_instance'])).'</li>';
}
echo '</ul>';
} elseif (!var_isset('vmid')) {
echo '<ul>';
foreach (proxmox_cluster_vms(var_get('cluster')) as $pmxvm) {
echo '<li>'.generate_link($pmxvm['vmid']." (".$pmxvm['description'].")", array('page' => 'proxmox', 'cluster' => var_get('cluster'), 'vmid' => $pmxvm['vmid'])).'</li>';
}
echo '</ul>';
} else {
include("pages/proxmox/vm.inc.php");
}
$pagetitle[] = 'Proxmox';

View File

@@ -1,60 +0,0 @@
<?php
/*
* Copyright (C) 2015 Mark Schouten <mark@tuxis.nl>
*
* 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; version 2 dated June,
* 1991.
*
* 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.
*
* See http://www.gnu.org/licenses/gpl.txt for the full license
*/
global $vars;
$vm = proxmox_vm_info(var_get('vmid'), var_get('cluster'));
$graphs = array(
'proxmox_traffic' => 'Traffic',
);
foreach ($vm['ports'] as $port) {
foreach ($graphs as $key => $text) {
$graph_type = 'proxmox_traffic';
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['id'] = $vm['app_id'];
$graph_array['device_id'] = $vm['device_id'];
$graph_array['type'] = 'application_'.$key;
$graph_array['port'] = $port['port'];
$graph_array['vmid'] = $vm['vmid'];
$graph_array['cluster'] = $vm['cluster'];
$graph_array['hostname'] = $vm['description'];
echo '<h3>'.$text.' '.$port['port'].'@'.$vm['description'].'</h3>';
echo "<tr bgcolor='$row_colour'><td colspan=5>";
include 'includes/print-graphrow.inc.php';
echo '</td></tr>';
}
}
#if (is_numeric($vars['id']) && ($auth || application_permitted($vars['id']))) {
# $app = get_application_by_id($vars['id']);
# $device = device_by_id_cache($app['device_id']);
# $title = generate_device_link($device);
# $title .= $graph_subtype;
# $auth = true;
#}