Remove Log::event (#14526)
* Remove Log::event Use the Eventlog class directly instead * wip * wip * wip * Apply fixes from StyleCI * Update Eventlog.php
This commit is contained in:
parent
0e9bb04071
commit
71d740770b
|
@ -31,6 +31,7 @@
|
|||
namespace LibreNMS\Alert;
|
||||
|
||||
use App\Facades\DeviceCache;
|
||||
use App\Models\Eventlog;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Enum\Alert;
|
||||
use LibreNMS\Enum\AlertState;
|
||||
|
@ -478,7 +479,7 @@ class RunAlerts
|
|||
|
||||
if ($this->isParentDown($alert['device_id'])) {
|
||||
$noiss = true;
|
||||
Log::event('Skipped alerts because all parent devices are down', $alert['device_id'], 'alert', 1);
|
||||
Eventlog::log('Skipped alerts because all parent devices are down', $alert['device_id'], 'alert', 1);
|
||||
}
|
||||
|
||||
if ($alert['state'] == AlertState::RECOVERED && $rextra['recovery'] == false) {
|
||||
|
@ -540,7 +541,7 @@ class RunAlerts
|
|||
$tmp = $instance->deliverAlert($obj, $item['opts'] ?? []);
|
||||
$this->alertLog($tmp, $obj, $obj['transport']);
|
||||
} catch (AlertTransportDeliveryException $e) {
|
||||
Log::event($e->getMessage(), $obj['device_id'], 'alert', Alert::ERROR);
|
||||
Eventlog::log($e->getMessage(), $obj['device_id'], 'alert', Alert::ERROR);
|
||||
$this->alertLog($e->getMessage(), $obj, $obj['transport']);
|
||||
} catch (\Exception $e) {
|
||||
$this->alertLog($e, $obj, $obj['transport']);
|
||||
|
@ -578,13 +579,13 @@ class RunAlerts
|
|||
|
||||
if ($result === true) {
|
||||
echo 'OK';
|
||||
Log::event('Issued ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "'", $obj['device_id'], 'alert', $severity);
|
||||
Eventlog::log('Issued ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "'", $obj['device_id'], 'alert', $severity);
|
||||
} elseif ($result === false) {
|
||||
echo 'ERROR';
|
||||
Log::event('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "'", $obj['device_id'], null, Alert::ERROR);
|
||||
Eventlog::log('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "'", $obj['device_id'], null, Alert::ERROR);
|
||||
} else {
|
||||
echo "ERROR: $result\r\n";
|
||||
Log::event('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "' Error: " . $result, $obj['device_id'], 'error', Alert::ERROR);
|
||||
Eventlog::log('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "' Error: " . $result, $obj['device_id'], 'error', Alert::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace LibreNMS;
|
|||
|
||||
use App\Models\ComponentPref;
|
||||
use App\Models\ComponentStatusLog;
|
||||
use App\Models\Eventlog;
|
||||
use Illuminate\Support\Arr;
|
||||
use Log;
|
||||
|
||||
|
@ -241,7 +242,7 @@ class Component
|
|||
}
|
||||
$component->save();
|
||||
|
||||
Log::event($message, $component->device_id, 'component', 3, $component->id);
|
||||
Eventlog::log($message, $component->device_id, 'component', 3, $component->id);
|
||||
}
|
||||
|
||||
// update preferences
|
||||
|
@ -257,18 +258,18 @@ class Component
|
|||
$invalid->forget($existing->id);
|
||||
$existing->fill(['value' => $value]);
|
||||
if ($existing->isDirty()) {
|
||||
Log::event("Component: $component->type($component->id). Attribute: $attribute, was modified from: " . $existing->getOriginal('value') . ", to: $value", $device_id, 'component', 3, $component->id);
|
||||
Eventlog::log("Component: $component->type($component->id). Attribute: $attribute, was modified from: " . $existing->getOriginal('value') . ", to: $value", $device_id, 'component', 3, $component->id);
|
||||
$existing->save();
|
||||
}
|
||||
} else {
|
||||
$component->prefs()->save(new ComponentPref(['attribute' => $attribute, 'value' => $value]));
|
||||
Log::event("Component: $component->type($component->id). Attribute: $attribute, was added with value: $value", $component->device_id, 'component', 3, $component->id);
|
||||
Eventlog::log("Component: $component->type($component->id). Attribute: $attribute, was added with value: $value", $component->device_id, 'component', 3, $component->id);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($invalid as $pref) {
|
||||
$pref->delete();
|
||||
Log::event("Component: $component->type($component->id). Attribute: $pref->attribute, was deleted.", $component->device_id, 'component', 4);
|
||||
Eventlog::log("Component: $component->type($component->id). Attribute: $pref->attribute, was deleted.", $component->device_id, 'component', 4);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
namespace LibreNMS\Data\Source;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Eventlog;
|
||||
use App\Polling\Measure\Measurement;
|
||||
use DeviceCache;
|
||||
use Illuminate\Support\Arr;
|
||||
|
@ -471,9 +472,9 @@ class NetSnmpQuery implements SnmpQueryInterface
|
|||
{
|
||||
if ($code) {
|
||||
if (Str::startsWith($error, 'Invalid authentication protocol specified')) {
|
||||
Log::event('Unsupported SNMP authentication algorithm - ' . $code, $this->device, 'poller', Alert::ERROR);
|
||||
Eventlog::log('Unsupported SNMP authentication algorithm - ' . $code, $this->device, 'poller', Alert::ERROR);
|
||||
} elseif (Str::startsWith($error, 'Invalid privacy protocol specified')) {
|
||||
Log::event('Unsupported SNMP privacy algorithm - ' . $code, $this->device, 'poller', Alert::ERROR);
|
||||
Eventlog::log('Unsupported SNMP privacy algorithm - ' . $code, $this->device, 'poller', Alert::ERROR);
|
||||
}
|
||||
Log::debug('Exitcode: ' . $code, [$error]);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
namespace LibreNMS\Modules;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Eventlog;
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Interfaces\Module;
|
||||
|
@ -60,7 +61,7 @@ class Core implements Module
|
|||
]);
|
||||
|
||||
foreach ($device->getDirty() as $attribute => $value) {
|
||||
Log::event($value . ' -> ' . $device->$attribute, $device, 'system', 3);
|
||||
Eventlog::log($value . ' -> ' . $device->$attribute, $device, 'system', 3);
|
||||
$os->getDeviceArray()[$attribute] = $value; // update device array
|
||||
}
|
||||
|
||||
|
@ -68,7 +69,7 @@ class Core implements Module
|
|||
$device->os = self::detectOS($device, false);
|
||||
|
||||
if ($device->isDirty('os')) {
|
||||
Log::event('Device OS changed: ' . $device->getOriginal('os') . ' -> ' . $device->os, $device, 'system', 3);
|
||||
Eventlog::log('Device OS changed: ' . $device->getOriginal('os') . ' -> ' . $device->os, $device, 'system', 3);
|
||||
$os->getDeviceArray()['os'] = $device->os;
|
||||
|
||||
echo 'Changed ';
|
||||
|
@ -271,7 +272,7 @@ class Core implements Module
|
|||
// set it if unless it is wrong
|
||||
if ($uptime > 0) {
|
||||
if ($uptime < $device->uptime) {
|
||||
Log::event('Device rebooted after ' . Time::formatInterval($device->uptime) . " -> {$uptime}s", $device, 'reboot', 4, $device->uptime);
|
||||
Eventlog::log('Device rebooted after ' . Time::formatInterval($device->uptime) . " -> {$uptime}s", $device, 'reboot', 4, $device->uptime);
|
||||
if (Config::get('discovery_on_reboot')) {
|
||||
$device->last_discovered = null;
|
||||
$device->save();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
namespace LibreNMS\Modules;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Eventlog;
|
||||
use App\Models\PrinterSupply;
|
||||
use App\Observers\ModuleModelObserver;
|
||||
use Illuminate\Support\Collection;
|
||||
|
@ -94,7 +95,7 @@ class PrinterSupplies implements Module
|
|||
|
||||
// Log empty supplies (but only once)
|
||||
if ($tonerperc == 0 && $toner['supply_current'] > 0) {
|
||||
Log::event(
|
||||
Eventlog::log(
|
||||
'Toner ' . $toner['supply_descr'] . ' is empty',
|
||||
$os->getDevice(),
|
||||
'toner',
|
||||
|
@ -105,7 +106,7 @@ class PrinterSupplies implements Module
|
|||
|
||||
// Log toner swap
|
||||
if ($tonerperc > $toner['supply_current']) {
|
||||
Log::event(
|
||||
Eventlog::log(
|
||||
'Toner ' . $toner['supply_descr'] . ' was replaced (new level: ' . $tonerperc . '%)',
|
||||
$os->getDevice(),
|
||||
'toner',
|
||||
|
|
|
@ -25,10 +25,10 @@
|
|||
|
||||
namespace LibreNMS\OS;
|
||||
|
||||
use App\Models\Eventlog;
|
||||
use App\Models\TnmsneInfo;
|
||||
use App\Observers\ModuleModelObserver;
|
||||
use LibreNMS\Interfaces\Polling\OSPolling;
|
||||
use Log;
|
||||
|
||||
class Coriant extends \LibreNMS\OS implements OSPolling
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ class Coriant extends \LibreNMS\OS implements OSPolling
|
|||
|
||||
if ($ne->isDirty()) {
|
||||
$ne->save();
|
||||
Log::event("Coriant enmsNETable Hardware $ne->neType : $ne->neName ($index) at $ne->neLocation Discovered", $this->getDevice(), 'system', 2);
|
||||
Eventlog::log("Coriant enmsNETable Hardware $ne->neType : $ne->neName ($index) at $ne->neLocation Discovered", $this->getDevice(), 'system', 2);
|
||||
}
|
||||
$c_list[] = $index;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class Coriant extends \LibreNMS\OS implements OSPolling
|
|||
foreach (TnmsneInfo::where('device_id', $this->getDeviceId())->whereNotIn('neID', $c_list)->get() as $ne) {
|
||||
/** @var TnmsneInfo $ne */
|
||||
$ne->delete();
|
||||
Log::event("Coriant enmsNETable Hardware $ne->neName at $ne->neLocation Removed", $this->getDevice(), 'system', $ne->neID);
|
||||
Eventlog::log("Coriant enmsNETable Hardware $ne->neName at $ne->neLocation Removed", $this->getDevice(), 'system', $ne->neID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ class Poller
|
|||
|
||||
// check if the poll took too long and log an event
|
||||
if ($measurement->getDuration() > Config::get('rrd.step')) {
|
||||
\Log::event('Polling took longer than ' . round(Config::get('rrd.step') / 60, 2) .
|
||||
\App\Models\Eventlog::log('Polling took longer than ' . round(Config::get('rrd.step') / 60, 2) .
|
||||
' minutes! This will cause gaps in graphs.', $this->device, 'system', 5);
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ class Poller
|
|||
} catch (Throwable $e) {
|
||||
// isolate module exceptions so they don't disrupt the polling process
|
||||
$this->logger->error("%rError polling $module module for {$this->device->hostname}.%n $e", ['color' => true]);
|
||||
\Log::event("Error polling $module module. Check log file for more details.", $this->device, 'poller', Alert::ERROR);
|
||||
\App\Models\Eventlog::log("Error polling $module module. Check log file for more details.", $this->device, 'poller', Alert::ERROR);
|
||||
report($e);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,11 +27,11 @@ namespace LibreNMS\Polling;
|
|||
|
||||
use App\Models\Device;
|
||||
use App\Models\DeviceOutage;
|
||||
use App\Models\Eventlog;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Data\Source\Fping;
|
||||
use LibreNMS\Data\Source\FpingResponse;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use Log;
|
||||
use SnmpQuery;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
|
@ -124,7 +124,7 @@ class ConnectivityHelper
|
|||
);
|
||||
|
||||
if ($status->duplicates > 0) {
|
||||
Log::event('Duplicate ICMP response detected! This could indicate a network issue.', $this->device, 'icmp', 4);
|
||||
Eventlog::log('Duplicate ICMP response detected! This could indicate a network issue.', $this->device, 'icmp', 4);
|
||||
$status->exit_code = 0; // when duplicate is detected fping returns 1. The device is up, but there is another issue. Clue admins in with above event.
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
namespace LibreNMS\Snmptrap;
|
||||
|
||||
use App\Models\Eventlog;
|
||||
use LibreNMS\Alert\AlertRules;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Snmptrap\Handlers\Fallback;
|
||||
|
@ -47,7 +48,7 @@ class Dispatcher
|
|||
// Even the TrapOid is not properly converted to text, so snmptrapd is probably not
|
||||
// configured with any MIBs (-M and/or -m).
|
||||
// LibreNMS snmptraps code cannot process received data. Let's inform the user.
|
||||
Log::event('Misconfigured MIBS or MIBDIRS for snmptrapd, check https://docs.librenms.org/Extensions/SNMP-Trap-Handler/ : ' . $trap->raw, $trap->getDevice(), 'system');
|
||||
Eventlog::log('Misconfigured MIBS or MIBDIRS for snmptrapd, check https://docs.librenms.org/Extensions/SNMP-Trap-Handler/ : ' . $trap->raw, $trap->getDevice(), 'system');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
namespace LibreNMS\Snmptrap;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Eventlog;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Enum\Alert;
|
||||
|
@ -129,6 +130,6 @@ class Trap
|
|||
*/
|
||||
public function log(string $message, int $severity = Alert::INFO, string $type = 'trap', int|null|string $reference = null): void
|
||||
{
|
||||
\Log::event($message, $this->getDevice(), $type, $severity, $reference);
|
||||
Eventlog::log($message, $this->getDevice(), $type, $severity, $reference);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Log.php
|
||||
*
|
||||
* Extending the built in logging to add an event logger function
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @link https://www.librenms.org
|
||||
*
|
||||
* @copyright 2019 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use LibreNMS\Enum\Alert;
|
||||
|
||||
class LogManager extends \Illuminate\Log\LogManager
|
||||
{
|
||||
/**
|
||||
* Log events to the event table
|
||||
*
|
||||
* @param string $text message describing the event
|
||||
* @param \App\Models\Device|int $device device array or device_id
|
||||
* @param string $type brief category for this event. Examples: sensor, state, stp, system, temperature, interface
|
||||
* @param int $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown
|
||||
* @param int|string|null $reference the id of the referenced entity. Supported types: interface, bgpPeer
|
||||
*/
|
||||
public function event($text, $device = null, $type = null, $severity = Alert::INFO, $reference = null)
|
||||
{
|
||||
(new \App\Models\Eventlog([
|
||||
'device_id' => $device instanceof \App\Models\Device ? $device->device_id : $device,
|
||||
'reference' => $reference,
|
||||
'type' => $type,
|
||||
'datetime' => \Carbon\Carbon::now(),
|
||||
'severity' => $severity,
|
||||
'message' => $text,
|
||||
'username' => Auth::user() ? Auth::user()->username : '',
|
||||
]))->save();
|
||||
}
|
||||
}
|
|
@ -3,9 +3,9 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Alert;
|
||||
use App\Models\Eventlog;
|
||||
use Illuminate\Http\Request;
|
||||
use LibreNMS\Config;
|
||||
use Log;
|
||||
|
||||
class AlertController extends Controller
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ class AlertController extends Controller
|
|||
if ($alert->save()) {
|
||||
if (in_array($state, [2, 22])) {
|
||||
$rule_name = $alert->rule->name;
|
||||
Log::event("$username acknowledged alert $rule_name note: $ack_msg", $alert->device_id, 'alert', 2, $alert->id);
|
||||
Eventlog::log("$username acknowledged alert $rule_name note: $ack_msg", $alert->device_id, 'alert', 2, $alert->id);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\Eventlog;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
@ -38,7 +39,6 @@ use LibreNMS\Alert\AlertRules;
|
|||
use LibreNMS\Config;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use LibreNMS\Util\Debug;
|
||||
use Log;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class PingCheck implements ShouldQueue
|
||||
|
@ -254,7 +254,7 @@ class PingCheck implements ShouldQueue
|
|||
// if changed, update reason
|
||||
$device->status_reason = $device->status ? '' : 'icmp';
|
||||
$type = $device->status ? 'up' : 'down';
|
||||
Log::event('Device status changed to ' . ucfirst($type) . ' from icmp check.', $device->device_id, $type);
|
||||
Eventlog::log('Device status changed to ' . ucfirst($type) . ' from icmp check.', $device->device_id, $type);
|
||||
}
|
||||
|
||||
$device->save(); // only saves if needed (which is every time because of last_ping)
|
||||
|
|
|
@ -38,17 +38,33 @@ class Eventlog extends DeviceRelatedModel
|
|||
protected $fillable = ['datetime', 'device_id', 'message', 'type', 'reference', 'username', 'severity'];
|
||||
|
||||
// ---- Helper Functions ----
|
||||
/**
|
||||
* This is used to be able to mock _log()
|
||||
*
|
||||
* @see _log()
|
||||
*
|
||||
* @param string $text message describing the event
|
||||
* @param Device|int|null $device related device
|
||||
* @param string $type brief category for this event. Examples: sensor, state, stp, system, temperature, interface
|
||||
* @param int $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown
|
||||
* @param int|string|null $reference the id of the referenced entity. Supported types: interface
|
||||
*/
|
||||
public static function log($text, $device = null, $type = null, $severity = Alert::INFO, $reference = null): void
|
||||
{
|
||||
$model = app()->make(Eventlog::class);
|
||||
$model->_log($text, $device, $type, $severity, $reference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log events to the event table
|
||||
*
|
||||
* @param string $text message describing the event
|
||||
* @param Device $device related device
|
||||
* @param string $type brief category for this event. Examples: sensor, state, stp, system, temperature, interface
|
||||
* @param int $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown
|
||||
* @param int $reference the id of the referenced entity. Supported types: interface
|
||||
* @param string $text
|
||||
* @param Device|int|null $device
|
||||
* @param string $type
|
||||
* @param int $severity
|
||||
* @param int|string|null $reference
|
||||
*/
|
||||
public static function log($text, $device = null, $type = null, $severity = Alert::INFO, $reference = null)
|
||||
public function _log($text, $device = null, $type = null, $severity = Alert::INFO, $reference = null): void
|
||||
{
|
||||
$log = new static([
|
||||
'reference' => $reference,
|
||||
|
@ -59,6 +75,10 @@ class Eventlog extends DeviceRelatedModel
|
|||
'username' => (class_exists('\Auth') && Auth::check()) ? Auth::user()->username : '',
|
||||
]);
|
||||
|
||||
if (is_numeric($device)) {
|
||||
$log->device_id = $device;
|
||||
}
|
||||
|
||||
if ($device instanceof Device) {
|
||||
$device->eventlogs()->save($log);
|
||||
} else {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace App\Observers;
|
|||
use App;
|
||||
use App\ApiClients\Oxidized;
|
||||
use App\Models\Device;
|
||||
use App\Models\Eventlog;
|
||||
use File;
|
||||
use Log;
|
||||
|
||||
|
@ -18,7 +19,7 @@ class DeviceObserver
|
|||
*/
|
||||
public function created(Device $device): void
|
||||
{
|
||||
Log::event("Device $device->hostname has been created", $device, 'system', 3);
|
||||
Eventlog::log("Device $device->hostname has been created", $device, 'system', 3);
|
||||
(new Oxidized)->reloadNodes();
|
||||
}
|
||||
|
||||
|
@ -39,17 +40,17 @@ class DeviceObserver
|
|||
if ($device->isDirty(['status', 'status_reason'])) {
|
||||
$type = $device->status ? 'up' : 'down';
|
||||
$reason = $device->status ? $device->getOriginal('status_reason') : $device->status_reason;
|
||||
Log::event('Device status changed to ' . ucfirst($type) . " from $reason check.", $device, $type);
|
||||
Eventlog::log('Device status changed to ' . ucfirst($type) . " from $reason check.", $device, $type);
|
||||
}
|
||||
|
||||
// key attribute changes
|
||||
foreach (['os', 'sysName', 'version', 'hardware', 'features', 'serial', 'icon', 'type', 'ip'] as $attribute) {
|
||||
if ($device->isDirty($attribute)) {
|
||||
Log::event(self::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)), $device, 'system', 3);
|
||||
Eventlog::log(self::attributeChangedMessage($attribute, $device->$attribute, $device->getOriginal($attribute)), $device, 'system', 3);
|
||||
}
|
||||
}
|
||||
if ($device->isDirty('location_id')) {
|
||||
Log::event(self::attributeChangedMessage('location', (string) $device->location, null), $device, 'system', 3);
|
||||
Eventlog::log(self::attributeChangedMessage('location', (string) $device->location, null), $device, 'system', 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,7 @@ class DeviceObserver
|
|||
Log::error("Could not delete RRD files for: $device->hostname", [$e]);
|
||||
}
|
||||
|
||||
Log::event("Device $device->hostname has been removed", 0, 'system', 3);
|
||||
Eventlog::log("Device $device->hostname has been removed", 0, 'system', 3);
|
||||
|
||||
(new Oxidized)->reloadNodes();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Eventlog;
|
||||
use App\Models\Package;
|
||||
use Log;
|
||||
|
||||
|
@ -15,7 +16,7 @@ class PackageObserver
|
|||
*/
|
||||
public function created(Package $package)
|
||||
{
|
||||
Log::event('Package installed: ' . $package, $package->device_id, 'package', 3);
|
||||
Eventlog::log('Package installed: ' . $package, $package->device_id, 'package', 3);
|
||||
Log::info("+ $package");
|
||||
}
|
||||
|
||||
|
@ -29,7 +30,7 @@ class PackageObserver
|
|||
{
|
||||
if ($package->getOriginal('version') !== $package->version || $package->getOriginal('build') !== $package->build) {
|
||||
$message = $package . ' from ' . $package->getOriginal('version') . ($package->getOriginal('build') ? '-' . $package->getOriginal('build') : '');
|
||||
Log::event('Package updated: ' . $message, $package->device_id, 'package', 3);
|
||||
Eventlog::log('Package updated: ' . $message, $package->device_id, 'package', 3);
|
||||
Log::info("u $message");
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +43,7 @@ class PackageObserver
|
|||
*/
|
||||
public function deleted(Package $package)
|
||||
{
|
||||
Log::event('Package removed: ' . $package, $package->device_id, 'package', 3);
|
||||
Eventlog::log('Package removed: ' . $package, $package->device_id, 'package', 3);
|
||||
Log::info("- $package");
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Eventlog;
|
||||
use App\Models\Stp;
|
||||
use Log;
|
||||
|
||||
class StpObserver
|
||||
{
|
||||
|
@ -16,16 +16,16 @@ class StpObserver
|
|||
public function updating(Stp $stp)
|
||||
{
|
||||
if ($stp->isDirty('designatedRoot')) {
|
||||
Log::event('STP designated root changed: ' . $stp->getOriginal('designatedRoot') . ' > ' . $stp->designatedRoot, $stp->device_id, 'stp', 4);
|
||||
Eventlog::log('STP designated root changed: ' . $stp->getOriginal('designatedRoot') . ' > ' . $stp->designatedRoot, $stp->device_id, 'stp', 4);
|
||||
}
|
||||
|
||||
if ($stp->isDirty('rootPort')) {
|
||||
Log::event('STP root port changed: ' . $stp->getOriginal('rootPort') . ' > ' . $stp->rootPort, $stp->device_id, 'stp', 4);
|
||||
Eventlog::log('STP root port changed: ' . $stp->getOriginal('rootPort') . ' > ' . $stp->rootPort, $stp->device_id, 'stp', 4);
|
||||
}
|
||||
|
||||
if ($stp->isDirty('rootPort')) {
|
||||
$time = \LibreNMS\Util\Time::formatInterval($stp->timeSinceTopologyChange);
|
||||
Log::event('STP topology changed after: ' . $time, $stp->device_id, 'stp', 4);
|
||||
Eventlog::log('STP topology changed after: ' . $time, $stp->device_id, 'stp', 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,10 +105,6 @@ class AppServiceProvider extends ServiceProvider
|
|||
|
||||
private function registerFacades()
|
||||
{
|
||||
// replace log manager so we can add the event function
|
||||
$this->app->singleton('log', function ($app) {
|
||||
return new \App\Facades\LogManager($app);
|
||||
});
|
||||
}
|
||||
|
||||
private function registerGeocoder()
|
||||
|
|
|
@ -65,7 +65,7 @@ foreach (dbFetchRows($sql, $params) as $service) {
|
|||
if (! $service['service_disabled']) {
|
||||
d_echo("\nService check - " . $service['service_id'] . "\nSkipping service check because device "
|
||||
. $service['hostname'] . " is down due to icmp.\n");
|
||||
Log::event(
|
||||
\App\Models\Eventlog::log(
|
||||
"Service check - {$service['service_desc']} ({$service['service_id']}) -
|
||||
Skipping service check because device {$service['hostname']} is down due to icmp",
|
||||
$service['device_id'],
|
||||
|
|
|
@ -72,9 +72,9 @@ function external_exec($command)
|
|||
|
||||
if ($proc->getExitCode()) {
|
||||
if (Str::startsWith($proc->getErrorOutput(), 'Invalid authentication protocol specified')) {
|
||||
Log::event('Unsupported SNMP authentication algorithm - ' . $proc->getExitCode(), optional($device)->device_id, 'poller', Alert::ERROR);
|
||||
\App\Models\Eventlog::log('Unsupported SNMP authentication algorithm - ' . $proc->getExitCode(), optional($device)->device_id, 'poller', Alert::ERROR);
|
||||
} elseif (Str::startsWith($proc->getErrorOutput(), 'Invalid privacy protocol specified')) {
|
||||
Log::event('Unsupported SNMP privacy algorithm - ' . $proc->getExitCode(), optional($device)->device_id, 'poller', Alert::ERROR);
|
||||
\App\Models\Eventlog::log('Unsupported SNMP privacy algorithm - ' . $proc->getExitCode(), optional($device)->device_id, 'poller', Alert::ERROR);
|
||||
}
|
||||
d_echo('Exitcode: ' . $proc->getExitCode());
|
||||
d_echo($proc->getErrorOutput());
|
||||
|
|
|
@ -154,7 +154,7 @@ function discover_device(&$device, $force_module = false)
|
|||
} catch (Throwable $e) {
|
||||
// isolate module exceptions so they don't disrupt the polling process
|
||||
Log::error("%rError discovering $module module for {$device['hostname']}.%n $e", ['color' => true]);
|
||||
Log::event("Error discovering $module module. Check log file for more details.", $device['device_id'], 'discovery', Alert::ERROR);
|
||||
\App\Models\Eventlog::log("Error discovering $module module. Check log file for more details.", $device['device_id'], 'discovery', Alert::ERROR);
|
||||
report($e);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,12 +68,12 @@ if ($vlanversion == 'version1' || $vlanversion == '2') {
|
|||
|
||||
//vlan does not exist
|
||||
if (! $vlanDB->exists) {
|
||||
Log::event("Vlan added: $vlan_id with name $vlan_name ", $device['device_id'], 'vlan', 4);
|
||||
\App\Models\Eventlog::log("Vlan added: $vlan_id with name $vlan_name ", $device['device_id'], 'vlan', 4);
|
||||
}
|
||||
|
||||
if ($vlanDB->vlan_name != $vlan_name) {
|
||||
$vlanDB->vlan_name = $vlan_name;
|
||||
Log::event("Vlan changed: $vlan_id new name $vlan_name", $device['device_id'], 'vlan', 4);
|
||||
\App\Models\Eventlog::log("Vlan changed: $vlan_id new name $vlan_name", $device['device_id'], 'vlan', 4);
|
||||
}
|
||||
|
||||
$vlanDB->save();
|
||||
|
|
|
@ -59,11 +59,11 @@ if (isset($sIndex)) {
|
|||
]);
|
||||
|
||||
if ($vlan->isDirty('vlan_name')) {
|
||||
Log::event("Vlan id: $vId changed name to: $vName from " . $vlan->getOriginal('vlan_name'), $device['device_id'], 'vlan', 4);
|
||||
\App\Models\Eventlog::log("Vlan id: $vId changed name to: $vName from " . $vlan->getOriginal('vlan_name'), $device['device_id'], 'vlan', 4);
|
||||
}
|
||||
|
||||
if (! $vlan->exists) {
|
||||
Log::event("Vlan id: $vId: $vName added", $device['device_id'], 'vlan', 4);
|
||||
\App\Models\Eventlog::log("Vlan id: $vId: $vName added", $device['device_id'], 'vlan', 4);
|
||||
}
|
||||
|
||||
$vlan->save();
|
||||
|
|
|
@ -520,7 +520,7 @@ function log_event($text, $device = null, $type = null, $severity = 2, $referenc
|
|||
$device = $device['device_id'];
|
||||
}
|
||||
|
||||
Log::event($text, $device, $type, $severity, $reference);
|
||||
\App\Models\Eventlog::log($text, $device, $type, $severity, $reference);
|
||||
}
|
||||
|
||||
// Parse string with emails. Return array with email (as key) and name (as value)
|
||||
|
|
|
@ -27,10 +27,10 @@ if ($port) {
|
|||
if ($port->save()) {
|
||||
if (empty($speed)) {
|
||||
$port->device->forgetAttrib('ifSpeed:' . $port->ifName);
|
||||
Log::event("{$port->ifName} Port speed cleared manually", $port->device, 'interface', 3, $port_id);
|
||||
\App\Models\Eventlog::log("{$port->ifName} Port speed cleared manually", $port->device, 'interface', 3, $port_id);
|
||||
} else {
|
||||
$port->device->setAttrib('ifSpeed:' . $port->ifName, 1);
|
||||
Log::event("{$port->ifName} Port speed set manually: $speed", $port->device, 'interface', 3, $port_id);
|
||||
\App\Models\Eventlog::log("{$port->ifName} Port speed set manually: $speed", $port->device, 'interface', 3, $port_id);
|
||||
$port_tune = $port->device->getAttrib('ifName_tune:' . $port->ifName);
|
||||
$device_tune = $port->device->getAttrib('override_rrdtool_tune');
|
||||
if ($port_tune == 'true' ||
|
||||
|
|
|
@ -341,7 +341,7 @@ function poll_device($device, $force_module = false)
|
|||
} catch (Throwable $e) {
|
||||
// isolate module exceptions so they don't disrupt the polling process
|
||||
Log::error("%rError polling $module module for {$device['hostname']}.%n $e", ['color' => true]);
|
||||
Log::event("Error polling $module module. Check log file for more details.", $device['device_id'], 'poller', Alert::ERROR);
|
||||
\App\Models\Eventlog::log("Error polling $module module. Check log file for more details.", $device['device_id'], 'poller', Alert::ERROR);
|
||||
report($e);
|
||||
}
|
||||
|
||||
|
@ -509,7 +509,7 @@ function update_application($app, $response, $metrics = [], $status = '')
|
|||
$event_msg = 'has UNKNOWN state';
|
||||
break;
|
||||
}
|
||||
Log::event('Application ' . $app->displayName() . ' ' . $event_msg, DeviceCache::getPrimary(), 'application', $severity);
|
||||
\App\Models\Eventlog::log('Application ' . $app->displayName() . ' ' . $event_msg, DeviceCache::getPrimary(), 'application', $severity);
|
||||
}
|
||||
|
||||
$app->save();
|
||||
|
|
|
@ -6260,11 +6260,6 @@ parameters:
|
|||
count: 1
|
||||
path: app/Exceptions/Handler.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Facades\\\\LogManager\\:\\:event\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: app/Facades/LogManager.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Http\\\\Controllers\\\\AboutController\\:\\:index\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
|
@ -8005,11 +8000,6 @@ parameters:
|
|||
count: 1
|
||||
path: app/Models/DeviceRelatedModel.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Models\\\\Eventlog\\:\\:log\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: app/Models/Eventlog.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Models\\\\IsisAdjacency\\:\\:device\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
|
|
|
@ -89,7 +89,7 @@ class OSModulesTest extends DBTestCase
|
|||
public function testOS($os, $variant, $modules)
|
||||
{
|
||||
$this->requireSnmpsim(); // require snmpsim for tests
|
||||
// stub out Log::event and Fping->ping, we don't need to store them for these tests
|
||||
// stub out Eventlog::log and Fping->ping, we don't need to store them for these tests
|
||||
$this->stubClasses();
|
||||
|
||||
try {
|
||||
|
@ -165,15 +165,15 @@ class OSModulesTest extends DBTestCase
|
|||
|
||||
private function stubClasses(): void
|
||||
{
|
||||
$this->app->bind('log', function ($app) {
|
||||
$mock = \Mockery::mock('\App\Facades\LogManager[event]', [$app]);
|
||||
$mock->shouldReceive('event');
|
||||
$this->app->bind(\App\Models\Eventlog::class, function ($app) {
|
||||
$mock = \Mockery::mock(\App\Models\Eventlog::class);
|
||||
$mock->shouldReceive('_log');
|
||||
|
||||
return $mock;
|
||||
});
|
||||
|
||||
$this->app->bind(Fping::class, function ($app) {
|
||||
$mock = \Mockery::mock('\LibreNMS\Data\Source\Fping');
|
||||
$mock = \Mockery::mock(\LibreNMS\Data\Source\Fping::class);
|
||||
$mock->shouldReceive('ping')->andReturn(FpingResponse::artificialUp());
|
||||
|
||||
return $mock;
|
||||
|
|
Loading…
Reference in New Issue