forked from incama/Zabbix-Dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
151 lines (133 loc) · 6.75 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
<?php
// load the Zabbix Php API which is included in this build (tested on Zabbix v6.4 and PhpZabbixApi v3.0.0 )
require_once __DIR__.'/vendor/autoload.php';
use Confirm\ZabbixApi\Exception;
use Confirm\ZabbixApi\ZabbixApi;
$token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; //zabbixuser1 token
// Connect to Zabbix API.
$api = new ZabbixApi(
'http://example.com/api_jsonrpc.php', // url api zabbix server
'zabbixuser1', // readonly zabbixuser1
'xxxxxxxxxx', // passowrd zabbixuser1
null, // if use HTTP Basic Authorization - enter a user
null, // if use HTTP Basic Authorization - enter a pass
$token
);
$api->setDefaultParams(array(
'output' => 'extend',
));
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Zabbix</title>
<link rel="stylesheet" type="text/css" href="style/reset.css" />
<link rel="stylesheet" type="text/css" href="style/theme-alt.css" />
<script src="lib/js/jquery-2.2.0.min.js"></script>
<!-- added the masonry js so all blocks are better alligned -->
<script src="lib/js/masonry.pkgd.min.js"></script>
<body id="bg-two">
<!-- START GET RENDER DATE - Which will show date and time of generating this file -->
<div id="timestamp">
<div id="date"><?php echo date("d F Y", time()); ?></div>
<div id="time"><?php echo date("H:i", time()); ?></div>
</div>
<!-- END GET RENDER DATE -->
<!-- We could use the Zabbix HostGroup name here, but would not work in a nice way when using a dozen of hostgroups, yet! So we hardcoded it here. -->
<div id="sheetname">Status</div>
<br />
<?php
// get hostgroupid with hosts
$groupids = $api->hostgroupGet(array(
//'output' => 'extend',
'selectHosts' => 'extend',
));
// get all hosts from each groupid
foreach($groupids as $groupid) {
$groupname = $groupid['name'];
$hosts = $groupid['hosts'];
//$gid = $groupid['groupid'];
if ($hosts) {
$count = "0";
// echo "<div class=\"groupbox\">"; // Again, we dont want to use the groupfunction yet
// echo "<div class=\"title\">" . $groupname . "</div>";
usort($hosts, function ($a, $b) {
if ($a['name'] == $b) return 0;
return ($a['name'] < $b['name'] ? -1 : 1);
});
// print all host IDs
foreach($hosts as $host) {
// Check if host is not disabled, we don't want them!
$flaghost = $host['flags'];
if ($flaghost == "0" && $count == "0") {
echo "<br /><div class=\"title\">" . $groupname . "</div>";
echo "<div class=\"groupbox js-masonry\" data-masonry-options='{ \"itemSelector\": \".hostbox\" }'\">";
$count++;
}
if ($flaghost == "0" && $count != "0") {
$hostid = $host['hostid'];
$hostname = $host['name'];
$maintenance = $host['maintenance_status'];
$trigger = $api->triggerGet(array(
'output' => 'extend',
'hostids' => $hostid,
'expandDescription' => 1,
'only_true' => 1,
'monitored' => 1,
'withLastEventUnacknowledged' => 1,
'sortfield' => 'priority',
'sortorder' => 'DESC',
'active' => 1, // include trigger state active not active
'withUnacknowledgedEvents' => 1 // show only unacknowledgeevents
));
if ($trigger) {
// Highest Priority error
$hostboxprio = $trigger[0]['priority'];
//First filter the hosts that are in maintenance and assign the maintenance class if is true
if ($maintenance != "0") {
echo "<div class=\"hostbox maintenance\">".PHP_EOL;
}
// If hosts are not in maintenance, check for trigger(s) and assign the appropriate class to the box
else {
echo "<div class=\"hostbox blink nok" . $hostboxprio . "\">".PHP_EOL;
}
echo "<div class=\"title\">" . $hostname . "</div><div class=\"hostid\">" . $hostid . "</div>".PHP_EOL;
$count = "0";
foreach ($trigger as $event) {
if ($count++ <= 2 ) {
$priority = $event['priority'];
$description = $event['description'];
// Remove hostname or host.name in description
//$search = array('{HOSTNAME}', '{HOST.NAME}');
//$description = str_replace($search, "", $description);
// View
echo "<div class=\"description nok" . $priority ."\" title=\"$description\">" . mb_strimwidth($description, 0, 54, "..."). "</div>".PHP_EOL;
} else {
break;
}
}
}
// If there are no trigger(s) for the host found, assign the "ok" class to the box
else {
echo "<div class=\"hostbox ok\">".PHP_EOL;
echo "<div class=\"title\">" . $hostname . "</div><div class=\"hostid\">" . $hostid . "</div>".PHP_EOL;
}
echo "</div>";
}
}
if ($count != "0") {echo "</div>".PHP_EOL;}
}
}
?>
<!-- Second piece of js to gracefully reload the page (value in ms) -->
<script>
function ReloadPage() {
location.reload();
};
$(document).ready(function() {
setTimeout("ReloadPage()", 31000);
});
</script>
</body>
</html>