Skip to content
Snippets Groups Projects
Commit 60e27153 authored by Caillat Michel's avatar Caillat Michel
Browse files

Added a route and a view for a monitoring of the FITS server (yafitss)

parent 9dc41909
Branches
No related tags found
No related merge requests found
var express = require('express');
var router = express.Router();
const request = require('request');
var yafitssHost = process.env.YAFITSS_HOST;
var yafitssPort = process.env.YAFITSS_PORT;
console.log("I'll collaborate with ..." + yafitssHost + ":" + yafitssPort + " ...for the FITS files services");
/*
** Prepare the communication with the FITS server ( yafitss )
*/
var clienthttp = {
server : "http://"+yafitssHost+":"+yafitssPort+"/artemix",
getDataBlockInfos : function(callback) {
request.post(this.server+"/getDataBlockInfos", function(error, response, body){
callback(error, response, body);
});
}
};
/*
** Define the http nodejs route
*/
router.get("/", function(req, res, next) {
console.log("monitor router.get("/", function(req, res, next) { : entering" );
clienthttp.getDataBlockInfos((error, response, body) => {
console.log("getDataBlockInfos callback : entering");
if (error ){
var message = error.toString();
res.setHeader('Content-type', 'application/json');
res.send(JSON.stringify({"status":false, "message": message}));
}
else if (response["statusCode"] == 500) {
res.send(JSON.stringify({status: false, message: response["body"]}));
}
else if (response["body"]["status"] == false) {
res.render("error", {message: response["body"]["message"], error : {"status" : "", "stack" : ""}});
}
else {
let x = JSON.parse(response["body"])
console.log(JSON.parse(response["body"]));
res.render("monitor", {dataBlockInfos: x["result"]});
}
console.log("getDataBlockInfos callback : exiting");
});
console.log("monitor router.get("/", function(req, res, next) { : exiting" );
});
module.exports = router;
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
<head>
<body>
<h2> FITS server infos </h2>
<table id="dataBlockInfos" class="table table-striped table-bordered" style="width:100%">
</table>
<body>
<script>
var dataBlockInfos = new Array();
var titlePassed = false;
var titles;
<% dataBlockInfos.forEach(function(dataBlockInfo) {%>
if (!titlePassed) {
title = ("<%=dataBlockInfo%>".split(","));
titlePassed = true;
}
else {
dataBlockInfos.push("<%=dataBlockInfo%>".split(","));
}
<%})%>
console.log(JSON.stringify(dataBlockInfos, 0, 4));
</script>
<script>
$(document).ready(function () {
$('#dataBlockInfos').DataTable({
data: dataBlockInfos
});
});
</script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment