From f7a2a9692b25629d75c77707ca2cd2ffda20658b Mon Sep 17 00:00:00 2001 From: zeus Date: Wed, 9 Dec 2020 13:01:21 +0200 Subject: [PATCH] getlog --- swarmlab-app/src/run/app.js | 57 ++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 0a53044..ed5680a 100755 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -291,7 +291,7 @@ app.get('/get_log', [ cors(corsOptions), (req, res, next) => { (async() => { -/* + 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, @@ -301,36 +301,41 @@ MongoClient.connect(mongourl, OPTS, function(err, client){ if(err){ console.log(err); } else { - const db = client.db('fluent'); - //db.collection('log', onCollection); - console.log(JSON.stringify('mongo connected')) + const db = client.db('fluent'); + //db.collection('log', onCollection); + console.log(JSON.stringify('mongo connected')) var stream = db.collection('logs').find({}, { - tailable: true, - awaitdata: true -}).stream(); + tailable: true, + awaitdata: true + }).stream(); -stream.on('data', function (doc) { + stream.on('data', function (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.json(RES) + + + + }); } }); -*/ - 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 = true - }else{ - console.log("Authserver no " + RES.token); - RES.error = false - } - RES.error_msg = "ok" - res.json(RES) + })() });