Browse Source

getlog

master
zeus 4 years ago
parent
commit
0fb2474061
  1. 49
      swarmlab-app/src/run/app.js

49
swarmlab-app/src/run/app.js

@ -291,13 +291,26 @@ app.get('/get_log', [
cors(corsOptions), (req, res, next) => { cors(corsOptions), (req, res, next) => {
(async() => { (async() => {
var RES = new Object();
var mongourl = "mongodb://"+CONFIG.mongo.user+":"+CONFIG.mongo.password+"@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017/fluent?replicaSet=rs1&authSource=swarmlabplaygroundstats" RES.token = req.query["token"]
const OPTS = { RES.start = req.query["start"]
RES.end = req.query["end"]
RES.filter = req.query["filter"]
var isvalid = await checkToken(RES.token);
if(isvalid.action == 'ok'){
console.log("Authserver ok " + RES.token);
RES.error = 'ok'
}else{
console.log("Authserver no " + RES.token);
RES.error = 'no'
}
if(RES.error == 'ok'){
var mongourl = "mongodb://"+CONFIG.mongo.user+":"+CONFIG.mongo.password+"@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017/fluent?replicaSet=rs1&authSource=swarmlabplaygroundstats"
const OPTS = {
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true useUnifiedTopology: true
}; };
MongoClient.connect(mongourl, OPTS, function(err, client){ MongoClient.connect(mongourl, OPTS, function(err, client){
if(err){ if(err){
console.log(err); console.log(err);
} else { } else {
@ -312,29 +325,17 @@ MongoClient.connect(mongourl, OPTS, function(err, client){
stream.on('data', function (doc) { stream.on('data', function (doc) {
console.log(JSON.stringify(doc)) console.log(JSON.stringify(doc))
//socket.write(JSON.stringify({'action': 'log','param': doc.log})); //socket.write(JSON.stringify({'action': 'log','param': doc.log}));
var RES = new Object();
RES.token = req.query["token"]
RES.start = req.query["start"]
RES.end = req.query["end"]
RES.filter = req.query["filter"]
var isvalid = await checkToken(RES.token);
if(isvalid.action == 'ok'){
console.log("Authserver ok " + RES.token);
RES.error = 'ok'
}else{
console.log("Authserver no " + RES.token);
RES.error = 'no'
}
RES.error_msg = "ok" RES.error_msg = "ok"
res.json(RES) res.json(RES)
}); });
} }
}); });
}else{
RES.error_msg = "tokeni err"
res.json(RES)
}
})() })()

Loading…
Cancel
Save