diff --git a/LibreNMS/Component.php b/LibreNMS/Component.php index f90710cfe9..d8d3b9cd65 100644 --- a/LibreNMS/Component.php +++ b/LibreNMS/Component.php @@ -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. diff --git a/LibreNMS/Device/Sensor.php b/LibreNMS/Device/Sensor.php index 7b12e3e252..20b42b5f8a 100644 --- a/LibreNMS/Device/Sensor.php +++ b/LibreNMS/Device/Sensor.php @@ -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 diff --git a/LibreNMS/Util/CliColorFormatter.php b/LibreNMS/Util/CliColorFormatter.php new file mode 100644 index 0000000000..35be8f553d --- /dev/null +++ b/LibreNMS/Util/CliColorFormatter.php @@ -0,0 +1,58 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2018 Tony Murray + * @author Tony Murray + */ + +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); + } +} diff --git a/LibreNMS/Util/FileLock.php b/LibreNMS/Util/FileLock.php index 3ab083d2ca..e27ca7c553 100644 --- a/LibreNMS/Util/FileLock.php +++ b/LibreNMS/Util/FileLock.php @@ -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); } diff --git a/alerts.php b/alerts.php index c3a8038e88..09b519a46a 100755 --- a/alerts.php +++ b/alerts.php @@ -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') { diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 4f7215c84d..87d54a9019 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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) diff --git a/check-services.php b/check-services.php index 0270b6c6aa..9d6d92b3f7 100755 --- a/check-services.php +++ b/check-services.php @@ -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'])) { diff --git a/discovery.php b/discovery.php index c418df14d9..3dc497e7b2 100755 --- a/discovery.php +++ b/discovery.php @@ -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 << '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 diff --git a/html/includes/print-accesspoint.inc.php b/html/includes/print-accesspoint.inc.php index d1149113d4..b3e3e884a2 100644 --- a/html/includes/print-accesspoint.inc.php +++ b/html/includes/print-accesspoint.inc.php @@ -37,9 +37,9 @@ echo "
\n"; echo ''; -echo " ".format_bi($ap[numasoclients]).' Clients
'; -echo " ".format_bi($ap[radioutil]).' % busy
'; -echo " ".format_bi($ap[interference]).' interference index
'; +echo " ".format_bi($ap['numasoclients']).' Clients
'; +echo " ".format_bi($ap['radioutil']).' % busy
'; +echo " ".format_bi($ap['interference']).' interference index
'; echo ''; diff --git a/html/includes/print-debug.php b/html/includes/print-debug.php deleted file mode 100644 index 7fdbbcc6d9..0000000000 --- a/html/includes/print-debug.php +++ /dev/null @@ -1,86 +0,0 @@ - - - - - diff --git a/html/includes/print-interface.inc.php b/html/includes/print-interface.inc.php index 7060ffcb92..3bc43c3e52 100644 --- a/html/includes/print-interface.inc.php +++ b/html/includes/print-interface.inc.php @@ -103,7 +103,7 @@ if ($port['ifSpeed']) { echo '
'; -if ($port[ifDuplex] != 'unknown') { +if ($port['ifDuplex'] != 'unknown') { echo ''.$port['ifDuplex'].''; } else { echo '-'; diff --git a/html/includes/table/address-search.inc.php b/html/includes/table/address-search.inc.php index c77be68467..1697468eee 100644 --- a/html/includes/table/address-search.inc.php +++ b/html/includes/table/address-search.inc.php @@ -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, "", errors); + $error_img = generate_port_link($interface, "", 'errors'); } else { $error_img = ''; } diff --git a/html/legacy_index.php b/html/legacy_index.php index 8956dee99f..d373a6fafa 100644 --- a/html/legacy_index.php +++ b/html/legacy_index.php @@ -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(""); } -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('