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