1
0
mirror of https://gitlab.com/JKANetwork/CheckServer.git synced 2026-02-13 16:51:36 +01:00

Uptime in BSD..

This commit is contained in:
2020-10-17 18:13:21 +02:00
parent 41d6ba04c5
commit a0ae0df455

View File

@@ -244,7 +244,16 @@ function cron_uptime($db_conn,$time,$pc){
$datetime = date_create_from_format ('YmdHis', (int)$resu ); $datetime = date_create_from_format ('YmdHis', (int)$resu );
$timestamp = date_timestamp_get ($datetime); $timestamp = date_timestamp_get ($datetime);
$uptime = time() - $timestamp; $uptime = time() - $timestamp;
}else{ //Systemd and init goes same way }else if ($pc['SO'] == "BSD"){
$line = commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pc['Password'],'uptime');
$line = trim($line);
$line = preg_replace("/[[:blank:]]+/",' ',$line);
$part = explode(' ',$line);
//Example: 6:07PM up 2 days, 20:30, 1 user, load averages: 0.20, 0.16, 0.15.
$exphour = explode(':',$part[4]);
$uptime = $line[2]*86400 + $exphour[0]*3600 + $exphour[1] * 60;
}else{ //Linux is standard reading /proc/uptime
$uptime = explode('.',commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pc['Password'],'cat /proc/uptime'))[0]; $uptime = explode('.',commandbyssh($pc['IP'],$pc['SSHPort'],$pc['User'],$pc['Password'],'cat /proc/uptime'))[0];
if (DEBUG) if (DEBUG)
echo $uptime; echo $uptime;