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

@@ -74,11 +74,11 @@
<td class=" ">
{{server.Freeram}}
</td>
<td {% if server.AlertHDD > 0 %} class="bg-danger" {% endif %}>
<td{% if server.AlertHDD > 0 %} class="bg-danger" {% endif %}>
{{server.HDDFastStats | raw}}
</td>
<td {% if server.SInactive > 0 %} class="bgcolor-warn" {%endif%}>
<td{% if server.SInactive > 0 %} class="bgcolor-warn" {%endif%}>
Monitorizando: {{server.SEnabled}}
{% if server.SEnabled > 0 %}<br>Funcionando: {{server.SActive}} {% endif %}
{% if server.SInactive > 0 %}<br>Parados: {{server.SInactive}} {% endif %}
@@ -86,11 +86,11 @@
</td>
<td>{{server.Uptime}}</td>
{% if server.Enabled == 1 %}
<td {% if server.Ping > -1 %}class="bgcolor-ok"{%else%}class="bgcolor-warn"{%endif%}>{{server.Ping}}ms</td>
<td{% if server.Ping > -1 %} class="bgcolor-ok"{%else%} class="bgcolor-warn"{%endif%}>{{server.Ping}}ms</td>
{% else %}
<td></td>
{% endif %}
<td class=" last"><a class="btn btn-success" href="admin.php?page=servers&id_serv={{server.ID_SERV}}">Ver</a>
<td class="last"><a class="btn btn-success" href="admin.php?page=servers&id_serv={{server.ID_SERV}}">Ver</a>
</td>
</tr>
{% endfor %}

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,31 +116,46 @@ function cron_status($db_conn,$time,$pc){
$pass =$pc['Password'];
//Get Free RAM and total RAM
if ($pc['SO'] == "WINDOWS"){
$wql = "select FreePhysicalMemory from Win32_OperatingSystem";
$freeramwmic = shell_exec('wmic -U \''.$pc['User'].'%'.$pass.'\' //'.$pc['IP'].' "'.$wql.'"');
switch ($pc['SO']){
case 'WINDOWS':
$wql = "select FreePhysicalMemory from Win32_OperatingSystem";
$freeramwmic = shell_exec('wmic -U \''.$pc['User'].'%'.$pass.'\' //'.$pc['IP'].' "'.$wql.'"');
//showdeb($freeramwmic);
//showdeb($freeramwmic);
$freeramexp = explode(PHP_EOL,$freeramwmic);
$freeram = explode('|',$freeramexp[2])[0]*1024; //Third line. Windows doesn't have tail -n+3 and cut. Also show in KB
$wql = "select TotalPhysicalMemory from Win32_ComputerSystem";
$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
$freeramexp = explode(PHP_EOL,$freeramwmic);
$freeram = explode('|',$freeramexp[2])[0]*1024; //Third line. Windows doesn't have tail -n+3 and cut. Also show in KB
$wql = "select TotalPhysicalMemory from Win32_ComputerSystem";
$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
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);
//Mem: total used free shared buff/cache available
$detram = $part[1]; //Total RAM
if (isset($part[6])){
$freeram = $part[6];//Avaiable
}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
}else{ //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);
//Mem: total used free shared buff/cache available
$detram = $part[1]; //Total RAM
if (isset($part[6])){
$freeram = $part[6];//Avaiable
}else{ //Some systems do not have avaiable col
$freeram = $part[4];//Free
}
$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')");