mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Dashboard widget update (#9515)
Implemented in Laravel Doesn't use legacy PHP session Several widgets have new features and settings, for example: - Multiple ports in one graph - Maps settings are configurable and override system settings but default to system settings - Graylog stream and/or device selection - Much improved graph widget selection - Many more 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` After you are done testing, you can remove the changes with `./scripts/github-remove`. If there are schema changes, you can ask on discord how to revert.
This commit is contained in:
committed by
Neil Lathwood
parent
dd695dde53
commit
74882e3950
71
LibreNMS/Util/Colors.php
Normal file
71
LibreNMS/Util/Colors.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* Colors.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2018 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
class Colors
|
||||
{
|
||||
public static function percentage($percentage, $component_perc_warn = null)
|
||||
{
|
||||
$perc_warn = 75;
|
||||
|
||||
if (isset($component_perc_warn)) {
|
||||
$perc_warn = round($component_perc_warn, 0);
|
||||
}
|
||||
|
||||
if ($percentage > $perc_warn) {
|
||||
return [
|
||||
'left' => 'c4323f',
|
||||
'right' => 'c96a73'
|
||||
];
|
||||
}
|
||||
|
||||
if ($percentage > 75) {
|
||||
return [
|
||||
'left' => 'bf5d5b',
|
||||
'right' => 'd39392'
|
||||
];
|
||||
}
|
||||
|
||||
if ($percentage > 50) {
|
||||
return [
|
||||
'left' => 'bf875b',
|
||||
'right' => 'd3ae92'
|
||||
];
|
||||
}
|
||||
|
||||
if ($percentage > 25) {
|
||||
return [
|
||||
'left' => '5b93bf',
|
||||
'right' => '92b7d3'
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'left' => '9abf5b',
|
||||
'right' => 'bbd392'
|
||||
];
|
||||
}
|
||||
}
|
84
LibreNMS/Util/Graph.php
Normal file
84
LibreNMS/Util/Graph.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Graph.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2018 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Config;
|
||||
|
||||
class Graph
|
||||
{
|
||||
public static function getTypes()
|
||||
{
|
||||
return ['device', 'port', 'application', 'munin'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of all graph subtypes for the given type
|
||||
* @param $type
|
||||
* @param Device $device
|
||||
* @return array
|
||||
*/
|
||||
public static function getSubtypes($type, $device = null)
|
||||
{
|
||||
$types = [];
|
||||
|
||||
// find the subtypes defined in files
|
||||
foreach (glob(base_path("/html/includes/graphs/$type/*.inc.php")) as $file) {
|
||||
$type = basename($file, '.inc.php');
|
||||
if ($type != 'auth') {
|
||||
$types[] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
if ($device != null) {
|
||||
// find the MIB subtypes
|
||||
$graphs = $device->graphs();
|
||||
|
||||
foreach (Config::get('graph_types') as $type => $type_data) {
|
||||
foreach (array_keys($type_data) as $subtype) {
|
||||
if ($graphs->contains($subtype) && self::isMibGraph($type, $subtype)) {
|
||||
$types[] = $subtype;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort($types);
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given graph is a mib graph
|
||||
*
|
||||
* @param $type
|
||||
* @param $subtype
|
||||
* @return bool
|
||||
*/
|
||||
public static function isMibGraph($type, $subtype)
|
||||
{
|
||||
return Config::get("graph_types.$type.$subtype.section") == 'mib';
|
||||
}
|
||||
}
|
@@ -25,6 +25,8 @@
|
||||
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
use HTMLPurifier;
|
||||
use HTMLPurifier_Config;
|
||||
use LibreNMS\Config;
|
||||
|
||||
class Html
|
||||
@@ -95,4 +97,58 @@ class Html
|
||||
|
||||
return $graph_data;
|
||||
}
|
||||
|
||||
public static function percentageBar($width, $height, $percent, $left_text, $left_colour, $left_background, $right_text, $right_colour, $right_background)
|
||||
{
|
||||
if ($percent > '100') {
|
||||
$size_percent = '100';
|
||||
} else {
|
||||
$size_percent = $percent;
|
||||
}
|
||||
|
||||
$output = '
|
||||
<div style="width:'.$width.'px; height:'.$height.'px; position: relative;">
|
||||
<div class="progress" style="min-width: 2em; background-color:#'.$right_background.'; height:'.$height.'px;margin-bottom:-'.$height.'px;">
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="'.$size_percent.'" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width:'.$size_percent.'%; background-color: #'.$left_background.';">
|
||||
</div>
|
||||
</div>
|
||||
<b style="padding-left: 2%; position: absolute; top: 0; left: 0;color:#'.$left_colour.';">'.$left_text.'</b>
|
||||
<b style="padding-right: 2%; position: absolute; top: 0; right: 0;color:#'.$right_colour.';">'.$right_text.'</b>
|
||||
</div>
|
||||
';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean a string for display in an html page.
|
||||
*
|
||||
* @param $value
|
||||
* @param array $purifier_config (key, value pair)
|
||||
* @return string
|
||||
*/
|
||||
public static function display($value, $purifier_config = [])
|
||||
{
|
||||
/** @var HTMLPurifier $purifier */
|
||||
static $purifier;
|
||||
|
||||
// If $purifier_config is non-empty then we don't want
|
||||
// to convert html tags and allow these to be controlled
|
||||
// by purifier instead.
|
||||
if (empty($purifier_config)) {
|
||||
$value = htmlentities($value);
|
||||
}
|
||||
|
||||
if (!isset($purifier)) {
|
||||
// initialize HTML Purifier here since this is the only user
|
||||
$p_config = HTMLPurifier_Config::createDefault();
|
||||
$p_config->set('Cache.SerializerPath', Config::get('temp_dir', '/tmp'));
|
||||
foreach ($purifier_config as $k => $v) {
|
||||
$p_config->set($k, $v);
|
||||
}
|
||||
$purifier = new HTMLPurifier($p_config);
|
||||
}
|
||||
|
||||
return $purifier->purify(stripslashes($value));
|
||||
}
|
||||
}
|
||||
|
@@ -103,6 +103,7 @@ class Rewrite
|
||||
'serviceinstance' => 'SI',
|
||||
'dwdm' => 'DWDM',
|
||||
'bundle-ether' => 'BE',
|
||||
'bridge-aggregation' => 'BA',
|
||||
];
|
||||
|
||||
return str_ireplace(array_keys($rewrite_shortif), array_values($rewrite_shortif), $name);
|
||||
|
81
LibreNMS/Util/StringHelpers.php
Normal file
81
LibreNMS/Util/StringHelpers.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Text.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2018 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
class StringHelpers
|
||||
{
|
||||
/**
|
||||
* Shorten text over 50 chars, if shortened, add ellipsis
|
||||
*
|
||||
* @param $string
|
||||
* @param int $max
|
||||
* @return string
|
||||
*/
|
||||
public static function shortenText($string, $max = 30)
|
||||
{
|
||||
if (strlen($string) > 50) {
|
||||
return substr($string, 0, $max) . "...";
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function niceCase($string)
|
||||
{
|
||||
$replacements = [
|
||||
'dbm' => 'dBm',
|
||||
'entropy' => 'Random entropy',
|
||||
'mysql' => 'MySQL',
|
||||
'powerdns' => 'PowerDNS',
|
||||
'bind' => 'BIND',
|
||||
'nfs-stats' => 'NFS Stats',
|
||||
'nfs-v3-stats' => 'NFS v3 Stats',
|
||||
'nfs-server' => 'NFS Server',
|
||||
'ntp' => 'NTP',
|
||||
'ntp-client' => 'NTP Client',
|
||||
'ntp-server' => 'NTP Server',
|
||||
'os-updates' => 'OS Updates',
|
||||
'smart' => 'SMART',
|
||||
'powerdns-recursor' => 'PowerDNS Recursor',
|
||||
'powerdns-dnsdist' => 'PowerDNS dnsdist',
|
||||
'dhcp-stats' => 'DHCP Stats',
|
||||
'ups-nut' => 'UPS nut',
|
||||
'ups-apcups' => 'UPS apcups',
|
||||
'gpsd' => 'GPSD',
|
||||
'exim-stats' => 'EXIM Stats',
|
||||
'fbsd-nfs-client' => 'FreeBSD NFS Client',
|
||||
'fbsd-nfs-server' => 'FreeBSD NFS Server',
|
||||
'php-fpm' => 'PHP-FPM',
|
||||
'opengridscheduler' => 'Open Grid Scheduler',
|
||||
'sdfsinfo' => 'SDFS info',
|
||||
'freeradius' => 'FreeRADIUS',
|
||||
'pi-hole' => 'pi-hole',
|
||||
'zfs' => 'ZFS',
|
||||
];
|
||||
|
||||
return isset($replacements[$string]) ? $replacements[$string] : ucfirst($string);
|
||||
}
|
||||
}
|
51
LibreNMS/Util/Time.php
Normal file
51
LibreNMS/Util/Time.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Time.php
|
||||
*
|
||||
* -Description-
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2018 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Util;
|
||||
|
||||
class Time
|
||||
{
|
||||
public static function legacyTimeSpecToSecs($description)
|
||||
{
|
||||
$conversion = [
|
||||
'now' => 0,
|
||||
'onehour' => 3600,
|
||||
'fourhour' => 14400,
|
||||
'sixhour' => 21600,
|
||||
'twelvehour' => 43200,
|
||||
'day' => 86400,
|
||||
'twoday' => 172800,
|
||||
'week' => 604800,
|
||||
'twoweek' => 1209600,
|
||||
'month' => 2678400,
|
||||
'twomonth' => 5356800,
|
||||
'threemonth' => 8035200,
|
||||
'year' => 31536000,
|
||||
'twoyear' => 63072000,
|
||||
];
|
||||
|
||||
return isset($conversion[$description]) ? $conversion[$description] : 0;
|
||||
}
|
||||
}
|
@@ -102,8 +102,7 @@ class Url
|
||||
if ($overlib == 0) {
|
||||
$link = $contents;
|
||||
} else {
|
||||
// escape quotes
|
||||
$contents = str_replace(["'", '"'], "\'", $contents);
|
||||
$contents = self::escapeBothQuotes($contents);
|
||||
$link = Url::overlibLink($url, $text, $contents, $class);
|
||||
}
|
||||
|
||||
@@ -177,6 +176,33 @@ class Url
|
||||
return self::generate(['page' => 'device', 'device' => $port->device_id, 'tab' => 'port', 'port' => $port->port_id], $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Port $port
|
||||
* @return string
|
||||
*/
|
||||
public static function portThumbnail($port)
|
||||
{
|
||||
$graph_array = [
|
||||
'port_id' => $port->port_id,
|
||||
'graph_type' => 'port_bits',
|
||||
'from' => Carbon::now()->subDay()->timestamp,
|
||||
'to' => Carbon::now()->timestamp,
|
||||
'width' => 150,
|
||||
'height' => 21,
|
||||
];
|
||||
|
||||
return self::portImage($graph_array);
|
||||
}
|
||||
|
||||
public static function portImage($args)
|
||||
{
|
||||
if (empty($args['bg'])) {
|
||||
$args['bg'] = 'FFFFFF00';
|
||||
}
|
||||
|
||||
return "<img src='graph.php?type=" . $args['graph_type'] . '&id=' . $args['port_id'] . '&from=' . $args['from'] . '&to=' . $args['to'] . '&width=' . $args['width'] . '&height=' . $args['height'] . '&bg=' . $args['bg'] . "'>";
|
||||
}
|
||||
|
||||
public static function generate($vars, $new_vars = [])
|
||||
{
|
||||
$vars = array_merge($vars, $new_vars);
|
||||
@@ -245,6 +271,22 @@ class Url
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function overlibContent($graph_array, $text)
|
||||
{
|
||||
$overlib_content = '<div class=overlib><span class=overlib-text>' . $text . '</span><br />';
|
||||
|
||||
$now = Carbon::now();
|
||||
|
||||
foreach ([1, 7, 30, 365] as $days) {
|
||||
$graph_array['from'] = $now->subDays($days)->timestamp;
|
||||
$overlib_content .= self::escapeBothQuotes(self::graphTag($graph_array));
|
||||
}
|
||||
|
||||
$overlib_content .= '</div>';
|
||||
|
||||
return $overlib_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate minigraph image url
|
||||
*
|
||||
@@ -321,4 +363,9 @@ class Url
|
||||
|
||||
return "interface-upup";
|
||||
}
|
||||
|
||||
private static function escapeBothQuotes($string)
|
||||
{
|
||||
return str_replace(["'", '"'], "\'", $string);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user