mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Definition of a new SLA module to migrate from old cisco-sla and support other devices : Juniper RPM and Huawei * Change wrong description name of module SLA * Re implementing Juniper RPM support in a new module Slas (Cisco SLA to be added) * Added Graphs for Juniper RPM types * Tried to make discover and poller generic : to handle Cisco SLA and Juniper RPM and others * Reimplementing Cisco SLA in the new Sla module and adding condition to manage both SLA and RPM * Definition of a new SLA module to migrate from old cisco-sla and support other devices : Juniper RPM and Huawei * Change wrong description name of module SLA * Re implementing Juniper RPM support in a new module Slas (Cisco SLA to be added) * Added Graphs for Juniper RPM types * Tried to make discover and poller generic : to handle Cisco SLA and Juniper RPM and others * Reimplementing Cisco SLA in the new Sla module and adding condition to manage both SLA and RPM * Fix some error due to Elequent object replacing SQL request * Fixing indentation * Fixed continuous integrations errors * Fixed continuous integrations errors part 2 * Fixed continuous integrations errors part 3 : missing last new lines * Fixed PHP Static Analysis checks * Fixed continuous integrations errors part 4 * Fixed PHP Static Analysis checks part 2 * Trying to convert existing cisco-sla to new slas one * Trying to add slas to fix test failure (I am pretty sure this is not enough but I don't know how to do it) * Switching old cisco-sla module declaration to new slas module in concerned OS files * Fixing wrong sla module name instead of slas in concerned OS files * Fixing wrong module name sla changed to slas (as is it in power-supplies reimplementation) * Fixing some warnings shown in the Inspection CI but skipping some that are already present * Adding tests files from virtual Juniper VMX and adding slas modules in /tests/module_tables * Adding missing SNMP data files * Module Slas modifications to use inheritance * Fix CI errors * Fix CI errors part 2 * Fix CI errors part 3 * Fixing no value on RTT graphs * Fixing only last SLA to be polled : problem with loops * Fix CI errors part 4 * Optimizing a little the Juniper RPM poller part I wanted to query only the required values but it is complicated to query a specific OID as Cisco-SLA does because the owner and tag are hardcoded in ASCII decimal with strange values. So I use the function snmp_walk which gets the whole OID values in text. And I index the Juniper MIB (because we want multiple values). But I changed the DISMAN MIB requests to get only what we want. * Fix CI errors * Fix CI errors part 2 * Fix CI errors part 3 * Fixing PHP Static Analysis error 2/4 * Fix CI errors * Implementing Interfaces to fix some errors that occurs with inheritance * Adding missing Interfaces files * Moving generic Sla discovery code into Junos Class * Fix CI errors * Fix CI errors part 2 * Fixing missing definition of SlaDiscovery in Cisco shared Class * Fixing missing import for Illuminate\Database\Eloquent\Collection * Fix CI errors part 3 * Fix PHP Static Analysis error * change type strings to use translations instead of config * IOSXR test data * remove test data garbage * simplify discovery * Fix style * Updating test files to adapt mock sla_nr ID starting from 0 and not 1 : CI tests should pass * clean up polling add rtt field in the db cisco icmpjitter seems to have confused a lot of values * rtt on discovery * use crc32 for consistent sla_nr values * revert snmprec * Fix style * correct schema Co-authored-by: Tony Murray <murraytony@gmail.com>
97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* helpers.php
|
|
*
|
|
* Functions available in both Laravel and Legacy code (must not call any other legacy functions)
|
|
*
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
*
|
|
* @link https://www.librenms.org
|
|
* @copyright 2018 Tony Murray
|
|
* @author Tony Murray <murraytony@gmail.com>
|
|
*/
|
|
|
|
use LibreNMS\Util\Debug;
|
|
use LibreNMS\Util\Laravel;
|
|
|
|
if (! function_exists('d_echo')) {
|
|
/**
|
|
* Legacy convenience function - please use this instead of 'if (Debug::isEnabled()) { echo ...; }'
|
|
* Use Log directly in pure Laravel code!
|
|
*
|
|
* @param string|array $text The error message or array to print
|
|
* @param string $no_debug_text Text to print if debug is disabled
|
|
*/
|
|
function d_echo($text, $no_debug_text = null)
|
|
{
|
|
if (Laravel::isBooted()) {
|
|
\Log::debug(is_string($text) ? rtrim($text) : $text);
|
|
} elseif (Debug::isEnabled()) {
|
|
print_r($text);
|
|
}
|
|
|
|
if (! Debug::isEnabled() && $no_debug_text) {
|
|
echo "$no_debug_text";
|
|
}
|
|
}
|
|
}
|
|
|
|
if (! function_exists('array_pairs')) {
|
|
/**
|
|
* Get all consecutive pairs of values in an array.
|
|
* [1,2,3,4] -> [[1,2],[2,3],[3,4]]
|
|
*
|
|
* @param array $array
|
|
* @return array
|
|
*/
|
|
function array_pairs($array)
|
|
{
|
|
$pairs = [];
|
|
|
|
for ($i = 1; $i < count($array); $i++) {
|
|
$pairs[] = [$array[$i - 1], $array[$i]];
|
|
}
|
|
|
|
return $pairs;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Cast string to int or float.
|
|
* Returns 0 if string is not numeric
|
|
*
|
|
* @param string $number
|
|
* @return float|int
|
|
*/
|
|
function cast_number($number)
|
|
{
|
|
return \LibreNMS\Util\Number::cast($number);
|
|
}
|
|
|
|
if (! function_exists('trans_fb')) {
|
|
/**
|
|
* Translate the given message with a fallback string if none exists.
|
|
*
|
|
* @param string $key
|
|
* @param string $fallback
|
|
* @param array $replace
|
|
* @param string $locale
|
|
* @return \Symfony\Component\Translation\TranslatorInterface|string
|
|
*/
|
|
function trans_fb($key, $fallback, $replace = [], $locale = null)
|
|
{
|
|
return ($key === ($translation = trans($key, $replace, $locale))) ? $fallback : $translation;
|
|
}
|
|
}
|