-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_settings.html
452 lines (375 loc) · 16.7 KB
/
log_settings.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>Log Settings</title>
<!-- link to JQuery and DataTables javascript libraries -->
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.jqueryui.js"></script>
<!-- link to JQuery and DataTables CSS definitions -->
<link rel="stylesheet" href="css/jquery-ui.css"/>
<link rel="stylesheet" href="css/dataTables.jqueryui.css"/>
<!-- define an internal style -->
<style type="text/css">
.right {
float:right;
}
.loading {
color:CornflowerBlue;
}
</style>
<script type="text/javascript">
var websocket_port = "6464";
var service_port = "6467";
var service_name = "/cloudi/api/erlang/logging";
var logging_file_set_service_name = "/cloudi/api/erlang/logging_file_set";
var logging_level_set_service_name = "/cloudi/api/erlang/logging_level_set";
var logging_redirect_set_service_name = "/cloudi/api/erlang/logging_redirect_set";
var logging_syslog_set_service_name = "/cloudi/api/erlang/logging_syslog_set";
var request_type = "get";
var web_socket = undefined;
var websocket_url = "";
var interval_id = undefined;
function is(type, obj) {
if (obj === undefined)
return type === 'undefined';
else if (obj === null)
return type === 'null';
else
return type === Object.prototype.toString.call(obj).slice(8, - 1);
}
String.prototype.startsWith = function (str) {
return this.slice(0, str.length) == str;
};
// This function uses a web socket to retrieve the current logging settings
function send() {
// if the web socket is undefined then display an error
if (web_socket == undefined) {
$('#connectionStatus').text("Not connected");
open();
}
// if the web socket is in an open status then send the request
if (web_socket.readyState == web_socket.OPEN) {
web_socket.send(request_type);
//console.log("Request (out): " + request_type);
}
}
// This function opens a web socket used to retrieve the current logging settings
function open() {
if (!("WebSocket" in window)) {
$('#connectionStatus').text("Not connected");
alert("This browser does not support WebSockets");
return;
}
$('#connectionStatus').text("Connecting");
websocket_url = "ws://" + $("#hostname").val() + ":" + websocket_port + service_name;
web_socket = new WebSocket(websocket_url);
console.log("Connecting to " + websocket_url);
// define function that is called when the web socket is opened
web_socket.onopen = function () {
$('#connectionStatus').text("Connected");
console.log("Connected");
send();
};
// define function that is called when an error occurs with the websocket
web_socket.onerror = function () {
$('#connectionStatus').text("Error");
console.log("Websocket error");
// turn off the timed page refresh
if (interval_id != undefined) {
clearInterval(interval_id);
interval_id = undefined;
}
// hide the loading message
$('#loadingMessage').hide();
alert("Error connecting to websocket " + websocket_url);
};
// define function that is called when data is available on the websocket
handle_message = function (data) {
if (data.startsWith("notification:")) {
// client state check to determine this is an incoming
// service request, not an incoming response
console.log("Request (in): " + data);
var response = "ok";
web_socket.send(response);
console.log("Response (in): " + response);
}
else {
console.log("Response (out): " + data);
if (data != "got connect! yay!") {
// update the current configuration
$('#current_configuration').text(data);
// parse the log level setting
searchString = "level,";
start = data.indexOf(searchString);
if (start > 0) {
end = data.indexOf("}", start);
levelValue = data.substring(start + searchString.length, end);
// set the value of the list
$("#set_level_input").val(levelValue);
}
// parse the file setting
searchString = "file,";
start = data.indexOf(searchString);
if (start > 0) {
end = data.indexOf("}", start);
fileValue = data.substring(start + searchString.length, end);
// set the value of the input field
$("#set_file_input").val(fileValue);
}
// parse the redirect setting
searchString = "redirect,";
start = data.indexOf(searchString);
if (start > 0) {
end = data.indexOf("}", start);
redirectValue = data.substring(start + searchString.length, end);
// set the value of the input field
$("#set_redirect_input").val(redirectValue);
}
// parse the syslog setting
searchString = "syslog,[";
start = data.indexOf(searchString);
if (start > 0) {
end = data.indexOf("]", start);
syslogValue = data.substring(start + searchString.length - 1, end + 1);
// set the value of the input field
$("#set_syslog_input").val(syslogValue);
}
// hide the loading message
$('#loadingMessage').hide();
// setup time interval to refresh page
if (interval_id == undefined) {
interval_id = setInterval("send();", 60000);
}
}
}
};
// define function that is called when a message is received on the web socket
web_socket.onmessage = function (evt) {
var data = evt.data;
if (is("Blob", data)) {
// for the example, treat binary as text
var reader = new FileReader();
reader.readAsText(data, "text/plain");
reader.onload = function (reader_evt) {
data = reader_evt.target.result;
handle_message(data);
};
}
else {
handle_message(data);
}
};
// define function that is called when the websocket is closed
web_socket.onclose = function () {
web_socket = undefined;
console.log("Connection closed");
};
}
// This function closes the web socket used to retrieve the current logging settings
function close() {
$('#connectionStatus').text("Not connected");
if (web_socket == undefined) {
return;
}
web_socket.close();
}
function createCORSRequest(method, url) {
console.log("Creating CORS Request " + method + " " + url);
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
}
else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
}
else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
console.log("XHR not supported by this browser");
}
return xhr;
}
// This function submits an HTTP request to set the log level
function setLevel() {
var service_url = "http://" + $("#hostname").val() + ":" + service_port + logging_level_set_service_name;
var xhr = createCORSRequest('POST', service_url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.onload = function () {
var responseText = xhr.responseText;
console.log(responseText);
// refresh the information shown on the screen
send();
};
xhr.onerror = function (xhr, textStatus, errorThrown) {
console.log('There was an error. Status ' + xhr.status);
console.log('Error response=' + xhr.responseText);
// refresh the information shown on the screen
send();
};
var value_to_send = $("#set_level_input").val();
console.log("Sending value " + value_to_send);
xhr.send(value_to_send);
}
// This function submits an HTTP request to set the log file
function setFile() {
var service_url = "http://" + $("#hostname").val() + ":" + service_port + logging_file_set_service_name;
var xhr = createCORSRequest('POST', service_url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.onload = function () {
var responseText = xhr.responseText;
console.log(responseText);
// refresh the information shown on the screen
send();
};
xhr.onerror = function (xhr, textStatus, errorThrown) {
console.log('There was an error. Status ' + xhr.status);
console.log('Error response=' + xhr.responseText);
// refresh the information shown on the screen
send();
};
var value_to_send = $("#set_file_input").val();
console.log("Sending value " + value_to_send);
xhr.send(value_to_send);
}
// This function submits an HTTP request to set the log redirection
function setRedirect() {
var service_url = "http://" + $("#hostname").val() + ":" + service_port + logging_redirect_set_service_name;
var xhr = createCORSRequest('POST', service_url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.onload = function () {
var responseText = xhr.responseText;
console.log(responseText);
// refresh the information shown on the screen
send();
};
xhr.onerror = function (xhr, textStatus, errorThrown) {
console.log('There was an error. Status ' + xhr.status);
console.log('Error response=' + xhr.responseText);
// refresh the information shown on the screen
send();
};
var value_to_send = $("#set_redirect_input").val();
console.log("Sending value " + value_to_send);
xhr.send(value_to_send);
}
// This function submits an HTTP request to set the syslog properties
function setSyslog() {
var service_url = "http://" + $("#hostname").val() + ":" + service_port + logging_syslog_set_service_name;
var xhr = createCORSRequest('POST', service_url);
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.onload = function () {
var responseText = xhr.responseText;
console.log(responseText);
// refresh the information shown on the screen
send();
};
xhr.onerror = function (xhr, textStatus, errorThrown) {
console.log('There was an error. Status ' + xhr.status);
console.log('Error response=' + xhr.responseText);
// refresh the information shown on the screen
send();
};
var value_to_send = $("#set_syslog_input").val();
console.log("Sending value " + value_to_send);
xhr.send(value_to_send);
}
</script>
</head>
<body>
<div id="logo">
<img class="right" src="powered_by_cloudi.png"></img>
<h1>Log Settings</h1>
<label class="right" id="connectionStatus"></label>
</div>
<div id="loadingMessage">
<h2 class="loading">Waiting for data...</h2>
</div>
<div>
<h2>
<label for="current_configuration">Current Configuration:</label>
</h2>
<textarea id="current_configuration" rows="9" cols="100"></textarea>
</div>
<div>
<input id="hostname" type="text" value="localhost" title="Host name or address to be monitored"></input>
<button class="left" onclick="send();">Refresh Current Configuration</button>
</div>
<hr></hr>
<div>
<h2>Detailed Log Settings</h2>
</div>
<table>
<tr>
<td>
<button onclick="setLevel();" title="Modify the loglevel. The loglevel is changed with an Erlang module update internally so any logging statements that are turned off create no latency. If set to 'undefined' or 'off', logging output will only be sent to syslog and formatters with an output module">Set Level</button>
</td>
<td>
<select id="set_level_input">
<option value="error">Error</option>
<option value="warn">Warn</option>
<option value="info">Info</option>
<option value="debug">Debug</option>
<option value="trace">Trace</option>
</select>
</td>
</tr>
<tr>
<td>
<button onclick="setFile();" title="Set the file path for logging output. If set to 'undefined', logging output will only be sent to syslog and formatters with an output module">Set File</button>
</td>
<td>
<input id="set_file_input" type="text"></input>
</td>
<td>Set the file path for logging output. Example:
"logs/cloudi_rotated.log"</td>
</tr>
<tr>
<td>
<button onclick="setRedirect();" title="Redirect all local log output to a remote CloudI node. Use 'undefined' as the node name to log locally">Set Redirection</button>
</td>
<td>
<input id="set_redirect_input" type="text"></input>
</td>
<td>Redirect all local log output to a remote CloudI node. Use
'undefined' as the node name to log locally. Example: cloudi@host</td>
</tr>
<tr>
<td>
<button onclick="setSyslog();" title="Send all logging output to syslog">Set Syslog</button>
</td>
<td>
<textarea id="set_syslog_input" rows="3" cols="40"></textarea>
</td>
<td>Example: [{identity, "CloudI"}, {facility, local0},
{level, trace}]</td>
</tr>
</table>
<script type="text/javascript">
$(document).ready(function () {
// assign default hostname
$("#hostname").val(location.host);
// show the loading message
$('#loadingMessage').show();
// set the connection status
$('#connectionStatus').text("Not connected");
// call the service request function now
send();
});
</script>
</body>
</html>