mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-17 18:51:35 +01:00
Preliminary BSD support
This commit is contained in:
@@ -55,6 +55,9 @@
|
|||||||
<label class="btn btn-default {%if server.SO == 'LINUX' %} active {%endif%}" data-toggle-class="btn-primary" data-toggle-passive-class="btn-default" data-toggle="tooltip" data-placement="top" title="Sistemas Linux. Soporta Systemd y service, y como fallback por procesos">
|
<label class="btn btn-default {%if server.SO == 'LINUX' %} active {%endif%}" data-toggle-class="btn-primary" data-toggle-passive-class="btn-default" data-toggle="tooltip" data-placement="top" title="Sistemas Linux. Soporta Systemd y service, y como fallback por procesos">
|
||||||
<input type="radio" name="so" value="LINUX" {%if server.SO == 'LINUX' %} checked="checked" {%endif%}> Linux
|
<input type="radio" name="so" value="LINUX" {%if server.SO == 'LINUX' %} checked="checked" {%endif%}> Linux
|
||||||
</label>
|
</label>
|
||||||
|
<label class="btn btn-default {%if server.SO == 'BSD' %} active {%endif%}" data-toggle-class="btn-primary" data-toggle-passive-class="btn-default" data-toggle="tooltip" data-placement="top" title="Sistemas BSD. Soporta FreeBSD, FreeNAS,..., Usa procesos para saber el estado de un servicio">
|
||||||
|
<input type="radio" name="so" value="BSD" {%if server.SO == 'BSD' %} checked="checked" {%endif%}> BSD
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -70,7 +70,10 @@ while ($pc = dbw_fetch_array($db_conn,$pcsenabled)){
|
|||||||
cron_status($db_conn,$time,$pc);
|
cron_status($db_conn,$time,$pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get type of linux
|
||||||
|
if ($pc['SO'] == 'LINUX'){ //Only update if needs (Todo? Well, as is only checks if no SYSTEMD or SERVICE found)
|
||||||
|
detect_linux($pc);
|
||||||
|
}
|
||||||
|
|
||||||
//Services
|
//Services
|
||||||
$services = dbw_query($db_conn,"SELECT ID_SERV,`Name` FROM S_SERVICES WHERE ID_SERV='$pc[ID_SERV]' AND `Enabled`=1 AND `Type`='SERVICE'");
|
$services = dbw_query($db_conn,"SELECT ID_SERV,`Name` FROM S_SERVICES WHERE ID_SERV='$pc[ID_SERV]' AND `Enabled`=1 AND `Type`='SERVICE'");
|
||||||
@@ -87,11 +90,6 @@ while ($pc = dbw_fetch_array($db_conn,$pcsenabled)){
|
|||||||
cron_uptime($db_conn,$time,$pc); //Uptime
|
cron_uptime($db_conn,$time,$pc); //Uptime
|
||||||
|
|
||||||
|
|
||||||
//Get type of linux
|
|
||||||
if ($pc['SO'] == 'LINUX'){ //Only update if needs (Todo?)
|
|
||||||
detect_linux($pc);
|
|
||||||
}
|
|
||||||
|
|
||||||
cron_getversion($db_conn,$pc); //Windows/Linux version name
|
cron_getversion($db_conn,$pc); //Windows/Linux version name
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,13 @@ function cron_service($db_conn,$time,$pc,$service){
|
|||||||
$status = $lastline != 0 ? 0 : 1; //3 is stop, 4 is non exist
|
$status = $lastline != 0 ? 0 : 1; //3 is stop, 4 is non exist
|
||||||
break;
|
break;
|
||||||
case 'LINUX_SERVICE':
|
case 'LINUX_SERVICE':
|
||||||
|
case 'BSD_SERVICE': //BSD Has too the service command, but I don't know if it's same as Linux
|
||||||
$lines = explode(PHP_EOL,commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pc['Password'],'service '.$service['Name'].' status;echo $?'));
|
$lines = explode(PHP_EOL,commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pc['Password'],'service '.$service['Name'].' status;echo $?'));
|
||||||
$lastline = $lines[count($lines)-1];
|
$lastline = $lines[count($lines)-1];
|
||||||
$status = $lastline != 0 ? 0 : 1; //3 is stop (TODO see number)
|
$status = $lastline != 0 ? 0 : 1; //3 is stop (TODO see number)
|
||||||
break;
|
break;
|
||||||
case 'LINUX': //Proceso
|
case 'LINUX': //Proceso
|
||||||
|
case 'BSD': //BSD Uses process too
|
||||||
$lines = explode(PHP_EOL,commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pc['Password'],'ps -A | grep '.$service['Name']));
|
$lines = explode(PHP_EOL,commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pc['Password'],'ps -A | grep '.$service['Name']));
|
||||||
//$lastline = $lines[count($lines)-1];
|
//$lastline = $lines[count($lines)-1];
|
||||||
if (count($lines)){
|
if (count($lines)){
|
||||||
@@ -114,7 +116,8 @@ function cron_status($db_conn,$time,$pc){
|
|||||||
$pass =$pc['Password'];
|
$pass =$pc['Password'];
|
||||||
|
|
||||||
//Get Free RAM and total RAM
|
//Get Free RAM and total RAM
|
||||||
if ($pc['SO'] == "WINDOWS"){
|
switch ($pc['SO']){
|
||||||
|
case 'WINDOWS':
|
||||||
$wql = "select FreePhysicalMemory from Win32_OperatingSystem";
|
$wql = "select FreePhysicalMemory from Win32_OperatingSystem";
|
||||||
$freeramwmic = shell_exec('wmic -U \''.$pc['User'].'%'.$pass.'\' //'.$pc['IP'].' "'.$wql.'"');
|
$freeramwmic = shell_exec('wmic -U \''.$pc['User'].'%'.$pass.'\' //'.$pc['IP'].' "'.$wql.'"');
|
||||||
|
|
||||||
@@ -127,8 +130,10 @@ function cron_status($db_conn,$time,$pc){
|
|||||||
$totalramwmic = shell_exec('wmic -U '.$pc['User'].'%'.$pass.' //'.$pc['IP'].' "'.$wql.'"');
|
$totalramwmic = shell_exec('wmic -U '.$pc['User'].'%'.$pass.' //'.$pc['IP'].' "'.$wql.'"');
|
||||||
$totalramexp = explode(PHP_EOL,$totalramwmic);
|
$totalramexp = explode(PHP_EOL,$totalramwmic);
|
||||||
$detram = explode('|',$totalramexp[2])[1]; //Third line. Windows doesn't have tail an cut. This is in KB directly
|
$detram = explode('|',$totalramexp[2])[1]; //Third line. Windows doesn't have tail an cut. This is in KB directly
|
||||||
|
break;
|
||||||
}else{ //Systemd and init goes same way
|
case 'LINUX_SYSTEMD':
|
||||||
|
case 'LINUX_SERVICE':
|
||||||
|
case 'LINUX': //Systemd and init goes same way
|
||||||
$resu = commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pass,'free -b | tail -n+2 | head -1');
|
$resu = commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pass,'free -b | tail -n+2 | head -1');
|
||||||
$line = preg_replace("/[[:blank:]]+/",' ',$resu);
|
$line = preg_replace("/[[:blank:]]+/",' ',$resu);
|
||||||
$part = explode(' ',$line);
|
$part = explode(' ',$line);
|
||||||
@@ -139,6 +144,18 @@ function cron_status($db_conn,$time,$pc){
|
|||||||
}else{ //Some systems do not have avaiable col
|
}else{ //Some systems do not have avaiable col
|
||||||
$freeram = $part[4];//Free
|
$freeram = $part[4];//Free
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case 'BSD':
|
||||||
|
$resu = commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pass,'sysctl hw.physmem');
|
||||||
|
$line = preg_replace("/[[:blank:]]+/",' ',$resu);
|
||||||
|
$part = explode(' ',$line);
|
||||||
|
//Mem: total used free shared buff/cache available
|
||||||
|
$detram = $part[1]; //Total RAM
|
||||||
|
|
||||||
|
$resu = commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pass,'vmstat | grep -E \'([0-9]+\w+)+\' | awk \'{print $5}\'');
|
||||||
|
$line = preg_replace("/[[:blank:]]+/",' ',$resu);
|
||||||
|
$freeram = $line; //Free RAM
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
dbw_query($db_conn,"INSERT INTO S_HISTRAM (ID_SERV,`Timestamp`,Freeram,Detram) VALUES ('$pc[ID_SERV]','$time','$freeram','$detram')");
|
dbw_query($db_conn,"INSERT INTO S_HISTRAM (ID_SERV,`Timestamp`,Freeram,Detram) VALUES ('$pc[ID_SERV]','$time','$freeram','$detram')");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user