diff --git a/doc/Extensions/Proxmox.md b/doc/Extensions/Proxmox.md new file mode 100644 index 0000000000..0691e1d273 --- /dev/null +++ b/doc/Extensions/Proxmox.md @@ -0,0 +1,23 @@ +# Proxmox graphing + +It is possible to create graphs of the Proxmox VMs that run on your monitored machines. Currently, only trafficgraphs are created. One for each interface on each VM. Possibly, IO grahps will be added later on. + +The ultimate goal is to be able to create traffic bills for VMs, no matter on which physical machine that VM runs. + +### Enabling Proxmox graphs + +To enable Proxmox graphs, do the following: + +In config.php, enable Proxmox: +```php +$config['enable_proxmox'] = 1 +``` + +Then, install librenms-agent on the machines running Proxmox, and enable the Proxmox-plugin using: +```bash +mk_enplug proxmox +``` + +Then, enable the unix-agent on the machines running Proxmox. + +You should now see an application in LibreNMS, as well as a new menu-item in the topmenu, allowing you to choose which cluster you want to look at. diff --git a/html/includes/application/proxmox.inc.php b/html/includes/application/proxmox.inc.php new file mode 100644 index 0000000000..bd775247b9 --- /dev/null +++ b/html/includes/application/proxmox.inc.php @@ -0,0 +1,50 @@ + + * + * 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 + */ + +/** + * Fetch all VM's in a Proxmox Cluster + * @param string $c Clustername + * @return array An array with all the VM's on this cluster + */ +function proxmox_cluster_vms($c) { + return dbFetchRows("SELECT * FROM proxmox WHERE cluster = ? ORDER BY vmid", array($c)); +} + +/** + * Fetch all VM's on a Proxmox node + * @param integer $n device_id + * @return array An array with all the VM's on this node + */ +function proxmox_node_vms($n) { + return dbFetchRows("SELECT * FROM proxmox WHERE device_id = ? ORDER BY vmid", array($n)); +} + +/** + * Fetch all info about a Proxmox VM + * @param integer $vmid Proxmox VM ID + * @param string $c Clustername + * @return array An array with all info of this VM on this cluster, including ports + */ +function proxmox_vm_info($vmid, $c) { + $vm = dbFetchRow("SELECT pm.*, d.hostname AS host, d.device_id FROM proxmox pm, devices d WHERE pm.device_id = d.device_id AND pm.vmid = ? AND pm.cluster = ?", array($vmid, $c)); + $appid = dbFetchRow("SELECT app_id FROM applications WHERE device_id = ? AND app_type = ?", array($vm['device_id'], 'proxmox')); + + $vm['ports'] = dbFetchRows("SELECT * FROM proxmox_ports WHERE vm_id = ?", array($vm['id'])); + $vm['app_id'] = $appid['app_id']; + return $vm; +} diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index b1c44481ba..7b7ea62ca5 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -12,6 +12,35 @@ * @copyright (C) 2013 LibreNMS Group */ +/** + * Compare $t with the value of $vars[$v], if that exists + * @param string $v Name of the var to test + * @param string $t Value to compare $vars[$v] to + * @return boolean true, if values are the same, false if $vars[$v] is unset or values differ + */ +function var_eq($v, $t) { + global $vars; + if (isset($vars[$v]) && $vars[$v] == $t) { + return true; + } + + return false; +} + +/** + * Get the value of $vars[$v], if it exists + * @param string $v Name of the var to get + * @return string|boolean The value of $vars[$v] if it exists, false if it does not exist + */ +function var_get($v) { + global $vars; + if (isset($vars[$v])) { + return $vars[$v]; + } + + return false; +} + function data_uri($file, $mime) { $contents = file_get_contents($file); diff --git a/html/includes/graphs/application/auth.inc.php b/html/includes/graphs/application/auth.inc.php index 15c8f01ca1..719145015d 100644 --- a/html/includes/graphs/application/auth.inc.php +++ b/html/includes/graphs/application/auth.inc.php @@ -3,7 +3,12 @@ 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; + if ($app['app_type'] != 'proxmox') { + $title = generate_device_link($device); + $title .= $graph_subtype; + } + else { + $title = $vars['port'].'@'.$vars['hostname'].' on '.generate_device_link($device); + } $auth = true; } diff --git a/html/includes/graphs/application/proxmox_traffic.inc.php b/html/includes/graphs/application/proxmox_traffic.inc.php new file mode 100644 index 0000000000..26d6e66823 --- /dev/null +++ b/html/includes/graphs/application/proxmox_traffic.inc.php @@ -0,0 +1,30 @@ + + * + * 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 + */ + +require 'includes/graphs/common.inc.php'; + +$proxmox_rrd = $config['rrd_dir'].'/proxmox/'.$vars['cluster'].'/'.$vars['vmid'].'_netif_'.$vars['port'].'.rrd'; + +if (is_file($proxmox_rrd)) { + $rrd_filename = $proxmox_rrd; +} + +$ds_in = 'INOCTETS'; +$ds_out = 'OUTOCTETS'; + +require 'includes/graphs/generic_data.inc.php'; diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 3e43f6c759..1cf1747e0f 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -360,21 +360,32 @@ foreach (array_keys($menu_sensors) as $item) { = '5' && ($app_count) > "0") { +if ($_SESSION['userlevel'] >= '5' && count($app_list) > "0") { ?>