|
@ -60,6 +60,8 @@ pubClient.on("connect", function() { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const MongoClient = require('mongodb').MongoClient; |
|
|
const MongoClient = require('mongodb').MongoClient; |
|
|
|
|
|
const { DateTime } = require("luxon"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var async = require("async"); |
|
|
var async = require("async"); |
|
|
const { check, validationResult } = require('express-validator'); |
|
|
const { check, validationResult } = require('express-validator'); |
|
@ -106,6 +108,7 @@ const corsOptions = { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************
|
|
|
// ***************************************************
|
|
|
// checktoken
|
|
|
// checktoken
|
|
|
// ***************************************************
|
|
|
// ***************************************************
|
|
@ -233,6 +236,64 @@ async function getpipelines(token,pipelinename) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ***************************************************
|
|
|
|
|
|
// get user pipelines
|
|
|
|
|
|
// ***************************************************
|
|
|
|
|
|
|
|
|
|
|
|
async function getuserpipelines(token,user) { |
|
|
|
|
|
var pipelinename = user |
|
|
|
|
|
const agent = new https.Agent({ |
|
|
|
|
|
rejectUnauthorized: false, |
|
|
|
|
|
}); |
|
|
|
|
|
const instance = axios.create({ |
|
|
|
|
|
baseURL: 'https://api.swarmlab.io', |
|
|
|
|
|
withCredentials: true, |
|
|
|
|
|
rejectUnauthorized: false, |
|
|
|
|
|
crossdomain: true, |
|
|
|
|
|
httpsAgent: agent, |
|
|
|
|
|
headers: { |
|
|
|
|
|
'Accept': 'application/json', |
|
|
|
|
|
'Content-Type': 'multipart/form-data', |
|
|
|
|
|
'Authorization': 'Bearer '+token |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
var pipelines = { |
|
|
|
|
|
"querytokenFilter":'uWr4FKRqrmpCRkJ9WLuI0DNuDWOGTkfcSzyZkJirZvJwwFDffLWrraqzzSPLeuQqL3TF9', |
|
|
|
|
|
"filter":pipelinename |
|
|
|
|
|
} |
|
|
|
|
|
//var params = {
|
|
|
|
|
|
// pipeline: pipelines
|
|
|
|
|
|
// }
|
|
|
|
|
|
var params = { |
|
|
|
|
|
querytokenFilter:'uWr4FKRqrmpCRkJ9WLuI0DNuDWOGTkfcSzyZkJirZvJwwFDffLWrraqzzSPLeuQqL3TF9', |
|
|
|
|
|
filter:pipelinename |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var options = { |
|
|
|
|
|
params: params, |
|
|
|
|
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
instance.defaults.timeout = 30000; |
|
|
|
|
|
const res = await instance.get('/getuserplaygrounds',options); |
|
|
|
|
|
if(res.status == 200){ |
|
|
|
|
|
return res.data |
|
|
|
|
|
}else{ |
|
|
|
|
|
console.log("noerror: " + res) |
|
|
|
|
|
return await res.status |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch (err) { |
|
|
|
|
|
console.error("error: "+err); |
|
|
|
|
|
var error = new Object(); |
|
|
|
|
|
error.action = '401' |
|
|
|
|
|
return await error |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global.online='ob'; |
|
|
global.online='ob'; |
|
|
global.pipelines=[]; |
|
|
global.pipelines=[]; |
|
@ -285,71 +346,66 @@ global.pipelines=[]; |
|
|
// ***************************************************
|
|
|
// ***************************************************
|
|
|
|
|
|
|
|
|
app.get('/get_log', [ |
|
|
app.get('/get_log', [ |
|
|
//check('access_token').isLength({ min: 40 }),
|
|
|
check('access_token').isLength({ min: 40 }) |
|
|
//check('llo').isBase64()
|
|
|
|
|
|
], |
|
|
], |
|
|
cors(corsOptions), (req, res, next) => { |
|
|
cors(corsOptions), (req, res, next) => { |
|
|
|
|
|
|
|
|
(async() => { |
|
|
(async() => { |
|
|
var RES = new Object(); |
|
|
var RES = new Object(); |
|
|
RES.token = req.query["token"] |
|
|
RES.token = req.query["token"] |
|
|
RES.start = req.query["start"] |
|
|
RES.start = req.query["start"] |
|
|
RES.end = req.query["end"] |
|
|
RES.end = req.query["end"] |
|
|
RES.filter = req.query["filter"]; |
|
|
var isvalid = await checkToken(RES.token); |
|
|
var isvalid = await checkToken(RES.token); |
|
|
if(isvalid.action == 'ok'){ |
|
|
if(isvalid.action == 'ok'){ |
|
|
console.log("Authserver ok " + RES.token); |
|
|
console.log("Authserver ok " + RES.token); |
|
|
RES.error = 'ok' |
|
|
RES.error = 'ok' |
|
|
}else{ |
|
|
}else{ |
|
|
console.log("Authserver no " + RES.token); |
|
|
console.log("Authserver no " + RES.token); |
|
|
RES.error = 'no' |
|
|
RES.error = 'no' |
|
|
} |
|
|
} |
|
|
if(RES.error == 'ok'){ |
|
|
if(RES.error == 'ok'){ |
|
|
var resdata = await getuserpipelines(token,isvalid.user) |
|
|
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" |
|
|
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 = { |
|
|
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 { |
|
|
const db = client.db('fluent'); |
|
|
const db = client.db('fluent'); |
|
|
//db.collection('log', onCollection);
|
|
|
//usersession.SOCKET.user = isvalid.user
|
|
|
console.log(JSON.stringify('mongo connected')) |
|
|
//usersession.SOCKET.scope = isvalid.scope // space delimeter
|
|
|
|
|
|
//usersession.SOCKET.token = isvalid.token
|
|
|
db.collection('logs').find({}, {}).toArray() |
|
|
//db.collection('log', onCollection);
|
|
|
.then(item => { |
|
|
console.log(JSON.stringify('mongo connected')) |
|
|
console.log(item) |
|
|
var datestart = DateTime.fromObject(RES.start).toISODate() |
|
|
RES.error_msg = "ok" |
|
|
var dateend = DateTime.fromObject(RES.end).toISODate() |
|
|
RES.data = item |
|
|
var search_term = { $and: [ { date: { $gt: datestart } }, { date: { $lt: dateend } } ] }; |
|
|
res.json(RES) |
|
|
|
|
|
}) |
|
|
var resdataarray = [] |
|
|
.catch(err => { |
|
|
db.collection('logs').find({}, {}).toArray() |
|
|
console.error(err) |
|
|
.then(item => { |
|
|
RES.error_msg = err |
|
|
console.log(item) |
|
|
RES.data = stream |
|
|
for (let i in resdata.data) { |
|
|
res.json(RES) |
|
|
var resdataobj = {} |
|
|
}) |
|
|
resdataobj.lab = resdata.data[i].res25swarmlabname |
|
|
|
|
|
resdataarray.push(resdataobj) |
|
|
|
|
|
} |
|
|
|
|
|
RES.error_msg = "ok" |
|
|
|
|
|
RES.data = item |
|
|
|
|
|
RES.dataserver = resdataarray |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(err => { |
|
|
|
|
|
console.error(err) |
|
|
|
|
|
RES.error_msg = err |
|
|
|
|
|
RES.data = stream |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
const find = async () => { |
|
|
|
|
|
try { |
|
|
|
|
|
var stream = await db.collection('logs').find({}, {}) |
|
|
|
|
|
RES.error_msg = "ok" |
|
|
|
|
|
RES.data = stream |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
} catch(err => { |
|
|
|
|
|
RES.error_msg = err |
|
|
|
|
|
RES.data = stream |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await find() |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
//stream.on('data', function (doc) {
|
|
|
//stream.on('data', function (doc) {
|
|
|
// console.log(JSON.stringify(doc))
|
|
|
// console.log(JSON.stringify(doc))
|
|
@ -360,7 +416,7 @@ await find() |
|
|
}else{ |
|
|
}else{ |
|
|
|
|
|
|
|
|
RES.data = 'no' |
|
|
RES.data = 'no' |
|
|
RES.error_msg = "tokeni err" |
|
|
RES.error_msg = "token err" |
|
|
res.json(RES) |
|
|
res.json(RES) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|