-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
177 lines (168 loc) · 7.43 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
require('vendor/autoload.php');
use IntelliTrend\Zabbix\ZabbixApi;
include_once './config.php';
$zabbixApiOptions = array('sslVerifyPeer' => true, 'sslVerifyHost' => true);
$zabbixApi = new ZabbixApi();
try {
$zabbixApi->loginToken($zabbixApiServerUri, $zabbixApiAccessToken, $zabbixApiOptions);
$zabbixServices = $zabbixApi->call('service.get', array("output" => "extend", "sortfield" => "sortorder"));
} catch (Exception $ex) {
print "==== Exception ===\n";
print 'ErrorCode: '.$ex->getCode()."\n";
print 'ErrorMessage: '.$ex->getMessage()."\n";
exit;
}
function getColBlockStyleForIndex($index) {
if ($index < 7) {
return 'd-none d-xl-block';
} else if ($index < 14) {
return 'd-none d-lg-block';
} else if ($index < 21) {
return 'd-none d-md-block';
} else {
return 'd-block';
}
}
function getColBlockColorFor($sliValue, $sloValue) {
if ($sliValue < $sloValue) {
return 'bg-warning';
} else {
return 'bg-success';
}
}
?>
<html>
<head>
<link href="https://assets.x3cdn.com/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
<link href="https://assets.x3cdn.com/bootstrap-icons/1.8.1/font/bootstrap-icons.css" rel="stylesheet">
<style>
main > .container {
padding-top: 60px;
}
</style>
<script src="https://assets.x3cdn.com/bootstrap/5.3.0/js/bootstrap.bundle.js"></script>
<script>
function onDomContentLoaded(event) {
const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]');
const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl));
}
document.addEventListener("DOMContentLoaded", onDomContentLoaded);
</script>
<meta charset="UTF-8">
<title>Status</title>
</head>
<body class="d-flex flex-column h-100">
<header>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<div class="container-xl">
<a class="navbar-brand" href="#">Status</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<main class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">Service status</h1>
<p class="lead">Current information pulled from Zabbix.</p>
<p>
<?php foreach($zabbixServices as $zabbixService) { ?>
<div class="card mt-2 mr-2 mb-4 ml-2" >
<div class="card-header">
<span><?php printf($zabbixService["name"]); ?></span>
<?php if($zabbixService["status"] == -1) { ?>
<span class="float-end text-success">Operational <i class="bi bi-check-circle"></i></span>
<?php } else if($zabbixService["status"] >= 2 && $zabbixService["status"] <= 3) { ?>
<span class="float-end text-warning">Degraded <i class="bi bi-exclamation-circle"></i></span>
<?php } else if($zabbixService["status"] >= 4) { ?>
<span class="float-end text-danger">Outage <i class="bi bi-x-circle"></i></span>
<?php } ?>
</div>
<div class="card-body">
<?php
$zabbixSlas = $zabbixApi->call('sla.get', array('output' => 'extend', 'serviceids' => $zabbixService['serviceid'], 'selectExcludedDowntimes' => array('name', 'period_from', 'period_to')));
$zabbixSlaExcludedDowntimes = $zabbixSlas[0]['excluded_downtimes'];
?>
<div class="row pt-2">
<?php
$zabbixSli = $zabbixApi->call('sla.getsli', array('periods' => '29', 'slaid' => $zabbixSlas[0]['slaid']));
$zabbixSliPeriods = $zabbixSli['periods'];
$zabbixSliSlis = $zabbixSli['sli'];
?>
<?php
$index = 0;
foreach($zabbixSliSlis as $zabbixSliSli) {
?>
<div
class="col <?php printf(getColBlockStyleForIndex($index)); ?> mx-1 <?php printf(getColBlockColorFor($zabbixSliSli[0]['sli'], $zabbixSlas[0]['slo'])); ?>"
style="min-height: 20px; height: 20px;"
data-bs-toggle="popover"
data-bs-placement="bottom"
data-bs-trigger="hover focus"
data-bs-title="<?php printf(date("D M j G:i:s T Y", $zabbixSliPeriods[$index]["period_from"])); ?>"
data-bs-content="Uptime: <?php printf($zabbixSliSli[0]['sli']); ?>%"
></div>
<?php
$index++;
}
?>
</div>
<div class="row pt-2">
<div class="d-none d-xl-block col-xl-2 text-muted text-start">28 days ago</div>
<div class="d-none d-lg-block d-xl-none col-lg-2 text-muted text-start">21 days ago</div>
<div class="d-none d-md-block d-lg-none col-md-2 text-muted text-start">14 days ago</div>
<div class="d-block d-md-none col-4 text-muted text-start">7 days ago</div>
<div class="col-4 col-sm-4 col-md-8 text-muted text-center"><hr/></div>
<div class="col-4 col-sm-4 col-md-2 text-muted text-end">Today</div>
</div>
<?php
if (count($zabbixSlaExcludedDowntimes) > 0) {
?>
<div class="row pt-2">
<div class="col-12">
<?php
foreach($zabbixSlaExcludedDowntimes as $zabbixSlaExcludedDowntime) {
$now = time();
$excludedDowntimeFrom = intval($zabbixSlaExcludedDowntime["period_from"]);
$excludedDowntimeTo = intval($zabbixSlaExcludedDowntime["period_to"]);
$excludedDowntimeName = $zabbixSlaExcludedDowntime["name"];
if ($now < $excludedDowntimeTo) {
?>
<div class="alert alert-primary d-flex align-items-center p-2 m-0" role="alert">
<i class="bi bi-info-circle-fill flex-shrink-0 me-2"></i>
<div>
<p class="p-0 m-0">From <b><?php printf(date("D M j G:i:s T Y", $excludedDowntimeFrom)); ?></b> until <b><?php printf(date("D M j G:i:s T Y", $excludedDowntimeTo)); ?></b>:</p>
<p class="p-0 m-0"><?php print($excludedDowntimeName); ?></p>
</div>
</div>
<?php
}
}
?>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php } ?>
</p>
</div>
</main>
<footer class="footer mt-auto py-3 bg-light">
<div class="container">
<span class="text-muted"><i class="bi bi-github"></i> <a href="https://github.com/joestrhq/status-page-zabbix" target="_blank">joestrhq/status-page-zabbix</span>
</div>
</footer>
</body>
</html>