|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* app/DataTables/AlertsDataTable.php |
|
4
|
|
|
* |
|
5
|
|
|
* Datatable for alerts |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
* @package LibreNMS |
|
21
|
|
|
* @link http://librenms.org |
|
22
|
|
|
* @copyright 2016 Neil Lathwood |
|
23
|
|
|
* @author Neil Lathwood <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace App\DataTables; |
|
27
|
|
|
|
|
28
|
|
|
use App\Models\Alerting\Alert; |
|
29
|
|
|
use Yajra\Datatables\Services\DataTable; |
|
30
|
|
|
|
|
31
|
|
|
class AlertsDataTable extends DataTable |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Display ajax response. |
|
35
|
|
|
* |
|
36
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
37
|
|
|
*/ |
|
38
|
|
|
public function ajax() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->datatables |
|
41
|
|
|
->eloquent($this->query()) |
|
42
|
|
|
->editColumn('state', '@if ($state == 0) |
|
43
|
|
|
<div class="label label-success">SUCCESS</div> |
|
44
|
|
|
@elseif ($state == 1) |
|
45
|
|
|
<div class="label label-danger">FAILED</div> |
|
46
|
|
|
@elseif ($state == 2) |
|
47
|
|
|
<div class="label label-warning">MUTED</div> |
|
48
|
|
|
@else |
|
49
|
|
|
<div class="label label-primary">UNKNOWN</div> |
|
50
|
|
|
@endif') |
|
51
|
|
|
->editColumn('rule.name', function($this) { |
|
|
|
|
|
|
52
|
|
|
return '<a href="'.url("alerting/rules/".$this['rule']['id']).'">'.$this['rule']['name'].'</a>'; |
|
53
|
|
|
}) |
|
54
|
|
|
->editColumn('device.hostname', function($this) { |
|
|
|
|
|
|
55
|
|
|
return '<a href="'.url("devices/".$this['device']['device_id']).'">'.$this['device']['hostname'].'</a>'; |
|
56
|
|
|
}) |
|
57
|
|
|
->addColumn('actions', function() { |
|
|
|
|
|
|
58
|
|
|
return ''; |
|
59
|
|
|
}) |
|
60
|
|
|
->make(true); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get the query object to be processed by datatables. |
|
65
|
|
|
* |
|
66
|
|
|
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder |
|
67
|
|
|
*/ |
|
68
|
|
|
public function query() |
|
69
|
|
|
{ |
|
70
|
|
|
$alerts = Alert::query()->where('state', '!=', '0')->with('device')->with('user')->with('rule')->select('alerts.*'); |
|
71
|
|
|
return $this->applyScopes($alerts); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Optional method if you want to use html builder. |
|
76
|
|
|
* |
|
77
|
|
|
* @return \Yajra\Datatables\Html\Builder |
|
78
|
|
|
*/ |
|
79
|
1 |
|
public function html() |
|
80
|
|
|
{ |
|
81
|
1 |
|
return $this->builder() |
|
82
|
1 |
|
->columns($this->getColumns()) |
|
83
|
1 |
|
->parameters($this->getBuilderParameters()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get columns. |
|
88
|
|
|
* |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
1 |
|
private function getColumns() |
|
92
|
|
|
{ |
|
93
|
|
|
return [ |
|
94
|
|
|
'state' => [ |
|
95
|
1 |
|
'title' => trans('alerting.alerts.text.state'), |
|
96
|
1 |
|
], |
|
97
|
|
|
'rule.name' => [ |
|
98
|
1 |
|
'title' => trans('alerting.alerts.text.rule'), |
|
99
|
1 |
|
], |
|
100
|
|
|
'device.hostname' => [ |
|
101
|
1 |
|
'title' => trans('devices.label.hostname'), |
|
102
|
1 |
|
], |
|
103
|
1 |
|
'timestamp', |
|
104
|
|
|
'rule.severity' => [ |
|
105
|
1 |
|
'title' => trans('alerting.alerts.text.severity'), |
|
106
|
1 |
|
], |
|
107
|
1 |
|
'actions', |
|
108
|
1 |
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get filename for export. |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function filename() |
|
117
|
|
|
{ |
|
118
|
|
|
return 'alerts'; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Get Builder Params |
|
123
|
|
|
* |
|
124
|
|
|
* @return array |
|
125
|
|
|
*/ |
|
126
|
1 |
|
protected function getBuilderParameters() |
|
127
|
|
|
{ |
|
128
|
|
|
return [ |
|
129
|
1 |
|
'dom' => 'Blfrtip', |
|
130
|
1 |
|
'lengthMenu' => [[25, 50, 100, -1], [25, 50, 100, "All"]], |
|
131
|
|
|
'buttons' => [ |
|
132
|
1 |
|
'csv', 'excel', 'pdf', 'print', 'reset', 'reload', |
|
133
|
1 |
|
], |
|
134
|
1 |
|
]; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: