mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Eventlog updates (#9633)
* Eventlog updates remove host from eventlog table, retain in api allow most fields nullable * updated schema * revert auth for legacy log_event function safer check in the model * add function modifiers
This commit is contained in:
@@ -487,7 +487,7 @@ class Device extends BaseModel
|
||||
|
||||
public function eventlogs()
|
||||
{
|
||||
return $this->hasMany('App\Models\General\Eventlog', 'host', 'device_id');
|
||||
return $this->hasMany('App\Models\Eventlog', 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function groups()
|
||||
|
||||
@@ -25,11 +25,43 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Eventlog extends BaseModel
|
||||
{
|
||||
protected $table = 'eventlog';
|
||||
protected $primaryKey = 'event_id';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['datetime', 'message', 'type', 'reference', 'username', 'severity'];
|
||||
|
||||
// ---- Helper Functions ----
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static function log($text, $device = null, $type = null, $severity = 2, $reference = null)
|
||||
{
|
||||
$log = new static([
|
||||
'reference' => $reference,
|
||||
'type' => $type,
|
||||
'datetime' => Carbon::now(),
|
||||
'severity' => $severity,
|
||||
'message' => $text,
|
||||
'username' => (class_exists('\Auth') && \Auth::check()) ? \Auth::user()->username : '',
|
||||
]);
|
||||
|
||||
if ($device instanceof Device) {
|
||||
$device->eventlogs()->save($log);
|
||||
} else {
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Query scopes ----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user