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:
@@ -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 %}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -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')");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user