mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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` After you are done testing, you can remove the changes with `./scripts/github-remove`. If there are schema changes, you can ask on discord how to revert. In #9252 search box and inside device eventlog where broken. Noticed in https://community.librenms.org/t/bug-set-filter-in-device-eventlog-shows-filtered-events-from-all-devices/5633 I hope my fix does the job :)
124 lines
3.7 KiB
PHP
124 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* EventlogController.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 App\Http\Controllers\Table;
|
|
|
|
use App\Models\Eventlog;
|
|
use Carbon\Carbon;
|
|
use LibreNMS\Config;
|
|
use LibreNMS\Util\Url;
|
|
|
|
class EventlogController extends TableController
|
|
{
|
|
public function rules()
|
|
{
|
|
return [
|
|
'device' => 'nullable|int',
|
|
'eventtype' => 'nullable|string',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Defines the base query for this resource
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
|
|
*/
|
|
public function baseQuery($request)
|
|
{
|
|
$query = Eventlog::hasAccess($request->user())->with('device');
|
|
|
|
if ($device_id = $request->get('device')) {
|
|
$query->where('device_id', $device_id);
|
|
}
|
|
|
|
if ($type = $request->get('eventtype')) {
|
|
$query->where('type', $type);
|
|
}
|
|
|
|
if ($searchPhrase = $request->get('searchPhrase')) {
|
|
$query->where('message', 'like', '%'.$searchPhrase.'%');
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function formatItem($eventlog)
|
|
{
|
|
return [
|
|
'datetime' => $this->formatDatetime($eventlog),
|
|
'device_id' => $eventlog->device ? Url::deviceLink($eventlog->device, $eventlog->device->shortDisplayName()) : null,
|
|
'type' => $this->formatType($eventlog),
|
|
'message' => htmlspecialchars($eventlog->message),
|
|
'username' => $eventlog->username ?: 'System',
|
|
];
|
|
}
|
|
|
|
private function formatType($eventlog)
|
|
{
|
|
if ($eventlog->type == 'interface') {
|
|
if (is_numeric($eventlog->reference)) {
|
|
$port = $eventlog->related;
|
|
return '<b>' . Url::portLink($port, $port->getShortLabel()) . '</b>';
|
|
}
|
|
}
|
|
|
|
return $eventlog->type;
|
|
}
|
|
|
|
private function formatDatetime($eventlog)
|
|
{
|
|
$output = "<span class='alert-status ";
|
|
$output .= $this->severityLabel($eventlog->severity);
|
|
$output .= " eventlog-status'></span><span style='display:inline;'>";
|
|
$output .= (new Carbon($eventlog->datetime))->format(Config::get('dateformat.compact'));
|
|
$output .= "</span>";
|
|
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* @param int $eventlog_severity
|
|
* @return string $eventlog_severity_icon
|
|
*/
|
|
private function severityLabel($eventlog_severity)
|
|
{
|
|
switch ($eventlog_severity) {
|
|
case 1:
|
|
return "label-success"; //OK
|
|
case 2:
|
|
return "label-info"; //Informational
|
|
case 3:
|
|
return "label-primary"; //Notice
|
|
case 4:
|
|
return "label-warning"; //Warning
|
|
case 5:
|
|
return "label-danger"; //Critical
|
|
default:
|
|
return "label-default"; //Unknown
|
|
}
|
|
} // end eventlog_severity
|
|
}
|