Improved Logging and Debugging (#8870)

Use Log facility when Laravel is booted.
Update init.php so we can easily boot Laravel for CLI scripts. (and just Eloquent, but that may go away)
Move all debug setup into set_debug() function and use that across all scripts.
Log Laravel database queries.
Send debug output to librenms log file when enabling debug in the webui.
Allow for colorized Log CLI output. (currently will leave % tags in log file output)

** Needs testing and perhaps tweaking still.

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`
This commit is contained in:
Tony Murray 2018-07-13 17:08:00 -05:00 committed by Neil Lathwood
parent 46eef4412c
commit eeb3d58f5b
100 changed files with 710 additions and 769 deletions

View File

@ -294,7 +294,7 @@ class Component
$OLD = $this->getComponents($device_id);
// Loop over each component.
foreach ($ARRAY as $COMPONENT => $AVP) {
foreach ((array)$ARRAY as $COMPONENT => $AVP) {
// Make sure the component already exists.
if (!isset($OLD[$device_id][$COMPONENT])) {
// Error. Component doesn't exist in the database.

View File

@ -304,7 +304,7 @@ class Sensor implements DiscoveryModule, PollerModule
}
// pre-fetch all standard sensors
$standard_sensors = call_user_func_array('array_merge', $sensors);
$standard_sensors = collect($sensors)->flatten(1)->all();
$pre_fetch = self::fetchSnmpData($os->getDevice(), $standard_sensors);
// poll standard sensors

View File

@ -0,0 +1,58 @@
<?php
/**
* CliColorFormatter.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 CliColorFormatter extends \Monolog\Formatter\LineFormatter
{
private $console_color;
private $console;
public function __construct()
{
$this->console_color = new \Console_Color2();
$this->console = \App::runningInConsole();
parent::__construct(
"%message%\n",
null,
true
);
}
public function format(array $record)
{
// only format messages where color is enabled
if (isset($record['context']['color']) && $record['context']['color']) {
if ($this->console) {
$record['message'] = $this->console_color->convert($record['message']);
} else {
$record['message'] = $this->console_color->strip($record['message']);
}
}
return parent::format($record);
}
}

View File

@ -63,7 +63,7 @@ class FileLock implements Lock
return;
}
if ($this->handle !== false) {
if (is_resource($this->handle)) {
flock($this->handle, LOCK_UN);
fclose($this->handle);
}

View File

@ -34,19 +34,8 @@ $options = getopt('d::');
$alerts_lock = FileLock::lockOrDie('alerts');
if (isset($options['d'])) {
if (set_debug(isset($options['d']))) {
echo "DEBUG!\n";
$debug = true;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
} else {
$debug = false;
// ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
// ini_set('error_reporting', 0);
}
if (!defined('TEST') && $config['alert']['disable'] != 'true') {

View File

@ -38,7 +38,8 @@ class AppServiceProvider extends ServiceProvider
Config::load();
// direct log output to librenms.log
Log::useFiles(Config::get('log_file', base_path('logs/librenms.log')));
Log::getMonolog()->popHandler(); // remove existing errorlog logger
Log::useFiles(Config::get('log_file', base_path('logs/librenms.log')), 'error');
// Blade directives (Yucky because of < L5.5)

View File

@ -17,19 +17,8 @@ $init_modules = array();
require __DIR__ . '/includes/init.php';
$options = getopt('d::h:f:;');
if (isset($options['d'])) {
if (set_debug(isset($options['d']))) {
echo "DEBUG!\n";
$debug = true;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
} else {
$debug = false;
// ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
// ini_set('error_reporting', 0);
}
if (isset($options['f'])) {

View File

@ -64,7 +64,7 @@ if (isset($options['i']) && $options['i'] && isset($options['n'])) {
$doing = $options['n'].'/'.$options['i'];
}
if (isset($options['d']) || isset($options['v'])) {
if (set_debug(isset($options['d'])) || isset($options['v'])) {
$versions = version_info();
echo <<<EOH
===================================
@ -83,18 +83,7 @@ EOH;
if (isset($options['v'])) {
$vdebug = true;
}
$debug = true;
update_os_cache(true); // Force update of OS Cache
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
} else {
$debug = false;
// ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
// ini_set('error_reporting', 0);
}
if (!$where) {

View File

@ -12,23 +12,11 @@
* the source code distribution for details.
*/
if (strpos($_SERVER['PATH_INFO'], 'debug')) {
$debug = '1';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
} else {
$debug = false;
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('error_reporting', 0);
}
$init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
set_debug(strpos($_SERVER['PATH_INFO'], 'debug'));
$report = mres($vars['report']);
if (!empty($report) && file_exists("includes/reports/$report.csv.inc.php")) {
if ($debug === false) {

View File

@ -48,7 +48,7 @@ if (is_numeric($_GET['interval'])) {
$time_interval=1; //Refresh time Interval
}
$fetch_link = "data.php?id=".$_GET[id];
$fetch_link = "data.php?id=".$_GET['id'];
//SVG attributes
$attribs['axis']='fill="black" stroke="black"';

View File

@ -13,23 +13,11 @@
$start = microtime(true);
if (isset($_GET['debug'])) {
$debug = true;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('error_reporting', E_ALL);
} else {
$debug = false;
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('error_reporting', 0);
}
$init_modules = array('web', 'graphs');
require realpath(__DIR__ . '/..') . '/includes/init.php';
set_debug(isset($_GET['debug']));
rrdtool_initialize(false);
require $config['install_dir'] . '/html/includes/graphs/graph.inc.php';

View File

@ -455,7 +455,7 @@ function del_device()
$device = device_by_id_cache($device_id);
}
if (!device) {
if (!$device) {
api_error(404, "Device $hostname not found");
}

View File

@ -1,6 +1,6 @@
<?php
$rrd_filename = rrd_name($device['hostname'], array('arubaap', $ap[name].$ap[radio_number]));
$rrd_filename = rrd_name($device['hostname'], array('arubaap', $ap['name'].$ap['radio_number']));
$rrd_list[0]['filename'] = $rrd_filename;
$rrd_list[0]['descr'] = 'MonBSSIDs';

View File

@ -2,7 +2,7 @@
require 'includes/graphs/common.inc.php';
$mysql_rrd = rrd_name($device['hostname'], array('app', mysql, $app['app_id']));
$mysql_rrd = rrd_name($device['hostname'], ['app', 'mysql', $app['app_id']]);
if (rrdtool_check_rrd_exists($mysql_rrd)) {
$rrd_filename = $mysql_rrd;

View File

@ -29,13 +29,13 @@ foreach (dbFetchRows('SELECT * FROM storage where device_id = ?', array($device[
$descr = rrdtool_escape($storage['storage_descr'], 12);
$rrd = rrd_name($device['hostname'], array('storage', $storage['storage_mib'], $storage['storage_descr']));
$rrd_options .= " DEF:$storage[storage_id]used=$rrd:used:AVERAGE";
$rrd_options .= " DEF:$storage[storage_id]free=$rrd:free:AVERAGE";
$rrd_options .= " CDEF:$storage[storage_id]size=$storage[storage_id]used,$storage[storage_id]free,+";
$rrd_options .= " CDEF:$storage[storage_id]perc=$storage[storage_id]used,$storage[storage_id]size,/,100,*";
$rrd_options .= " LINE1.25:$storage[storage_id]perc#".$colour.":'$descr'";
$rrd_options .= " GPRINT:$storage[storage_id]size:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:$storage[storage_id]used:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:$storage[storage_id]perc:LAST:%5.2lf%%\\l";
$rrd_options .= " DEF:{$storage['storage_id']}used=$rrd:used:AVERAGE";
$rrd_options .= " DEF:{$storage['storage_id']}free=$rrd:free:AVERAGE";
$rrd_options .= " CDEF:{$storage['storage_id']}size={$storage['storage_id']}used,{$storage['storage_id']}free,+";
$rrd_options .= " CDEF:{$storage['storage_id']}perc={$storage['storage_id']}used,{$storage['storage_id']}size,/,100,*";
$rrd_options .= " LINE1.25:{$storage['storage_id']}perc#".$colour.":'$descr'";
$rrd_options .= " GPRINT:{$storage['storage_id']}size:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:{$storage['storage_id']}used:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:{$storage['storage_id']}perc:LAST:%5.2lf%%\\l";
$iter++;
}//end foreach

View File

@ -28,35 +28,35 @@ $descr = rrdtool_escape(short_hrDeviceDescr($mempool['mempool_descr']), $descr_l
$perc = round($mempool['mempool_perc'], 0);
$background = get_percentage_colours($perc, $mempool['mempool_perc_warn']);
$rrd_options .= " DEF:$mempool[mempool_id]used=$rrd_filename:used:AVERAGE";
$rrd_options .= " DEF:$mempool[mempool_id]free=$rrd_filename:free:AVERAGE";
$rrd_options .= " CDEF:$mempool[mempool_id]size=$mempool[mempool_id]used,$mempool[mempool_id]free,+";
$rrd_options .= " CDEF:$mempool[mempool_id]perc=$mempool[mempool_id]used,$mempool[mempool_id]size,/,100,*";
$rrd_options .= " CDEF:$mempool[mempool_id]percx=100,$mempool[mempool_id]perc,-";
$rrd_options .= " AREA:$mempool[mempool_id]perc#".$background['right'].':';
$rrd_options .= " DEF:{$mempool['mempool_id']}used=$rrd_filename:used:AVERAGE";
$rrd_options .= " DEF:{$mempool['mempool_id']}free=$rrd_filename:free:AVERAGE";
$rrd_options .= " CDEF:{$mempool['mempool_id']}size={$mempool['mempool_id']}used,{$mempool['mempool_id']}free,+";
$rrd_options .= " CDEF:{$mempool['mempool_id']}perc={$mempool['mempool_id']}used,{$mempool['mempool_id']}size,/,100,*";
$rrd_options .= " CDEF:{$mempool['mempool_id']}percx=100,{$mempool['mempool_id']}perc,-";
$rrd_options .= " AREA:{$mempool['mempool_id']}perc#".$background['right'].':';
if ($width > '500') {
$rrd_options .= " LINE1.25:$mempool[mempool_id]perc#".$background['left'].":'$descr'";
$rrd_options .= " GPRINT:$mempool[mempool_id]size:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:$mempool[mempool_id]used:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:$mempool[mempool_id]free:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:$mempool[mempool_id]free:MIN:%5.2lf%sB";
$rrd_options .= " GPRINT:$mempool[mempool_id]free:MAX:%5.2lf%sB";
$rrd_options .= " GPRINT:$mempool[mempool_id]free:AVERAGE:%5.2lf%sB\\n";
$rrd_options .= " LINE1.25:{$mempool['mempool_id']}perc#".$background['left'].":'$descr'";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}size:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}used:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}free:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}free:MIN:%5.2lf%sB";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}free:MAX:%5.2lf%sB";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}free:AVERAGE:%5.2lf%sB\\n";
$rrd_options .= " COMMENT:'".substr(str_pad('', ($descr_len + 12)), 0, ($descr_len + 12))." '";
$rrd_options .= " GPRINT:$mempool[mempool_id]perc:LAST:'%5.2lf%% '";
$rrd_options .= " GPRINT:$mempool[mempool_id]percx:LAST:'%5.2lf%% '";
$rrd_options .= " GPRINT:$mempool[mempool_id]perc:MIN:'%5.2lf%% '";
$rrd_options .= " GPRINT:$mempool[mempool_id]perc:MAX:'%5.2lf%% '";
$rrd_options .= " GPRINT:$mempool[mempool_id]perc:AVERAGE:%5.2lf%%\\n";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}perc:LAST:'%5.2lf%% '";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}percx:LAST:'%5.2lf%% '";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}perc:MIN:'%5.2lf%% '";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}perc:MAX:'%5.2lf%% '";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}perc:AVERAGE:%5.2lf%%\\n";
} else {
$rrd_options .= " LINE1.25:$mempool[mempool_id]perc#".$background['left'].":'$descr'";
$rrd_options .= " GPRINT:$mempool[mempool_id]size:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:$mempool[mempool_id]used:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:$mempool[mempool_id]free:LAST:%6.2lf%sB";
$rrd_options .= " LINE1.25:{$mempool['mempool_id']}perc#".$background['left'].":'$descr'";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}size:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}used:LAST:%6.2lf%sB";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}free:LAST:%6.2lf%sB";
$rrd_options .= " COMMENT:'\l'";
$rrd_options .= " COMMENT:'".substr(str_pad('', ($descr_len + 12)), 0, ($descr_len + 12))." '";
$rrd_options .= " GPRINT:$mempool[mempool_id]perc:LAST:'%5.2lf%% '";
$rrd_options .= " GPRINT:$mempool[mempool_id]percx:LAST:'%5.2lf%% '";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}perc:LAST:'%5.2lf%% '";
$rrd_options .= " GPRINT:{$mempool['mempool_id']}percx:LAST:'%5.2lf%% '";
$rrd_options .= " COMMENT:'\l'";
}//end if

View File

@ -37,9 +37,9 @@ echo "<br>\n";
echo '</td><td width=120>';
echo "<i class='fa fa-wifi fa-lg icon-theme' aria-hidden='true'></i> ".format_bi($ap[numasoclients]).' Clients<br />';
echo "<i class='fa fa-wifi fa-lg icon-theme' aria-hidden='true'></i> ".format_bi($ap[radioutil]).' % busy<br />';
echo "<i class='fa fa-wifi fa-lg icon-theme' aria-hidden='true'></i> ".format_bi($ap[interference]).' interference index<br />';
echo "<i class='fa fa-wifi fa-lg icon-theme' aria-hidden='true'></i> ".format_bi($ap['numasoclients']).' Clients<br />';
echo "<i class='fa fa-wifi fa-lg icon-theme' aria-hidden='true'></i> ".format_bi($ap['radioutil']).' % busy<br />';
echo "<i class='fa fa-wifi fa-lg icon-theme' aria-hidden='true'></i> ".format_bi($ap['interference']).' interference index<br />';
echo '</td></tr>';

View File

@ -1,86 +0,0 @@
<?php
$total_queries = count($sql_debug);
$total_php_issues = count($php_debug);
?>
<div class="modal fade" id="sql_debug" tabindex="-1" role="dialog" aria-labelledby="sql_debug_label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">SQL Debug</h4>
</div>
<div class="modal-body">
<table class="table table-condensed table-hover">
<?php
foreach ($sql_debug as $sql_error) {
echo "
<tr>
<td>
$sql_error
</td>
</tr>
";
}
echo "
<tr>
<td>
$total_queries total SQL queries run.
</td>
</tr>
";
?>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="php_debug" tabindex="-1" role="dialog" aria-labelledby="php_debug_label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">PHP Debug</h4>
</div>
<div class="modal-body">
<table class="table table-condensed table-hover">
<?php
foreach ($php_debug as $php_error) {
echo '
<tr>
<td>
';
print_r($php_error);
echo '
</td>
</tr>
';
}
echo "
<tr>
<td>
$total_php_issues total PHP issues / errors.
</td>
</tr>
";
?>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-default navbar-fixed-bottom navbar-debug">
<div class="container-fluid">
<p><strong>Debug options:</strong> <a href="#" data-toggle="modal" data-target="#sql_debug">Show SQL Debug</a> / <a href="#" data-toggle="modal" data-target="#php_debug">Show PHP Debug</a></p>
</div>
</nav>

View File

@ -103,7 +103,7 @@ if ($port['ifSpeed']) {
echo '<br />';
if ($port[ifDuplex] != 'unknown') {
if ($port['ifDuplex'] != 'unknown') {
echo '<span class=box-desc>'.$port['ifDuplex'].'</span>';
} else {
echo '-';

View File

@ -93,7 +93,7 @@ foreach (dbFetchRows($sql, $param) as $interface) {
}
if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0) {
$error_img = generate_port_link($interface, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", errors);
$error_img = generate_port_link($interface, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", 'errors');
} else {
$error_img = '';
}

View File

@ -22,32 +22,6 @@ if (empty($_SERVER['PATH_INFO'])) {
}
}
if (strpos($_SERVER['REQUEST_URI'], "debug")) {
$debug = true;
ini_set('display_errors', 0);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
global $php_debug;
$php_debug[] = array('errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline);
});
register_shutdown_function(function () {
$last_error = error_get_last();
if ($last_error['type'] == 1) {
$log_error = array($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']);
print_r($log_error);
}
});
$sql_debug = array();
$php_debug = array();
} else {
$debug = false;
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('error_reporting', 0);
}
// Set variables
$msg_box = array();
@ -61,6 +35,8 @@ if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') {
$init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
set_debug(str_contains($_SERVER['REQUEST_URI'], 'debug'));
LibreNMS\Plugins::start();
$runtime_start = microtime(true);
@ -68,7 +44,6 @@ $runtime_start = microtime(true);
ob_start();
ini_set('allow_url_fopen', 0);
ini_set('display_errors', 0);
if (strstr($_SERVER['REQUEST_URI'], 'widescreen=yes')) {
$_SESSION['widescreen'] = 1;
@ -341,10 +316,6 @@ if (is_array($msg_box)) {
echo("</script>");
}
if (is_array($sql_debug) && is_array($php_debug) && Auth::check()) {
require_once "includes/print-debug.php";
}
if ($no_refresh !== true && $config['page_refresh'] != 0) {
$refresh = $config['page_refresh'] * 1000;
echo('<script type="text/javascript">

View File

@ -13,18 +13,12 @@
use LibreNMS\Authentication\Auth;
ini_set('allow_url_fopen', 0);
ini_set('display_errors', 0);
if ($_GET[debug]) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
}
$init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
set_debug($_GET['debug']);
if (!Auth::check()) {
echo 'unauthenticated';
exit;

View File

@ -13,16 +13,17 @@
use LibreNMS\Authentication\Auth;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
$links = 1;
$init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
$options = getopt('d::');
if (set_debug(isset($options['d']))) {
echo "DEBUG!\n";
}
if (strpos($_SERVER['REQUEST_URI'], 'anon')) {
$anon = 1;
}

View File

@ -18,9 +18,9 @@ if (bill_permitted($bill_id)) {
$tomorrow = str_replace('-', '', dbFetchCell('SELECT DATE_ADD(CURDATE(), INTERVAL 1 DAY)'));
$last_month = str_replace('-', '', dbFetchCell('SELECT DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'));
$rightnow = $today.date(His);
$before = $yesterday.date(His);
$lastmonth = $last_month.date(His);
$rightnow = $today.date('His');
$before = $yesterday.date('His');
$lastmonth = $last_month.date('His');
$bill_name = $bill_data['bill_name'];
$dayofmonth = $bill_data['bill_day'];
@ -215,7 +215,7 @@ if ($vars['view'] == 'edit' && Auth::user()->hasGlobalAdmin()) {
$lastmonth = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))');
$yesterday = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))');
$rightnow = date(U);
$rightnow = date('U');
if ($vars['view'] == 'accurate') {
$bi = "<img src='billing-graph.php?bill_id=".$bill_id.'&amp;bill_code='.$_GET['bill_code'];

View File

@ -28,7 +28,7 @@ $unix_prev_from = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastfrom')");
$unix_prev_to = dbFetchCell("SELECT UNIX_TIMESTAMP('$lastto')");
$lastmonth = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 MONTH))');
$yesterday = dbFetchCell('SELECT UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 DAY))');
$rightnow = date(U);
$rightnow = date('U');
$cur_days = date('d', (strtotime('now') - strtotime($datefrom)));
$total_days = date('d', (strtotime($dateto) - strtotime($datefrom)));

View File

@ -50,7 +50,7 @@ if ($vars['view'] == 'incoming') {
$graph_array['type'] = 'device_smokeping_in_all';
$graph_array['device'] = $device['device_id'];
$graph_array['legend'] = no;
$graph_array['legend'] = 'no';
echo '<tr><td>';
echo '<h3>Aggregate</h3>';
@ -94,7 +94,7 @@ if ($vars['view'] == 'incoming') {
echo '</td></tr>';
$graph_array['type'] = 'device_smokeping_out_all';
$graph_array['legend'] = no;
$graph_array['legend'] = 'no';
echo '<tr><td>';
echo '<h3>Aggregate</h3>';

View File

@ -204,7 +204,7 @@ if (empty($vars['dtpickerto'])) {
zoomMax: <?php
$first_date = reset($data);
$last_date = end($data);
$milisec_diff = abs(strtotime($first_date[x]) - strtotime($last_date[x])) * 1000;
$milisec_diff = abs(strtotime($first_date['x']) - strtotime($last_date['x'])) * 1000;
echo $milisec_diff;
?>,
orientation: 'top'

View File

@ -50,13 +50,13 @@ echo '</table></div>';
$pos = strpos(strtolower($ifname), 'vlan');
if ($pos !== false) {
$broke = yes;
$broke = 'yes';
}
$pos = strpos(strtolower($ifname), 'loopback');
if ($pos !== false) {
$broke = yes;
$broke = 'yes';
}
echo "<div style='clear: both;'>";

View File

@ -47,32 +47,32 @@ if ($vars['subview'] == 'top10') {
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Day</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], sort => $vars['sort'], 'period' => 'day'))."'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'day'))."'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;stat='.$vars['graph'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Two Day</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], sort => $vars['sort'], 'period' => 'twoday'))."/'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'twoday'))."/'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;stat='.$vars['graph'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;from='.$config['time']['twoday'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Week</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], sort => $vars['sort'], 'period' => 'week'))."/'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'week'))."/'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;stat='.$vars['graph'].'&amp;from='.$config['time']['week'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Month</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], sort => $vars['sort'], 'period' => 'month'))."/'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'month'))."/'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;stat='.$vars['graph'].'&amp;from='.$config['time']['month'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Year</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], sort => $vars['sort'], 'period' => 'year'))."/'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'year'))."/'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;stat='.$vars['graph'].'&amp;from='.$config['time']['year'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
@ -83,31 +83,31 @@ if ($vars['subview'] == 'top10') {
<div style=' margin:0px; float: left;';>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Traffic</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'bits', sort => $vars['sort'], 'period' => $vars['period']))."'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'bits', 'sort' => $vars['sort'], 'period' => $vars['period']))."'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;stat=bits&amp;type=port_mac_acc_total&amp;sort='.$vars['sort']."&amp;from=$from&amp;to=".$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Packets</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'pkts', sort => $vars['sort'], 'period' => $vars['period']))."/'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'pkts', 'sort' => $vars['sort'], 'period' => $vars['period']))."/'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;stat=pkts&amp;type=port_mac_acc_total&amp;sort='.$vars['sort']."&amp;from=$from&amp;to=".$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Top Input</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], sort => 'in', 'period' => $vars['period']))."'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => 'in', 'period' => $vars['period']))."'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;stat='.$vars['graph']."&amp;type=port_mac_acc_total&amp;sort=in&amp;from=$from&amp;to=".$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Top Output</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], sort => 'out', 'period' => $vars['period']))."'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => 'out', 'period' => $vars['period']))."'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;stat='.$vars['graph']."&amp;type=port_mac_acc_total&amp;sort=out&amp;from=$from&amp;to=".$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>
<div style='margin: 0px 0px 5px 10px; padding:5px; background: #e5e5e5;'>
<span class=device-head>Top Aggregate</span><br />
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], sort => 'both', 'period' => $vars['period']))."'>
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => 'both', 'period' => $vars['period']))."'>
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&amp;stat='.$vars['graph']."&amp;type=port_mac_acc_total&amp;sort=both&amp;from=$from&amp;to=".$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>

View File

@ -37,7 +37,7 @@ foreach ($vlans as $vlan) {
if ($otherport['untagged']) {
$traverse_ifvlan = false;
}
$vlan_ports[$otherport[ifIndex]] = $otherport;
$vlan_ports[$otherport['ifIndex']] = $otherport;
}
if ($traverse_ifvlan) {
@ -46,7 +46,7 @@ foreach ($vlans as $vlan) {
array($device['device_id'], $vlan['vlan'])
);
foreach ($otherports as $otherport) {
$vlan_ports[$otherport[ifIndex]] = array_merge($otherport, array('untagged' => '1'));
$vlan_ports[$otherport['ifIndex']] = array_merge($otherport, array('untagged' => '1'));
}
}

View File

@ -14,7 +14,7 @@ foreach ($ports as $port) {
$port['out_rate'] = formatRates(($port['ifOutOctets_rate'] * 8));
if ($port['in_errors'] > 0 || $port['out_errors'] > 0) {
$error_img = generate_port_link($port, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", errors);
$error_img = generate_port_link($port, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", 'errors');
} else {
$error_img = '';
}

View File

@ -12,23 +12,11 @@
* the source code distribution for details.
*/
if (strpos($_SERVER['PATH_INFO'], 'debug')) {
$debug = '1';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
} else {
$debug = false;
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
ini_set('error_reporting', 0);
}
$init_modules = array('web', 'auth');
require realpath(__DIR__ . '/..') . '/includes/init.php';
set_debug(strpos($_SERVER['PATH_INFO'], 'debug'));
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator($config['project_name']);

View File

@ -94,14 +94,14 @@ function getLastPortCounter($port_id, $bill_id)
$return = array();
$row = dbFetchRow("SELECT timestamp, in_counter, in_delta, out_counter, out_delta FROM bill_port_counters WHERE `port_id` = ? AND `bill_id` = ?", array($port_id, $bill_id));
if (!is_null($row)) {
$return[timestamp] = $row['timestamp'];
$return[in_counter] = $row['in_counter'];
$return[in_delta] = $row['in_delta'];
$return[out_counter] = $row['out_counter'];
$return[out_delta] = $row['out_delta'];
$return[state] = 'ok';
$return['timestamp'] = $row['timestamp'];
$return['in_counter'] = $row['in_counter'];
$return['in_delta'] = $row['in_delta'];
$return['out_counter'] = $row['out_counter'];
$return['out_delta'] = $row['out_delta'];
$return['state'] = 'ok';
} else {
$return[state] = 'failed';
$return['state'] = 'failed';
}
return $return;
}//end getLastPortCounter()
@ -112,13 +112,13 @@ function getLastMeasurement($bill_id)
$return = array();
$row = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id = ? ORDER BY timestamp DESC LIMIT 1", array($bill_id));
if (!is_null($row)) {
$return[delta] = $row['delta'];
$return[delta_in] = $row['delta_in'];
$return[delta_out] = $row['delta_out'];
$return[timestamp] = $row['timestamp'];
$return[state] = 'ok';
$return['delta'] = $row['delta'];
$return['delta_in'] = $row['delta_in'];
$return['delta_out'] = $row['delta_out'];
$return['timestamp'] = $row['timestamp'];
$return['state'] = 'ok';
} else {
$return[state] = 'failed';
$return['state'] = 'failed';
}
return ($return);
}//end getLastMeasurement()
@ -260,7 +260,7 @@ function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
$out_data = array();
$tot_data = array();
$ticks = array();
if (!isset($reducefactor) || !is_numeric($reducefactor) || $reducefactor < 1) {
// Auto calculate reduce factor
$expectedpoints = ceil(($to - $from) / 300);
@ -316,7 +316,7 @@ function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
'to' => $to,
'first' => $first,
'last' => $last,
'in_data' => $in_data,
'out_data' => $out_data,
'tot_data' => $tot_data,
@ -379,7 +379,7 @@ function getHistoricTransferGraphData($bill_id)
}
$graph_name = 'Historical bandwidth over the last 12 billing periods';
return array(
'graph_name' => $graph_name,
'in_data' => $in_data,

View File

@ -667,14 +667,15 @@ function is_valid_hostname($hostname)
*/
function d_echo($text, $no_debug_text = null)
{
global $debug, $php_debug;
if ($debug) {
if (isset($php_debug)) {
$php_debug[] = $text;
} else {
print_r($text);
}
} elseif ($no_debug_text) {
global $debug;
if (class_exists('\Log')) {
\Log::debug(is_string($text) ? rtrim($text) : $text);
} elseif ($debug) {
print_r($text);
}
if (!$debug && $no_debug_text) {
echo "$no_debug_text";
}
} // d_echo
@ -1684,12 +1685,12 @@ function uw_to_dbm($value)
*/
function set_null($value, $default = null, $min = null)
{
if (is_nan($value)) {
if (!is_numeric($value)) {
return $default;
} elseif (is_nan($value)) {
return $default;
} elseif (is_infinite($value)) {
return $default;
} elseif (!is_numeric($value)) {
return $default;
} elseif (isset($min) && $value < $min) {
return $default;
}
@ -1702,10 +1703,9 @@ function set_null($value, $default = null, $min = null)
*/
function set_numeric($value, $default = 0)
{
if (is_nan($value) ||
is_infinite($value) ||
!isset($value) ||
!is_numeric($value)
if (!is_numeric($value) ||
is_nan($value) ||
is_infinite($value)
) {
$value = $default;
}

View File

@ -114,18 +114,17 @@ function dbConnect($db_host = null, $db_user = '', $db_pass = '', $db_name = '',
function dbQuery($sql, $parameters = array())
{
global $fullSql, $debug, $sql_debug, $database_link, $config;
global $fullSql, $debug, $database_link, $config;
$fullSql = dbMakeQuery($sql, $parameters);
if ($debug) {
if (php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
$fullSql = str_replace(PHP_EOL, '', $fullSql);
if (preg_match('/(INSERT INTO `alert_log`).*(details)/i', $fullSql)) {
echo "\nINSERT INTO `alert_log` entry masked due to binary data\n";
} else {
c_echo('SQL[%y'.$fullSql."%n] \n");
}
$fullSql = str_replace(PHP_EOL, '', $fullSql);
// hide binary field updates and inserts
$fullSql = preg_replace("/(.*alert_log.*details[` ]*= *')[^']*('.*)/i", '$1<binary data>$2', $fullSql);
if (class_exists('Log')) {
Log::info("SQL[%y$fullSql%n]", ['color' => true]);
} else {
$sql_debug[] = $fullSql;
c_echo("SQL[%y$fullSql%n] \n");
}
}
@ -374,26 +373,28 @@ function dbDeleteOrphans($target_table, $parents)
function dbFetchRows($sql, $parameters = array())
{
$time_start = microtime(true);
$result = dbQuery($sql, $parameters);
$result = dbQuery($sql, $parameters);
if (mysqli_num_rows($result) > 0) {
$rows = array();
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
if ($result !== false) {
if (mysqli_num_rows($result) > 0) {
$rows = [];
while ($row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
mysqli_free_result($result);
recordDbStatistic('fetchrows', $time_start);
return $rows;
}
mysqli_free_result($result);
recordDbStatistic('fetchrows', $time_start);
return $rows;
}
mysqli_free_result($result);
// no records, thus return empty array
// which should evaluate to false, and will prevent foreach notices/warnings
recordDbStatistic('fetchrows', $time_start);
return array();
return [];
}//end dbFetchRows()
@ -654,7 +655,7 @@ function dbGenPlaceholders($count)
*/
function recordDbStatistic($stat, $start_time)
{
global $db_stats;
global $db_stats, $db_stats_last;
if (!isset($db_stats)) {
$db_stats = array(
@ -677,6 +678,7 @@ function recordDbStatistic($stat, $start_time)
'fetchrows' => 0.0,
),
);
$db_stats_last = $db_stats;
}
$runtime = microtime(true) - $start_time;

View File

@ -769,7 +769,6 @@ $config['poller_modules']['applications'] = true;
$config['poller_modules']['mib'] = false;
$config['poller_modules']['stp'] = true;
$config['poller_modules']['ntp'] = true;
$config['poller_modules']['services'] = true;
$config['poller_modules']['loadbalancers'] = false;
$config['poller_modules']['mef'] = false;

View File

@ -25,6 +25,8 @@
* @subpackage Devices
*/
use LibreNMS\Config;
/**
* Add a new device group
* @param $pattern
@ -263,9 +265,10 @@ function GetGroupsFromDevice($device_id, $extra = 0)
*/
function RunGroupMacros($rule, $x = 1)
{
global $config;
krsort($config['alert']['macros']['group']);
foreach ($config['alert']['macros']['group'] as $macro => $value) {
$macros = Config::get('alert.macros.group', []);
krsort($macros);
foreach ($macros as $macro => $value) {
if (!strstr($macro, " ")) {
$rule = str_replace('%macros.'.$macro, '('.$value.')', $rule);
}

View File

@ -84,7 +84,7 @@ if ($device['os_group'] == 'cisco') {
// No Error, lets process things.
// Add each overlay to the array.
foreach ($tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.2'] as $index => $name) {
foreach ((array)$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.2'] as $index => $name) {
$result = array();
$message = false;
$result['index'] = $index;
@ -132,7 +132,7 @@ if ($device['os_group'] == 'cisco') {
}
// Add each adjacency to the array.
foreach ($tblAdjacentDevName as $key => $value) {
foreach ((array)$tblAdjacentDevName as $key => $value) {
preg_match('/^1.3.6.1.4.1.9.9.810.1.3.1.1.4.(\d+).1.4.(\d+.\d+.\d+.\d+)$/', $key, $matches);
$result = array();
$result['index'] = $matches[1];
@ -202,7 +202,7 @@ if ($device['os_group'] == 'cisco') {
$component_key = false;
// Loop over our components to determine if the component exists, or we need to add it.
foreach ($components as $compid => $child) {
foreach ((array)$components as $compid => $child) {
if ($child['UID'] === $array['UID']) {
$component_key = $compid;
}
@ -224,7 +224,7 @@ if ($device['os_group'] == 'cisco') {
/*
* Loop over the Component data to see if we need to DELETE any components.
*/
foreach ($components as $key => $array) {
foreach ((array)$components as $key => $array) {
// Guilty until proven innocent
$found = false;

View File

@ -3,18 +3,13 @@
use LibreNMS\Config;
if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
unset($cpw_count);
unset($cpw_exists);
$pws_db = [];
// Pre-cache the existing state of pseudowires for this device from the database
$pws_db_raw = dbFetchRows('SELECT * FROM `pseudowires` WHERE `device_id` = ?', array($device['device_id']));
foreach ($pws_db_raw as $pw_db) {
$device['pws_db'][$pw_db['cpwVcID']] = $pw_db['pseudowire_id'];
$pws_db[$pw_db['cpwVcID']] = $pw_db['pseudowire_id'];
}
unset($pws_db_raw);
unset($pw_db);
$pws = snmpwalk_cache_oid($device, 'cpwVcID', array(), 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcName', $pws, 'CISCO-IETF-PW-MPLS-MIB');
$pws = snmpwalk_cache_oid($device, 'cpwVcType', $pws, 'CISCO-IETF-PW-MPLS-MIB');
@ -28,8 +23,8 @@ if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
list($cpw_remote_id) = explode(':', $pw['cpwVcMplsPeerLdpID']);
$cpw_remote_device = dbFetchCell('SELECT device_id from ipv4_addresses AS A, ports AS I WHERE A.ipv4_address=? AND A.port_id=I.port_id', array($cpw_remote_id));
$if_id = dbFetchCell('SELECT port_id from ports WHERE `ifDescr`=? AND `device_id`=?', array($pw['cpwVcName'], $device['device_id']));
if (!empty($device['pws_db'][$pw['cpwVcID']])) {
$pseudowire_id = $device['pws_db'][$pw['cpwVcID']];
if (!empty($pws_db[$pw['cpwVcID']])) {
$pseudowire_id = $pws_db[$pw['cpwVcID']];
echo '.';
} else {
$pseudowire_id = dbInsert(
@ -53,7 +48,7 @@ if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
}//end foreach
// Cycle the list of pseudowires we cached earlier and make sure we saw them again.
foreach ($device['pws_db'] as $pw_id => $pseudowire_id) {
foreach ($pws_db as $pw_id => $pseudowire_id) {
if (empty($device['pws'][$pw_id])) {
dbDelete('pseudowires', '`pseudowire_id` = ?', array($pseudowire_id));
}
@ -61,3 +56,5 @@ if (Config::get('enable_pseudowires') && $device['os_group'] == 'cisco') {
echo "\n";
} //end if
unset($pws_db, $pws_db_raw, $pw_db);

View File

@ -62,7 +62,7 @@ if (Config::get('enable_vrf_lite_cisco')) {
}
unset($listIntance);
foreach ($tableVrf as $context => $vrf) {
foreach ((array)$tableVrf as $context => $vrf) {
if ($debug) {
echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n");
}

View File

@ -30,7 +30,7 @@ foreach ($vtpdomains as $vtpdomain_id => $vtpdomain) {
$portid_dict[$portLocal] = $port['port_id'];
}
foreach ($fdbPort_table['dot1dTpFdbPort'] as $mac => $dot1dBasePort) {
foreach ((array)$fdbPort_table['dot1dTpFdbPort'] as $mac => $dot1dBasePort) {
$mac_address = implode(array_map('zeropad', explode(':', $mac)));
if (strlen($mac_address) != 12) {
d_echo("MAC address padding failed for $mac\n");

View File

@ -947,7 +947,7 @@ function can_skip_sensor($value, $data, $group, $pre_cache = array())
}
}
$skip_value_gt = array_reduce((array)$group['skip_value_gt'], (array)$data['skip_value_gt']);
$skip_value_gt = array_replace((array)$group['skip_value_gt'], (array)$data['skip_value_gt']);
foreach ($skip_value_gt as $skip_value) {
if ($value > $skip_value) {
return true;

View File

@ -45,7 +45,7 @@ $components = $keep;
// Begin our master array, all other values will be processed into this array.
$tblBigIP = array();
if ((snmp_get($device, 'sysModuleAllocationProvisionLevel.3.103.116.109', '-Ovqs', 'F5-BIGIP-SYSTEM-MIB')) !=none) {
if ((snmp_get($device, 'sysModuleAllocationProvisionLevel.3.103.116.109', '-Ovqs', 'F5-BIGIP-SYSTEM-MIB')) != false) {
$gtmWideIPEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.3.12.1.2.1', 0);
if (!is_null($gtmWideIPEntry)) {
$gtmWideStatusEntry = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.3.12.3.2.1', 0);

View File

@ -46,18 +46,18 @@ $tblBigIP = array();
// Virtual Server Data
$ltmVirtualServOID = array(
ip => '1.3.6.1.4.1.3375.2.2.10.1.2.1.3',
port => '1.3.6.1.4.1.3375.2.2.10.1.2.1.6',
defaultpool => '1.3.6.1.4.1.3375.2.2.10.1.2.1.19',
state => '1.3.6.1.4.1.3375.2.2.10.13.2.1.2',
errorcode => '1.3.6.1.4.1.3375.2.2.10.13.2.1.5',
'ip' => '1.3.6.1.4.1.3375.2.2.10.1.2.1.3',
'port' => '1.3.6.1.4.1.3375.2.2.10.1.2.1.6',
'defaultpool' => '1.3.6.1.4.1.3375.2.2.10.1.2.1.19',
'state' => '1.3.6.1.4.1.3375.2.2.10.13.2.1.2',
'errorcode' => '1.3.6.1.4.1.3375.2.2.10.13.2.1.5',
);
$ltmVirtualServEntry = [];
//Check for Virtual Server Enries
$ltmVirtualServEntry[name] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.10.1.2.1.1', 0);
$ltmVirtualServEntry['name'] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.10.1.2.1.1', 0);
//If no Virtual Servers are found don't look for statistics
if (!empty($ltmVirtualServEntry[name])) {
if (!empty($ltmVirtualServEntry['name'])) {
foreach ($ltmVirtualServOID as $key => $value) {
$ltmVirtualServEntry[$key] = snmpwalk_array_num($device, $value, 0);
}
@ -67,40 +67,40 @@ if (!empty($ltmVirtualServEntry[name])) {
// Pool Data
$ltmPoolEntryOID = array(
mode => '1.3.6.1.4.1.3375.2.2.5.1.2.1.2',
minup => '1.3.6.1.4.1.3375.2.2.5.1.2.1.4',
minupstatus => '1.3.6.1.4.1.3375.2.2.5.1.2.1.5',
minupaction => '1.3.6.1.4.1.3375.2.2.5.1.2.1.6',
currentup => '1.3.6.1.4.1.3375.2.2.5.1.2.1.8',
monitor => '1.3.6.1.4.1.3375.2.2.5.1.2.1.17',
'mode' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.2',
'minup' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.4',
'minupstatus' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.5',
'minupaction' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.6',
'currentup' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.8',
'monitor' => '1.3.6.1.4.1.3375.2.2.5.1.2.1.17',
);
// Pool Member Data
$ltmPoolMemberEntryOID = array(
ip => '1.3.6.1.4.1.3375.2.2.5.3.2.1.3',
port => '1.3.6.1.4.1.3375.2.2.5.3.2.1.4',
ratio => '1.3.6.1.4.1.3375.2.2.5.3.2.1.6',
weight => '1.3.6.1.4.1.3375.2.2.5.3.2.1.7',
priority => '1.3.6.1.4.1.3375.2.2.5.3.2.1.8',
state => '1.3.6.1.4.1.3375.2.2.5.6.2.1.5',
available => '1.3.6.1.4.1.3375.2.2.5.6.2.1.6',
errorcode => '1.3.6.1.4.1.3375.2.2.5.6.2.1.8',
'ip' => '1.3.6.1.4.1.3375.2.2.5.3.2.1.3',
'port' => '1.3.6.1.4.1.3375.2.2.5.3.2.1.4',
'ratio' => '1.3.6.1.4.1.3375.2.2.5.3.2.1.6',
'weight' => '1.3.6.1.4.1.3375.2.2.5.3.2.1.7',
'priority' => '1.3.6.1.4.1.3375.2.2.5.3.2.1.8',
'state' => '1.3.6.1.4.1.3375.2.2.5.6.2.1.5',
'available' => '1.3.6.1.4.1.3375.2.2.5.6.2.1.6',
'errorcode' => '1.3.6.1.4.1.3375.2.2.5.6.2.1.8',
);
//Check for Pool Enries
$ltmPoolEntry = [];
$ltmPoolMemberEntry = [];
$ltmPoolEntry[name] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.1.2.1.1', 0);
$ltmPoolEntry['name'] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.1.2.1.1', 0);
//If no Pools are found don't look for statistics or pool members
if (!empty($ltmPoolEntry[name])) {
if (!empty($ltmPoolEntry['name'])) {
// If there are pools gather Pool Member Data
foreach ($ltmPoolEntryOID as $key => $value) {
$ltmPoolEntry[$key] = snmpwalk_array_num($device, $value, 0);
}
// Gather Pool Member Data if pool members found
$ltmPoolMemberEntry[name] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.3.2.1.1', 0);
if (!empty($ltmPoolMemberEntry[name])) {
$ltmPoolMemberEntry['name'] = snmpwalk_array_num($device, '1.3.6.1.4.1.3375.2.2.5.3.2.1.1', 0);
if (!empty($ltmPoolMemberEntry['name'])) {
foreach ($ltmPoolMemberEntryOID as $key => $value) {
$ltmPoolMemberEntry[$key] = snmpwalk_array_num($device, $value, 0);
}
@ -118,8 +118,8 @@ if (!empty($ltmVirtualServEntry) || !empty($ltmPoolEntry) || !empty($ltmPoolMemb
d_echo("Objects Found:\n");
// Process the Virtual Servers
if (is_array($ltmVirtualServEntry[name])) {
foreach ($ltmVirtualServEntry[name] as $oid => $value) {
if (is_array($ltmVirtualServEntry['name'])) {
foreach ($ltmVirtualServEntry['name'] as $oid => $value) {
$result = array();
// Find all Virtual server names and UID's, then we can find everything else we need.
@ -132,25 +132,25 @@ if (!empty($ltmVirtualServEntry) || !empty($ltmPoolEntry) || !empty($ltmPoolMemb
$result['hash'] = hash('crc32', $result['UID']);
// Trim IPv4 response to remove route domain ID
if (strlen($ltmVirtualServEntry[ip]['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index]) == 23) {
$ltmVirtualServEntry[ip]['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index] = substr($ltmVirtualServEntry[ip]['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], 0, 11);
if (strlen($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index]) == 23) {
$ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index] = substr($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], 0, 11);
}
// Now that we have our UID we can pull all the other data we need.
$result['IP'] = IP::fromHexString($ltmVirtualServEntry[ip]['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], true);
$result['port'] = $ltmVirtualServEntry[port]['1.3.6.1.4.1.3375.2.2.10.1.2.1.6.'.$index];
$result['pool'] = $ltmVirtualServEntry[defaultpool]['1.3.6.1.4.1.3375.2.2.10.1.2.1.19.'.$index];
$result['IP'] = IP::fromHexString($ltmVirtualServEntry['ip']['1.3.6.1.4.1.3375.2.2.10.1.2.1.3.'.$index], true);
$result['port'] = $ltmVirtualServEntry['port']['1.3.6.1.4.1.3375.2.2.10.1.2.1.6.'.$index];
$result['pool'] = $ltmVirtualServEntry['defaultpool']['1.3.6.1.4.1.3375.2.2.10.1.2.1.19.'.$index];
// 0 = None, 1 = Green, 2 = Yellow, 3 = Red, 4 = Blue
$result['state'] = $ltmVirtualServEntry[state]['1.3.6.1.4.1.3375.2.2.10.13.2.1.2.'.$index];
$result['state'] = $ltmVirtualServEntry['state']['1.3.6.1.4.1.3375.2.2.10.13.2.1.2.'.$index];
if ($result['state'] == 2) {
// Looks like one of the VS Pool members is down.
$result['status'] = 1;
$result['error'] = $ltmVirtualServEntry[errorcode]['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
$result['error'] = $ltmVirtualServEntry['errorcode']['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
} elseif ($result['state'] == 3) {
// Looks like ALL of the VS Pool members is down.
$result['status'] = 2;
$result['error'] = $ltmVirtualServEntry[errorcode]['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
$result['error'] = $ltmVirtualServEntry['errorcode']['1.3.6.1.4.1.3375.2.2.10.13.2.1.5.'.$index];
} else {
// All is good.
$result['status'] = 0;
@ -172,8 +172,8 @@ if (!empty($ltmVirtualServEntry) || !empty($ltmPoolEntry) || !empty($ltmPoolMemb
}
// Process the Pools
if (is_array($ltmPoolEntry[name])) {
foreach ($ltmPoolEntry[name] as $oid => $value) {
if (is_array($ltmPoolEntry['name'])) {
foreach ($ltmPoolEntry['name'] as $oid => $value) {
$result = array ();
// Find all Pool names and UID's, then we can find everything else we need.
@ -186,12 +186,12 @@ if (!empty($ltmVirtualServEntry) || !empty($ltmPoolEntry) || !empty($ltmPoolMemb
$result['hash'] = hash('crc32', $result['UID']);
// Now that we have our UID we can pull all the other data we need.
$result['mode'] = $ltmPoolEntry[mode]['1.3.6.1.4.1.3375.2.2.5.1.2.1.2.'.$index];
$result['minup'] = $ltmPoolEntry[minup]['1.3.6.1.4.1.3375.2.2.5.1.2.1.4.'.$index];
$result['minupstatus'] = $ltmPoolEntry[minupstatus]['1.3.6.1.4.1.3375.2.2.5.1.2.1.5.'.$index];
$result['currentup'] = $ltmPoolEntry[currentup]['1.3.6.1.4.1.3375.2.2.5.1.2.1.8.'.$index];
$result['minupaction'] = $ltmPoolEntry[minupaction]['1.3.6.1.4.1.3375.2.2.5.1.2.1.6.'.$index];
$result['monitor'] = $ltmPoolEntry[monitor]['1.3.6.1.4.1.3375.2.2.5.1.2.1.17.'.$index];
$result['mode'] = $ltmPoolEntry['mode']['1.3.6.1.4.1.3375.2.2.5.1.2.1.2.'.$index];
$result['minup'] = $ltmPoolEntry['minup']['1.3.6.1.4.1.3375.2.2.5.1.2.1.4.'.$index];
$result['minupstatus'] = $ltmPoolEntry['minupstatus']['1.3.6.1.4.1.3375.2.2.5.1.2.1.5.'.$index];
$result['currentup'] = $ltmPoolEntry['currentup']['1.3.6.1.4.1.3375.2.2.5.1.2.1.8.'.$index];
$result['minupaction'] = $ltmPoolEntry['minupaction']['1.3.6.1.4.1.3375.2.2.5.1.2.1.6.'.$index];
$result['monitor'] = $ltmPoolEntry['monitor']['1.3.6.1.4.1.3375.2.2.5.1.2.1.17.'.$index];
// If we have less pool members than the minimum, we should error.
if ($result['currentup'] < $result['minup']) {
@ -219,8 +219,8 @@ if (!empty($ltmVirtualServEntry) || !empty($ltmPoolEntry) || !empty($ltmPoolMemb
}
// Process the Pool Members
if (is_array($ltmPoolMemberEntry[name])) {
foreach ($ltmPoolMemberEntry[name] as $oid => $value) {
if (is_array($ltmPoolMemberEntry['name'])) {
foreach ($ltmPoolMemberEntry['name'] as $oid => $value) {
$result = array ();
// Find all Pool member names and UID's, then we can find everything else we need.
@ -233,25 +233,25 @@ if (!empty($ltmVirtualServEntry) || !empty($ltmPoolEntry) || !empty($ltmPoolMemb
$result['hash'] = hash('crc32', $result['UID']);
//Remove route domain ID from v4 IPs
if (strlen($ltmPoolMemberEntry[ip]['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index]) == 23) {
$ltmPoolMemberEntry[ip]['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index] = substr($ltmPoolMemberEntry[ip]['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], 0, 11);
if (strlen($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index]) == 23) {
$ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index] = substr($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], 0, 11);
}
// Now that we have our UID we can pull all the other data we need.
$result['IP'] = IP::fromHexString($ltmPoolMemberEntry[ip]['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], true);
$result['port'] = $ltmPoolMemberEntry[port]['1.3.6.1.4.1.3375.2.2.5.3.2.1.4.'.$index];
$result['ratio'] = $ltmPoolMemberEntry[ratio]['1.3.6.1.4.1.3375.2.2.5.3.2.1.6.'.$index];
$result['weight'] = $ltmPoolMemberEntry[weight]['1.3.6.1.4.1.3375.2.2.5.3.2.1.7.'.$index];
$result['priority'] = $ltmPoolMemberEntry[priority]['1.3.6.1.4.1.3375.2.2.5.3.2.1.8.'.$index];
$result['state'] = $ltmPoolMemberEntry[state]['1.3.6.1.4.1.3375.2.2.5.6.2.1.5.'.$index];
$result['available'] = $ltmPoolMemberEntry[available]['1.3.6.1.4.1.3375.2.2.5.6.2.1.6.'.$index];
$result['IP'] = IP::fromHexString($ltmPoolMemberEntry['ip']['1.3.6.1.4.1.3375.2.2.5.3.2.1.3.'.$index], true);
$result['port'] = $ltmPoolMemberEntry['port']['1.3.6.1.4.1.3375.2.2.5.3.2.1.4.'.$index];
$result['ratio'] = $ltmPoolMemberEntry['ratio']['1.3.6.1.4.1.3375.2.2.5.3.2.1.6.'.$index];
$result['weight'] = $ltmPoolMemberEntry['weight']['1.3.6.1.4.1.3375.2.2.5.3.2.1.7.'.$index];
$result['priority'] = $ltmPoolMemberEntry['priority']['1.3.6.1.4.1.3375.2.2.5.3.2.1.8.'.$index];
$result['state'] = $ltmPoolMemberEntry['state']['1.3.6.1.4.1.3375.2.2.5.6.2.1.5.'.$index];
$result['available'] = $ltmPoolMemberEntry['available']['1.3.6.1.4.1.3375.2.2.5.6.2.1.6.'.$index];
// If available and bad state
// 0 = None, 1 = Green, 2 = Yellow, 3 = Red, 4 = Blue
if (($result['available'] == 1) && ($result['state'] == 3)) {
// Warning Alarm, the pool member is down.
$result['status'] = 1;
$result['error'] = "Pool Member is Down: ".$ltmPoolMemberEntry[errorcode]['1.3.6.1.4.1.3375.2.2.5.6.2.1.8.'.$index];
$result['error'] = "Pool Member is Down: ".$ltmPoolMemberEntry['errorcode']['1.3.6.1.4.1.3375.2.2.5.6.2.1.8.'.$index];
} else {
// All is good.
$result['status'] = 0;

View File

@ -7,7 +7,7 @@ if ($device['os'] == 'pbn') {
d_echo($version);
// specified MIB supported since build 16607
if ($version[build] >= 16607) {
if ($version['build'] >= 16607) {
$usage = snmp_get($device, 'nmsMemoryPoolUtilization.0', '-OUvQ', 'NMS-MEMORY-POOL-MIB', 'pbn');
if (is_numeric($usage)) {

View File

@ -42,7 +42,7 @@ if (is_null($cntpPeersVarEntry)) {
d_echo("Objects Found:\n");
// Let's grab the index for each NTP peer
foreach ($cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][2] as $index => $value) {
foreach ((array)$cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][2] as $index => $value) {
$result = array();
$result['UID'] = (string)$index; // This is cast as a string so it can be compared with the database value.
$result['peer'] = $cntpPeersVarEntry['1.3.6.1.4.1.9.9.168.1.2.1.1'][3][$index];
@ -97,7 +97,7 @@ if (is_null($cntpPeersVarEntry)) {
/*
* Loop over the Component data to see if we need to DELETE any components.
*/
foreach ($components as $key => $array) {
foreach ((array)$components as $key => $array) {
// Guilty until proven innocent
$found = false;
@ -121,7 +121,7 @@ if (is_null($cntpPeersVarEntry)) {
} // End if not error
$module = strtolower($module);
if (count($components) > 0) {
if (!empty($components)) {
if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', array($device['device_id'], $module)) == '0') {
dbInsert(array('device_id' => $device['device_id'], 'app_type' => $module, 'app_status' => '', 'app_instance' => ''), 'applications');
}

View File

@ -2,6 +2,7 @@
$sql = "SELECT * FROM `ports_stack` WHERE `device_id` = '".$device['device_id']."'";
$stack_db_array = [];
foreach (dbFetchRows($sql) as $entry) {
$stack_db_array[$entry['port_id_high']][$entry['port_id_low']]['ifStackStatus'] = $entry['ifStackStatus'];
}

View File

@ -64,9 +64,6 @@ foreach ($port_stats as $ifIndex => $port) {
} else {
echo '.';
}
// We've seen it. Remove it from the cache.
unset($ports_l[$ifIndex]);
} else {
// Port vanished (mark as deleted)
if (is_array($ports_db[$port_id])) {
@ -86,17 +83,6 @@ unset(
$port
);
// End New interface detection
// Interface Deletion
// If it's in our $ports_l list, that means it's not been seen. Mark it deleted.
foreach ($ports_l as $ifIndex => $port_id) {
if ($ports_db[$ifIndex]['deleted'] == '0') {
dbUpdate(array('deleted' => '1'), 'ports', '`port_id` = ?', array($port_id));
echo '-'.$ifIndex;
}
}
// End interface deletion
echo "\n";
// Clear Variables Here

View File

@ -18,7 +18,7 @@ foreach ($pre_cache['ciscosb_rlPhyTestGetResult'] as $index => $ciscosb_data) {
foreach ($ciscosb_data as $key => $value) {
$oid = '.1.3.6.1.4.1.9.6.1.101.90.1.2.1.3.'.$index.'.7';
$sensor_type = 'rlPhyTestTableTxBias';
$port_descr = get_port_by_index_cache($device, str_replace('1.', '', $index));
$port_descr = get_port_by_index_cache($device['device_id'], str_replace('1.', '', $index));
$descr = $port_descr['ifDescr'] . ' Bias Current';
$current = $value['rlPhyTestTableTxBias'] / $divisor;
$entPhysicalIndex = $index;

View File

@ -19,7 +19,7 @@ foreach ($pre_cache['ciscosb_rlPhyTestGetResult'] as $index => $ciscosb_data) {
if (is_numeric($value['rlPhyTestTableTxOutput']) && ($value['rlPhyTestTableRxOpticalPower'] != 0)) {
$oid = '.1.3.6.1.4.1.9.6.1.101.90.1.2.1.3.'.$index.'.8';
$sensor_type = 'rlPhyTestTableTxOutput';
$port_descr = get_port_by_index_cache($device, str_replace('1.', '', $index));
$port_descr = get_port_by_index_cache($device['device_id'], str_replace('1.', '', $index));
$descr = $port_descr['ifDescr'] . ' Transmit Power';
$dbm = $value['rlPhyTestTableTxOutput'] / $divisor;
$entPhysicalIndex = $index;
@ -29,7 +29,7 @@ foreach ($pre_cache['ciscosb_rlPhyTestGetResult'] as $index => $ciscosb_data) {
if (is_numeric($value['rlPhyTestTableRxOpticalPower']) && ($value['rlPhyTestTableTxOutput'] != 0)) {
$oid = '.1.3.6.1.4.1.9.6.1.101.90.1.2.1.3.'.$index.'.9';
$sensor_type = 'rlPhyTestTableRxOpticalPower';
$port_descr = get_port_by_index_cache($device, str_replace('1.', '', $index));
$port_descr = get_port_by_index_cache($device['device_id'], str_replace('1.', '', $index));
$descr = $port_descr['ifDescr'] . ' Receive Power';
$dbm = $value['rlPhyTestTableRxOpticalPower'] / $divisor;
$entPhysicalIndex = $index;

View File

@ -12,21 +12,20 @@ if (empty($entity_array)) {
}
if (!empty($entity_array)) {
$oids = array();
echo ' entPhySensorType';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorType', $oids, 'ENTITY-SENSOR-MIB');
$entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorType', [], 'ENTITY-SENSOR-MIB');
echo ' entPhySensorScale';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorScale', $oids, 'ENTITY-SENSOR-MIB');
$entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorScale', $entity_oids, 'ENTITY-SENSOR-MIB');
echo ' entPhySensorPrecision';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorPrecision', $oids, 'ENTITY-SENSOR-MIB');
$entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorPrecision', $entity_oids, 'ENTITY-SENSOR-MIB');
echo ' entPhySensorValue';
$oids = snmpwalk_cache_multi_oid($device, 'entPhySensorValue', $oids, 'ENTITY-SENSOR-MIB');
$entity_oids = snmpwalk_cache_multi_oid($device, 'entPhySensorValue', $entity_oids, 'ENTITY-SENSOR-MIB');
if ($device['os'] === 'arista_eos') {
require 'includes/discovery/sensors/misc/arista-eos-limits.inc.php';
}
}
if (!empty($oids)) {
if (!empty($entity_oids)) {
$entitysensor = array(
'voltsDC' => 'voltage',
'voltsAC' => 'voltage',
@ -39,7 +38,7 @@ if (!empty($oids)) {
'dBm' => 'dbm',
);
foreach ($oids as $index => $entry) {
foreach ($entity_oids as $index => $entry) {
$low_limit = null;
$low_warn_limit = null;
$warn_limit = null;

View File

@ -2,4 +2,4 @@
use LibreNMS\Config;
include_once Config::get('install_dir') . '/includes/discovery/sensors/fanspeeds/supermicro.inc.php';
include_once Config::get('install_dir') . '/includes/discovery/sensors/fanspeed/supermicro.inc.php';

View File

@ -3,22 +3,24 @@
* raspberry pi frequencies
* requires snmp extend agent script from librenms-agent
*/
$sensor_type = "raspberry_freq";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.';
if (!empty($pre_cache['raspberry_pi_sensors'])) {
$sensor_type = "raspberry_freq";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.';
for ($freq = 6; $freq < 8; $freq++) {
switch ($freq) {
case "6":
$descr = "ARM";
for ($freq = 6; $freq < 8; $freq++) {
switch ($freq) {
case "6":
$descr = "ARM";
break;
case "7":
$descr = "Core";
break;
}
$value = isset($pre_cache['raspberry_pi_sensors']["raspberry." . $freq]);
if (is_numeric($value)) {
discover_sensor($valid['sensor'], 'frequency', $device, $oid . $freq, $freq, $sensor_type, $descr, 1, 1, null, null, null, null, $value);
} else {
break;
case "7":
$descr = "Core";
break;
}
$value = current($pre_cache['raspberry_pi_sensors']["raspberry.".$freq]);
if (is_numeric($value)) {
discover_sensor($valid['sensor'], 'frequency', $device, $oid.$freq, $freq, $sensor_type, $descr, 1, 1, null, null, null, null, $value);
} else {
break;
}
}
}

View File

@ -2,7 +2,7 @@
/*
* LibreNMS
*
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.com>
* Copyright (c) 2016 Søren Friis Rosiak <sorenrosiak@gmail.com>
* 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
@ -17,7 +17,7 @@ if (is_array($temp)) {
$divisor = '1000';
foreach ($temp as $index => $entry) {
if (is_numeric($temp[$index]['rlPethPsePortOutputPower']) && $temp[$index]['rlPethPsePortOutputPower'] > 0) {
$port_descr = get_port_by_index_cache($device, str_replace('1.', '', $index));
$port_descr = get_port_by_index_cache($device['device_id'], str_replace('1.', '', $index));
$descr = $port_descr['ifDescr'] . ' PoE';
$highlimit = $temp[$index]['rlPethPsePortOperPowerLimit'] / $divisor;
discover_sensor($valid['sensor'], 'power', $device, $cur_oid . $index, $index, 'ciscosb', $descr, $divisor, '1', null, null, null, $highlimit, $temp[$index]['rlPethPsePortOutputPower'] / $divisor, 'snmp', $index);

View File

@ -41,11 +41,11 @@ if ($device['os'] === 'boss') {
);
dbInsert($insert, 'state_translations');
}
// get fans (6) and temp (5) sensor only from walk
$ers_sensors = array();
foreach ($oid as $key => $value) {
if ($key[s5ChasComGrpIndx] == 5 || $key[s5ChasComGrpIndx] == 6) {
if ($key['s5ChasComGrpIndx'] == 5 || $key['s5ChasComGrpIndx'] == 6) {
$ers_sensors[$key] = $value;
}
}
@ -56,7 +56,7 @@ if ($device['os'] === 'boss') {
$unit = floor($unit_array[1]/10);
$descr = "Unit $unit: $entry[s5ChasComDescr]";
//Discover Sensors
discover_sensor($valid['sensor'], 'state', $device, $cur_oid.$index, "s5ChasComOperState.$index", $state_name, $descr, '1', '1', null, null, null, null, $entry[s5ChasComOperState]);
discover_sensor($valid['sensor'], 'state', $device, $cur_oid.$index, "s5ChasComOperState.$index", $state_name, $descr, '1', '1', null, null, null, null, $entry['s5ChasComOperState']);
//Create Sensor To State Index
create_sensor_to_state_index($device, $state_name, "s5ChasComOperState.$index");
}

View File

@ -157,7 +157,7 @@ foreach ($tables as $tablevalue) {
$swstatenumber++;
$descr = $tablevalue[3] . $swstatenumber;
} elseif ($state_name == 'cswStackPortOperStatus') {
$stack_port_descr = get_port_by_index_cache($device, $index);
$stack_port_descr = get_port_by_index_cache($device['device_id'], $index);
$descr = $tablevalue[3] . $stack_port_descr['ifDescr'];
} elseif ($state_name == 'cefcFRUPowerOperStatus') {
$descr = snmp_get($device, 'entPhysicalName.'.$index, '-Oqv', 'ENTITY-MIB');

View File

@ -2,7 +2,7 @@
/*
* LibreNMS
*
* Copyright (c) 2017 Søren Friis Rosiak <sorenrosiak@gmail.com>
* Copyright (c) 2017 Søren Friis Rosiak <sorenrosiak@gmail.com>
* 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
@ -37,7 +37,7 @@ if (is_array($temp)) {
}
foreach ($temp as $index => $entry) {
$port_descr = get_port_by_index_cache($device, str_replace('1.', '', $index));
$port_descr = get_port_by_index_cache($device['device_id'], str_replace('1.', '', $index));
$descr = $port_descr['ifDescr'] . ' Suspended Status';
if (str_contains($descr, 'ethernet')) {
//Discover Sensors

View File

@ -3,52 +3,54 @@
* codec states for raspberry pi
* requires snmp extend agent script from librenms-agent
*/
$state = "raspberry_codec";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.';
for ($codec = 8; $codec < 14; $codec++) {
switch ($codec) {
case "8":
$descr = "H264 codec";
break;
case "9":
$descr = "MPG2 codec";
break;
case "10":
$descr = "WVC1 codec";
break;
case "11":
$descr = "MPG4 codec";
break;
case "12":
$descr = "MJPG codec";
break;
case "13":
$descr = "WMV9 codec";
break;
}
$value = current($pre_cache['raspberry_pi_sensors']["raspberry.".$codec]);
if (stripos($value, 'abled') !== false) {
$state_index_id = create_state_index($state);
if ($state_index_id) {
$states = array(
array($state_index_id, 'enabled', 1, 2, 0),
array($state_index_id, 'disabled', 1, 3 , 2),
);
if (!empty($pre_cache['raspberry_pi_sensors'])) {
$state = "raspberry_codec";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.';
for ($codec = 8; $codec < 14; $codec++) {
switch ($codec) {
case "8":
$descr = "H264 codec";
break;
case "9":
$descr = "MPG2 codec";
break;
case "10":
$descr = "WVC1 codec";
break;
case "11":
$descr = "MPG4 codec";
break;
case "12":
$descr = "MJPG codec";
break;
case "13":
$descr = "WMV9 codec";
break;
}
$value = current($pre_cache['raspberry_pi_sensors']["raspberry." . $codec]);
if (stripos($value, 'abled') !== false) {
$state_index_id = create_state_index($state);
if ($state_index_id) {
$states = [
[$state_index_id, 'enabled', 1, 2, 0],
[$state_index_id, 'disabled', 1, 3, 2],
];
}
foreach ($states as $value) {
$insert = array(
'state_index_id' => $value[0],
'state_descr' => $value[1],
'state_draw_graph' => $value[2],
'state_value' => $value[3],
'state_generic_value' => $value[4]
);
dbInsert($insert, 'state_translations');
foreach ($states as $value) {
$insert = [
'state_index_id' => $value[0],
'state_descr' => $value[1],
'state_draw_graph' => $value[2],
'state_value' => $value[3],
'state_generic_value' => $value[4]
];
dbInsert($insert, 'state_translations');
}
discover_sensor($valid['sensor'], 'state', $device, $oid . $codec, $codec, $state, $descr, '1', '1', null, null, null, null, $value, 'snmp', $codec);
create_sensor_to_state_index($device, $state, $codec);
} else {
break;
}
discover_sensor($valid['sensor'], 'state', $device, $oid.$codec, $codec, $state, $descr, '1', '1', null, null, null, null, $value, 'snmp', $codec);
create_sensor_to_state_index($device, $state, $codec);
} else {
break;
}
}

View File

@ -18,7 +18,7 @@ foreach ($pre_cache['ciscosb_rlPhyTestGetResult'] as $index => $ciscosb_data) {
foreach ($ciscosb_data as $key => $value) {
$oid = '.1.3.6.1.4.1.9.6.1.101.90.1.2.1.3.'.$index.'.5';
$sensor_type = 'rlPhyTestTableTransceiverTemp';
$port_descr = get_port_by_index_cache($device, str_replace('1.', '', $index));
$port_descr = get_port_by_index_cache($device['device_id'], str_replace('1.', '', $index));
$descr = $port_descr['ifDescr'] . ' Module';
$temperature = $value['rlPhyTestTableTransceiverTemp'];
$entPhysicalIndex = $index;

View File

@ -18,7 +18,7 @@ foreach ($pre_cache['ciscosb_rlPhyTestGetResult'] as $index => $ciscosb_data) {
foreach ($ciscosb_data as $key => $value) {
$oid = '.1.3.6.1.4.1.9.6.1.101.90.1.2.1.3.'.$index.'.6';
$sensor_type = 'rlPhyTestTableTransceiverSupply';
$port_descr = get_port_by_index_cache($device, str_replace('1.', '', $index));
$port_descr = get_port_by_index_cache($device['device_id'], str_replace('1.', '', $index));
$descr = $port_descr['ifDescr'] . ' Supply Voltage';
$voltage = $value['rlPhyTestTableTransceiverSupply'] / $divisor;
$entPhysicalIndex = $index;

View File

@ -3,28 +3,30 @@
* voltages for raspberry pi
* requires snmp extend agent script from librenms-agent
*/
$sensor_type = "rasbperry_volts";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.';
for ($volt = 2; $volt < 6; $volt++) {
switch ($volt) {
case "2":
$descr = "Core";
if (!empty($pre_cache['raspberry_pi_sensors'])) {
$sensor_type = "rasbperry_volts";
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.';
for ($volt = 2; $volt < 6; $volt++) {
switch ($volt) {
case "2":
$descr = "Core";
break;
case "3":
$descr = "SDRAMc";
break;
case "4":
$descr = "SDRAMi";
break;
case "5":
$descr = "SDRAMp";
break;
}
$value = current($pre_cache['raspberry_pi_sensors']["raspberry." . $volt]);
if (is_numeric($value)) {
discover_sensor($valid['sensor'], 'voltage', $device, $oid . $volt, $volt, $sensor_type, $descr, '1', '1', null, null, null, null, $value);
} else {
break;
case "3":
$descr = "SDRAMc";
break;
case "4":
$descr = "SDRAMi";
break;
case "5":
$descr = "SDRAMp";
break;
}
$value = current($pre_cache['raspberry_pi_sensors']["raspberry.".$volt]);
if (is_numeric($value)) {
discover_sensor($valid['sensor'], 'voltage', $device, $oid.$volt, $volt, $sensor_type, $descr, '1', '1', null, null, null, null, $value);
} else {
break;
}
}
}

View File

@ -1,6 +1,6 @@
<?php
/*
* LibreNMS
* LibreNMS
*
* Copyright (c) 2015 Vitali Kari <vitali.kari@gmail.com>
*
@ -29,7 +29,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
// some vendors like PBN dont follow the 802.1D implementation and use seconds in SNMP
if ($device['os'] == 'pbn') {
preg_match('/^.* Build (?<build>\d+)/', $device['version'], $version);
if ($version[build] <= 16607) { // Buggy version :-(
if ($version['build'] <= 16607) { // Buggy version :-(
$tm = '1';
}
}
@ -56,7 +56,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
// read the 802.1D bridge address and set as MAC in database
$mac_raw = snmp_get($device, 'dot1dBaseBridgeAddress.0', '-Oqv', 'RSTP-MIB');
// read Time as timetics (in hundredths of a seconds) since last topology change and convert to seconds
$time_since_change = snmp_get($device, 'dot1dStpTimeSinceTopologyChange.0', '-Ovt', 'RSTP-MIB');
if ($time_since_change > '100') {
@ -100,7 +100,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
log_event('STP added, bridge address: ' . $stp['bridgeAddress'], $device, 'stp', 3);
echo '+';
}
if ($stp_db['bridgeAddress'] && !$stp['bridgeAddress']) {
dbDelete('stp', 'device_id = ?', array($device['device_id']));
log_event('STP removed', $device, 'stp', 4);
@ -119,17 +119,17 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
'designatedPort' => $stp_raw[$port]['dot1dStpPortDesignatedPort'],
'forwardTransitions' => $stp_raw[$port]['dot1dStpPortForwardTransitions']
);
// set device binding
$stp_port['device_id'] = $device['device_id'];
// set port binding
$stp_port['port_id'] = dbFetchCell('SELECT port_id FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $stp_raw[$port]['dot1dStpPort']));
$dr = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[$port]['dot1dStpPortDesignatedRoot']));
$dr = substr($dr, -12); //remove first two octets
$stp_port['designatedRoot'] = $dr;
$db = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[$port]['dot1dStpPortDesignatedBridge']));
$db = substr($db, -12); //remove first two octets
$stp_port['designatedBridge'] = $db;
@ -149,7 +149,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
$dp = substr($stp_raw[$port]['dot1dStpPortDesignatedPort'], -2); //discard the first octet (priority part)
$stp_port['designatedPort'] = hexdec($dp);
}
d_echo($stp_port);
// Write to db

View File

@ -3,6 +3,7 @@
// Pre-cache the existing state of VLANs for this device from the database
use LibreNMS\Config;
$vlans_db = [];
$vlans_db_raw = dbFetchRows('SELECT * FROM `vlans` WHERE `device_id` = ?', array($device['device_id']));
foreach ($vlans_db_raw as $vlan_db) {
$vlans_db[$vlan_db['vlan_domain']][$vlan_db['vlan_vlan']] = $vlan_db;
@ -46,8 +47,8 @@ foreach ($device['vlans'] as $domain_id => $vlans) {
echo str_pad('dot1d id', 10).str_pad('ifIndex', 10).str_pad('Port Name', 25).str_pad('Priority', 10).str_pad('State', 15).str_pad('Cost', 10)."\n";
}
foreach ($vlan_data as $ifIndex => $vlan_port) {
$port = get_port_by_index_cache($device, $ifIndex);
foreach ((array)$vlan_data as $ifIndex => $vlan_port) {
$port = get_port_by_index_cache($device['device_id'], $ifIndex);
echo str_pad($vlan_port_id, 10).str_pad($ifIndex, 10).str_pad($port['ifDescr'], 25).str_pad($vlan_port['dot1dStpPortPriority'], 10).str_pad($vlan_port['dot1dStpPortState'], 15).str_pad($vlan_port['dot1dStpPortPathCost'], 10);
$db_w = array(

View File

@ -20,7 +20,7 @@ if (($device['os'] == 'vmware') || ($device['os'] == 'linux')) {
* Fetch information about Virtual Machines.
*/
$oids = snmpwalk_cache_multi_oid($device, 'vmwVmTable', $oids, '+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB', 'vmware');
$oids = snmpwalk_cache_multi_oid($device, 'vmwVmTable', [], '+VMWARE-ROOT-MIB:VMWARE-VMINFO-MIB', 'vmware');
foreach ($oids as $index => $entry) {
$vmwVmDisplayName = $entry['vmwVmDisplayName'];

View File

@ -11,6 +11,7 @@
*
*/
use Illuminate\Database\Events\QueryExecuted;
use LibreNMS\Authentication\Auth;
use LibreNMS\Config;
use LibreNMS\Exceptions\HostExistsException;
@ -24,15 +25,101 @@ use LibreNMS\Exceptions\SnmpVersionUnsupportedException;
use LibreNMS\Util\IP;
use LibreNMS\Util\MemcacheLock;
function set_debug($debug)
/**
* Set debugging output
*
* @param bool $state If debug is enabled or not
* @param bool $silence When not debugging, silence every php error
* @return bool
*/
function set_debug($state = true, $silence = false)
{
if (isset($debug)) {
global $debug;
$debug = $state; // set to global
$db = \LibreNMS\DB\Eloquent::DB();
restore_error_handler(); // disable Laravel error handler
if ($debug) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 0);
ini_set('allow_url_fopen', 0);
ini_set('error_reporting', E_ALL);
error_reporting(E_ALL & ~E_NOTICE);
if (class_exists('Log')) {
$logger = Log::getMonolog();
// only install if not existing
$install = true;
$logfile = Config::get('log_file', base_path('logs/librenms.log'));
foreach ($logger->getHandlers() as $handler) {
if ($handler instanceof \Monolog\Handler\StreamHandler) {
if ($handler->getUrl() == 'php://stdout') {
$install = false;
} elseif ($handler->getUrl() == $logfile) {
// send to librenms log file if not a cli app
if (!App::runningInConsole()) {
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
Log::error("$errno $errfile:$errline $errstr");
});
$handler->setLevel(\Monolog\Logger::DEBUG);
}
}
}
}
if ($install) {
$handler = new \Monolog\Handler\StreamHandler(
'php://stdout',
\Monolog\Logger::DEBUG
);
$handler->setFormatter(new LibreNMS\Util\CliColorFormatter());
$logger->pushHandler($handler);
}
}
if ($db && !$db->getEventDispatcher()->hasListeners('Illuminate\Database\Events\QueryExecuted')) {
$db->listen(function (QueryExecuted $query) {
// collect bindings and make them a little more readable
$bindings = collect($query->bindings)->map(function ($item) {
if ($item instanceof \Carbon\Carbon) {
return $item->toDateTimeString();
}
return $item;
})->toJson();
if (class_exists('Log')) {
Log::debug("SQL[%Y{$query->sql} %y$bindings%n {$query->time}ms] \n", ['color' => true]);
} else {
c_echo("SQL[%Y{$query->sql} %y$bindings%n {$query->time}ms] \n");
}
});
}
} else {
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 1);
error_reporting($silence ? 0 : E_ERROR);
if (class_exists('Log')) {
$handlers = Log::getMonolog()->getHandlers();
if (isset($handlers[0]) && $handlers[0]->getUrl() == 'php://stdout') {
Log::getMonolog()->popHandler();
}
}
if ($db) {
// remove all query executed event handlers
$db->getEventDispatcher()->flush('Illuminate\Database\Events\QueryExecuted');
}
}
return $debug;
}//end set_debug()
function array_sort_by_column($array, $on, $order = SORT_ASC)
@ -689,12 +776,12 @@ function isSNMPable($device)
* Check if the given host responds to ICMP echo requests ("pings").
*
* @param string $hostname The hostname or IP address to send ping requests to.
* @param int $address_family The address family (AF_INET for IPv4 or AF_INET6 for IPv6) to use. Defaults to IPv4. Will *not* be autodetected for IP addresses, so it has to be set to AF_INET6 when pinging an IPv6 address or an IPv6-only host.
* @param int $address_family The address family ('ipv4' or 'ipv6') to use. Defaults to IPv4. Will *not* be autodetected for IP addresses, so it has to be set to 'ipv6' when pinging an IPv6 address or an IPv6-only host.
* @param array $attribs The device attributes
*
* @return array 'result' => bool pingable, 'last_ping_timetaken' => int time for last ping, 'db' => fping results
*/
function isPingable($hostname, $address_family = AF_INET, $attribs = array())
function isPingable($hostname, $address_family = 'ipv4', $attribs = array())
{
global $config;
@ -1444,7 +1531,7 @@ function ip_exists($ip)
return false;
}
function fping($host, $params, $address_family = AF_INET)
function fping($host, $params, $address_family = 'ipv4')
{
global $config;
@ -1455,9 +1542,9 @@ function fping($host, $params, $address_family = AF_INET)
2 => array("pipe", "w")
);
// Default to AF_INET (IPv4)
// Default to ipv4
$fping_path = $config['fping'];
if ($address_family == AF_INET6) {
if ($address_family == 'ipv6') {
$fping_path = $config['fping6'];
}
@ -1533,23 +1620,19 @@ function force_influx_data($data)
* "udp6", "tcp", or "tcp6". See `man snmpcmd`,
* section "Agent Specification" for a full list.
*
* @return int The address family associated with the given transport
* specifier: AF_INET for IPv4 (or local connections not associated
* with an IP stack), AF_INET6 for IPv6.
* @return string The address family associated with the given transport
* specifier: 'ipv4' (or local connections not associated
* with an IP stack) or 'ipv6'.
*/
function snmpTransportToAddressFamily($transport)
{
if (!isset($transport)) {
$transport = 'udp';
}
$ipv6_snmp_transport_specifiers = array('udp6', 'udpv6', 'udpipv6', 'tcp6', 'tcpv6', 'tcpipv6');
$ipv6_snmp_transport_specifiers = ['udp6', 'udpv6', 'udpipv6', 'tcp6', 'tcpv6', 'tcpipv6'];
if (in_array($transport, $ipv6_snmp_transport_specifiers)) {
return AF_INET6;
} else {
return AF_INET;
return 'ipv6';
}
return 'ipv4';
}
/**
@ -2033,6 +2116,7 @@ function get_toner_levels($device, $raw_value, $capacity)
function initStats()
{
global $snmp_stats, $rrd_stats;
global $snmp_stats_last, $rrd_stats_last;
if (!isset($snmp_stats, $rrd_stats)) {
$snmp_stats = array(
@ -2047,6 +2131,7 @@ function initStats()
'snmpwalk' => 0.0,
)
);
$snmp_stats_last = $snmp_stats;
$rrd_stats = array(
'ops' => array(
@ -2060,6 +2145,7 @@ function initStats()
'other' => 0.0,
),
);
$rrd_stats_last = $rrd_stats;
}
}
@ -2098,47 +2184,55 @@ function printStats()
{
global $snmp_stats, $db_stats, $rrd_stats;
printf(
"SNMP [%d/%.2fs]: Get[%d/%.2fs] Getnext[%d/%.2fs] Walk[%d/%.2fs]\n",
array_sum($snmp_stats['ops']),
array_sum($snmp_stats['time']),
$snmp_stats['ops']['snmpget'],
$snmp_stats['time']['snmpget'],
$snmp_stats['ops']['snmpgetnext'],
$snmp_stats['time']['snmpgetnext'],
$snmp_stats['ops']['snmpwalk'],
$snmp_stats['time']['snmpwalk']
);
printf(
"MySQL [%d/%.2fs]: Cell[%d/%.2fs] Row[%d/%.2fs] Rows[%d/%.2fs] Column[%d/%.2fs] Update[%d/%.2fs] Insert[%d/%.2fs] Delete[%d/%.2fs]\n",
array_sum($db_stats['ops']),
array_sum($db_stats['time']),
$db_stats['ops']['fetchcell'],
$db_stats['time']['fetchcell'],
$db_stats['ops']['fetchrow'],
$db_stats['time']['fetchrow'],
$db_stats['ops']['fetchrows'],
$db_stats['time']['fetchrows'],
$db_stats['ops']['fetchcolumn'],
$db_stats['time']['fetchcolumn'],
$db_stats['ops']['update'],
$db_stats['time']['update'],
$db_stats['ops']['insert'],
$db_stats['time']['insert'],
$db_stats['ops']['delete'],
$db_stats['time']['delete']
);
printf(
"RRD [%d/%.2fs]: Update[%d/%.2fs] Create [%d/%.2fs] Other[%d/%.2fs]\n",
array_sum($rrd_stats['ops']),
array_sum($rrd_stats['time']),
$rrd_stats['ops']['update'],
$rrd_stats['time']['update'],
$rrd_stats['ops']['create'],
$rrd_stats['time']['create'],
$rrd_stats['ops']['other'],
$rrd_stats['time']['other']
);
if ($snmp_stats) {
printf(
"SNMP [%d/%.2fs]: Get[%d/%.2fs] Getnext[%d/%.2fs] Walk[%d/%.2fs]\n",
array_sum($snmp_stats['ops']),
array_sum($snmp_stats['time']),
$snmp_stats['ops']['snmpget'],
$snmp_stats['time']['snmpget'],
$snmp_stats['ops']['snmpgetnext'],
$snmp_stats['time']['snmpgetnext'],
$snmp_stats['ops']['snmpwalk'],
$snmp_stats['time']['snmpwalk']
);
}
if ($db_stats) {
printf(
"MySQL [%d/%.2fs]: Cell[%d/%.2fs] Row[%d/%.2fs] Rows[%d/%.2fs] Column[%d/%.2fs] Update[%d/%.2fs] Insert[%d/%.2fs] Delete[%d/%.2fs]\n",
array_sum($db_stats['ops']),
array_sum($db_stats['time']),
$db_stats['ops']['fetchcell'],
$db_stats['time']['fetchcell'],
$db_stats['ops']['fetchrow'],
$db_stats['time']['fetchrow'],
$db_stats['ops']['fetchrows'],
$db_stats['time']['fetchrows'],
$db_stats['ops']['fetchcolumn'],
$db_stats['time']['fetchcolumn'],
$db_stats['ops']['update'],
$db_stats['time']['update'],
$db_stats['ops']['insert'],
$db_stats['time']['insert'],
$db_stats['ops']['delete'],
$db_stats['time']['delete']
);
}
if ($rrd_stats) {
printf(
"RRD [%d/%.2fs]: Update[%d/%.2fs] Create [%d/%.2fs] Other[%d/%.2fs]\n",
array_sum($rrd_stats['ops']),
array_sum($rrd_stats['time']),
$rrd_stats['ops']['update'],
$rrd_stats['time']['update'],
$rrd_stats['ops']['create'],
$rrd_stats['time']['create'],
$rrd_stats['ops']['other'],
$rrd_stats['time']['other']
);
}
}
/**

View File

@ -99,8 +99,6 @@ ini_set('display_errors', 1);
if (!module_selected('nodb', $init_modules)) {
// Connect to database
try {
// \LibreNMS\DB\Eloquent::boot();
dbConnect();
} catch (\LibreNMS\Exceptions\DatabaseConnectException $e) {
if (isCli()) {
@ -113,6 +111,17 @@ if (!module_selected('nodb', $init_modules)) {
}
}
if (module_selected('laravel', $init_modules)) {
// make sure Laravel isn't already booted
if (!class_exists('App') || !App::isBooted()) {
$app = require_once $install_dir . '/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
}
} elseif (module_selected('eloquent', $init_modules)) {
\LibreNMS\DB\Eloquent::boot();
}
// Load config if not already loaded (which is the case if inside Laravel)
if (!Config::has('install_dir')) {
Config::load();

View File

@ -33,7 +33,7 @@ try {
return;
}
$f2b = $f2b[data];
$f2b = $f2b['data'];
$metrics = [];

View File

@ -13,7 +13,7 @@ $json = snmp_get($device, $oid, $options, $mib);
$zfs=json_decode(stripslashes($json), true);
$rrd_name = array('app', $name, $app_id);
$rrd_name = ['app', $name, $app_id];
$rrd_def = RrdDefinition::make()
->addDataset('deleted', 'DERIVE', 0)
->addDataset('evict_skip', 'DERIVE', 0)
@ -69,70 +69,70 @@ $rrd_def = RrdDefinition::make()
->addDataset('meta_misses_per', 'GAUGE', 0)
->addDataset('pre_meta_misses_per', 'GAUGE', 0);
$fields = array(
'deleted' => $zfs{deleted},
'evict_skip' => $zfs{evict_skip},
'mutex_skip' => $zfs{mutex_skip},
'recycle_miss' => $zfs{recycle_miss},
'arc_size' => $zfs{arc_size},
'target_size_max' => $zfs{target_size_max},
'target_size_min' => $zfs{target_size_min},
'target_size' => $zfs{target_size},
'target_size_per' => $zfs{target_size_per},
'arc_size_per' => $zfs{arc_size_per},
'target_size_arat' => $zfs{target_size_arat},
'min_size_per' => $zfs{min_size_per},
'mfu_size' => $zfs{mfu_size},
'p' => $zfs{p},
'rec_used_per' => $zfs{rec_used_per},
'freq_used_per' => $zfs{freq_used_per},
'arc_hits' => $zfs{arc_hits},
'arc_misses' => $zfs{arc_misses},
'demand_data_hits' => $zfs{demand_data_hits},
'demand_data_misses' => $zfs{demand_data_misses},
'demand_meta_hits' => $zfs{demand_meta_hits},
'demand_meta_misses' => $zfs{demand_meta_misses},
'mfu_ghost_hits' => $zfs{mfu_ghost_hits},
'mfu_hits' => $zfs{mfu_hits},
'mru_ghost_hits' => $zfs{mru_ghost_hits},
'mru_hits' => $zfs{mru_hits},
'pre_data_hits' => $zfs{pre_data_hits},
'pre_data_misses' => $zfs{pre_data_misses},
'pre_meta_hits' => $zfs{pre_meta_hits},
'pre_meta_misses' => $zfs{pre_meta_misses},
'anon_hits' => $zfs{anon_hits},
'arc_accesses_total' => $zfs{arc_accesses_total},
'demand_data_total' => $zfs{demand_data_total},
'pre_data_total' => $zfs{pre_data_total},
'real_hits' => $zfs{real_hits},
'cache_hits_per' => $zfs{cache_hits_per},
'cache_miss_per' => $zfs{cache_miss_per},
'actual_hit_per' => $zfs{actual_hit_per},
'data_demand_per' => $zfs{data_demand_per},
'data_pre_per' => $zfs{data_pre_per},
'anon_hits_per' => $zfs{anon_hits_per},
'mru_per' => $zfs{mru_per},
'mfu_per' => $zfs{mfu_per},
'mru_ghost_per' => $zfs{mru_ghost_per},
'mfu_ghost_per' => $zfs{mfu_ghost_per},
'demand_hits_per' => $zfs{demand_hits_per},
'pre_hits_per' => $zfs{pre_hits_per},
'meta_hits_per' => $zfs{meta_hits_per},
'pre_meta_hits_per' => $zfs{pre_meta_hits_per},
'demand_misses_per' => $zfs{demand_misses_per},
'pre_misses_per' => $zfs{pre_misses_per},
'meta_misses_per' => $zfs{meta_misses_per},
'pre_meta_misses_per' => $zfs{pre_meta_misses_per},
);
$fields = [
'deleted' => $zfs['deleted'],
'evict_skip' => $zfs['evict_skip'],
'mutex_skip' => $zfs['mutex_skip'],
'recycle_miss' => $zfs['recycle_miss'],
'arc_size' => $zfs['arc_size'],
'target_size_max' => $zfs['target_size_max'],
'target_size_min' => $zfs['target_size_min'],
'target_size' => $zfs['target_size'],
'target_size_per' => $zfs['target_size_per'],
'arc_size_per' => $zfs['arc_size_per'],
'target_size_arat' => $zfs['target_size_arat'],
'min_size_per' => $zfs['min_size_per'],
'mfu_size' => $zfs['mfu_size'],
'p' => $zfs['p'],
'rec_used_per' => $zfs['rec_used_per'],
'freq_used_per' => $zfs['freq_used_per'],
'arc_hits' => $zfs['arc_hits'],
'arc_misses' => $zfs['arc_misses'],
'demand_data_hits' => $zfs['demand_data_hits'],
'demand_data_misses' => $zfs['demand_data_misses'],
'demand_meta_hits' => $zfs['demand_meta_hits'],
'demand_meta_misses' => $zfs['demand_meta_misses'],
'mfu_ghost_hits' => $zfs['mfu_ghost_hits'],
'mfu_hits' => $zfs['mfu_hits'],
'mru_ghost_hits' => $zfs['mru_ghost_hits'],
'mru_hits' => $zfs['mru_hits'],
'pre_data_hits' => $zfs['pre_data_hits'],
'pre_data_misses' => $zfs['pre_data_misses'],
'pre_meta_hits' => $zfs['pre_meta_hits'],
'pre_meta_misses' => $zfs['pre_meta_misses'],
'anon_hits' => $zfs['anon_hits'],
'arc_accesses_total' => $zfs['arc_accesses_total'],
'demand_data_total' => $zfs['demand_data_total'],
'pre_data_total' => $zfs['pre_data_total'],
'real_hits' => $zfs['real_hits'],
'cache_hits_per' => $zfs['cache_hits_per'],
'cache_miss_per' => $zfs['cache_miss_per'],
'actual_hit_per' => $zfs['actual_hit_per'],
'data_demand_per' => $zfs['data_demand_per'],
'data_pre_per' => $zfs['data_pre_per'],
'anon_hits_per' => $zfs['anon_hits_per'],
'mru_per' => $zfs['mru_per'],
'mfu_per' => $zfs['mfu_per'],
'mru_ghost_per' => $zfs['mru_ghost_per'],
'mfu_ghost_per' => $zfs['mfu_ghost_per'],
'demand_hits_per' => $zfs['demand_hits_per'],
'pre_hits_per' => $zfs['pre_hits_per'],
'meta_hits_per' => $zfs['meta_hits_per'],
'pre_meta_hits_per' => $zfs['pre_meta_hits_per'],
'demand_misses_per' => $zfs['demand_misses_per'],
'pre_misses_per' => $zfs['pre_misses_per'],
'meta_misses_per' => $zfs['meta_misses_per'],
'pre_meta_misses_per' => $zfs['pre_meta_misses_per'],
];
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
$tags = ['name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name];
data_update($device, 'app', $tags, $fields);
//
// process additional info returned
//
$pools=array();
$pools = [];
$pool_rrd_def = RrdDefinition::make()
->addDataset('size', 'GAUGE', 0)
->addDataset('alloc', 'GAUGE', 0)
@ -143,21 +143,21 @@ $pool_rrd_def = RrdDefinition::make()
->addDataset('dedup', 'GAUGE', 0);
$pools_int=0;
$pools_for_metrics=array(); // used later for replacing pools when inserting into the metrics table
while (isset($zfs{'pools'}{$pools_int})) {
$pools[]=$zfs{'pools'}{$pools_int}{'name'};
$pools_for_mertrics[$zfs{'pools'}{$pools_int}{'name'}]=$zfs{'pools'}{$pools_int}; // copy the pool over later
$rrd_name = array('app', $name, $app_id, $zfs{'pools'}{$pools_int}{'name'});
$fields = array(
'size' => $zfs{'pools'}{$pools_int}{'size'},
'alloc' => $zfs{'pools'}{$pools_int}{'alloc'},
'free' => $zfs{'pools'}{$pools_int}{'free'},
'expandsz' => $zfs{'pools'}{$pools_int}{'expandsz'},
'frag' => $zfs{'pools'}{$pools_int}{'frag'},
'cap' => $zfs{'pools'}{$pools_int}{'cap'},
'dedup' => $zfs{'pools'}{$pools_int}{'dedup'},
);
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $pool_rrd_def, 'rrd_name' => $rrd_name);
$pools_for_metrics = []; // used later for replacing pools when inserting into the metrics table
while (isset($zfs['pools'][$pools_int])) {
$pools[] = $zfs['pools'][$pools_int]['name'];
$pools_for_metrics[$zfs['pools'][$pools_int]['name']] = $zfs['pools'][$pools_int]; // copy the pool over later
$rrd_name = ['app', $name, $app_id, $zfs['pools'][$pools_int]['name']];
$fields = [
'size' => $zfs['pools'][$pools_int]['size'],
'alloc' => $zfs['pools'][$pools_int]['alloc'],
'free' => $zfs['pools'][$pools_int]['free'],
'expandsz' => $zfs['pools'][$pools_int]['expandsz'],
'frag' => $zfs['pools'][$pools_int]['frag'],
'cap' => $zfs['pools'][$pools_int]['cap'],
'dedup' => $zfs['pools'][$pools_int]['dedup'],
];
$tags = ['name' => $name, 'app_id' => $app_id, 'rrd_def' => $pool_rrd_def, 'rrd_name' => $rrd_name];
data_update($device, 'app', $tags, $fields);
$pools_int++;
@ -167,12 +167,12 @@ while (isset($zfs{'pools'}{$pools_int})) {
// component processing for ZFS
//
$device_id=$device['device_id'];
$options=array(
'filter' => array(
'device_id' => array('=', $device_id),
'type' => array('=', 'zfs'),
),
);
$options= [
'filter' => [
'device_id' => ['=', $device_id],
'type' => ['=', 'zfs'],
],
];
$component=new LibreNMS\Component();
$components=$component->getComponents($device_id, $options);
@ -199,5 +199,5 @@ if (empty($pools)) {
}
//replace $zfs{'pools'} with a array where the keys are the pool names and update metrics
$zfs{'pools'}=$pools_for_mertrics;
$zfs['pools'] = $pools_for_metrics;
update_application($app, $json, $zfs);

View File

@ -338,8 +338,6 @@ if ($config['enable_bgp']) {
$safis['multicast'] = 2;
$afis['ipv4'] = 1;
$afis['ipv6'] = 2;
$type['ipv4'] = 4;
$type['ipv6'] = 16;
if (preg_match('/:/', $peer['bgpPeerIdentifier'])) {
$tmp_peer = str_replace(':', '', $peer['bgpPeerIdentifier']);
$tmp_peer = preg_replace('/([\w\d]{2})/', '\1:', $tmp_peer);

View File

@ -26,7 +26,7 @@ if ($device['os_group'] == "cisco") {
$components = $components[$device['device_id']];
// Only collect SNMP data if we have enabled components
if (count($components > 0)) {
if (is_array($components) && count($components) > 0) {
// Let's gather the stats..
$tblcbQosClassMapStats = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.15.1.1', 2);

View File

@ -96,7 +96,7 @@ if ($device['os_group'] == 'cisco') {
// FIXME - need to delete old ones. FIXME REALLY.
print_r($cefs_db);
foreach ($cefs_db as $cef_switching_id) {
foreach ((array)$cefs_db as $cef_switching_id) {
dbDelete('cef_switching', '`cef_switching_id` = ?', array($cef_switching_id));
echo '-';
}

View File

@ -69,7 +69,7 @@ if ($device['os_group'] == "cisco") {
$components = $components[$device['device_id']];
// Only collect SNMP data if we have enabled components
if (count($components) > 0) {
if (is_array($components) && count($components) > 0) {
// Let's gather the stats..
$tblOverlayEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.2.1.1');
$tblAdjacencyDatabaseEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.3.1.1', 0);

View File

@ -12,7 +12,7 @@ use LibreNMS\RRD\RrdDefinition;
if ($device['os_group'] == 'cisco') {
$data = snmpwalk_cache_oid($device, 'cvpdnSystemEntry', null, 'CISCO-VPDN-MGMT-MIB');
foreach ($data as $type => $vpdn) {
foreach ((array)$data as $type => $vpdn) {
if ($vpdn['cvpdnSystemTunnelTotal'] || $vpdn['cvpdnSystemSessionTotal']) {
$rrd_name = array('vpdn', $type);
$rrd_def = RrdDefinition::make()

View File

@ -25,7 +25,7 @@ foreach (dbFetch('SELECT * FROM `entPhysical_state` WHERE `device_id` = ?', arra
// End Set Entity Attrivs
// Delete Entity state
foreach ($entPhysical_state as $epi => $entity) {
foreach ((array)$entPhysical_state as $epi => $entity) {
foreach ($entity as $subindex => $si) {
foreach ($si as $group => $ti) {
foreach ($ti as $key => $value) {

View File

@ -244,7 +244,8 @@ function poll_device($device, $force_module = false)
echo 'Device ID: ' . $device['device_id'] . PHP_EOL;
echo 'OS: ' . $device['os'];
$ip = dnslookup($device);
$db_ip = inet_pton($ip);
$db_ip = isset($ip) ? inet_pton($ip) : null;
if (!empty($db_ip) && inet6_ntop($db_ip) != inet6_ntop($device['ip'])) {
log_event('Device IP changed to ' . $ip, $device, 'system', 3);

View File

@ -23,7 +23,7 @@ if (!is_array($mempool_cache['fiberhome-switch'])) {
d_echo($mempool_cache);
}
$entry = $mempool_cache['fiberhome-switch'][$mempool[mempool_index]];
$entry = $mempool_cache['fiberhome-switch'][$mempool['mempool_index']];
if ($entry['memoryPoolTotalBytes'] < 0) {
$entry['memoryPoolTotalBytes'] = ($entry['memoryPoolTotalBytes'] * -1);

View File

@ -14,7 +14,7 @@ if (!is_array($mempool_cache['hpGlobal'])) {
d_echo('Cached!');
}
$entry = $mempool_cache['hpGlobal'][$mempool[mempool_index]];
$entry = $mempool_cache['hpGlobal'][$mempool['mempool_index']];
$mempool['units'] = '1';
$mempool['used'] = $entry['hpGlobalMemAllocBytes'];

View File

@ -14,7 +14,7 @@ if (!is_array($mempool_cache['hpLocal'])) {
d_echo('Cached!');
}
$entry = $mempool_cache['hpLocal'][$mempool[mempool_index]];
$entry = $mempool_cache['hpLocal'][$mempool['mempool_index']];
$mempool['units'] = '1';
$mempool['used'] = $entry['hpLocalMemAllocBytes'];

View File

@ -8,7 +8,7 @@ if (!is_array($storage_cache['hrstorage'])) {
d_echo('Cached!');
}
$entry = $storage_cache['hrstorage'][$mempool[mempool_index]];
$entry = $storage_cache['hrstorage'][$mempool['mempool_index']];
$mempool['units'] = $entry['hrStorageAllocationUnits'];
$mempool['used'] = ($entry['hrStorageUsed'] * $mempool['units']);

View File

@ -27,7 +27,7 @@ else {
$mempool_cache['ironware-dyn'] = snmpwalk_cache_multi_oid($device, 'snAgentBrdMemoryTotal', $mempool_cache['ironware-dyn'], 'FOUNDRY-SN-AGENT-MIB');
d_echo($mempool_cache);
$entry = $mempool_cache['ironware-dyn'][$mempool[mempool_index]];
$entry = $mempool_cache['ironware-dyn'][$mempool['mempool_index']];
$perc = $entry['snAgentBrdMemoryUtil100thPercent'];

View File

@ -14,7 +14,7 @@ if (!is_array($mempool_cache['junos'])) {
d_echo($mempool_cache);
}
$entry = $mempool_cache['junos'][$mempool[mempool_index]];
$entry = $mempool_cache['junos'][$mempool['mempool_index']];
$perc = $entry['jnxOperatingBuffer'];
// FIX ME -- Maybe another OID? Some equipment do not provide jnxOperatingDRAMSize like MX960

View File

@ -7,7 +7,7 @@ preg_match('/^.* Build (?<build>\d+)/', $device['version'], $version);
d_echo($version);
// specified MIB supported since build 16607
if ($version[build] >= 16607) {
if ($version['build'] >= 16607) {
$perc = snmp_get($device, 'nmsMemoryPoolUtilization.0', '-OUvQ', 'NMS-MEMORY-POOL-MIB', 'pbn');
$memory_available = snmp_get($device, 'nmsMemoryPoolTotalMemorySize.0', '-OUvQ', 'NMS-MEMORY-POOL-MIB', 'pbn');
$mempool['total'] = $memory_available;

View File

@ -13,7 +13,7 @@ if (!is_array($mempool_cache['vrp'])) {
d_echo($mempool_cache);
}
$entry = $mempool_cache['vrp'][$mempool[mempool_index]];
$entry = $mempool_cache['vrp'][$mempool['mempool_index']];
if ($entry['hwEntityMemSize'] < 0) {
$entry['hwEntityMemSize'] = ($entry['hwEntityMemSize'] * -1);

View File

@ -26,7 +26,7 @@ $components = $component->getComponents($device['device_id'], $options);
$components = $components[$device['device_id']];
// Only collect SNMP data if we have enabled components
if (count($components > 0)) {
if (is_array($components) && count($components) > 0) {
// Let's gather the stats..
$cntpPeersVarEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.168.1.2.1.1', 2);

View File

@ -1,6 +1,7 @@
<?php
// Build SNMP Cache Array
use LibreNMS\Config;
use LibreNMS\RRD\RrdDefinition;
$data_oids = array(
@ -214,7 +215,8 @@ if ($device['os'] === 'f5' && (version_compare($device['version'], '11.2.0', '>=
unset($data);
} else {
// For devices that are on the bad_ifXentry list, try fetching ifAlias to have nice interface descriptions.
if (!in_array(strtolower($device['hardware']), array_map('strtolower', $config['os'][$device['os']]['bad_ifXEntry']))) {
if (!in_array(strtolower($device['hardware']), array_map('strtolower', (array)Config::getOsSetting($device['os'], 'bad_ifXEntry', [])))) {
$port_stats = snmpwalk_cache_oid($device, 'ifXEntry', $port_stats, 'IF-MIB');
} else {
$port_stats = snmpwalk_cache_oid($device, 'ifAlias', $port_stats, 'IF-MIB', null, '-OQUst');
@ -731,7 +733,7 @@ foreach ($ports as $port) {
$port['stats']['ifOutBits_rate'] = round(($port['stats']['ifOutOctets_rate'] * 8));
// If we have a valid ifSpeed we should populate the stats for checking.
if (is_numeric($this_port['ifSpeed'])) {
if (is_numeric($this_port['ifSpeed']) && $this_port['ifSpeed'] > 0) {
$port['stats']['ifInBits_perc'] = round(($port['stats']['ifInBits_rate'] / $this_port['ifSpeed'] * 100));
$port['stats']['ifOutBits_perc'] = round(($port['stats']['ifOutBits_rate'] / $this_port['ifSpeed'] * 100));
}

View File

@ -60,8 +60,8 @@ foreach ($storage_cache2['eql-storage'] as $index => $vsentry) {
}
d_echo($storage_cache20);
$entry1 = $storage_cache10[$storage[storage_index]];
$entry2 = $storage_cache20[$storage[storage_index]];
$entry1 = $storage_cache10[$storage['storage_index']];
$entry2 = $storage_cache20[$storage['storage_index']];
$storage['units'] = 1000000;
$storage['size'] = ($entry1['eqliscsiVolumeSize'] * $storage['units']);

View File

@ -6,7 +6,7 @@ if (!is_array($storage_cache['hpe-ilo'])) {
echo("HPE ILO4 ");
}
$entry = $storage_cache['hpe-ilo'][$storage[storage_index]];
$entry = $storage_cache['hpe-ilo'][$storage['storage_index']];
$storage['units'] = 1024*1024;
$storage['size'] = ($entry['cpqHoFileSysSpaceTotal'] * $storage['units']);

View File

@ -6,7 +6,7 @@ if (!is_array($storage_cache['hrstorage'])) {
d_echo($storage_cache);
}
$entry = $storage_cache['hrstorage'][$storage[storage_index]];
$entry = $storage_cache['hrstorage'][$storage['storage_index']];
$storage['units'] = $entry['hrStorageAllocationUnits'];
$entry['hrStorageUsed'] = fix_integer_value($entry['hrStorageUsed']);

View File

@ -27,7 +27,7 @@ if (!is_array($storage_cache['intelliflash-pl'])) {
d_echo($storage_cache);
}
//Tegile uses a high 32bit counter and a low 32bit counter to make a 64bit counter. Storage units are in bytes.
$entry = $storage_cache['intelliflash-pl'][$storage[storage_index]];
$entry = $storage_cache['intelliflash-pl'][$storage['storage_index']];
$storage['units'] = 1;
$storage['size'] = (($entry['poolSizeHigh'] << 32 ) + $entry['poolSizeLow']) * $storage['units'];
$storage['used'] = (($entry['poolUsedSizeHigh'] << 32 ) + $entry['poolUsedSizeLow']) * $storage['units'];

View File

@ -27,7 +27,7 @@ if (!is_array($storage_cache['intelliflash-pr'])) {
d_echo($storage_cache);
}
//Tegile uses a high 32bit counter and a low 32bit counter to make a 64bit counter. Storage units are in bytes.
$entry = $storage_cache['intelliflash-pr'][$storage[storage_index]];
$entry = $storage_cache['intelliflash-pr'][$storage['storage_index']];
$storage['units'] = 1;
$pdsh = ($entry['projectDataSizeHigh'] << 32 );
$pdsl = ($entry['projectDataSizeLow']);

View File

@ -5,7 +5,7 @@ if (!is_array($storage_cache['netapp-storage'])) {
d_echo($storage_cache);
}
$entry = $storage_cache['netapp-storage'][$storage[storage_index]];
$entry = $storage_cache['netapp-storage'][$storage['storage_index']];
$storage['units'] = 1024;
if (isset($entry['df64TotalKBytes']) && is_numeric($entry['df64TotalKBytes'])) {

View File

@ -26,7 +26,7 @@ if (!is_array($storage_cache['nimbleos'])) {
$storage_cache['nimbleos'] = snmpwalk_cache_oid($device, 'volEntry', null, 'NIMBLE-MIB');
d_echo($storage_cache);
}
$entry = $storage_cache['nimbleos'][$storage[storage_index]];
$entry = $storage_cache['nimbleos'][$storage['storage_index']];
$storage['units'] = 1024*1024;
//nimble uses a high 32bit counter and a low 32bit counter to make a 64bit counter
$storage['size'] = (($entry['volSizeHigh'] << 32 ) + $entry['volSizeLow']) * $storage['units'];

View File

@ -5,7 +5,7 @@ if (!is_array($storage_cache['dsk'])) {
d_echo($storage_cache);
}
$entry = $storage_cache['dsk'][$storage[storage_index]];
$entry = $storage_cache['dsk'][$storage['storage_index']];
$storage['units'] = 1024;
$storage['size'] = ($entry['dskTotal'] * $storage['units']);

View File

@ -1,6 +1,6 @@
<?php
/*
* LibreNMS
* LibreNMS
*
* Copyright (c) 2015 Vitali Kari <vitali.kari@gmail.com>
*
@ -28,11 +28,11 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
// some vendors like PBN dont follow the 802.1D implementation and use seconds in SNMP
if ($device['os'] == 'pbn') {
preg_match('/^.* Build (?<build>\d+)/', $device['version'], $version);
if ($version[build] <= 16607) { // Buggy version :-(
if ($version['build'] <= 16607) { // Buggy version :-(
$tm = '1';
}
}
// read the 802.1D subtree
$stp_raw = snmpwalk_cache_oid($device, 'dot1dStp', array(), 'RSTP-MIB');
d_echo($stp_raw);
@ -56,7 +56,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
// read the 802.1D bridge address and set as MAC in database
$mac_raw = snmp_get($device, 'dot1dBaseBridgeAddress.0', '-Oqv', 'RSTP-MIB');
// read Time as timetics (in hundredths of a seconds) since last topology change and convert to seconds
$time_since_change = snmp_get($device, 'dot1dStpTimeSinceTopologyChange.0', '-Ovt', 'RSTP-MIB');
if ($time_since_change > '100') {
@ -94,12 +94,12 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
if ($stp_db['designatedRoot'] != $stp['designatedRoot']) {
log_event('STP designated root changed: ' . $stp_db['designatedRoot'] . ' > ' . $stp['designatedRoot'], $device, 'stp', 4);
}
// Logging if designated root port changed since last db update
if (isset($stp['rootPort']) && $stp_db['rootPort'] != $stp['rootPort']) {
log_event('STP root port changed: ' . $stp_db['rootPort'] . ' > ' . $stp['rootPort'], $device, 'stp', 4);
}
// Logging if topology changed since last db update
if ($stp_db['timeSinceTopologyChange'] > $stp['timeSinceTopologyChange']) {
// FIXME log_event should log really changing time, not polling time
@ -129,17 +129,17 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
'designatedPort' => $stp_raw[$port]['dot1dStpPortDesignatedPort'],
'forwardTransitions' => $stp_raw[$port]['dot1dStpPortForwardTransitions']
);
// set device binding
$stp_port['device_id'] = $device['device_id'];
// set port binding
$stp_port['port_id'] = dbFetchCell('SELECT port_id FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $stp_raw[$port]['dot1dStpPort']));
$dr = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[$port]['dot1dStpPortDesignatedRoot']));
$dr = substr($dr, -12); //remove first two octets
$stp_port['designatedRoot'] = $dr;
$db = str_replace(array(' ', ':', '-'), '', strtolower($stp_raw[$port]['dot1dStpPortDesignatedBridge']));
$db = substr($db, -12); //remove first two octets
$stp_port['designatedBridge'] = $db;
@ -159,7 +159,7 @@ if ($stpprotocol == 'ieee8021d' || $stpprotocol == 'unknown') {
$dp = substr($stp_raw[$port]['dot1dStpPortDesignatedPort'], -2); //discard the first octet (priority part)
$stp_port['designatedPort'] = hexdec($dp);
}
//d_echo($stp_port);
// Update db

View File

@ -64,10 +64,10 @@ function CollectData($bill_id)
$last_counters = getLastPortCounter($port_id, $bill_id);
if ($last_counters['state'] == 'ok') {
$port_data['last_in_measurement'] = $last_counters[in_counter];
$port_data['last_in_delta'] = $last_counters[in_delta];
$port_data['last_out_measurement'] = $last_counters[out_counter];
$port_data['last_out_delta'] = $last_counters[out_delta];
$port_data['last_in_measurement'] = $last_counters['in_counter'];
$port_data['last_in_delta'] = $last_counters['in_delta'];
$port_data['last_out_measurement'] = $last_counters['out_counter'];
$port_data['last_out_delta'] = $last_counters['out_delta'];
$tmp_period = dbFetchCell("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('".mres($last_counters['timestamp'])."')");
@ -78,7 +78,7 @@ function CollectData($bill_id)
} else {
$port_data['in_delta'] = $port_data['last_in_delta'];
}
if ($port_data['ifSpeed'] > 0 && (delta_to_bits($port_data['out_measurement'], $tmp_period)-delta_to_bits($port_data['last_out_measurement'], $tmp_period)) > $port_data['ifSpeed']) {
$port_data['out_delta'] = $port_data['last_out_delta'];
} elseif ($port_data['out_measurement'] >= $port_data['last_out_measurement']) {
@ -105,11 +105,11 @@ function CollectData($bill_id)
$last_data = getLastMeasurement($bill_id);
if ($last_data[state] == 'ok') {
$prev_delta = $last_data[delta];
$prev_in_delta = $last_data[in_delta];
$prev_out_delta = $last_data[out_delta];
$prev_timestamp = $last_data[timestamp];
if ($last_data['state'] == 'ok') {
$prev_delta = $last_data['delta'];
$prev_in_delta = $last_data['in_delta'];
$prev_out_delta = $last_data['out_delta'];
$prev_timestamp = $last_data['timestamp'];
$period = dbFetchCell("SELECT UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) - UNIX_TIMESTAMP('".mres($prev_timestamp)."')");
} else {
$prev_delta = '0';

View File

@ -77,7 +77,7 @@ if (!$where) {
exit;
}
if (isset($options['d']) || isset($options['v'])) {
if (set_debug(isset($options['d'])) || isset($options['v'])) {
$versions = version_info();
echo <<<EOH
===================================
@ -96,18 +96,7 @@ EOH;
if (isset($options['v'])) {
$vdebug = true;
}
$debug = true;
update_os_cache(true); // Force update of OS Cache
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
} else {
$debug = false;
// ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
// ini_set('error_reporting', 0);
}
if (isset($options['r'])) {

View File

@ -9,14 +9,7 @@ $options = getopt('h:o:t:v:d::');
if ($options['h'] && $options['o'] && $options['t'] && $options['v']) {
$type = $options['t'];
$vendor = $options['v'];
if (isset($options['d'])) {
$debug = true;
$vdebug = true;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
}
set_debug(isset($options['d']));
$device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']);
$device = device_by_id_cache($device_id);

View File

@ -7,13 +7,8 @@ require __DIR__ . '/../includes/init.php';
$options = getopt('t:h:r:p:s:d::');
if ($options['r'] && $options['h']) {
if (isset($options['d'])) {
$debug = true;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
}
set_debug(isset($options['d']));
$rule_id = (int)$options['r'];
$device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']);
$where = "alerts.device_id = $device_id && alerts.rule_id = $rule_id";

View File

@ -7,13 +7,8 @@ require __DIR__ . '/../includes/init.php';
$options = getopt('t:h:r:p:s:d::');
if ($options['t'] && $options['h'] && $options['r']) {
if (isset($options['d'])) {
$debug = true;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
}
set_debug(isset($options['d']));
$template_id = $options['t'];
$device_id = ctype_digit($options['h']) ? $options['h'] : getidbyname($options['h']);
$rule_id = $options['r'];

View File

@ -13,14 +13,15 @@
chdir(__DIR__); // cwd to the directory containing this script
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', E_ALL);
$init_modules = array();
require __DIR__ . '/includes/init.php';
$options = getopt('d::');
if (set_debug(isset($options['d']))) {
echo "DEBUG!\n";
}
$entry = explode(',', $argv[1]);
logfile($argv[1]);