-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviewFunctions.php
82 lines (66 loc) · 1.68 KB
/
viewFunctions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
use Ghunti\HaproxyPHP\ServerStats;
use \DateTime;
function buildDataForView($haproxyData)
{
$viewData = [];
foreach ($haproxyData as $serverStats) {
$serverStats = new ServerStats($serverStats);
$proxyName = $serverStats->getProxyName();
$viewData[$proxyName][] = $serverStats;
}
return $viewData;
}
function getElapsedTime($seconds)
{
$now = new DateTime();
$past = clone $now;
$past->sub(DateInterval::createFromDateString($seconds . ' seconds'));
$diff = $now->diff($past);
return $diff->format('%H:%Ih');
}
function getServerStatusColor(ServerStats $serverStats)
{
if (!$serverStats->isListener()) {
return 'active';
}
switch (true) {
case $serverStats->isUp():
return 'success';
case $serverStats->isDown():
return 'danger';
case $serverStats->isMaint():
return 'warning';
case $serverStats->isDrain():
return 'info';
}
}
function getWeightLabelColor(ServerStats $serverStats)
{
if ($serverStats->getWeight() <= 0 || $serverStats->getWeight() > 100) {
return 'info';
}
if ($serverStats->getWeight() >= 80) {
return 'success';
} elseif ($serverStats->getWeight() >= 50) {
return 'warning';
}
return 'danger';
}
function getStatusLabelColor(ServerStats $serverStats)
{
switch ($serverStats->getStatus()) {
case 'DOWN':
return 'danger';
case 'UP':
return 'success';
case 'MAINT':
return 'warning';
default:
return 'info';
}
}
function isPost()
{
return $_SERVER['REQUEST_METHOD'] === 'POST';
}