Skip to content

Commit b5e239d

Browse files
author
Simon Esprit
committed
allow user to specify specific apps to see in the logs
This commit allows a user to specifiy which apps will be shown in the viewer.
1 parent 4fecd33 commit b5e239d

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

static/viewer.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ body {
4040
float: right;
4141
}
4242

43-
#filters {
43+
#filters, #apps {
4444
float: left;
4545
clear: both;
4646
margin-top: 15px;

static/viewer.js

+59-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function Filter(app_expr, severity_expr, action, state) {
7474
return matchRuleShort(appname, this.app_expr);
7575
};
7676

77+
// TODO refactor this so that apps can reuse this logic!
7778
this.evaluateSeverity = function (severity) {
7879
rule_int = this.severityToInt(this.sev_expr.replace(/\W/g, ''));
7980
sev_int = this.severityToInt(severity);
@@ -158,6 +159,17 @@ function Filter(app_expr, severity_expr, action, state) {
158159
};
159160
}
160161

162+
function App(app_expr, state) {
163+
this.app_expr = app_expr;
164+
// state = enabled | disabled
165+
this.state = state;
166+
167+
// TODO at some point refactor this as this is the same for the filter!
168+
this.evaluateApp = function (appname) {
169+
return matchRuleShort(appname, this.app_expr);
170+
};
171+
}
172+
161173
/* Class that acts as a wrapper around the WebSocket class.
162174
It's goal is to create a robust connection with the server.
163175
This means that it will test the connection & reconnect if needed.
@@ -256,16 +268,51 @@ app.controller('MessagesController', ['$scope', '$window', function ($scope, $wi
256268
// this buffer will hold messages while the app is paused
257269
$scope.paused_messages = [];
258270

271+
$scope.apps = [];
272+
// put a placeholder app
273+
$scope.apps.push(new App("my_app", "disabled"));
274+
259275
$scope.filters = [];
260276
// put a placeholder filter
261277
var filter = new Filter("myapp", ">= warning", "hide", "disabled");
262278
$scope.filters.push(filter);
263279

280+
$scope.applyApps = function (message) {
281+
if (!message)
282+
return null;
283+
284+
var hasAppEnabled = false;
285+
286+
for (var index = 0; index < $scope.apps.length; index++) {
287+
var app = $scope.apps[index];
288+
if (app.state == "enabled") {
289+
hasAppEnabled = true;
290+
if (app.evaluateApp(message.appname)) {
291+
return message;
292+
}
293+
}
294+
else
295+
continue;
296+
}
297+
298+
// if we got here and an enabled app was found, it means none of them match the message so we discard it
299+
if(hasAppEnabled) {
300+
console.log("discarded message with non-matching app");
301+
return null;
302+
}
303+
else {
304+
return message;
305+
}
306+
};
307+
264308
/*
265309
* Function to evaluate all user-specified filters on a message.
266310
* These filters will modify the message and return it.
267311
*/
268312
$scope.applyFilters = function (message) {
313+
if (!message)
314+
return null;
315+
269316
for (var index = 0; index < $scope.filters.length; index++) {
270317
message = $scope.filters[index].handleMessage(message);
271318
// if filter removed the message, stop immediately
@@ -284,7 +331,10 @@ app.controller('MessagesController', ['$scope', '$window', function ($scope, $wi
284331
return;
285332
}
286333

287-
// first evaluate filters, if this becomes too intense for the browser, offload it to server
334+
// first check if only specific apps should be shown
335+
message = $scope.applyApps(message);
336+
337+
// evaluate filters, if this becomes too intense for the browser, offload it to server
288338
message = $scope.applyFilters(message);
289339
if (!message) {
290340
console.log("filtered out message");
@@ -342,6 +392,14 @@ app.controller('MessagesController', ['$scope', '$window', function ($scope, $wi
342392
$scope.filters.splice(index, 1);
343393
};
344394

395+
$scope.addApp = function () {
396+
$scope.apps.push(new App("my_app", "disabled"));
397+
};
398+
399+
$scope.removeApp = function (index) {
400+
$scope.apps.splice(index, 1);
401+
};
402+
345403
$scope.gotoEndTable = function () {
346404
// scroll to bottom of table
347405
var objDiv = document.getElementById("viewer");

templates/viewer.html

+17
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,27 @@ <h3>Syslogw <small>Web Viewer</small></h3>
1919
</div>
2020
<div id="controller">
2121
<button type="button" class="btn btn-primary btn-warning" ng-click="onClear()">Clear</button>
22+
<button data-toggle="collapse" data-target="#apps" class="btn btn-primary btn-warning">Apps</button>
2223
<button data-toggle="collapse" data-target="#filters" class="btn btn-primary btn-warning">Filters</button>
2324
<button type="button" class="btn btn-primary btn-warning" ng-click="onPause()" ng-hide="isPaused">Pause</button>
2425
<button type="button" class="btn btn-primary btn-success" ng-click="onResume()" ng-show="isPaused">Resume</button>
2526
</div>
27+
<div id="apps" class="collapse">
28+
<form class="form-inline filter" ng-repeat="app in apps">
29+
<input type="text" class="form-control" placeholder="*" ng-model="app.app_expr">
30+
<select class="form-control" ng-model="app.state">
31+
<option>enabled</option>
32+
<option>disabled</option>
33+
</select>
34+
<button type="button" class="btn btn-danger" ng-hide="$last" ng-click="removeApp($index)">
35+
<span class="glyphicon glyphicon-remove"></span>
36+
</button>
37+
<button type="button" class="btn btn-success" ng-show="$last" ng-click="addApp()">
38+
<span class="glyphicon glyphicon-plus"></span>
39+
</button>
40+
</form>
41+
42+
</div>
2643
<div id="filters" class="collapse">
2744
<form class="form-inline filter" ng-repeat="filter in filters">
2845
<input type="text" class="form-control" id="app_expr" placeholder="myapp*" ng-model="filter.app_expr">

0 commit comments

Comments
 (0)