2023-10-31 20:38:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once(__DIR__ . "/monitor.php");
|
|
|
|
|
|
|
|
class Group {
|
|
|
|
|
2023-11-01 15:13:05 +01:00
|
|
|
public string $name;
|
|
|
|
public int $online = 0;
|
|
|
|
public array $monitors = [];
|
2023-10-31 20:38:31 +01:00
|
|
|
|
|
|
|
public function __construct(string $name) {
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function add_monitor(Monitor $monitor) {
|
|
|
|
array_push($this->monitors, $monitor);
|
|
|
|
if($monitor->is_online()) $this->online++;
|
|
|
|
}
|
|
|
|
|
2023-10-31 22:15:05 +01:00
|
|
|
public function get_online(): int {
|
|
|
|
return $this->online;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_total(): int {
|
|
|
|
return count($this->monitors);
|
2023-10-31 20:38:31 +01:00
|
|
|
}
|
|
|
|
|
2023-10-31 22:15:05 +01:00
|
|
|
public static function convert(array $oldGroup, array $heartbeat): Group {
|
|
|
|
$group = new Group($oldGroup["name"]);
|
|
|
|
foreach ($oldGroup["monitorList"] as $oldMonitor) {
|
|
|
|
$group->add_monitor(Monitor::convert($oldMonitor, $heartbeat));
|
|
|
|
}
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
2023-10-31 20:38:31 +01:00
|
|
|
}
|