Improved maintenance mode & small changes

This commit is contained in:
Filip Znachor 2023-11-02 18:32:38 +01:00
parent ce500b6357
commit 6b9f1cccb0
11 changed files with 41 additions and 43 deletions

View file

@ -3,21 +3,11 @@
require_once("../vendor/autoload.php");
function globalstatus() {
return new \Twig\TwigFilter('globalstatus', function (int $online, int $total) {
if ($online == $total) return 1;
elseif ($online == 0) return 0;
else return 2;
});
}
function globalstatustext() {
return new \Twig\TwigFilter('globalstatustext', function (int $status) {
$msgs = [
"none",
"all",
"some"
];
return "header.title.$msgs[$status]";
return new \Twig\TwigFilter('globalstatus', function (array $stats, int $total) {
if ($stats[3] > 0) return 3;
if ($stats[1] == $total) return 1;
if ($stats[1] == 0) return 0;
return 2;
});
}

View file

@ -35,7 +35,6 @@ class UptimeStatus {
$twig = new \Twig\Environment($loader, $twig_config);
$twig->addFilter(\Filters\globalstatus());
$twig->addFilter(\Filters\globalstatustext());
$twig->addFilter(\Filters\statusicon());
$locale = new \Locale\Locale($this->cfg("default_language"));

View file

@ -1,13 +1,15 @@
{
"header.title.all": "Všechny služby běží",
"header.title.some": "Některé služby neběží",
"header.title.none": "Všechny služby jsou offline",
"header.title.1": "Všechny služby běží",
"header.title.0": "Všechny služby jsou offline",
"header.title.2": "Některé služby neběží",
"header.title.3": "Právě probíhá údržba",
"header.updated": "Poslední aktualizace {{date}}.",
"monitor.uptime": "<b>{{pct}}%</b> uptime",
"status.1": "V pořádku",
"status.0": "Výpadek",
"status.2": "Problém",
"status.3": "Údržba",
"heartbeat.ping": "Odezva: {{ping}}ms",
"dateformat": "j. m. Y G:i",
"footer.poweredby": "Poháněno projektem <b><a href=\"{{link}}\" target=\"_blank\">Uptime Status</a></b>"
}

View file

@ -1,13 +1,15 @@
{
"header.title.all": "All services are online",
"header.title.some": "Some services are down",
"header.title.none": "All services are down",
"header.title.1": "All services are online",
"header.title.0": "All services are down",
"header.title.2": "Some services are down",
"header.title.3": "Under Maintenance",
"header.updated": "Last updated on {{date}}.",
"monitor.uptime": "<b>{{pct}}%</b> uptime",
"status.1": "Operational",
"status.0": "Downtime",
"status.2": "Problem",
"status.3": "Maintenance",
"heartbeat.ping": "Ping: {{ping}}ms",
"dateformat": "M j, Y, g:i a",
"footer.poweredby": "Powered by <b><a href=\"{{link}}\" target=\"_blank\">Uptime Status</a></b>"
}

View file

@ -5,7 +5,7 @@ require_once(__DIR__ . "/monitor.php");
class Group {
public string $name;
public int $online = 0;
public array $stats = [0, 0, 0, 0];
public array $monitors = [];
public function __construct(string $name) {
@ -14,15 +14,12 @@ class Group {
public function add_monitor(Monitor $monitor) {
array_push($this->monitors, $monitor);
if($monitor->is_online()) $this->online++;
$status = $monitor->get_status();
$this->stats[$status]++;
}
public function get_online(): int {
return $this->online;
}
public function get_total(): int {
return count($this->monitors);
public function get_stats(): array {
return $this->stats;
}
public static function convert(UptimeStatus $s, array $oldGroup, array $heartbeat): Group {

View file

@ -16,8 +16,8 @@ class Monitor {
$this->opt = $opt;
}
public function is_online() {
return $this->last["status"] == 1;
public function get_status() {
return $this->last["status"] ?? 0;
}
public static function convert(UptimeStatus $s, array $oldMonitor, array $heartbeat): Monitor {

View file

@ -5,7 +5,7 @@ require_once(__DIR__ . "/group.php");
class Page {
private array $page;
private int $online = 0;
private array $stats = [0, 0, 0, 0];
private int $total = 0;
private array $groups = [];
@ -15,14 +15,18 @@ class Page {
public function add_group(Group $group) {
array_push($this->groups, $group);
$this->online += $group->get_online();
$this->total += $group->get_total();
$stats = $group->get_stats();
for ($i = 0; $i < count($this->stats); $i++) {
$count = $stats[$i];
$this->stats[$i] += $count;
$this->total += $count;
}
}
public function export(): array {
return [
"page" => $this->page,
"online" => $this->online,
"stats" => $this->stats,
"total" => $this->total,
"groups" => $this->groups
];

View file

@ -12,6 +12,7 @@
--green-color: 16, 185, 129;
--red-color: 248, 113, 113;
--yellow-color: 255, 187, 109;
--blue-color: 149, 117, 205;
}
@ -171,15 +172,14 @@ footer {
z-index: 10;
background-color: rgb(var(--card-bg-color));
border-radius: var(--border-radius);
border: 1px solid rgb(var(--card-border-color));
top: 100%;
left: 50%;
margin-top: 5px;
margin-left: -90px;
width: 180px;
box-shadow: 0 0 10px 0 #0005;
opacity: 0;
pointer-events: none;
overflow: hidden;
transform: translate(-50%, 5px);
}
.heartbeats .tooltip > * {
@ -253,4 +253,8 @@ footer {
.status-2 {
--color: var(--yellow-color);
}
.status-3 {
--color: var(--blue-color);
}

View file

@ -1,7 +1,7 @@
<div class="group">
<div class="header item">
<h3>{{ group.name }}</h3>
<div class="status">{{ group.online }} / {{ group.monitors | length }}</div>
<div class="status">{{ group.stats[1] + group.stats[3] }} / {{ group.monitors | length }}</div>
</div>
{% for monitor in group.monitors %}
{{ include("./monitor.twig") }}

View file

@ -1,8 +1,8 @@
{% set gs = online | globalstatus(total) %}
{% set gs = stats | globalstatus(total) %}
<header class="status-{{ gs }}">
<div class="inner">
<img class="icon" src="{{ gs | statusicon }}" />
<h1>{{ gs | globalstatustext | t }}</h1>
<h1>{{ ("header.title." ~ gs) | t }}</h1>
<p>{{ "header.updated" | t({date: now | date}) }}</p>
</div>
</header>

View file

@ -11,7 +11,7 @@
</div>
{% if heartbeat.ping %}
<div>
Ping: {{ heartbeat.ping }}ms
{{ "heartbeat.ping" | t({ping: heartbeat.ping}) }}
</div>
{% endif %}
</div>