diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 4bea50b6..2220c52c 100644 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -167,6 +167,72 @@ app.get("/length", cors(corsOptions), (req, res) => { ); }); +app.get("/services", cors(corsOptions), (req, res) => { + console.error("getting length of logs"); + + var url = "mongodb://mongo:27017/"; + + MongoClient.connect( + url, + { useNewUrlParser: true, useUnifiedTopology: true }, + function (err, db) { + if (err) throw err; + var dbo = db.db("fluentdb"); + dbo + .collection("test") + .find({}) + .toArray(function (err, result) { + if (err) throw err; + // EPIDI EXW NESTED JSON PREPEI NA TO KANW PARSE DUO FORES + var obj = JSON.parse(JSON.stringify(result)); + var services = []; + var flag = false; + obj.forEach((value) => { + if (flag == false) { + services.push(value.container_name); + flag = true; + } else { + var tmp = "none"; + var count = 0; + services.forEach((val) => { + var length = services.length; + + var found = false; + if ( + val != value.container_name && + count + 1 < length && + found == false + ) { + count++; + //services.push(value.container_name) + } else if ( + val != value.container_name && + count + 1 == length && + found == false + ) { + //found =true; + tmp = value.container_name; + } else if (val == value.container_name) { + found = true; + } + }); + + if (tmp != "none") { + services.push(tmp); + } + } + }); + var RES = new Object(); + + RES.data = services; + // console.log("Sending Data: " + jsonfinal); + res.json(RES.data); + db.close(); + }); + } + ); +}); + // Lefos - mongo test read app.get("/test", cors(corsOptions), (req, res) => { console.log("reading from db...."); @@ -222,6 +288,13 @@ app.get("/test2", cors(corsOptions), (req, res) => { var sorttmp1 = sort.split("|"); var sortname = sorttmp1[0]; var sortorder = sorttmp1[1]; + + // text to search in logs + var logtext = req.query["logtext"]; + // service to choose from all containers + var selected = req.query["selected"]; + + console.error("EXTRA PARAMS: " + logtext); //console.log("TEST LOG"); var url = "mongodb://mongo:27017/"; @@ -243,13 +316,31 @@ app.get("/test2", cors(corsOptions), (req, res) => { obj.forEach((value) => { if (value.log.includes("app_name")) { var tmp = JSON.parse(value.log); + var container_name = value.container_name; if (tmp.type == "out") { tmp.type = '