Newer
Older
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
/**
* App\Server
*
* @property int $id
* @property int $organization_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string $name
* @property string $token
* @property string $read_token
* @property-read \App\Organization $organization
* @method static \Illuminate\Database\Eloquent\Builder|Server newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Server newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Server query()
* @method static \Illuminate\Database\Eloquent\Builder|Server whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereOrganizationId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereReadToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Server extends Model
{
protected $fillable = ["token"];
/**
* Last record from this server (used for caching).
* @var String
*/
private $last_record = null;
// \App\Sensor\DiskEvolution::class,
\App\Sensor\CPUtemperature::class,
$attributes["token"] = str_random(32);
parent::__construct($attributes);
}
public function records()
{
return $this->hasMany(Record::class);
}
public function lastRecord() : ?Record
$this->last_record = $this->records()->orderBy("time", "desc")->first();
if ($this->records_1day == null) {
$start = time() - 24 * 3600;
$this->records_1day = $this->records()->where("time", ">", $start)->get()->all();
public function hasData() : bool
{
return $this->lastRecord() != null;
}
if (is_null($this->info)) {
$this->info = new ServerInfo($this->lastRecord());
}
*
* @return \App\Status
} catch (\Exception $ex) {
Log::error("Sensor $sensor_name failed : " . $ex->getTraceAsString());
}
$sensorsNOK[] = $sensor;
}
}
return $sensorsNOK;
}
$sensors = [];
foreach (self::$sensors as $sensor) {
$sensors[] = new SensorWrapper(new $sensor($this), $records);
return [];
//return StatusChange::getLastChangesForServer($this->id, $count);
public static function id(int $id) : Server