mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-24 22:13:47 +01:00
Preliminary BSD support
This commit is contained in:
@@ -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')");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user