suseendhiran

This commit is contained in:
suseendhiran17 2022-09-12 10:03:06 +05:30
parent 126ad3deb9
commit d756ed3e58
6 changed files with 132 additions and 54 deletions

View File

@ -5,18 +5,20 @@ const request = require('request');
// api status check Api // api status check Api
exports.APIstatus = async (req, res) => exports.APIstatus = async (req, res) =>
{ {
try try
{ {
token_data = await TestHelper.TokenAPI();
apiArr = [ ]; apiArr = [ ];
serverArr = [ ]; serverArr = [ ];
dbArr = [ ];
StatusFailArr = [ ]; StatusFailArr = [ ];
ApiData = JSON.parse(process.env.STATUSARRAY); ApiData = await JSON.parse(process.env.STATUSARRAY);
token_data = await TestHelper.TokenAPI(); if (token_data.status == 200) { apiArr.push({ "Api" : "Token API" , "StatusCode" : token_data.status , "Status" : "Up"}); }
if (token_data.status == 200) { apiArr.push({ "Api" : "Token Api" , "StatusCode" : token_data.status , "Status" : "Up"}); } else { apiArr.push({ "Api" : "Token API" , "StatusCode" : token_data.status , "Status" : "Down"}); StatusFailArr.push(token_data.status) }
else { apiArr.push({ "Api" : "Token Api" , "StatusCode" : token_data.status , "Status" : "Down"}); StatusFailArr.push(token_data.status) }
for (const object of ApiData) for (const object of ApiData)
{ {
reqObj = { }; reqObj = { };
@ -28,16 +30,18 @@ exports.APIstatus = async (req, res) =>
request(reqObj, async function (error, response, body) { request(reqObj, async function (error, response, body) {
if (response.statusCode == 200) if (response.statusCode == 200)
{ {
if (object.type == "api") { apiArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Up"}); } if (object.type == "api") { apiArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Up"}); }
else { serverArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Up"}); } if (object.type == "server") { serverArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Up"}); }
if (object.type == "db") { dbArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Up"}); }
} }
if (response.statusCode != 200) if (response.statusCode != 200)
{ {
if (object.type == "api") { apiArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Down"}); StatusFailArr.push(token_data.status) } if (object.type == "api") { apiArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Down"}); StatusFailArr.push(response.statusCode) }
else { serverArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Down"}); StatusFailArr.push(token_data.status) } if (object.type == "server") { serverArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Down"}); StatusFailArr.push(response.statusCode) }
if (object.type == "db") { dbArr.push({ "Api" : object.name , "StatusCode" : response.statusCode , "Status" : "Down"}); StatusFailArr.push(response.statusCode) }
} }
if (ApiData.length + 1 == apiArr.length + serverArr.length) { if (ApiData.length + 1 == apiArr.length + serverArr.length + dbArr.length) {
await TestHelper.HTML( req , res , apiArr , serverArr , StatusFailArr ); await TestHelper.HTML( req , res , apiArr , serverArr , dbArr , StatusFailArr );
} }
}) })
}; };
@ -60,10 +64,10 @@ exports.SingleApiStatus = async (req, res) =>
ApiName = req.body.api; ApiName = req.body.api;
ApiData = JSON.parse(process.env.STATUSARRAY); ApiData = JSON.parse(process.env.STATUSARRAY);
token_data = await TestHelper.TokenAPI(); token_data = await TestHelper.TokenAPI();
if (ApiName == "Token Api") if (ApiName == "Token API")
{ {
if (token_data.status == 200) { res.send({ "Api" : "Token Api" , "StatusCode" : token_data.status , "Status" : "Up" , "success" : true}) } if (token_data.status == 200) { res.send({ "Api" : "Token API" , "StatusCode" : token_data.status , "Status" : "Up" , "success" : true}) }
else { res.send({ "Api" : "Token Api" , "StatusCode" : token_data.status , "Status" : "Down" , "success" : true}) } else { res.send({ "Api" : "Token API" , "StatusCode" : token_data.status , "Status" : "Down" , "success" : true}) }
} }
else else
{ {

View File

@ -16,7 +16,6 @@ module.exports = app => {
// routes started here // routes started here
app.use('/api', router); app.use('/api', router);

View File

@ -23,33 +23,32 @@ function TokenAPI()
} }
} }
function HTML( req , res , apiStatusArr , serverStatusArr , apiFailStatusArr )
function HTML( req , res , apiStatusArr , serverStatusArr , dbStatusArr , apiFailStatusArr )
{ {
try try
{ {
date = new Date().toLocaleTimeString(); date = new Date().toLocaleTimeString();
if (apiFailStatusArr.length == 0) if (apiFailStatusArr.length == 0)
{ {
res.render( 'status' , { data : apiStatusArr , data1 : serverStatusArr , down : 0 , date : date } , function (err, html ) { res.render( 'status' , { data : apiStatusArr , data1 : serverStatusArr , data2 : dbStatusArr , down : 0 , date : date } , function (err, html ) {
res.send(html) res.send(html)
}) })
} }
else else
{ {
res.render( 'status' , { data : apiStatusArr , data1 : serverStatusArr , down : 1 , date : date } , function (err, html ) { res.render( 'status' , { data : apiStatusArr , data1 : serverStatusArr , data2 : dbStatusArr , down : 1 , date : date } , function (err, html ) {
res.send(html) res.send(html)
}) })
} }
} }
catch (error) { catch (error) {
console.log(error); console.log(error);
} }
} }
module.exports = { module.exports = {
TokenAPI : TokenAPI, TokenAPI : TokenAPI,
HTML : HTML HTML : HTML
} }

