Miscellaneous fixes (#15162)

This commit is contained in:
Tony Murray 2023-07-25 18:08:10 -05:00 committed by GitHub
parent ffffdd2663
commit 3908bddb49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 44 additions and 34 deletions

View File

@ -494,7 +494,7 @@ class Config
{
if (! self::has($key)) {
if (is_string($value)) {
$format_values = array_map('self::get', $format_values);
$format_values = array_map('\LibreNMS\Config::get', $format_values);
self::set($key, vsprintf($value, $format_values));
} else {
self::set($key, $value);

View File

@ -84,7 +84,7 @@ class GraphParameters
$this->is_small = $this->width < self::SMALL;
$this->font = Config::get('mono_font');
$this->font_color = Clean::alphaDash($vars['font']);
$this->font_color = Clean::alphaDash($vars['font'] ?? '');
$this->font_size = $this->width <= self::MEDIUM_SMALL ? 7 : 8;
$this->canvas = Clean::alphaDash($vars['bg'] ?? '');

View File

@ -52,7 +52,9 @@ class Trap
$this->hostname = array_shift($lines);
$line = array_shift($lines);
preg_match('/\[([0-9.:a-fA-F]+)]/', $line, $matches);
if ($line) {
preg_match('/\[([0-9.:a-fA-F]+)]/', $line, $matches);
}
$this->ip = $matches[1] ?? '';
// parse the oid data

View File

@ -58,13 +58,15 @@ class Clean
* Clean a string for display in an html page.
* For use in non-blade pages
*
* @param string $value
* @param string|null $value
* @param array $purifier_config (key, value pair)
* @return string
*/
public static function html($value, $purifier_config = [])
public static function html($value, $purifier_config = []): string
{
static $purifier;
if (empty($value)) {
return '';
}
// If $purifier_config is non-empty then we don't want
// to convert html tags and allow these to be controlled
@ -73,6 +75,8 @@ class Clean
$value = htmlentities($value);
}
static $purifier;
if (! $purifier instanceof HTMLPurifier) {
// initialize HTML Purifier here since this is the only user
$p_config = HTMLPurifier_Config::createDefault();

View File

@ -101,7 +101,10 @@ class Graph
*/
public static function get($vars): GraphImage
{
define('IGNORE_ERRORS', true);
if (! defined('IGNORE_ERRORS')) {
define('IGNORE_ERRORS', true);
}
chdir(base_path());
include_once base_path('includes/dbFacile.php');

View File

@ -198,7 +198,7 @@ class AlertSchedule extends Model
})
// Check we are on the correct day of the week
->where(function ($query) use ($localDayNum) {
$query->where('recurring_day', 'like', "%${localDayNum}%")
$query->where('recurring_day', 'like', "%{$localDayNum}%")
->orWhereNull('recurring_day');
});
});

View File

@ -877,8 +877,10 @@ function discovery_process(&$valid, $os, $sensor_class, $pre_cache)
d_echo("Data $tmp_name: ");
d_echo($raw_data);
$count = 0;
foreach ($raw_data as $index => $snmp_data) {
$count++;
$user_function = null;
if (isset($data['user_func'])) {
$user_function = $data['user_func'];
@ -886,7 +888,7 @@ function discovery_process(&$valid, $os, $sensor_class, $pre_cache)
// get the value for this sensor, check 'value' and 'oid', if state string, translate to a number
$data['value'] = isset($data['value']) ? $data['value'] : $data['oid']; // fallback to oid if value is not set
$snmp_value = $snmp_data[$data['value']];
$snmp_value = $snmp_data[$data['value']] ?? '';
if (! is_numeric($snmp_value)) {
if ($sensor_class === 'temperature') {
// For temp sensors, try and detect fahrenheit values

View File

@ -14,7 +14,7 @@ d_echo($hrDevices);
if (is_array($hrDevices)) {
foreach ($hrDevices as $hrDevice) {
if (is_array($hrDevice) && is_numeric($hrDevice['hrDeviceIndex'])) {
if (is_array($hrDevice) && isset($hrDevice['hrDeviceIndex']) && is_numeric($hrDevice['hrDeviceIndex'])) {
if (dbFetchCell('SELECT COUNT(*) FROM `hrDevice` WHERE device_id = ? AND hrDeviceIndex = ?', [$device['device_id'], $hrDevice['hrDeviceIndex']])) {
$update_array = [
'hrDeviceType' => $hrDevice['hrDeviceType'],

View File

@ -17,9 +17,9 @@ require 'includes/html/graphs/common.inc.php';
$stacked = generate_stacked_graphs();
if (! isset($descr_len)) {
$descr_len = 12;
}
$descr_len = $descr_len ?? 12;
$unitlen = $unitlen ?? 0;
$rrd_optionsb = '';
if ($nototal) {
$descr_len += '2';
@ -56,7 +56,7 @@ foreach ($rrd_list as $rrd) {
$rrd_options .= ' DEF:' . $id . "=$filename:$ds:AVERAGE";
if ($simple_rrd) {
if (! empty($simple_rrd)) {
$rrd_options .= ' CDEF:' . $id . 'min=' . $id . ' ';
$rrd_options .= ' CDEF:' . $id . 'max=' . $id . ' ';
} else {
@ -64,7 +64,7 @@ foreach ($rrd_list as $rrd) {
$rrd_options .= ' DEF:' . $id . "max=$filename:$ds:MAX";
}
if ($rrd['invert']) {
if (! empty($rrd['invert'])) {
$rrd_options .= ' CDEF:' . $id . 'i=' . $id . ',' . $stacked['stacked'] . ',*';
$rrd_optionsb .= ' LINE1.25:' . $id . 'i#' . $colour . ":'$descr'";

View File

@ -23,10 +23,17 @@ $transparency = $transparency ?? false;
$stack = $stack ?? '';
$rrd_optionsb = '';
$in_thing = '';
$out_thing = '';
$in_thingX = '';
$out_thingX = '';
$plus = '';
$pluses = '';
$plusesX = '';
$rrddescr_len = 14; // length of the padded rrd_descr in legend
$seperator = '';
$descr = '';
$descr_out = '';
if ($width > '1500') {
$rrddescr_len = 30;
@ -40,7 +47,7 @@ if ($width > '1500') {
$stacked = generate_stacked_graphs();
$units_descr = \LibreNMS\Data\Store\Rrd::fixedSafeDescr($units_descr, $rrddescr_len + 5);
$units_descr = \LibreNMS\Data\Store\Rrd::fixedSafeDescr($units_descr ?? '', $rrddescr_len + 5);
if ($format == 'octets' || $format == 'bytes') {
$units = 'Bps';
@ -89,16 +96,8 @@ foreach ($rrd_list ?? [] as $rrd) {
$iter = 0;
}
$colour_in = Config::get("graph_colours.$colours_in.$iter");
$colour_out = Config::get("graph_colours.$colours_out.$iter");
if ($rrd['colour_area_in']) {
$colour_in = $rrd['colour_area_in'];
}
if ($rrd['colour_area_out']) {
$colour_out = $rrd['colour_area_out'];
}
$colour_in = $rrd['colour_area_in'] ?? Config::get("graph_colours.$colours_in.$iter");
$colour_out = $rrd['colour_area_out'] ?? Config::get("graph_colours.$colours_out.$iter");
$rrd_options .= ' DEF:inB' . $i . '=' . $rrd['filename'] . ':' . $rrd['ds_in'] . ':AVERAGE ';
$rrd_options .= ' DEF:outB' . $i . '=' . $rrd['filename'] . ':' . $rrd['ds_out'] . ':AVERAGE ';

View File

@ -1,6 +1,7 @@
<?php
$scale_min = '0';
$current_id = $current_id ?? '';
require 'includes/html/graphs/common.inc.php';

View File

@ -66,10 +66,7 @@ $type_text = [
$active_metric = basename($vars['metric'] ?? 'processor');
if (! $vars['view']) {
$vars['view'] = 'detail';
}
$vars['view'] = $vars['view'] ?? 'detail';
$link_array = ['page' => 'health'];
$navbar = '<span style="font-weight: bold;">Health</span> &#187; ';
@ -88,6 +85,7 @@ foreach ($datas as $texttype) {
}
unset($sep);
$displayoptions = '';
if ($vars['view'] == 'graphs') {
$displayoptions = '<span class="pagemenu-selected">';
}

View File

@ -76,8 +76,6 @@ foreach (dbFetchRows($sql, $param) as $sensor) {
// FIXME - make this "four graphs in popup" a function/include and "small graph" a function.
// FIXME - So now we need to clean this up and move it into a function. Isn't it just "print-graphrow"?
// FIXME - DUPLICATED IN device/overview/sensors
$graph_colour = str_replace('#', '', $row_colour);
$graph_array = [];
$graph_array['height'] = '100';
$graph_array['width'] = '210';

View File

@ -37,7 +37,10 @@ global $vars, $console_color;
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
const IGNORE_ERRORS = true;
if (! defined('IGNORE_ERRORS')) {
define('IGNORE_ERRORS', true);
}
$install_dir = realpath(__DIR__ . '/..');
chdir($install_dir);

View File

@ -52,7 +52,7 @@ abstract class SnmpTrapTestCase extends TestCase
$trap = Mockery::mock('LibreNMS\Snmptrap\Trap[log,getDevice]', [$rawTrap]);
$trap->shouldReceive('getDevice')->andReturn($device); // mock getDevice to avoid saving to database
foreach (Arr::wrap($log) as $index => $message) {
$call_args = is_array($args[$index]) ? $args[$index] : $args;
$call_args = is_array($args[$index] ?? null) ? $args[$index] : $args;
$trap->shouldReceive('log')->once()->with(SimpleTemplate::parse($message, $template_variables), ...$call_args);
}