-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
100 lines (83 loc) · 2.8 KB
/
index.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
90
91
92
93
94
95
96
97
98
99
100
var express = require('express');
var hbs = require('hbs');
var http = require('http');
var async = require('async');
var _ = require('lodash');
var AppServer = require('./lib/AppServer');
var SyncServer = require('./lib/SyncServer');
var favicon = require('serve-favicon');
var redis = require('redis');
var icingaClient = require('./icingaClient')();
var server = function () {
var app = express();
var httpServer;
var sync;
var applicationRoot = __dirname + (process.env.NODE_ENV === 'dev' ? '/' : '/dist/');
var client = redis.createClient(6379, "10.44.72.53");
app.set('view engine', 'html');
app.set('views', applicationRoot + 'views');
app.engine('html', hbs.__express);
app.use("/static", express.static(applicationRoot + 'static'));
app.use(favicon(applicationRoot + 'static' + '/favicon.ico'));
app.get('/admin', function (req, res) {
res.render('admin.hbs');
});
app.get('/admin/connections', function (req, res) {
res.send({
connections: sync.getListOfConnections()
});
});
app.get('/admin/command/setName/:session/:name', function (req, res) {
sync.setSessionName(req.params.session, req.params.name);
res.send();
});
app.get('/admin/command/reload/:session', function (req, res) {
sync.reloadScreen(req.params.session);
res.send();
});
app.get('/admin/command/identify', function (req, res) {
sync.identify();
res.send();
});
app.get('/admin/command/messageAll', function (req, res) {
sync.messageAll(req.query.message);
res.send();
});
app.get('/icinga/health', icingaClient.checkHealth);
app.get('/icinga/byFilter', icingaClient.checkFilter);
app.get('/redis/hash/:key', function (req, res) {
client.hgetall(req.params.key, function (err, obj) {
res.send(JSON.stringify(JSON.parse(obj.teams)));
});
});
app.get(/^(.*)$/, function (req, res, next) {
if (req.originalUrl.indexOf('.') === -1) {
return res.render('index.hbs');
}
next();
});
return {
start: function (options, callback) {
httpServer = new AppServer(app, options);
async.waterfall([
httpServer.start,
function (http, socket, callback) {
sync = new SyncServer();
sync.start(socket, callback);
}
],
function (err, http, socket) {
(callback || function () {})(err);
});
},
stop: function (callback) {
httpServer.stop(callback);
}
};
};
if (require.main === module) {
new server().start({
port: 1234
});
}
module.exports = server;