Newer
Older
/**
* Represents a change of status, that will be saved in MongoDB.
*
* @author tibo
*/
public $server_id = 0;
public $status = 0;
public $time = 0;
public $id;
if ($array == null) {
return;
}
$fields = ["server_id", "status", "time"];
foreach ($fields as $field) {
if (isset($array[$field])) {
$this->$field = $array[$field];
}
}
return $this;
}
public function statusName()
{
return \App\Server::getNameForStatus($this->status);
}
return AbstractSensor::getBadgeForStatus($this->status);
}
public function save()
$this->time = time();
$data = [
"time" => $this->time,
"server_id" => $this->server_id,
"status" => $this->status,
];
$collection = \Mongo::get()->monitoring->statuschanges;
$r = $collection->insertOne($data);
$this->id = $r->getInsertedId()->__toString();
public static function getLastChangesForServer(int $server_id, int $count) : array
{
$collection = \Mongo::get()->monitoring->statuschanges;
$records = $collection->find(
["server_id" => $server_id],
["limit" => $count, "sort" => ["_id" => -1]]
);
$changes = [];
foreach ($records as $record) {
$changes[] = (new StatusChange())->parse($record);
}
return $changes;
}
public static function getLastChangeForServer(int $server_id) : StatusChange
{
$collection = \Mongo::get()->monitoring->statuschanges;
$record = $collection->findOne(
["server_id" => $server_id],
["sort" => ["_id" => -1]]
);
$change = new StatusChange();
$change->server_id = $server_id;