Skip to content

Commit

Permalink
Added Application downtime graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Aravindh-Muthuswamy committed Feb 2, 2021
1 parent fcc2664 commit bd03244
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extra.aaxt
admin/test.php
15 changes: 15 additions & 0 deletions admin/apivalai.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
':id'=>$data['equipid']
));
echo 'success';
}else if($data['act'] == 'retissues'){
$ret = khatral::khquery('SELECT down_time, down_id, down_name, down_mess, down_ip, down_group, COUNT(down_time) AS dupe_cnt FROM down_record WHERE down_ip=:ip AND down_group=:group
GROUP BY down_time
HAVING COUNT(down_time) >= 1
ORDER BY COUNT(down_id) DESC
LIMIT 5
', array(
':ip'=>$data['ip'],
':group'=>$data['group']
));
$retval = array();
foreach($ret as $p){
$retval[] = array('date'=>$p['down_time'], 'count'=>$p['dupe_cnt'], 'name'=>$p['down_name'], 'mess'=>$p['down_mess']);
}$expo = $retval;
echo(json_encode($expo));
}
else{
echo 'failure';
Expand Down
5 changes: 4 additions & 1 deletion admin/basicinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@
<div class="p-4" id="process">
<div class="card border bor-ten ">
<div class="card-header bg-dark text-white">Process Monitor</div>
<div class="card-body" id="incproc">
<div class="card-body">
<div id="incproc">
</div>
<a href="processrundet.php?ip=<?php echo $_GET['ip']; ?>&group=<?php echo $_GET['group']; ?>">View Details</a>
</div>
<div class="card-footer">Need information about this section click <a href="#">here</a></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion admin/dash.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function removeData(chart) {
};

var myPieChart = new Chart(ctx, {
type: 'doughnut',
type: 'pie',
data: data,
options: {
legend: {
Expand Down
52 changes: 52 additions & 0 deletions admin/processrundet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
$curr = 'dash';
include '../header.php';

?>
<div style="display: none;">
<input type="text" name="ip" id="ip" value="<?php echo $_GET['ip']; ?>">
<input type="text" name="group" id="group" value="<?php echo $_GET['group']; ?>">
</div>
<div class="container" style="margin-top: 5%;">
<a href="basicinfo.php?ip=<?php echo $_GET['ip']; ?>&group=<?php echo $_GET['group']; ?>#process" class="btn btn-dark" style="margin-left: 1.5%;">Back</a>
<!-- <a onclick="window.history.back();" href="#" class="btn btn-dark">Back</a> -->
<canvas id="myChart" width="15" height="15">Loading...</canvas>
<div id="app" style="margin-bottom: 5%; margin-top: 5%;"></div>
<script type="module" src="/valainet/js/components/issues/issues.js"></script>
</div>
<script>

var ctx = document.getElementById('myChart');
data = {
datasets: [{
data: [10,20],
fill: false,
borderColor: 'red',
label: "Number of alerts"
}],

// These labels appear in the legend and in the tooltips when hovering different arcs



};

var myPieChart = new Chart(ctx, {
type: 'line',
data: data,
label: "Errors",
options: {
title: {
display: true,
text: 'Alerts for the last 5 days'
},
scales: {
yAxes: [{
ticks: {
min: 0,
}
}]
}
}
});
</script>
4 changes: 3 additions & 1 deletion api.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@
// valai::UpdateAlerts($_POST['nm'], $_POST['mess'], $_POST['ip'], $_POST['group']);
}else{
if($_POST['stat'] != 'success'){
valai::InsertAlerts($_POST['nm'], "failure", $_POST['ip'], $_POST['group'], $_POST['stat']);
valai::InsertAlerts($_POST['nm'], "failure", $_POST['ip'], $_POST['group'], $_POST['stat']);
valai::insertDownRec($_POST['nm'], "failure", $_POST['ip'], $_POST['group']);
}else{
valai::DeleteAlerts($id);
}
Expand All @@ -274,6 +275,7 @@
}else{
if($_POST['stat'] != 'success'){
valai::InsertAlerts($_POST['nm'], "failure", $_POST['ip'], $_POST['group'], $_POST['stat']);
valai::insertDownRec($_POST['nm'], "failure", $_POST['ip'], $_POST['group']);
}
}
}else if($_POST['act'] == "updateipstat"){
Expand Down
13 changes: 13 additions & 0 deletions classes/dbOper.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@
}else{
echo '<br /><img src="../images/error.svg" style="width: 18px;">&nbsp;&nbsp;Error creating table ip_addr_moni ' . $conn->error;
}
$query = 'CREATE TABLE IF NOT EXISTS down_record(
down_id INTEGER NOT NULL AUTO_INCREMENT,
down_name VARCHAR(255) NOT NULL,
down_mess VARCHAR(255) NOT NULL,
down_ip VARCHAR(255) NOT NULL,
down_group VARCHAR(255) NOT NULL,
down_time VARCHAR(255) NOT NULL,
PRIMARY KEY(down_id))';
if($conn->query($query) == TRUE){
echo '<br /><img src="../images/tick.png" style="width: 22px;">&nbsp;&nbsp;Table down_record created successfully';
}else{
echo '<br /><img src="../images/error.svg" style="width: 18px;">&nbsp;&nbsp;Error creating table down_record ' . $conn->error;
}
echo '<br /><br />';
echo '<a href="../installation/second.php" class="btn btn-dark bor-ten float-left">&lt; Previous</a>
<a href="../installation/finish.php" class="btn btn-dark bor-ten float-right">Next &gt;</a>';
Expand Down
46 changes: 43 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,54 @@
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/softview.css">
<script src="js/jquery.min.js"></script>
<style>
.image {
-webkit-animation:spin 4s linear infinite;
-moz-animation:spin 4s linear infinite;
animation:spin 4s linear infinite;
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
</style>
<body class="bg-white">
<div class="text-center" style="margin-top: 10%;">
<img class="d-block mx-auto" src="images/valaiweb.svg" style="width: 256px;"><h2 class="text-center">Welcome to Valai</h2>
click <a href="loginhandle/login.php">here</a> to login
<div id="inc">
<img class="d-block mx-auto image" src="images/valaiweb.svg" style="width: 200px;">
</div>
<div id="inc1">
<img class="d-block mx-auto" src="images/valaiweb.svg" style="width: 200px;"><br><h1 class="text-center">Welcome to Valai</h1>
click <a href="loginhandle/login.php">here</a> to login
</div>

</div>
<?php
include 'classes/khatral.php';
try{
khatral::khquerypar('SELECT * FROM stat');
}catch(exception $ex){
header('Location: installation');
}
?>
?>
<script>
$('#inc1').hide();
$('#inc').show();
setInterval(function () {
$.post("api.php",
{
act:"sayhello",
ip:"192.168.1.5",
nm:"stat",
stat:"failure",
inbox:"influx"
},
function(data, status){
// alert(data);
if(data == 'hello'){
$('#inc').hide();
$('#inc1').show();
}
});
}, 1000);
</script>
11 changes: 11 additions & 0 deletions js/components/issues/issues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getObjID, renderHTML, renderText } from "../../avesengine/aves.js"
// import { retSoft } from './retsoft.js';
import { retissues } from './retissues.js';

window.addEventListener('DOMContentLoaded', (event) => {
// retequip();

retissues();
console.log('DOM fully loaded and parsed');

});
69 changes: 69 additions & 0 deletions js/components/issues/retissues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { getObjID, renderHTML, renderText } from "../../avesengine/aves.js"
function retissues(){
var ipaddr = getObjID('ip').value;
var group = getObjID('group').value;
const payload = {
act: 'retissues',
apikey: 'influx',
ip: ipaddr,
group: group
};
function sayHello(){
return "alert('hello 1')";
}
fetch('apivalai.php',{
method: 'post',
body: JSON.stringify(payload),
headers:{
'content-type': 'application/json'
}
}).then(function(response){
return response.json();
}).then(function(data){
function addData(chart, label, data) {
chart.data.labels.push(label);
chart.data.datasets.forEach((dataset) => {
dataset.data.push(data);
});
chart.update(0);
}

function removeData(chart) {
chart.data.labels.pop();
chart.data.datasets.forEach((dataset) => {
dataset.data.pop();
});
chart.update(0);
}
if(data.length >0){
console.log(data);
var output = '<table class="table table-striped">';
output += `<tr class="bg-dark text-white">
<th>SL.NO</th>
<th>Date</th>
<th>Count</th>
</tr>
`;
var count = 0;
removeData(myPieChart);
removeData(myPieChart);
data.forEach(function(comp){
count += 1;
addData(myPieChart, comp.date, comp.count);
output += `
<tr><td>${count}</td>
<td>${comp.date}</td>
<td>${comp.count}</td>
</tr>
`;

getObjID('app').innerHTML = output;
});
}else{
var output = '<h4 class="text-center text-danger">No value to show</h4>';
getObjID('app').innerHTML = output;
}
})
console.log("final");
}
export { retissues }
2 changes: 1 addition & 1 deletion loginhandle/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
</div>
<div class="col-xl-4"></div>
</div>
<h6 class="text-left fixed-bottom" style="">
<h6 class="text-center fixed-bottom" style="">
<p class="text-dark"> &copy; 2021 Valai Net. All Rights Reserved.|
<?php include '../valai.php'; valai::DisplayVerBuild() ?></p>
</h6>
Expand Down
14 changes: 14 additions & 0 deletions valai.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ public static function insertNONIT($nm, $coll, $des, $purdt, $expdt, $rendt, $co
':loc'=>$loc
));
}
public static function insertDownRec($nm, $mess, $ip, $group){
date_default_timezone_set('Asia/Kolkata');
$date = date('dmYhis', time());
$date1 = date('d/m/Y', time());
$date2 = date('d/m/Y h:i:s', time());
khatral::khquery('INSERT INTO down_record VALUES(NULL, :nm, :mess, :ip, :group, :tim)', array(
':nm'=>$nm,
':mess'=>$date2,
':ip'=>$ip,
':group'=>$group,
':tim'=>$date1
));
echo 'inserted';
}
//Display Build Information
public static function DisplayVerBuild(){
// Australia/Adelaide
Expand Down

0 comments on commit bd03244

Please sign in to comment.