Skip to content

Commit

Permalink
Update alertlog-widget to allow filtering by device group (librenms#1…
Browse files Browse the repository at this point in the history
…3380)

* Add group filter to alertlog widget

* Remove extra characters from settings

* Apply fixes from StyleCI

Co-authored-by: ottorei <[email protected]>
  • Loading branch information
ottorei and ottorei authored Oct 19, 2021
1 parent fb7d89c commit d3726e6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/Widgets/AlertlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AlertlogController extends WidgetController
protected $defaults = [
'title' => null,
'device_id' => '',
'device_group' => null,
'state' => -1,
'min_severity' => null,
'hidenavigation' => 0,
Expand Down
5 changes: 5 additions & 0 deletions includes/html/table/alertlog.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
$where .= get_sql_filter_min_severity($vars['min_severity'], 'R');
}

if (is_numeric($vars['device_group'])) {
$where .= ' AND D.device_id IN (SELECT `device_id` FROM `device_group_device` WHERE `device_group_id` = ?)';
$param[] = $vars['device_group'];
}

if (! Auth::user()->hasGlobalRead()) {
$device_ids = Permissions::devicesForUser()->toArray() ?: [0];
$where .= ' AND `E`.`device_id` IN ' . dbGenPlaceholders(count($device_ids));
Expand Down
1 change: 1 addition & 0 deletions resources/views/widgets/alertlog.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
return {
id: "alertlog",
device_id: "",
device_group: "{{ $device_group }}",
state: '{{ $state }}',
min_severity: '{{ $min_severity }}',
};
Expand Down
13 changes: 11 additions & 2 deletions resources/views/widgets/settings/alertlog.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
<input type="text" class="form-control" name="title" id="title-{{ $id }}" placeholder="@lang('Custom title')" value="{{ $title }}">
</div>
<div class="form-group">
<label for="state-{{ $id }}" class="control-label">@lang('State'):</label>
<label for="state-{{ $id }}" class="control-label">@lang('State')</label>
<select class="form-control" name="state" id="state-{{ $id }}">
<option value="-1">@lang('not filtered')</option>
<option value="0" @if($state === '1') selected @endif>@lang('OK')</option>
<option value="1" @if($state === '0') selected @endif>@lang('Alert')</option>
</select>
</div>
<div class="form-group">
<label for="min_severity-{{ $id }}" class="control-label">@lang('Displayed severity'):</label>
<label for="min_severity-{{ $id }}" class="control-label">@lang('Displayed severity')</label>
<select class="form-control" name="min_severity" id="min_severity-{{ $id }}">
<option value="">@lang('any severity')</option>
@foreach($severities as $name => $val)
<option value="{{ $val }}" @if($min_severity == $val) selected @endif>{{ $name }}{{$val > 3 ? '' : ' ' . __('or higher')}}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="device_group-{{ $id }}" class="control-label">@lang('Device group')</label>
<select class="form-control" name="device_group" id="device_group-{{ $id }}" data-placeholder="@lang('All Devices')">
@if($device_group)
<option value="{{ $device_group->id }}" selected>{{ $device_group->name }}</option>
@endif
</select>
</div>
<div class="form-group">
<label for="hidenavigation-{{ $id }}" class="control-label">@lang('Hide Navigation')</label>
<input type="checkbox" class="form-control" name="hidenavigation" id="hidenavigation-{{ $id }}" value="{{ $hidenavigation }}" data-size="normal" @if($hidenavigation) checked @endif>
Expand All @@ -30,6 +38,7 @@

@section('javascript')
<script type="text/javascript">
init_select2('#device_group-{{ $id }}', 'device-group', {});
$('#hidenavigation-{{ $id }}')
.bootstrapSwitch('offColor','danger')
.on('switchChange.bootstrapSwitch', function (e, data) {
Expand Down

0 comments on commit d3726e6

Please sign in to comment.