Skip to content

Commit adfdb36

Browse files
murrantStyleCIBot
andauthored
Refactor device log pages (librenms#18309)
* Refactor device log pages Port to Laravel to allow future features * Apply fixes from StyleCI * Use redirect instead of different route --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent 8c4f98f commit adfdb36

16 files changed

Lines changed: 690 additions & 107 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* EventlogController.php
5+
*
6+
* -Description-
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* @link https://www.librenms.org
22+
*
23+
* @copyright 2025 Tony Murray
24+
* @author Tony Murray <murraytony@gmail.com>
25+
*/
26+
27+
namespace App\Http\Controllers\Device\Tabs;
28+
29+
use App\Http\Controllers\Controller;
30+
use App\Models\Device;
31+
use Illuminate\Http\Request;
32+
use Illuminate\View\View;
33+
34+
class EventlogController extends Controller
35+
{
36+
public function __invoke(Device $device, Request $request): View
37+
{
38+
$request->validate([
39+
'eventtype' => 'nullable|string',
40+
]);
41+
42+
return view('device.tabs.logs.eventlog', [
43+
'device' => $device,
44+
'filter_device' => false,
45+
'eventtype' => $request->input('eventtype', ''),
46+
]);
47+
}
48+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* GraylogController.php
5+
*
6+
* -Description-
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* @link https://www.librenms.org
22+
*
23+
* @copyright 2025 Tony Murray
24+
* @author Tony Murray <murraytony@gmail.com>
25+
*/
26+
27+
namespace App\Http\Controllers\Device\Tabs;
28+
29+
use App\Facades\LibrenmsConfig;
30+
use App\Http\Controllers\Controller;
31+
use App\Models\Device;
32+
use Illuminate\Http\Request;
33+
use Illuminate\View\View;
34+
35+
class GraylogController extends Controller
36+
{
37+
public function __invoke(Device $device, Request $request): View
38+
{
39+
$request->validate([
40+
'stream' => 'nullable|string',
41+
'range' => 'nullable|int',
42+
'loglevel' => 'nullable|int',
43+
]);
44+
45+
return view('device.tabs.logs.graylog', [
46+
'device' => $device,
47+
'timezone' => LibrenmsConfig::has('graylog.timezone'),
48+
'filter_device' => true,
49+
'show_form' => true,
50+
'stream' => $request->input('stream', ''),
51+
'range' => $request->input('range', '0'),
52+
'loglevel' => $request->input('loglevel', ''),
53+
]);
54+
}
55+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* OutagesController.php
5+
*
6+
* -Description-
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* @link https://www.librenms.org
22+
*
23+
* @copyright 2025 Tony Murray
24+
* @author Tony Murray <murraytony@gmail.com>
25+
*/
26+
27+
namespace App\Http\Controllers\Device\Tabs;
28+
29+
use App\Http\Controllers\Controller;
30+
use App\Models\Device;
31+
use Illuminate\Http\Request;
32+
use Illuminate\View\View;
33+
34+
class OutagesController extends Controller
35+
{
36+
public function __invoke(Device $device, Request $request): View
37+
{
38+
$request->validate([
39+
'to' => 'nullable|int',
40+
'from' => 'nullable|int',
41+
]);
42+
43+
return view('device.tabs.logs.outages', [
44+
'device' => $device,
45+
'to' => $request->input('to', ''),
46+
'from' => $request->input('from', ''),
47+
]);
48+
}
49+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* SyslogController.php
5+
*
6+
* -Description-
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* @link https://www.librenms.org
22+
*
23+
* @copyright 2025 Tony Murray
24+
* @author Tony Murray <murraytony@gmail.com>
25+
*/
26+
27+
namespace App\Http\Controllers\Device\Tabs;
28+
29+
use App\Facades\LibrenmsConfig;
30+
use App\Http\Controllers\Controller;
31+
use App\Models\Device;
32+
use Illuminate\Http\Request;
33+
use Illuminate\Support\Carbon;
34+
use Illuminate\View\View;
35+
36+
class SyslogController extends Controller
37+
{
38+
public function __invoke(Device $device, Request $request): View
39+
{
40+
$request->validate([
41+
'program' => 'nullable|string',
42+
'priority' => 'nullable|string',
43+
'from' => 'nullable|string',
44+
'to' => 'nullable|string',
45+
]);
46+
47+
return view('device.tabs.logs.syslog', [
48+
'device' => $device,
49+
'filter_device' => false,
50+
'now' => Carbon::now()->format(LibrenmsConfig::get('dateformat.byminute', 'Y-m-d H:i')),
51+
'default_date' => Carbon::now()->subDay()->format(LibrenmsConfig::get('dateformat.byminute', 'Y-m-d H:i')),
52+
'program' => $request->input('program', ''),
53+
'priority' => $request->input('priority', ''),
54+
'from' => $request->input('from', ''),
55+
'to' => $request->input('to', ''),
56+
]);
57+
}
58+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/**
4+
* LogTabs.php
5+
*
6+
* -Description-
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
* @link https://www.librenms.org
22+
*
23+
* @copyright 2025 Tony Murray
24+
* @author Tony Murray <murraytony@gmail.com>
25+
*/
26+
27+
namespace App\View\Components\Device;
28+
29+
use App\Facades\LibrenmsConfig;
30+
use App\Models\Device;
31+
use Closure;
32+
use Illuminate\Contracts\View\View;
33+
use Illuminate\View\Component;
34+
35+
class LogTabs extends Component
36+
{
37+
public array $tabs = [];
38+
39+
public function __construct(
40+
public readonly Device $device,
41+
public readonly ?string $tab = null,
42+
) {
43+
$this->tabs['outages'] = [
44+
'text' => __('Outages'),
45+
'link' => route('device.outages', $this->device->device_id),
46+
];
47+
48+
$this->tabs['eventlog'] = [
49+
'text' => __('Event Log'),
50+
'link' => route('device.eventlog', $this->device->device_id),
51+
];
52+
53+
if (LibrenmsConfig::get('enable_syslog')) {
54+
$this->tabs['syslog'] = [
55+
'text' => __('Syslog'),
56+
'link' => route('device.syslog', $this->device->device_id),
57+
];
58+
}
59+
60+
if (LibrenmsConfig::get('graylog.server')) {
61+
$this->tabs['graylog'] = [
62+
'text' => __('Graylog'),
63+
'link' => route('device.graylog', $this->device->device_id),
64+
];
65+
}
66+
}
67+
68+
/**
69+
* Get the view / contents that represent the component.
70+
*/
71+
public function render(): View|Closure|string
72+
{
73+
return view('components.device.log-tabs');
74+
}
75+
}

app/View/Components/Device/Page.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ class Page extends Component
4040
public ?int $parentDeviceId;
4141
public ?string $typeIcon = null;
4242
public string $typeText = '';
43+
public string $pagetitle;
4344

4445
public function __construct(
4546
public readonly Device $device,
4647
public readonly array $dropdownLinks = [],
48+
public readonly string $subtitle = '',
4749
) {
50+
$this->pagetitle = $subtitle ? ($device->displayName() . ': ' . $subtitle) : $device->displayName();
4851
$this->alertClass = $device->disabled ? 'alert-info' : ($device->status ? '' : 'alert-danger');
4952
$this->parentDeviceId = Vminfo::guessFromDevice($device)->value('device_id');
5053
$this->populateTypeFields();

0 commit comments

Comments
 (0)