forked from graylog-labs/cli-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graylog-dashboard.js
executable file
·90 lines (78 loc) · 3.17 KB
/
graylog-dashboard.js
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
#!/usr/bin/env node
/**
* This file is part of Graylog2.
*
* Graylog2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog2. If not, see <http://www.gnu.org/licenses/>.
*/
var fs = require('fs')
var yaml = require('js-yaml')
var argv = require('yargs')
.usage('Usage: graylog-dashboard --stream-id [stream-id] --host [graylog-server REST API URL]')
.demand(['s','h'])
.alias('s', 'stream-id')
.alias('h', 'host')
.argv
var graylog = require("./lib/graylog-api.js")
var ui = require("./lib/screen.js")
var handlers = require("./lib/handlers.js")
/*
*
* ┈╱╱▏┈┈╱╱╱╱▏╱╱▏┈┈┈ ┈╱╱▏┈┈╱╱╱╱▏╱╱▏┈┈┈ ┈╱╱▏┈┈╱╱╱╱▏╱╱▏┈┈┈
* ┈▇╱▏┈┈▇▇▇╱▏▇╱▏┈┈┈ ┈▇╱▏┈┈▇▇▇╱▏▇╱▏┈┈┈ ┈▇╱▏┈┈▇▇▇╱▏▇╱▏┈┈┈
* ┈▇╱▏▁┈▇╱▇╱▏▇╱▏▁┈┈ ┈▇╱▏▁┈▇╱▇╱▏▇╱▏▁┈┈ ┈▇╱▏▁┈▇╱▇╱▏▇╱▏▁┈┈
* ┈▇╱╱╱▏▇╱▇╱▏▇╱╱╱▏┈ ┈▇╱╱╱▏▇╱▇╱▏▇╱╱╱▏┈ ┈▇╱╱╱▏▇╱▇╱▏▇╱╱╱▏┈
* ┈▇▇▇╱┈▇▇▇╱┈▇▇▇╱┈┈ ┈▇▇▇╱┈▇▇▇╱┈▇▇▇╱┈┈ ┈▇▇▇╱┈▇▇▇╱┈▇▇▇╱┈┈
*
* I have no clue about JavaScript or even node.js and this is
* going to be pretty terrible code. It is a wonder that I got
* it running at all lol.
*
* I wish this was Java.
*
* Have fun in here! (Lennart, 01/2015)
*
*/
// CLI arguments
var streamId = argv.s
var serverUrl = argv.h
// Make sure serverUrl has a trailing slash. (computers.)
var lastChar = serverUrl.substr(-1);
if (lastChar != '/') {
serverUrl = serverUrl + '/';
}
// Read user credentials.
var credFilePath = process.env['HOME'] + "/.graylog_dashboard"
try {
var config = yaml.safeLoad(fs.readFileSync(credFilePath, 'utf8'))
} catch (err) {
throw new Error("Could not read Graylog user credentials file at " + credFilePath + " - Please create it "
+ "as described in the README. (" + err + ")")
}
// Check config.
if(config.username == undefined) {
throw new Error("No username defined in " + credFilePath)
}
if(config.password == undefined) {
throw new Error("No password defined in " + credFilePath)
}
var apiUser = config.username.toString()
var apiPass = config.password.toString()
setInterval(function() {
graylog.lastMessagesOfStream({
serverUrl: serverUrl,
streamId: streamId,
username: apiUser,
password: apiPass
}, handlers.updateMessagesList)
}, 1000)