2018-09-20 15:33:03 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Url.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
|
2021-02-09 00:29:04 +01:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-09-20 15:33:03 -05:00
|
|
|
*
|
2021-02-09 00:29:04 +01:00
|
|
|
* @link https://www.librenms.org
|
2021-09-10 20:09:53 +02:00
|
|
|
*
|
2018-09-20 15:33:03 -05:00
|
|
|
* @copyright 2018 Tony Murray
|
|
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace LibreNMS\Util;
|
|
|
|
|
|
|
|
use App\Models\Device;
|
2018-09-24 02:07:00 -05:00
|
|
|
use App\Models\Port;
|
2018-09-20 15:33:03 -05:00
|
|
|
use Carbon\Carbon;
|
2020-04-29 07:25:13 -05:00
|
|
|
use Carbon\CarbonImmutable;
|
2021-04-08 15:14:49 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2022-09-03 13:02:25 -05:00
|
|
|
use Illuminate\Support\Facades\URL as LaravelUrl;
|
2019-03-01 23:06:01 -06:00
|
|
|
use Illuminate\Support\Str;
|
2018-09-20 15:33:03 -05:00
|
|
|
use LibreNMS\Config;
|
2022-09-03 12:48:43 -05:00
|
|
|
use Request;
|
2020-05-06 09:12:33 -05:00
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
2018-09-20 15:33:03 -05:00
|
|
|
|
|
|
|
class Url
|
|
|
|
{
|
|
|
|
/**
|
2023-11-02 06:41:19 +01:00
|
|
|
* @param Device|null $device
|
|
|
|
* @param string|null $text
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param array $vars
|
|
|
|
* @param int $start
|
|
|
|
* @param int $end
|
|
|
|
* @param int $escape_text
|
|
|
|
* @param int $overlib
|
2018-09-20 15:33:03 -05:00
|
|
|
* @return string
|
|
|
|
*/
|
2023-11-02 06:41:19 +01:00
|
|
|
public static function deviceLink($device, $text = '', $vars = [], $start = 0, $end = 0, $escape_text = 1, $overlib = 1)
|
2018-09-20 15:33:03 -05:00
|
|
|
{
|
2021-03-30 14:47:11 -05:00
|
|
|
if (! $device instanceof Device || ! $device->hostname) {
|
2023-11-02 06:41:19 +01:00
|
|
|
return (string) $text;
|
2019-11-26 08:14:09 -06:00
|
|
|
}
|
|
|
|
|
2019-10-21 19:04:23 +02:00
|
|
|
if (! $device->canAccess(Auth::user())) {
|
|
|
|
return $device->displayName();
|
|
|
|
}
|
|
|
|
|
2018-09-20 15:33:03 -05:00
|
|
|
if (! $start) {
|
2019-11-26 08:14:09 -06:00
|
|
|
$start = Carbon::now()->subDay()->timestamp;
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $end) {
|
|
|
|
$end = Carbon::now()->timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $text) {
|
|
|
|
$text = $device->displayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($escape_text) {
|
|
|
|
$text = htmlentities($text);
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = self::deviceLinkDisplayClass($device);
|
2020-05-19 14:35:32 -05:00
|
|
|
$graphs = Graph::getOverviewGraphsForDevice($device);
|
2018-09-20 15:33:03 -05:00
|
|
|
$url = Url::deviceUrl($device, $vars);
|
|
|
|
|
|
|
|
// beginning of overlib box contains large hostname followed by hardware & OS details
|
|
|
|
$contents = '<div><span class="list-large">' . $device->displayName() . '</span>';
|
2023-11-16 22:54:29 +08:00
|
|
|
$devinfo = '';
|
2018-09-20 15:33:03 -05:00
|
|
|
if ($device->hardware) {
|
2023-11-16 22:54:29 +08:00
|
|
|
$devinfo .= htmlentities($device->hardware);
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($device->os) {
|
2023-11-16 22:54:29 +08:00
|
|
|
$devinfo .= ($devinfo ? ' - ' : '') . htmlentities(Config::getOsSetting($device->os, 'text'));
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($device->version) {
|
2023-11-16 22:54:29 +08:00
|
|
|
$devinfo .= ($devinfo ? ' - ' : '') . htmlentities($device->version);
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($device->features) {
|
2023-11-16 22:54:29 +08:00
|
|
|
$devinfo .= ' (' . htmlentities($device->features) . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($devinfo) {
|
|
|
|
$contents .= '<br />' . $devinfo;
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
2018-12-07 16:24:53 -06:00
|
|
|
if ($device->location_id) {
|
2023-11-16 22:54:29 +08:00
|
|
|
$contents .= '<br />' . htmlentities($device->location ?? '');
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
2023-11-16 22:54:29 +08:00
|
|
|
$contents .= '</div><br />';
|
2018-09-20 15:33:03 -05:00
|
|
|
|
|
|
|
foreach ((array) $graphs as $entry) {
|
|
|
|
$graph = isset($entry['graph']) ? $entry['graph'] : 'unknown';
|
|
|
|
$graphhead = isset($entry['text']) ? $entry['text'] : 'unknown';
|
|
|
|
$contents .= '<div class="overlib-box">';
|
|
|
|
$contents .= '<span class="overlib-title">' . $graphhead . '</span><br />';
|
|
|
|
$contents .= Url::minigraphImage($device, $start, $end, $graph);
|
2020-04-29 07:25:13 -05:00
|
|
|
$contents .= Url::minigraphImage($device, Carbon::now()->subWeek()->timestamp, $end, $graph);
|
2018-09-20 15:33:03 -05:00
|
|
|
$contents .= '</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($overlib == 0) {
|
|
|
|
$link = $contents;
|
|
|
|
} else {
|
2018-12-16 15:18:17 -06:00
|
|
|
$contents = self::escapeBothQuotes($contents);
|
2018-09-20 15:33:03 -05:00
|
|
|
$link = Url::overlibLink($url, $text, $contents, $class);
|
|
|
|
}
|
|
|
|
|
2019-10-21 19:04:23 +02:00
|
|
|
return $link;
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
2018-09-24 02:07:00 -05:00
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param Port $port
|
|
|
|
* @param string $text
|
|
|
|
* @param string $type
|
|
|
|
* @param bool $overlib
|
|
|
|
* @param bool $single_graph
|
2018-09-24 02:07:00 -05:00
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
public static function portLink($port, $text = null, $type = null, $overlib = true, $single_graph = false)
|
|
|
|
{
|
2021-08-23 21:19:55 -05:00
|
|
|
if ($port === null) {
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2018-09-24 02:07:00 -05:00
|
|
|
$label = Rewrite::normalizeIfName($port->getLabel());
|
|
|
|
if (! $text) {
|
|
|
|
$text = $label;
|
|
|
|
}
|
|
|
|
|
2023-04-17 13:51:35 +02:00
|
|
|
$content = '<div class=list-large>' . addslashes(htmlentities($port->device?->displayName() . ' - ' . $label)) . '</div>';
|
2021-09-10 08:07:08 -05:00
|
|
|
if ($description = $port->getDescription()) {
|
|
|
|
$content .= addslashes(htmlentities($description)) . '<br />';
|
2018-09-24 02:07:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$content .= "<div style=\'width: 850px\'>";
|
|
|
|
$graph_array = [
|
|
|
|
'type' => $type ?: 'port_bits',
|
|
|
|
'legend' => 'yes',
|
|
|
|
'height' => 100,
|
|
|
|
'width' => 340,
|
|
|
|
'to' => Carbon::now()->timestamp,
|
|
|
|
'from' => Carbon::now()->subDay()->timestamp,
|
|
|
|
'id' => $port->port_id,
|
|
|
|
];
|
|
|
|
|
|
|
|
$content .= self::graphTag($graph_array);
|
|
|
|
if (! $single_graph) {
|
|
|
|
$graph_array['from'] = Carbon::now()->subWeek()->timestamp;
|
|
|
|
$content .= self::graphTag($graph_array);
|
|
|
|
$graph_array['from'] = Carbon::now()->subMonth()->timestamp;
|
|
|
|
$content .= self::graphTag($graph_array);
|
|
|
|
$graph_array['from'] = Carbon::now()->subYear()->timestamp;
|
|
|
|
$content .= self::graphTag($graph_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
$content .= '</div>';
|
|
|
|
|
|
|
|
if (! $overlib) {
|
|
|
|
return $content;
|
|
|
|
} elseif ($port->canAccess(Auth::user())) {
|
|
|
|
return self::overlibLink(self::portUrl($port), $text, $content, self::portLinkDisplayClass($port));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Rewrite::normalizeIfName($text);
|
|
|
|
}
|
|
|
|
|
2020-04-19 19:57:49 +02:00
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\Sensor $sensor
|
|
|
|
* @param string $text
|
|
|
|
* @param string $type
|
|
|
|
* @param bool $overlib
|
|
|
|
* @param bool $single_graph
|
2020-04-19 19:57:49 +02:00
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
public static function sensorLink($sensor, $text = null, $type = null, $overlib = true, $single_graph = false)
|
|
|
|
{
|
|
|
|
$label = $sensor->sensor_descr;
|
|
|
|
if (! $text) {
|
|
|
|
$text = $label;
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = '<div class=list-large>' . addslashes(htmlentities($sensor->device->displayName() . ' - ' . $label)) . '</div>';
|
|
|
|
|
|
|
|
$content .= "<div style=\'width: 850px\'>";
|
|
|
|
$graph_array = [
|
|
|
|
'type' => $type ?: 'sensor_' . $sensor->sensor_class,
|
|
|
|
'legend' => 'yes',
|
|
|
|
'height' => 100,
|
|
|
|
'width' => 340,
|
|
|
|
'to' => Carbon::now()->timestamp,
|
|
|
|
'from' => Carbon::now()->subDay()->timestamp,
|
|
|
|
'id' => $sensor->sensor_id,
|
|
|
|
];
|
|
|
|
|
|
|
|
$content .= self::graphTag($graph_array);
|
|
|
|
if (! $single_graph) {
|
|
|
|
$graph_array['from'] = Carbon::now()->subWeek()->timestamp;
|
|
|
|
$content .= self::graphTag($graph_array);
|
|
|
|
$graph_array['from'] = Carbon::now()->subMonth()->timestamp;
|
|
|
|
$content .= self::graphTag($graph_array);
|
|
|
|
$graph_array['from'] = Carbon::now()->subYear()->timestamp;
|
|
|
|
$content .= self::graphTag($graph_array);
|
|
|
|
}
|
|
|
|
|
|
|
|
$content .= '</div>';
|
|
|
|
|
|
|
|
if (! $overlib) {
|
|
|
|
return $content;
|
|
|
|
}
|
2020-09-21 14:54:51 +02:00
|
|
|
|
2020-04-19 19:57:49 +02:00
|
|
|
return self::overlibLink(self::sensorUrl($sensor), $text, $content, self::sensorLinkDisplayClass($sensor));
|
|
|
|
}
|
|
|
|
|
2020-04-29 07:25:13 -05:00
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param int|Device $device
|
|
|
|
* @param array $vars
|
2020-04-29 07:25:13 -05:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-09-20 15:33:03 -05:00
|
|
|
public static function deviceUrl($device, $vars = [])
|
|
|
|
{
|
2022-08-05 09:01:15 -05:00
|
|
|
$routeParams = [($device instanceof Device) ? $device->device_id : (int) $device];
|
2020-04-29 07:25:13 -05:00
|
|
|
if (isset($vars['tab'])) {
|
|
|
|
$routeParams[] = $vars['tab'];
|
|
|
|
unset($vars['tab']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return route('device', $routeParams) . self::urlParams($vars);
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
2018-09-24 02:07:00 -05:00
|
|
|
public static function portUrl($port, $vars = [])
|
|
|
|
{
|
|
|
|
return self::generate(['page' => 'device', 'device' => $port->device_id, 'tab' => 'port', 'port' => $port->port_id], $vars);
|
|
|
|
}
|
|
|
|
|
2020-04-19 19:57:49 +02:00
|
|
|
public static function sensorUrl($sensor, $vars = [])
|
|
|
|
{
|
|
|
|
return self::generate(['page' => 'device', 'device' => $sensor->device_id, 'tab' => 'health', 'metric' => $sensor->sensor_class], $vars);
|
|
|
|
}
|
|
|
|
|
2018-12-16 15:18:17 -06:00
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param Port $port
|
2018-12-16 15:18:17 -06:00
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
2021-05-31 19:40:45 +02:00
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param Port $port
|
2021-05-31 19:40:45 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function portErrorsThumbnail($port)
|
|
|
|
{
|
|
|
|
$graph_array = [
|
|
|
|
'port_id' => $port->port_id,
|
|
|
|
'graph_type' => 'port_errors',
|
|
|
|
'from' => Carbon::now()->subDay()->timestamp,
|
|
|
|
'to' => Carbon::now()->timestamp,
|
|
|
|
'width' => 150,
|
|
|
|
'height' => 21,
|
|
|
|
];
|
|
|
|
|
|
|
|
return self::portImage($graph_array);
|
|
|
|
}
|
|
|
|
|
2018-12-16 15:18:17 -06:00
|
|
|
public static function portImage($args)
|
|
|
|
{
|
|
|
|
if (empty($args['bg'])) {
|
|
|
|
$args['bg'] = 'FFFFFF00';
|
|
|
|
}
|
|
|
|
|
2019-05-21 08:50:45 -05:00
|
|
|
return '<img src="' . url('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'] . '">';
|
2018-12-16 15:18:17 -06:00
|
|
|
}
|
|
|
|
|
2018-09-20 15:33:03 -05:00
|
|
|
public static function generate($vars, $new_vars = [])
|
|
|
|
{
|
|
|
|
$vars = array_merge($vars, $new_vars);
|
|
|
|
|
2020-07-17 08:32:30 -05:00
|
|
|
$url = url(Config::get('base_url', true) . $vars['page'] . '');
|
2018-09-20 15:33:03 -05:00
|
|
|
unset($vars['page']);
|
|
|
|
|
2020-04-29 07:25:13 -05:00
|
|
|
return $url . self::urlParams($vars);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate url parameters to append to url
|
|
|
|
* $prefix will only be prepended if there are parameters
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param array $vars
|
|
|
|
* @param string $prefix
|
2020-04-29 07:25:13 -05:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private static function urlParams($vars, $prefix = '/')
|
|
|
|
{
|
|
|
|
$url = empty($vars) ? '' : $prefix;
|
2018-09-20 15:33:03 -05:00
|
|
|
foreach ($vars as $var => $value) {
|
2020-04-17 17:37:56 -05:00
|
|
|
if ($value == '0' || $value != '' && ! Str::contains($var, 'opt') && ! is_numeric($var)) {
|
2021-02-08 02:43:34 +01:00
|
|
|
$url .= urlencode($var) . '=' . urlencode($value) . '/';
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2022-09-03 12:48:43 -05:00
|
|
|
/**
|
|
|
|
* @param array|string $args
|
|
|
|
*/
|
|
|
|
public static function forExternalGraph($args): string
|
|
|
|
{
|
|
|
|
// handle pasted string
|
|
|
|
if (is_string($args)) {
|
|
|
|
$path = str_replace(url('/') . '/', '', $args);
|
|
|
|
$args = self::parseLegacyPathVars($path);
|
|
|
|
}
|
|
|
|
|
2022-09-03 13:02:25 -05:00
|
|
|
return LaravelUrl::signedRoute('graph', $args);
|
2022-09-03 12:48:43 -05:00
|
|
|
}
|
|
|
|
|
2018-09-24 02:07:00 -05:00
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param array $args
|
2018-09-24 02:07:00 -05:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function graphTag($args)
|
|
|
|
{
|
|
|
|
$urlargs = [];
|
|
|
|
foreach ($args as $key => $arg) {
|
2022-08-30 12:55:37 -05:00
|
|
|
$urlargs[] = $key . '=' . ($arg === null ? '' : urlencode($arg));
|
2018-09-24 02:07:00 -05:00
|
|
|
}
|
|
|
|
|
2019-05-21 08:50:45 -05:00
|
|
|
return '<img src="' . url('graph.php') . '?' . implode('&', $urlargs) . '" style="border:0;" />';
|
2018-11-29 19:23:40 -06:00
|
|
|
}
|
|
|
|
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
public static function graphPopup($args, $content = null, $link = null)
|
2020-04-29 07:25:13 -05:00
|
|
|
{
|
|
|
|
// Take $args and print day,week,month,year graphs in overlib, hovered over graph
|
|
|
|
$original_from = $args['from'];
|
|
|
|
$now = CarbonImmutable::now();
|
|
|
|
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$graph = $content ?: self::graphTag($args);
|
|
|
|
$popup = '<div class=list-large>' . $args['popup_title'] . '</div>';
|
|
|
|
$popup .= '<div style="width: 850px">';
|
2020-04-29 07:25:13 -05:00
|
|
|
$args['width'] = 340;
|
|
|
|
$args['height'] = 100;
|
|
|
|
$args['legend'] = 'yes';
|
|
|
|
$args['from'] = $now->subDay()->timestamp;
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$popup .= self::graphTag($args);
|
2020-04-29 07:25:13 -05:00
|
|
|
$args['from'] = $now->subWeek()->timestamp;
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$popup .= self::graphTag($args);
|
2020-04-29 07:25:13 -05:00
|
|
|
$args['from'] = $now->subMonth()->timestamp;
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$popup .= self::graphTag($args);
|
2020-04-29 07:25:13 -05:00
|
|
|
$args['from'] = $now->subYear()->timestamp;
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$popup .= self::graphTag($args);
|
|
|
|
$popup .= '</div>';
|
2020-04-29 07:25:13 -05:00
|
|
|
|
|
|
|
$args['from'] = $original_from;
|
|
|
|
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
$args['link'] = $link ?: self::generate($args, ['page' => 'graphs', 'height' => null, 'width' => null, 'bg' => null]);
|
2020-04-29 07:25:13 -05:00
|
|
|
|
Modernize mempools (#12282)
* mempools to modern module
quick hacky hrstorage port
* port ucd-snmp-mib to Mempools
* Populate DB for ucd
Prep for yaml
* initial yaml attempt
* more complex conversions
fixes to YamlDiscovery, make leading $ optional and allow mib::oid format
* walk full tables and skip values
normalize percentages above 100
* handle precent only ones (specify total as 100)
* Move default polling out of YamlMempoolsDiscovery
* fixes
* Update test data hrstorage should be correct.
* perc_warn for hrstorage
* Host Resources, record buffer, cached, and shared
* Host Resources is always better, don't do both HR and UCD
* fix unix, include warning levels
* variable size
* consolidate skip_values
* define mempools schema
* number instead of integer
* more schema refactor
* one more skip_values reference
* throw error for invalid oid translation
aos6
* a* and Cisco
* updated test data
* update almost all hrstorage data files
* b*
* c* with test data
use standard cache for hrStorage
* use cache for storage module too
* hand bsnmp properly
* bdcom
* exclude total oid from yaml so it is not polled
May add a way to ignore this behavior and poll it, but I don't know if that is needed.
* automatically handle percent only values
* ciscowlc
* only poll used or free if we have used, free, and total.
* fix skipping
* the dlinkoning
fix find value when value "name" is numeric
* support numeric oids
* dnos/ftos attempt
* I guess we can't filter on total > 0
* edgecos
* e*
* f WIP
* f*
* gwd (aka g*)
* h* + procurve
* i*
* j*
* m*
* support 0% used memory (however unlikely)
* n*
* CISCO-PROCESS-MIB memory, share cache with processors module
* ignore mempools with invalid total
* p*
* quanta
* r*
fix raisecom mibs terribly broken
* s-z
* style fixes
* Move VRP back to PHP and make it actually work
* fix zynos
* update schema
* Update Cisco processor data for description bug fixes
* fix comware processors
* comware mempools with memory size
default precision to 1
* sophos-xg updated data
* hrstorage use ram size for buffers, cache, and shared
* Show memory available instead of free in device overview
* UCD, use same rrd format, store available instead of free in the db.
* Calculate availability for HOST-RESOURCES-MIB
* Convert UCD to standard polling
* rename old rrd files
* initial graph work
* graph WIP
* Graph looking decent
* Graph looking decent for hr
* remove old ucd_graph code
* handle availability mempool
more graph cleanup
* color adjustments
* remove accidental free calculation
* Update test data and fix corner cases
* fis pfsense
* update schema
* add default value for mempool_class
* fix whitespace
* update schema
* update schema correctly
* one more time
* fortigate_1500d-sensors missing oids
* Update docs.
* fix indent
* add implements MempoolsDiscovery explicitly to OS
* remove ucd_memory graph references
remove unused device_memory graph
* remove unused functions
* set devices with mempools to rediscover to prevent/minimize gaps
* use a subquery
* add overview graph
* port health mempools table
* Update device mempool
* only show overview if multiple
* Don't override user set warn percentages in discovery
* fix missed usage
* fix style
* Safety check to not rename rrd files incorrectly if migration has not been run.
* Fix overview percent bar and represent available and used on the bar
* missed an item to convert to mempool_class
* percent on the wrong side
2020-11-23 15:35:35 -06:00
|
|
|
return self::overlibLink($args['link'], $graph, $popup, null);
|
2020-04-29 07:25:13 -05:00
|
|
|
}
|
|
|
|
|
2018-11-29 19:23:40 -06:00
|
|
|
public static function lazyGraphTag($args)
|
|
|
|
{
|
|
|
|
$urlargs = [];
|
|
|
|
|
|
|
|
foreach ($args as $key => $arg) {
|
2022-08-30 12:55:37 -05:00
|
|
|
$urlargs[] = $key . '=' . ($arg === null ? '' : urlencode($arg));
|
2018-11-29 19:23:40 -06:00
|
|
|
}
|
|
|
|
|
2021-04-08 04:24:53 -05:00
|
|
|
$tag = '<img class="img-responsive" src="' . url('graph.php') . '?' . implode('&', $urlargs) . '" style="border:0;"';
|
|
|
|
|
2018-11-29 19:23:40 -06:00
|
|
|
if (Config::get('enable_lazy_load', true)) {
|
2021-04-11 19:40:47 -05:00
|
|
|
return $tag . ' loading="lazy" />';
|
2018-11-29 19:23:40 -06:00
|
|
|
}
|
|
|
|
|
2021-04-08 04:24:53 -05:00
|
|
|
return $tag . ' />';
|
2018-09-24 02:07:00 -05:00
|
|
|
}
|
|
|
|
|
2018-09-20 15:33:03 -05:00
|
|
|
public static function overlibLink($url, $text, $contents, $class = null)
|
|
|
|
{
|
2019-06-04 02:40:56 +02:00
|
|
|
$contents = "<div class=\'overlib-contents\'>" . $contents . '</div>';
|
2018-09-20 15:33:03 -05:00
|
|
|
$contents = str_replace('"', "\'", $contents);
|
|
|
|
if ($class === null) {
|
|
|
|
$output = '<a href="' . $url . '"';
|
|
|
|
} else {
|
|
|
|
$output = '<a class="' . $class . '" href="' . $url . '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Config::get('web_mouseover', true)) {
|
|
|
|
$defaults = Config::get('overlib_defaults', ",FGCOLOR,'#ffffff', BGCOLOR, '#e5e5e5', BORDER, 5, CELLPAD, 4, CAPCOLOR, '#555555', TEXTCOLOR, '#3e3e3e'");
|
|
|
|
$output .= " onmouseover=\"return overlib('$contents'$defaults,WRAP,HAUTO,VAUTO); \" onmouseout=\"return nd();\">";
|
|
|
|
} else {
|
|
|
|
$output .= '>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$output .= $text . '</a>';
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2018-12-16 15:18:17 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-09-20 15:33:03 -05:00
|
|
|
/**
|
|
|
|
* Generate minigraph image url
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param Device $device
|
|
|
|
* @param int $start
|
|
|
|
* @param int $end
|
|
|
|
* @param string $type
|
|
|
|
* @param string $legend
|
|
|
|
* @param int $width
|
|
|
|
* @param int $height
|
|
|
|
* @param string $sep
|
|
|
|
* @param string $class
|
|
|
|
* @param int $absolute_size
|
2018-09-20 15:33:03 -05:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function minigraphImage($device, $start, $end, $type, $legend = 'no', $width = 275, $height = 100, $sep = '&', $class = 'minigraph-image', $absolute_size = 0)
|
|
|
|
{
|
|
|
|
$vars = ['device=' . $device->device_id, "from=$start", "to=$end", "width=$width", "height=$height", "type=$type", "legend=$legend", "absolute=$absolute_size"];
|
2020-09-21 14:54:51 +02:00
|
|
|
|
2019-05-21 08:50:45 -05:00
|
|
|
return '<img class="' . $class . '" width="' . $width . '" height="' . $height . '" src="' . url('graph.php') . '?' . implode($sep, $vars) . '">';
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param Device $device
|
2018-09-20 15:33:03 -05:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private static function deviceLinkDisplayClass($device)
|
|
|
|
{
|
|
|
|
if ($device->disabled) {
|
|
|
|
return 'list-device-disabled';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($device->ignore) {
|
|
|
|
return $device->status ? 'list-device-ignored-up' : 'list-device-ignored';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $device->status ? 'list-device' : 'list-device-down';
|
|
|
|
}
|
2018-09-24 02:07:00 -05:00
|
|
|
|
2018-12-07 16:24:53 -06:00
|
|
|
/**
|
|
|
|
* Get html class for a port using ifAdminStatus and ifOperStatus
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param Port $port
|
2018-12-07 16:24:53 -06:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function portLinkDisplayClass($port)
|
2018-09-24 02:07:00 -05:00
|
|
|
{
|
|
|
|
if ($port->ifAdminStatus == 'down') {
|
|
|
|
return 'interface-admindown';
|
|
|
|
}
|
|
|
|
|
2020-01-15 15:28:36 +01:00
|
|
|
if ($port->ifAdminStatus == 'up' && $port->ifOperStatus != 'up') {
|
2018-09-24 02:07:00 -05:00
|
|
|
return 'interface-updown';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'interface-upup';
|
|
|
|
}
|
2018-12-16 15:18:17 -06:00
|
|
|
|
2020-04-19 19:57:49 +02:00
|
|
|
/**
|
|
|
|
* Get html class for a sensor
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param \App\Models\Sensor $sensor
|
2020-04-19 19:57:49 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function sensorLinkDisplayClass($sensor)
|
|
|
|
{
|
2020-04-21 10:19:41 -05:00
|
|
|
if ($sensor->sensor_current > $sensor->sensor_limit) {
|
2020-04-19 19:57:49 +02:00
|
|
|
return 'sensor-high';
|
|
|
|
}
|
|
|
|
|
2020-04-21 10:19:41 -05:00
|
|
|
if ($sensor->sensor_current < $sensor->sensor_limit_low) {
|
2020-04-19 19:57:49 +02:00
|
|
|
return 'sensor-low';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'sensor-ok';
|
|
|
|
}
|
|
|
|
|
2019-03-01 23:06:01 -06:00
|
|
|
/**
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param string $os
|
2022-09-05 15:32:04 -05:00
|
|
|
* @param string|null $feature
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param string $icon
|
|
|
|
* @param string $dir directory to search in (images/os/ or images/logos)
|
2019-03-01 23:06:01 -06:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function findOsImage($os, $feature, $icon = null, $dir = 'images/os/')
|
|
|
|
{
|
|
|
|
$possibilities = [$icon];
|
|
|
|
|
|
|
|
if ($os) {
|
2022-09-05 15:32:04 -05:00
|
|
|
if ($os == 'linux' && $feature) {
|
2020-01-21 20:37:10 -05:00
|
|
|
// first, prefer the first word of $feature
|
2019-03-01 23:06:01 -06:00
|
|
|
$distro = Str::before(strtolower(trim($feature)), ' ');
|
|
|
|
$possibilities[] = "$distro.svg";
|
|
|
|
$possibilities[] = "$distro.png";
|
2020-01-21 20:37:10 -05:00
|
|
|
|
|
|
|
// second, prefer the first two words of $feature (i.e. 'Red Hat' becomes 'redhat')
|
|
|
|
if (strpos($feature, ' ') !== false) {
|
2021-04-08 15:14:49 +02:00
|
|
|
$distro = Str::replaceFirst(' ', '', strtolower(trim($feature)));
|
2020-01-21 20:37:10 -05:00
|
|
|
$distro = Str::before($distro, ' ');
|
|
|
|
$possibilities[] = "$distro.svg";
|
|
|
|
$possibilities[] = "$distro.png";
|
|
|
|
}
|
2019-03-01 23:06:01 -06:00
|
|
|
}
|
|
|
|
$os_icon = Config::getOsSetting($os, 'icon', $os);
|
|
|
|
$possibilities[] = "$os_icon.svg";
|
|
|
|
$possibilities[] = "$os_icon.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($possibilities as $file) {
|
|
|
|
if (is_file(Config::get('html_dir') . "/$dir" . $file)) {
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fallback to the generic icon
|
|
|
|
return 'generic.svg';
|
|
|
|
}
|
|
|
|
|
2020-05-06 09:12:33 -05:00
|
|
|
/**
|
|
|
|
* parse a legacy path (one without ? or &)
|
|
|
|
*
|
2021-09-08 23:35:56 +02:00
|
|
|
* @param string $path
|
2020-05-06 09:12:33 -05:00
|
|
|
* @return ParameterBag
|
|
|
|
*/
|
|
|
|
public static function parseLegacyPath($path)
|
|
|
|
{
|
|
|
|
$parts = array_filter(explode('/', $path), function ($part) {
|
|
|
|
return Str::contains($part, '=');
|
|
|
|
});
|
|
|
|
|
|
|
|
$vars = [];
|
|
|
|
foreach ($parts as $part) {
|
2020-05-19 14:35:32 -05:00
|
|
|
[$key, $value] = explode('=', $part);
|
2020-05-06 09:12:33 -05:00
|
|
|
$vars[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ParameterBag($vars);
|
|
|
|
}
|
|
|
|
|
2022-01-30 16:28:18 -06:00
|
|
|
/**
|
|
|
|
* Parse options from the url including get/post parameters and any url segments containing an =
|
|
|
|
*
|
|
|
|
* @param int|string|null $key Optional key to pull from the options
|
|
|
|
* @param mixed $default The default value to return when the given key does not exist
|
|
|
|
* @return array|mixed|null
|
|
|
|
*/
|
|
|
|
public static function parseOptions($key = null, $default = null)
|
|
|
|
{
|
|
|
|
$request = request();
|
|
|
|
$options = $request->all();
|
|
|
|
|
|
|
|
foreach (explode('/', $request->path()) as $segment) {
|
|
|
|
$segment = urldecode($segment);
|
|
|
|
if (Str::contains($segment, '=')) {
|
|
|
|
[$name, $value] = explode('=', $segment, 2);
|
|
|
|
$options[$name] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_null($key) ? $options : $options[$key] ?? $default;
|
|
|
|
}
|
|
|
|
|
2022-09-03 12:48:43 -05:00
|
|
|
/**
|
|
|
|
* Parse variables from legacy path /key=value/key=value or regular get/post variables
|
|
|
|
*/
|
|
|
|
public static function parseLegacyPathVars(?string $path = null): array
|
|
|
|
{
|
|
|
|
$vars = [];
|
|
|
|
$parsed_get_vars = [];
|
|
|
|
if (empty($path)) {
|
|
|
|
$path = Request::path();
|
|
|
|
} elseif (Str::startsWith($path, 'http') || str_contains($path, '?')) {
|
|
|
|
$parsed_url = parse_url($path);
|
|
|
|
$path = $parsed_url['path'] ?? '';
|
|
|
|
parse_str($parsed_url['query'] ?? '', $parsed_get_vars);
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't parse the subdirectory, if there is one in the path
|
|
|
|
$base_url = parse_url(Config::get('base_url'))['path'] ?? '';
|
|
|
|
if (strlen($base_url) > 1) {
|
|
|
|
$segments = explode('/', trim(str_replace($base_url, '', $path), '/'));
|
|
|
|
} else {
|
|
|
|
$segments = explode('/', trim($path, '/'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the path
|
|
|
|
foreach ($segments as $pos => $segment) {
|
|
|
|
$segment = urldecode($segment);
|
|
|
|
if ($pos === 0) {
|
|
|
|
$vars['page'] = $segment;
|
|
|
|
} else {
|
|
|
|
[$name, $value] = array_pad(explode('=', $segment), 2, null);
|
2023-04-14 16:46:56 -05:00
|
|
|
if ($value === null) {
|
2022-09-03 12:48:43 -05:00
|
|
|
if ($vars['page'] == 'device' && $pos < 3) {
|
|
|
|
// translate laravel device routes properly
|
|
|
|
$vars[$pos === 1 ? 'device' : 'tab'] = $name;
|
|
|
|
} elseif ($name) {
|
|
|
|
$vars[$name] = 'yes';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$vars[$name] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$vars = array_merge($vars, $parsed_get_vars);
|
|
|
|
|
|
|
|
// don't leak login data
|
|
|
|
unset($vars['username'], $vars['password']);
|
|
|
|
|
|
|
|
return $vars;
|
|
|
|
}
|
|
|
|
|
2018-12-16 15:18:17 -06:00
|
|
|
private static function escapeBothQuotes($string)
|
|
|
|
{
|
|
|
|
return str_replace(["'", '"'], "\'", $string);
|
|
|
|
}
|
2018-09-20 15:33:03 -05:00
|
|
|
}
|