forked from aletson/zabbixweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
369 lines (322 loc) · 16.9 KB
/
index.html
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<head>
<script src="js/ext/jquery.min.js"></script>
<script src="js/ext/jquery-ui.min.js"></script>
<link rel="stylesheet" href="css/ext/jquery-ui.min.css" type="text/css" media="all" />
<script src="js/ext/bootstrap.min.js"></script>
<link href="css/ext/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/font-awesome.min.css" type="text/css">
<script src="js/zabbix_library.js"></script>
<script src="js/jquery.circleprogress.js"></script>
<!--<link rel="stylesheet" href="css/stylesheet.css" type="text/css"> This is to import the Bebas Neue font - which I believe is left over from a previous Bootstrap theme. Skipping this doesn't seem to break anything -->
<style>
.nounderline{text-decoration: none !important}
body {
font-family: "BebasNeue";
}
/* This is for the jquery-circleprogress plugin */
.circle {
width: 100px;
margin: 6px 6px 20px;
display: inline-block;
position: relative;
text-align: center;
line-height: 1.2;
}
.circle canvas {
vertical-align: top;
}
.circle strong {
position: absolute;
top: 20px;
left: 0;
width: 100%;
text-align: center;
line-height: 40px;
font-size: 26px;
}
.circle strong i {
font-style: normal;
font-size: 0.6em;
font-weight: normal;
}
.circle span {
display: block;
color: #aaa;
margin-top: 12px;
}
/* Left border for the server cells */
.col-md-3 {
margin-left: 0;
padding-left: 19px;
border-left: 1px solid #555;
}
/* This is for the freak-out-and-alert animation. It's done through CSS, but there are also jQuery UI plugins if you prefer those. */
.blink{
-webkit-animation: blink 700ms infinite alternate;
-moz-animation: blink 700ms infinite alternate;
-o-animation: blink 700ms infinite alternate;
animation: blink 700ms infinite alternate;
background-color: red;
}
@-webkit-keyframes blink {
from { background:rgba(255, 0, 0, 1); }
to { background:rgba(255, 0, 0, 0); }
}
@-o-keyframes blink {
from { background:rgba(255, 0, 0, 1); }
to { background:rgba(255, 0, 0, 0); }
}
@-moz-keyframes blink {
from { background:rgba(255, 0, 0, 1); }
to { background:rgba(255, 0, 0, 0); }
}
@keyframes blink {
from { background:rgba(255, 0, 0, 1); }
to { background:rgba(255, 0, 0, 0); }
};
.row{
overflow: hidden;
}
</style>
<title>Zabbix Monitoring System</title>
</head>
<body>
<div class="content">
<div class="container-fluid">
<div class="row"><div class="col-md-12"><span style="float: right; font-size: 9px;"><a data-toggle="modal" data-target="#settings-modal">settings</a></span></div>
<div id="hosts-list" class="row"></div>
<div class="text-muted">Original work by <a href="http://www.andrewletson.com">Andrew Letson</a> with some changes from <a href="https://github.com/eburgueno">@eburgueno</a></div>
<div class="modal fade" id="settings-modal" tabindex="-1" role="dialog" aria-labelledby="Settings" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="Settings">Settings</h4>
</div>
<div class="modal-body">
<label for="network-dropdown"><input type="checkbox" name="network-dropdown" id="network-dropdown" /> Show network statistics in a clickable dropdown</label>
<label for="disks-dropdown"><input type="checkbox" name="disks-dropdown" id="disks-dropdown" /> Show disk statistics in a clickable dropdown</label>
<label for="show-meters"><input type="checkbox" name="show-meters" id="show-meters" /> Display meter graphics for CPU and RAM usage (disable this for a more compact view)</label>
<label for="view-list"><input type="radio" name="view-select" id="view-list" value="list" />List view</label>
<label for="view-grid"><input type="radio" name="view-select" id="view-grid" value="grid" />Grid view</label>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="save-changes">Save Preferences</button>
</div>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function() {
var zabbix = new $.zabbix ('http://zabbix.org/zabbix/api_jsonrpc.php', 'guest', ''); //Change zabbix.org to your server's IP, guest to a Zabbix user and the blank to the password
if(zabbix.getApiVersion() >= '2.5.1') {
throw new Error('Zabbix has been updated, check the new documentation then update the code and Zabbix api version');
//API changes can be problematic. The current code seems to work well with 2.2, 2.4 and 2.5 (unreleased, used by zabbix.org/zabbix) version
}
zabbix.authenticate(); //this gives us our API key, which gets assigned to the zabbix object
// Putting the mess that is filterHostsAndOutput into a setInterval would have been cruel and unusual to the maintenance programmer
filterHostsAndOutput(zabbix);
setInterval(function() { filterHostsAndOutput(zabbix) }, 54000);
});
//I apologize for everything.
function filterHostsAndOutput(zabbix) {
var hosts = zabbix.call('host.get', {
"selectInventory": true,
"selectItems": [
"name",
"lastvalue",
"units",
"itemid",
"key_",
"lastclock",
"value_type",
"itemid"
],//Next line is thanks to eburgueno, disabled unless you want to use it
// "groupids": "11", //Only display hosts in this groupID #. You should create a new one with all the hosts you want, and templates
"output": "extend",
"search" : {"host" : ""},
"expandDescription": 1,
"expandData": 1
});
var anError = 0;
$('#hosts-list').empty();
$.each(hosts, function() {
var thisHost = $(this);
var thisHostObj = thisHost[0];
var processorCount = 1; //default to one CPU (or thread) in case system.cpu.num is not being gathered for the host
var loadTotals = 0;
thisHostObj.agentPing = '';
thisHostObj.usedDiskSpacesPcts = new Array;
thisHostObj.totalDiskSpaces = new Array;
thisHostObj.usedDiskSpaces = new Array;
thisHostObj.totalMem = 0;
thisHostObj.freeMem = 0;
thisHostObj.numProcesses = 0;
thisHostObj.networkTraffic = 0;
$.each(thisHostObj.items, function() { //Parse the statistics to human-readable.
switch ($(this)[0].key_) {
case 'system.cpu.num': //You may have to add this to your Zabbix templates.
processorCount = $(this)[0].lastvalue;
break;
case 'system.cpu.load': //You may have to add this to your Zabbix templates (as float)
loadTotals += $(this)[0].lastvalue;
break;
case 'agent.ping':
thisHostObj.agentPing = $(this)[0].lastvalue;
break;
case 'vm.memory.size[total]': //You may have to add these as well
thisHostObj.totalMem = $(this)[0].lastvalue / 1073741824; //1024^3 => GB
break;
case 'vm.memory.size[free]':
thisHostObj.freeMem += $(this)[0].lastvalue / 1073741824; //free(avail)=free+cached+inactive on linux, free on Windows
break;
case 'vm.memory.size[cached]':
thisHostObj.freeMem += $(this)[0].lastvalue / 1073741824;
break;
case 'vm.memory.size[inactive]':
thisHostObj.freeMem += $(this)[0].lastvalue / 1073741824;
break;
case 'proc.num[]':
thisHostObj.numProcesses = $(this)[0].lastvalue;
break;
//as seen in http://stackoverflow.com/a/22099079 for case substring matching. There may be a better way to do this...
case ( ($(this)[0].key_.match(/vfs.fs.size/) )? $(this)[0].key_: undefined ):
switch ($(this)[0].key_) {
case ( ($(this)[0].key_.match(/,pfree/) )? $(this)[0].key_: undefined ):
thisHostObj.usedDiskSpacesPcts.push(100 - $(this)[0].lastvalue);
break;
case ( ($(this)[0].key_.match(/,used/) )? $(this)[0].key_: undefined ):
thisHostObj.usedDiskSpaces.push(($(this)[0].lastvalue / 1073741824));
break;
case ( ($(this)[0].key_.match(/,total/) )? $(this)[0].key_: undefined ):
thisHostObj.totalDiskSpaces.push(($(this)[0].lastvalue / 1073741824));
break;
}
break;
case ( ($(this)[0].key_.match(/net.if.in/) || $(this)[0].key_.match(/net.if.out/) ) ? $(this)[0].key_ : undefined ): //FIXME: filter by network interface
thisHostObj.networkTraffic += $(this)[0].lastvalue / 8192; // KBps
break;
case 'net.tcp.service[http]':
if($(this)[0].lastvalue == 0) {
thisHostObj.error = 1;
thisHostObj.errorText = 'Web service is down (httpd or IIS)';
}
break;
}
});
if (thisHostObj.error != '' && thisHostObj.error != 1) {
thisHostObj.errorText = new String;
thisHostObj.errorText = thisHostObj.error;
}
if(thisHostObj.errorText && thisHostObj.errorText.indexOf('Interrupted system call') > -1) {
thisHostObj.errorText = 'Couldn\'t reach agent - check firewall settings';
}
if(thisHostObj.errorText && thisHostObj.errorText.indexOf('Connection refused') > -1) {
thisHostObj.errorText = 'Connection refused - check agent settings';
}
if(thisHostObj.errorText && thisHostObj.errorText.indexOf('timed out') > -1) {
thisHostObj.errorText = 'Connection timed out - SERVER MAY BE DOWN';
anError = 1;
}
if(thisHostObj.inventory.os) {
if(thisHostObj.inventory.os.indexOf('Windows Server 2008 R2') > -1) {
thisHostObj.os = 'Win Server 2008 R2';
} else if (thisHostObj.inventory.os.indexOf('Windows Server 2012') > -1) {
thisHostObj.os = 'Win Server 2012';
} else if (thisHostObj.inventory.os.indexOf('Windows Server 2003') > -1) {
thisHostObj.os = 'Win Server 2003';
} else if (thisHostObj.inventory.os.indexOf('el7') > -1) {
thisHostObj.os = 'CentOS 7';
} else if (thisHostObj.inventory.os.indexOf('el6') > -1) {
thisHostObj.os = 'CentOS 6.5';
} else if (thisHostObj.inventory.os.indexOf('Ubuntu') > -1) {//Ubuntu's uname -a does not give us the OS version
thisHostObj.os = 'Ubuntu';
} else if (thisHostObj.inventory.os.indexOf('Version 10') > -1) { //Does this conflict with any other OS?
thisHostObj.os = 'Mac OS 10.6';
} else if (thisHostObj.inventory.os.indexOf('Version 11') > -1) {
thisHostObj.os = 'Mac OS 10.7';
} else if (thisHostObj.inventory.os.indexOf('Version 12') > -1) {
thisHostObj.os = 'Mac OS 10.8';
} else if (thisHostObj.inventory.os.indexOf('Version 13') > -1) {
thisHostObj.os = 'Mac OS 10.9';
} else if (thisHostObj.inventory.os.indexOf('Version 14') > -1) {
thisHostObj.os = 'Mac OS 10.10';
} else if (thisHostObj.inventory.os.indexOf('Version 15') > -1) {
thisHostObj.os = 'Mac OS 10.11'; //Even though it doesn't exist yet....
//Feel free to roll your own OS stuff here as well! Don't feel restrained by my life choices!
} else {
//Return the unfriendly string if no patterns were matched
thisHostObj.os = thisHost[0].inventory.os;
}
} else if (thisHostObj.inventory.os_full) { //Per eburgueno, his install uses an item for Hostname to populate OS (Full Details) in Inventory
if(thisHostObj.inventory.os_full.indexOf('Linux') > -1) {
thisHostObj.os = 'Linux';
}
} else {
thisHostObj.os = 'OS Unavailable';
}
//Math
thisHostObj.usedMem = thisHostObj.totalMem - thisHostObj.freeMem;
thisHostObj.avgCpuLoad = loadTotals / processorCount;
thisHostObj.memPct = thisHostObj.usedMem / thisHostObj.totalMem;
var disks = new String;
var diskTopUsage = 0;
$.each(thisHostObj.totalDiskSpaces, function(key, value) {
disks += '<small>' + thisHostObj.usedDiskSpaces[key].toFixed(1) + 'G / ' + value.toFixed(1) + 'G (' + thisHostObj.usedDiskSpacesPcts[key].toFixed(1) + '%)</small><br/>';
if (diskTopUsage < thisHostObj.usedDiskSpacesPcts[key]) {
diskTopUsage = thisHostObj.usedDiskSpacesPcts[key];
}
});
var diskUsageClass = new String;
if (diskTopUsage && diskTopUsage > 90) {
diskUsageClass = 'panel-danger';
} else if (diskTopUsage && diskTopUsage > 75) {
diskUsageClass = 'panel-warning';
} else {
diskUsageClass = 'panel-default';
}
if(!thisHostObj.error) {
//Build the server entry.
$('#hosts-list').append('<div class="col-md-3" id="' + thisHostObj.hostid +
'"><h4 style="text-align: center">' + thisHostObj.name + '<small> - ' + thisHostObj.os + '</small></h4><span class="circle" data-pct="' +
thisHostObj.avgCpuLoad + '"><strong></strong><span>' + thisHostObj.numProcesses +
' PROCS</span></span><div class="pull-right"><span class="circle" data-pct="' + thisHostObj.memPct +
'"><strong></strong><span>USED: ' + thisHostObj.usedMem.toFixed(1) + 'G / ' +
thisHostObj.totalMem.toFixed(1) + 'G' + '</span></span></div><br/><div class="row"><div class="col-md-6">PING: ' +
thisHostObj.agentPing + 'ms<br/>TRAFFIC: ' + thisHostObj.networkTraffic.toFixed(1) +
'KBps</div><div class="col-md-6"><span class="pull-right"><div class="panel-group" id="accordion-' + thisHostObj.hostid + '"><div class="panel ' + diskUsageClass + '"><div class="panel-heading"><div class="panel-title"><a data-toggle="collapse" data-parent="#accordion-' + thisHostObj.hostid + '" href="#collapser-' + thisHostObj.hostid + '">DISKS</a></div></div><div id="collapser-' + thisHostObj.hostid + '" class="panel-collapse collapse"><div class="panel-body">' + disks +
'</div></div></div></div></span></div></div></div>');
$('#ohgod').empty();
} else {
$('#hosts-list').append('<div class="col-md-3 blink" id="' + thisHostObj.hostid + '"><h3 style="text-align: center; font-weight: bolder">' +
thisHostObj.name + '</h3><h4 style="font-weight: bolder">' + thisHostObj.errorText + '</h4></div>');
}
});
//Play the tornado siren if a server is unreachable
if(anError === 1) { //We do this outside the for loop because we only want the sound to play...once.
var times = 3;
function repeat() {
times--;
if (times === 0) {
clearInterval(loop);
}
var audio = document.createElement("audio");
audio.src = "audio/tornado2.ogg";
audio.play();
}
var loop = setInterval(repeat, 6000);
repeat();
}
$('.circle').each(function() {
$(this).circleProgress({
value: $(this).attr('data-pct'),
fill: {gradient: ['#1EB33C', '#F72323']},
thickness: 15
}).on('circle-animation-progress', function (event, progress, stepValue) {
$(this).find('strong').html(String((100 * stepValue).toFixed(1)) + '<i>%</i>');
});
});
}
</script>