View File

@ -3,32 +3,25 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- CSS -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/alertifyjs@1.13.1/build/css/alertify.min.css" />
<!-- Default theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/alertifyjs@1.13.1/build/css/themes/default.min.css" />
<!-- JavaScript -->
<script src="//cdn.jsdelivr.net/npm/alertifyjs@1.13.1/build/alertify.min.js"></script>
<script> <script>
setInterval(function() { setInterval(function() {
window.location.reload(); window.location.reload();
}, 300000); }, 300000);
</script> </script>
<style> <style>
/* table, th, td {
border:1px solid rgb(20, 2, 2);
padding: 8px;
border-bottom: 1px solid #DDD;
text-align: center;
}
table {
border-collapse: collapse;
border: 2px solid #161614;
width: 87%;
}
th {
font-size: 20px;
}
th , h1 , td {
font-family: Arial, Helvetica, sans-serif;
} */
b { b {
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
color: #3bd671 !important color: #3bd671 !important;
}
b1 {
font-family: Arial, Helvetica, sans-serif;
color: red
} }
.dot { .dot {
height: 25px; height: 25px;
@ -153,6 +146,24 @@
left: 220px; left: 220px;
top: 100px; top: 100px;
} }
.header6 {
background: white;
text-align: left;
padding: 10px 0;
width: 80%;
position: relative;
left: 220px;
top: 100px;
}
.header7 {
background: white;
text-align: left;
padding: 10px 0;
width: 80%;
position: relative;
left: 220px;
top: 100px;
}
.uk-text-primary { .uk-text-primary {
color: #3bd671 !important; color: #3bd671 !important;
} }
@ -166,24 +177,28 @@
width: 87%; width: 87%;
} }
#tab-des td, #tab-des th { #tab-des th , #tab-des td {
border: 1px solid #ddd; border: 1px solid #ddd;
width: 0em; width: 0em;
padding: 8px; padding: 8px;
text-align: center;
} }
#tab-des tr:nth-child(even){background-color: #f2f2f2;} #tab-des tr:nth-child(even){background-color: #f2f2f2;}
#tab-des tr:hover {background-color: #ddd;} #tab-des tr:hover {
background-color: #ddd;
}
#tab-des th { #tab-des th {
padding-top: 12px; padding-top: 12px;
padding-bottom: 12px; padding-bottom: 12px;
text-align: left; text-align: center;
background-color: #04AA6D; background-color: #04AA6D;
color: white; color: white;
} }
#tab-des-2 { #tab-des-2 {
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse; border-collapse: collapse;
@ -195,6 +210,7 @@
border: 1px solid #ddd; border: 1px solid #ddd;
width: 0em; width: 0em;
padding: 8px; padding: 8px;
text-align: center;
} }
#tab-des-2 tr:nth-child(even){background-color: #f2f2f2;} #tab-des-2 tr:nth-child(even){background-color: #f2f2f2;}
@ -204,10 +220,21 @@
#tab-des-2 th { #tab-des-2 th {
padding-top: 12px; padding-top: 12px;
padding-bottom: 12px; padding-bottom: 12px;
text-align: left; text-align: center;
background-color: #04AA6D; background-color: #04AA6D;
color: white; color: white;
} }
.xd-content .xd-body .xd-body-inner {
max-height: unset;
}
.xd-content .xd-body p {
color: #f0f;
text-shadow: 0 0 5px rgba(0, 0, 0, 0.75);
}
.xd-content .xd-button.xd-ok {
background: #734caf;
}
</style> </style>
<title class="bi-alarm">Status</title> <title class="bi-alarm">Status</title>
<% if ( down == 0) { %> <% if ( down == 0) { %>
@ -220,7 +247,7 @@
<body> <body>
<div class = "header"> <div class = "header">
<div> <div>
<h1 class="with-in-header">Service status</h1> <h1 class="with-in-header">Service Status</h1>
<div class="last-update"> <div class="last-update">
Last updated <%=date %> Last updated <%=date %>
</div> </div>
@ -236,12 +263,12 @@
<% } %> <% } %>
</div> </div>
</div> </div>
<div class = "header2"><h1><i style="font-size:18px;color:black"></i> <strong>Api Services</strong></h1></div> <div class = "header2"><h1><i style="font-size:18px;color:black"></i> <strong>API Services</strong></h1></div>
<div class = "header3"> <div class = "header3">
<table id="tab-des"> <table id="tab-des">
<thead> <thead>
<tr> <tr>
<th>Api</th> <th>API</th>
<th>StatusCode</th> <th>StatusCode</th>
<th>Status</th> <th>Status</th>
<th>Refresh</th> <th>Refresh</th>
@ -249,8 +276,8 @@
</thead> </thead>
<% data.forEach(function(status , index ) { %> <% data.forEach(function(status , index ) { %>
<tbody> <tbody>
<tr class=index> <tr>
<td><%=status.Api %></td> <td><div style="text-align: left;"><%=status.Api %></div></td>
<td><%=status.StatusCode %></td> <td><%=status.StatusCode %></td>
<td> <td>
<% if( status.Status == "Up") { %> <% if( status.Status == "Up") { %>
@ -260,7 +287,7 @@
<i class="dot1" style="font-size:14px;color: red;height:15px;width:15px;"></i> <b1><%=status.Status %></b1> <i class="dot1" style="font-size:14px;color: red;height:15px;width:15px;"></i> <b1><%=status.Status %></b1>
<% } %> <% } %>
</td> </td>
<td><a href="#" class="btn btn-info btn-sm" style="color: white;background-color: #3bd671 !important;">Refresh</a></td> <td class=index><a href="#" class="btn btn-info btn-sm" style="color: white;background-color: #3bd671 !important;">Refresh</a></td>
</tr> </tr>
</tbody> </tbody>
<% }) %> <% }) %>
@ -279,8 +306,8 @@
</thead> </thead>
<% data1.forEach(function(status , index ) { %> <% data1.forEach(function(status , index ) { %>
<tbody> <tbody>
<tr class=index> <tr>
<td><%=status.Api %></td> <td><div style="text-align: left;"><%=status.Api %></div></td>
<td><%=status.StatusCode %></td> <td><%=status.StatusCode %></td>
<td> <td>
<% if( status.Status == "Up") { %> <% if( status.Status == "Up") { %>
@ -290,7 +317,37 @@
<i class="dot1" style="font-size:14px;color: red;height:15px;width:15px;"></i> <b1><%=status.Status %></b1> <i class="dot1" style="font-size:14px;color: red;height:15px;width:15px;"></i> <b1><%=status.Status %></b1>
<% } %> <% } %>
</td> </td>
<td><a href="#" class="btn btn-info btn-sm" style="color: white;background-color: #3bd671 !important;">Refresh</a></td> <td class=index><a href="#" class="btn btn-info btn-sm" style="color: white;background-color: #3bd671 !important;">Refresh</a></td>
</tr>
</tbody>
<% }) %>
</table>
</div>
<div class = "header6"><h1><i style="font-size:18px;color:black"></i> <strong>Database Services</strong></h1></div>
<div class = "header7">
<table id="tab-des-2">
<thead>
<tr>
<th>Database</th>
<th>StatusCode</th>
<th>Status</th>
<th>Refresh</th>
</tr>
</thead>
<% data2.forEach(function(status , index ) { %>
<tbody>
<tr>
<td><div style="text-align: left;"><%=status.Api %></div></td>
<td><%=status.StatusCode %></td>
<td>
<% if( status.Status == "Up") { %>
<i class="dot" style="font-size:14px;color: #3bd671 !important;height:15px;width:15px;"></i> <b><%=status.Status %></b>
<% } %>
<% if( status.Status == "Down") { %>
<i class="dot1" style="font-size:14px;color: red;height:15px;width:15px;"></i> <b1><%=status.Status %></b1>
<% } %>
</td>
<td class=index><a href="#" class="btn btn-info btn-sm" style="color: white;background-color: #3bd671 !important;">Refresh</a></td>
</tr> </tr>
</tbody> </tbody>
<% }) %> <% }) %>
@ -309,7 +366,10 @@
success: function(response) { success: function(response) {
if (response.success == true) if (response.success == true)
{ {
alert(response.Api+" called"); alertify.alert(response.Api+" called", () => {
// alertify.message('OK');
}).set('title', 'Status')
// alert(response.Api+" called");
if (response.Status == "Up") if (response.Status == "Up")
{ {
var success = '<i class="dot" style="font-size:14px;color: #3bd671 !important;height:15px;width:15px;"></i> <b>'+response.Status+'</b>' var success = '<i class="dot" style="font-size:14px;color: #3bd671 !important;height:15px;width:15px;"></i> <b>'+response.Status+'</b>'

15
package-lock.json generated
View File

@ -22,6 +22,7 @@
"sequelize": "^6.6.5", "sequelize": "^6.6.5",
"swagger-jsdoc": "^6.1.0", "swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.1.6", "swagger-ui-express": "^4.1.6",
"sweetalert2": "^11.4.32",
"winston": "^3.3.3", "winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5" "winston-daily-rotate-file": "^4.5.5"
}, },
@ -10676,6 +10677,15 @@
"express": ">=4.0.0" "express": ">=4.0.0"
} }
}, },
"node_modules/sweetalert2": {
"version": "11.4.32",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.4.32.tgz",
"integrity": "sha512-fcXWPzWjqYoLqlfPLL4GHpZDZr4Lm7opkaADKAD1LDM4KHJ5ZHN/8/Les5HWP7+yl+0mrqHHkbsSxjXdvDHHlg==",
"funding": {
"type": "individual",
"url": "https://sweetalert2.github.io/#donations"
}
},
"node_modules/tapable": { "node_modules/tapable": {
"version": "0.2.9", "version": "0.2.9",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-0.2.9.tgz", "resolved": "https://registry.npmjs.org/tapable/-/tapable-0.2.9.tgz",
@ -21473,6 +21483,11 @@
"swagger-ui-dist": ">=4.1.3" "swagger-ui-dist": ">=4.1.3"
} }
}, },
"sweetalert2": {
"version": "11.4.32",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.4.32.tgz",
"integrity": "sha512-fcXWPzWjqYoLqlfPLL4GHpZDZr4Lm7opkaADKAD1LDM4KHJ5ZHN/8/Les5HWP7+yl+0mrqHHkbsSxjXdvDHHlg=="
},
"tapable": { "tapable": {
"version": "0.2.9", "version": "0.2.9",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-0.2.9.tgz", "resolved": "https://registry.npmjs.org/tapable/-/tapable-0.2.9.tgz",

View File

@ -22,6 +22,7 @@
"sequelize": "^6.6.5", "sequelize": "^6.6.5",
"swagger-jsdoc": "^6.1.0", "swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.1.6", "swagger-ui-express": "^4.1.6",
"sweetalert2": "^11.4.32",
"winston": "^3.3.3", "winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5" "winston-daily-rotate-file": "^4.5.5"
}, },