mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-15 09:41:33 +01:00
Cron fixes
This commit is contained in:
@@ -47,6 +47,8 @@ a backup of your sqlite.db3 database.
|
||||
|
||||
-TODO: More info in admin page
|
||||
|
||||
-Fix duplicate entries for failed checks
|
||||
|
||||
### Version 0.9.1 (Beta)
|
||||
|
||||
-See uptime percent
|
||||
|
||||
37
cronchk.php
37
cronchk.php
@@ -1,33 +1,29 @@
|
||||
<?php
|
||||
require_once "functions.php";
|
||||
|
||||
function PING_IP($db_conn,$ID_C,$URL,$timestamp){
|
||||
function PING_IP($db_conn,$ID_C,$URL){
|
||||
if (strpos($URL, ":")){ //Si usa un puerto, dividir
|
||||
$host = explode(":", $URL)[0];
|
||||
$port = explode(":", $URL)[1];
|
||||
}else{$host=$URL;}
|
||||
$result = isset($port) ? ping($host,$port) : ping($host); //Ping IP with or without port
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','$result','$timestamp')");
|
||||
return $result; //Returns result
|
||||
}
|
||||
|
||||
function HTTP_CODE($db_conn,$ID_C,$URL,$Param,$timestamp){
|
||||
function HTTP_CODE($db_conn,$ID_C,$URL,$Param){
|
||||
$httpCode = httpCode($URL); //Code
|
||||
|
||||
$code = (int)$Param != 0 ? $Param : 200; //Establish the code test want to see
|
||||
|
||||
if ($httpCode == $code){ //Si es igual
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','0','$timestamp')");
|
||||
$ret = 0; //All right
|
||||
}else{ //Si no es igual (Incluye false)
|
||||
$httpCode = (int)$httpCode; //Force int
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`codeText`,`timestamp`) VALUES ('$ID_C','1','$httpCode','$timestamp')");
|
||||
$ret = 1;
|
||||
$ret = (int)$httpCode; //Code not 0 (And it's received code)
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function DATABASE_CONN($db_conn,$ID_C,$URL,$timestamp){
|
||||
function DATABASE_CONN($db_conn,$ID_C,$URL){
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $URL);
|
||||
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
||||
@@ -37,13 +33,10 @@ function DATABASE_CONN($db_conn,$ID_C,$URL,$timestamp){
|
||||
curl_close($ch);
|
||||
$result = htmlentities($body);
|
||||
if($result == 'OK'){
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','0','$timestamp')");
|
||||
$ret = 0;
|
||||
}else{ //Fail if it's not ok.
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','1','$timestamp')");
|
||||
$ret = 1;
|
||||
return 0;
|
||||
}else{ //Fail if it returns other than "OK".
|
||||
return 1;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,18 +50,28 @@ while ($site = dbw_fetch_array($db_conn,$sites)){
|
||||
|
||||
switch ($site['ID_TC']) {
|
||||
case '1': //Ping to IP:Port
|
||||
$exitC = PING_IP($db_conn,$ID_C,$site['URL'],time());
|
||||
$exitC = PING_IP($db_conn,$ID_C,$site['URL']);
|
||||
break;
|
||||
|
||||
case '2': //HttpCode
|
||||
$exitC = HTTP_CODE($db_conn,$ID_C,$site['URL'],$site['TCParam'],time());
|
||||
$exitC = HTTP_CODE($db_conn,$ID_C,$site['URL'],$site['TCParam']);
|
||||
break;
|
||||
|
||||
case '4': //MySQL|Database connect
|
||||
$exitC = DATABASE_CONN($db_conn,$ID_C,$site['URL'],time());
|
||||
$exitC = DATABASE_CONN($db_conn,$ID_C,$site['URL']);
|
||||
break;
|
||||
}
|
||||
}while($try <= 2 && $exitC == 1);
|
||||
$timestamp = time();
|
||||
if ($exitC == 0){ //Check successful
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','0','$timestamp')");
|
||||
}else if ($exitC == 1){ //Normal check failed
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`timestamp`) VALUES ('$ID_C','1','$timestamp')");
|
||||
}else{ //Other code of check failed
|
||||
dbw_query($db_conn, "INSERT INTO `CHKHIST` (`ID_C`,`code`,`errorText`,`timestamp`) VALUES ('$ID_C','1','$exitC','$timestamp')");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ function checkUptime($db_conn,$ID_C,$precision = 0){
|
||||
$count++;
|
||||
$err += $fila['code'];
|
||||
}
|
||||
echo $count."-";
|
||||
if ($count == 0){
|
||||
return '-1'; //No registers
|
||||
}else{
|
||||
|
||||
Reference in New Issue
Block a user