mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-25 22:43:47 +01:00
Optimize index and fix delete older checks from hist
This commit is contained in:
@@ -3,49 +3,31 @@
|
||||
require_once "connect.php";
|
||||
require_once 'lib/loadTwig.php';
|
||||
|
||||
/** Function checkStatus checks last "Checks" and their return
|
||||
Return can be:
|
||||
A value from 0-1-2 for status. 3 for Out Of Service. 3 and 4 can be turned up manually (
|
||||
0-Perfect
|
||||
1-Little problems
|
||||
2-Problems
|
||||
3-Out of service
|
||||
4-In maintenance
|
||||
255-Not results recolected (grey)
|
||||
*/
|
||||
function checkStatus($db_conn,$ID_C){
|
||||
//First, check if the status is marked to any manual value
|
||||
$manualPage = dbw_query_fetch_array($db_conn,"SELECT ID_C,manStatus FROM CHECKS WHERE ID_C='$ID_C'")['manStatus'];
|
||||
if ($manualPage != NULL){return $manualPage;}
|
||||
//If it's not manual-setted, see real status
|
||||
$result = checkUptime($db_conn,$ID_C);
|
||||
//Return status
|
||||
if ($result == 255){return 255;}
|
||||
if ($result > 95 && $result <= 100){return 0;}
|
||||
if ($result > 60 && $result <= 95){return 1;}
|
||||
if ($result > 10 && $result <= 60){return 2;}
|
||||
if ($result >= 0 && $result <= 10){return 3;} //If test fail much (90% fail)
|
||||
}
|
||||
|
||||
function checkUptime($db_conn,$ID_C,$precision = 0){
|
||||
if ($precision == 0){
|
||||
$time = time()-30*24*3600; //Last month
|
||||
$time = time()-30*7*3600; //Last week
|
||||
}else{
|
||||
$time = $precision;
|
||||
}
|
||||
if ($precision != 0){
|
||||
$good = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND code == 0 AND `timestamp` > $time")[0];
|
||||
$all = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND `timestamp` > $time")[0];
|
||||
}else{ //Uptime of all time
|
||||
$good = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C' AND code == 0")[0];
|
||||
$all = dbw_query_fetch_array($db_conn,"SELECT COUNT(*) FROM CHKHIST WHERE ID_C = '$ID_C'")[0];
|
||||
$res = dbw_query($db_conn,"SELECT code FROM CHKHIST WHERE ID_C='$ID_C' AND `timestamp` > $time");
|
||||
$count = 0;
|
||||
$err = 0;
|
||||
while ($fila = dbw_fetch_array($db_conn,$res)){
|
||||
$count++;
|
||||
$err += $fila['code'];
|
||||
}
|
||||
if ($all != 0){
|
||||
$uptime = round(($good/$all)*100,2);
|
||||
return $uptime;
|
||||
echo $count."-";
|
||||
if ($count == 0){
|
||||
return '-1'; //No registers
|
||||
}else{
|
||||
return 100;
|
||||
if ($err != 0){
|
||||
$uptime = (100 - round(($err/$count)*100,2));
|
||||
return $uptime;
|
||||
}else{
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -103,13 +85,12 @@ function RandomString($length)
|
||||
|
||||
/** 1 if its logued, 0 if not */
|
||||
function isLogued(){
|
||||
if (isset($_COOKIE['SessionID'])){
|
||||
if (isset($_SESSION['UserID'])){
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function requireLogin(){
|
||||
if (isLogued() == 0){
|
||||
die('You dont have admin rights'); //This blocks edit or create nothing if its not logued
|
||||
|
||||
Reference in New Issue
Block a user