1 | <?php |
||||
2 | /* |
||||
3 | * LibreNMS |
||||
4 | * |
||||
5 | * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa> |
||||
6 | * |
||||
7 | * This program is free software: you can redistribute it and/or modify it |
||||
8 | * under the terms of the GNU General Public License as published by the |
||||
9 | * Free Software Foundation, either version 3 of the License, or (at your |
||||
10 | * option) any later version. Please see LICENSE.txt at the top level of |
||||
11 | * the source code distribution for details. |
||||
12 | * |
||||
13 | * @package LibreNMS |
||||
14 | * @subpackage webui |
||||
15 | * @link https://www.librenms.org |
||||
16 | * @copyright 2017 LibreNMS |
||||
17 | * @author LibreNMS Contributors |
||||
18 | */ |
||||
19 | |||||
20 | use App\Models\Device; |
||||
21 | |||||
22 | if (empty($results_limit)) { |
||||
23 | $results_limit = 25; |
||||
24 | } |
||||
25 | $tmp_output = ' |
||||
26 | |||||
27 | <div class="table-responsive"> |
||||
28 | <table id="graylog" class="table table-hover table-condensed graylog"> |
||||
29 | <thead> |
||||
30 | <tr> |
||||
31 | <th data-column-id="severity" data-sortable="false"></th> |
||||
32 | <th data-column-id="timestamp" data-formatter="browserTime">Timestamp</th> |
||||
33 | <th data-column-id="level">Level</th> |
||||
34 | <th data-column-id="source">Source</th> |
||||
35 | <th data-column-id="message" data-sortable="false">Message</th> |
||||
36 | <th data-column-id="facility">Facility</th> |
||||
37 | </tr> |
||||
38 | </thead> |
||||
39 | </table> |
||||
40 | </div> |
||||
41 | |||||
42 | <script> |
||||
43 | |||||
44 | searchbar = "<div id=\"{{ctx.id}}\" class=\"{{css.header}}\"><div class=\"row\">"+ |
||||
45 | "<div class=\"col-sm-8\"><form method=\"post\" action=\"\" class=\"form-inline\">"+ |
||||
46 | "' . addslashes(csrf_field()) . '" + |
||||
47 | "Filter: "+ |
||||
48 | '; |
||||
49 | |||||
50 | $tmp_output .= '"<div class=\"form-group\"><select name=\"stream\" id=\"stream\" class=\"form-control\" data-placeholder=\"All Messages\">"+'; |
||||
51 | if ($vars['stream']) { |
||||
52 | $tmp_output .= '"<option value=\"' . \LibreNMS\Util\Clean::html($vars['stream'], []) . '\">' . \LibreNMS\Util\Clean::html($vars['stream'], []) . '</option>" +'; |
||||
53 | $filter_device = $device->device_id; |
||||
54 | } |
||||
55 | $tmp_output .= '"</select> </div>"+'; |
||||
56 | |||||
57 | if (! empty($filter_device)) { |
||||
58 | $tmp_output .= ' |
||||
59 | "<input type=\"hidden\" name=\"device\" id=\"device\" value=\"' . $filter_device . '\">"+ |
||||
60 | '; |
||||
61 | } else { |
||||
62 | $tmp_output .= ' |
||||
63 | "<div class=\"form-group\"><select name=\"device\" id=\"device\" class=\"form-control\" data-placeholder=\"All Devices\">"+ |
||||
64 | |||||
65 | '; |
||||
66 | if ($vars['device'] && $device = Device::find($vars['device'])) { |
||||
67 | $tmp_output .= '"<option value=\"' . $device->device_id . '\">' . $device->displayName() . '</option>" +'; |
||||
68 | $filter_device = $device->device_id; |
||||
69 | } |
||||
70 | |||||
71 | $tmp_output .= ' |
||||
72 | "</select> </div>"+ |
||||
73 | '; |
||||
74 | } |
||||
75 | |||||
76 | if (\LibreNMS\Config::has('graylog.timezone')) { |
||||
77 | $timezone = 'row.timestamp;'; |
||||
78 | } else { |
||||
79 | $timezone = 'moment.parseZone(row.timestamp).local().format("YYYY-MM-DD HH:MM:SS");'; |
||||
80 | } |
||||
81 | |||||
82 | $tmp_output .= ' |
||||
83 | "<div class=\"form-group\">"+ |
||||
84 | "<select name=\"loglevel\" id=\"loglevel\" class=\"form-control\">"+ |
||||
85 | "<option value=\"\" disabled selected>Log Level</option>"+ |
||||
86 | "<option value=\"0\">' . ('(0) ' . __('syslog.severity.0')) . '</option>"+ |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
87 | "<option value=\"1\">' . ('(1) ' . __('syslog.severity.1')) . '</option>"+ |
||||
0 ignored issues
–
show
Are you sure
__('syslog.severity.1') of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
88 | "<option value=\"2\">' . ('(2) ' . __('syslog.severity.2')) . '</option>"+ |
||||
0 ignored issues
–
show
Are you sure
__('syslog.severity.2') of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
89 | "<option value=\"3\">' . ('(3) ' . __('syslog.severity.3')) . '</option>"+ |
||||
0 ignored issues
–
show
Are you sure
__('syslog.severity.3') of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
90 | "<option value=\"4\">' . ('(4) ' . __('syslog.severity.4')) . '</option>"+ |
||||
0 ignored issues
–
show
Are you sure
__('syslog.severity.4') of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
91 | "<option value=\"5\">' . ('(5) ' . __('syslog.severity.5')) . '</option>"+ |
||||
0 ignored issues
–
show
Are you sure
__('syslog.severity.5') of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
92 | "<option value=\"6\">' . ('(6) ' . __('syslog.severity.6')) . '</option>"+ |
||||
0 ignored issues
–
show
Are you sure
__('syslog.severity.6') of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
93 | "<option value=\"7\">' . ('(7) ' . __('syslog.severity.7')) . '</option>"+ |
||||
0 ignored issues
–
show
Are you sure
__('syslog.severity.7') of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
94 | "</select> </div>"+ |
||||
95 | "<div class=\"form-group\"><select name=\"range\" class=\"form-control\">"+ |
||||
96 | "<option value=\"0\">Search all time</option>"+ |
||||
97 | "<option value=\"300\">Search last 5 minutes</option>"+ |
||||
98 | "<option value=\"900\">Search last 15 minutes</option>"+ |
||||
99 | "<option value=\"1800\">Search last 30 minutes</option>"+ |
||||
100 | "<option value=\"3600\">Search last 1 hour</option>"+ |
||||
101 | "<option value=\"7200\">Search last 2 hours</option>"+ |
||||
102 | "<option value=\"28800\">Search last 8 hours</option>"+ |
||||
103 | "<option value=\"86400\">Search last 1 day</option>"+ |
||||
104 | "<option value=\"172800\">Search last 2 days</option>"+ |
||||
105 | "<option value=\"432000\">Search last 5 days</option>"+ |
||||
106 | "<option value=\"604800\">Search last 7 days</option>"+ |
||||
107 | "<option value=\"1209600\">Search last 14 days</option>"+ |
||||
108 | "<option value=\"2592000\">Search last 30 days</option>"+ |
||||
109 | "</select> </div>"+ |
||||
110 | "<button type=\"submit\" class=\"btn btn-success\">Filter</button> "+ |
||||
111 | "</form></div>"+ |
||||
112 | "<div class=\"col-sm-4 actionBar\"><p class=\"{{css.search}}\"></p><p class=\"{{css.actions}}\"></p></div></div></div>"; |
||||
113 | |||||
114 | var graylog_grid = $("#graylog").bootgrid({ |
||||
115 | ajax: true, |
||||
116 | rowCount: [' . $results_limit . ', 25,50,100,250,-1], |
||||
117 | formatters: { |
||||
118 | "browserTime": function(column, row) { |
||||
119 | return ' . $timezone . ' |
||||
120 | } |
||||
121 | }, |
||||
122 | '; |
||||
123 | |||||
124 | if (! isset($no_form) && $no_form !== true) { |
||||
125 | $tmp_output .= ' |
||||
126 | templates: { |
||||
127 | header: searchbar |
||||
128 | }, |
||||
129 | '; |
||||
130 | } |
||||
131 | |||||
132 | $tmp_output .= ' |
||||
133 | post: function () |
||||
134 | { |
||||
135 | return { |
||||
136 | stream: "' . (isset($_POST['stream']) ? $_POST['stream'] : '') . '", |
||||
137 | device: "' . (isset($filter_device) ? $filter_device : '') . '", |
||||
138 | range: "' . (isset($_POST['range']) ? $_POST['range'] : '') . '", |
||||
139 | loglevel: "' . (isset($_POST['loglevel']) ? $_POST['loglevel'] : '') . '", |
||||
140 | }; |
||||
141 | }, |
||||
142 | url: "' . url('/ajax/table/graylog') . '", |
||||
143 | }); |
||||
144 | |||||
145 | init_select2("#stream", "graylog-streams", {}, "' . (isset($_POST['stream']) ? $_POST['stream'] : '') . '"); |
||||
146 | init_select2("#device", "device", {limit: 100}, "' . (isset($filter_device) ? $filter_device : '') . '"); |
||||
147 | </script> |
||||
148 | |||||
149 | '; |
||||
150 | |||||
151 | $common_output[] = $tmp_output; |
||||
152 |