-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
130 lines (115 loc) · 5.18 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Marian Mihailescu">
<title>CollectionJS Charts</title>
<!-- Bootstrap core CSS -->
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>
<p class="navbar-text" style="color: white"><b>Hostname: </b></p>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span id="s_hostname">click to select</span> <b class="caret"></b></a>
<ul id="hostname" class="dropdown-menu">
</ul>
</li>
<li>
<p class="navbar-text" style="color: white"><b>Plugin: </b></p>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span id="s_plugin">click to select</span> <b class="caret"></b></a>
<ul id="plugin" class="dropdown-menu">
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div id="charts" class="container" style="margin-top: 100px; padding-bottom: 30px; max-width: 800px;">
</div><!-- /.container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="http://fgnass.github.io/spin.js/spin.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
<script src="lib/collection.js"></script>
<script type='text/javascript'>
// function to load when page is loaded
$(document).ready(function() {
// define additional variables
CollectionJS.events = $('body');
CollectionJS.s_host = '';
CollectionJS.s_plugin = '';
// get hosts and plugins, then display them in the dropdown menus
$.getJSON('bin/getHosts.cgi', function (data) {
var hosts = [];
$.each(data.hosts, function (index, host) {
hosts.push('<li><a href="#">' + host + '</a></li>');
});
$('#hostname').html(hosts.join(""));
$('#hostname li').on('click', function () {
CollectionJS.s_host = $(this).find('a').html();
$('#s_hostname').html(CollectionJS.s_host);
CollectionJS.events.trigger('draw');
});
var plugins = [];
$.each(data.plugins, function (index, plugin) {
plugins.push('<li><a href="#">' + plugin + '</a></li>');
});
$('#plugin').html(plugins.join(""));
$('#plugin li').on('click', function () {
CollectionJS.s_plugin = $(this).find('a').html();
$('#s_plugin').html(CollectionJS.s_plugin);
CollectionJS.events.trigger('draw');
});
});
// function run when selecting hosts or plugins in the menu
CollectionJS.events.on('draw', function () {
// do not get charts if we don't have both hostname and plugin
if (CollectionJS.s_host.length > 0 && CollectionJS.s_plugin.length > 0) {
// get a list of existing charts
$.getJSON('bin/getPlugin.cgi?hostname=' + CollectionJS.s_host + '&plugin=' + CollectionJS.s_plugin, function (data) {
$('#charts').empty();
$.each(data.charts, function (index, chart) {
var url = 'bin/getChart.cgi?hostname=' + chart.hostname + '&plugin=' + chart.plugin;
if (chart.plugin_instance) url += '&plugin_instance=' + chart.plugin_instance;
if (chart.type) url += '&type=' + chart.type;
if (chart.type_instance && !chart.ignore_type_instance) url += '&type_instance=' + chart.type_instance;
// create div to cotain the highchart
jQuery('<div/>', {
class: 'highchart',
style: 'min-width: 400px; height: 300px; margin: 0 auto; padding-bottom: 20px;',
'data-url': url,
'data-start': '-10800',
'data-options': '{}'
}).appendTo('#charts');
}); // end each
renderCharts();
}); // end getJSON
} // end if
}); // end draw function
}); // end document-ready function
</script>
</body>
</html>