1
0
mirror of https://gitlab.com/JKANetwork/CheckServer.git synced 2026-02-15 17:51:39 +01:00

Preliminary BSD support

This commit is contained in:
2020-10-17 13:29:17 +02:00
parent 99ed1f862b
commit b907ed0765
4 changed files with 50 additions and 32 deletions

View File

@@ -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">
<input type="radio" name="so" value="LINUX" {%if server.SO == 'LINUX' %} checked="checked" {%endif%}> Linux
</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>

View File

@@ -70,7 +70,10 @@ while ($pc = dbw_fetch_array($db_conn,$pcsenabled)){
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 = 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
//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
}

View File

@@ -49,11 +49,13 @@ function cron_service($db_conn,$time,$pc,$service){
$status = $lastline != 0 ? 0 : 1; //3 is stop, 4 is non exist
break;
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 $?'));
$lastline = $lines[count($lines)-1];
$status = $lastline != 0 ? 0 : 1; //3 is stop (TODO see number)
break;
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']));
//$lastline = $lines[count($lines)-1];
if (count($lines)){
@@ -114,7 +116,8 @@ function cron_status($db_conn,$time,$pc){
$pass =$pc['Password'];
//Get Free RAM and total RAM
if ($pc['SO'] == "WINDOWS"){
switch ($pc['SO']){
case 'WINDOWS':
$wql = "select FreePhysicalMemory from Win32_OperatingSystem";
$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.'"');
$totalramexp = explode(PHP_EOL,$totalramwmic);
$detram = explode('|',$totalramexp[2])[1]; //Third line. Windows doesn't have tail an cut. This is in KB directly
}else{ //Systemd and init goes same way
break;
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');
$line = preg_replace("/[[:blank:]]+/",' ',$resu);
$part = explode(' ',$line);
@@ -139,6 +144,18 @@ function cron_status($db_conn,$time,$pc){
}else{ //Some systems do not have avaiable col
$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')");