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
|
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>hostinfo</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css" />
<style>
a {
cursor: pointer;
color: #F00;
font-weight: bold;
}
a:hover {
color: rgb(168, 0, 0);
}
h1 {
text-align: center;
}
#hosts li {
list-style-type: none;
text-align: center;
line-height: 100px;
margin: 10px;
}
#hosts li a {
display: block;
}
#hosts li a:hover {
background-color: #CCC;
color: #000;
text-decoration: none;
}
td.centering, p.centering {
text-align: center;
}
</style>
<script src="js/js-yaml.min.js"></script>
<script src="js/jquery-2.0.0.min.js"></script>
<script src="js/jquery.mustache.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/mustache.js"></script>
<script src="js/underscore.min.js"></script>
<script type="text/javascript">
var strip = function(data) { return data.split('.')[0] };
render = {
'index' : function() {
jQuery.get('data/hosts', function(raw) {
var data = jsyaml.load(raw),
hosts = [];
for(var i=0; i < data.hosts.length; i++) {
var entry = data.hosts[i];
hosts.push({
'name' : strip(entry),
'uri' : entry
});
}
$.Mustache.load('./templates/index.html').done(function () {
$('#content').mustache('hosts', {'hosts':hosts});
$("#hosts a").click("hover", function(event){
var uri = $(this).attr('data-uri');
render.host(uri);
});
});
});
},
'host' : function(uri) {
jQuery.get('data/'+uri, function(raw) {
var data = jsyaml.load(raw);
data.name = strip(data.hostname);
data.interfaces = _.map(
_.groupBy(data.addresses, function(x) {
return x.interface;
}), function(obj, key) { obj.device = key; return obj; });
$.Mustache.load('./templates/host.html').done(function () {
$('#content').mustache('hostinfo', data, {method:'html'});
});
$("#index").click("hover", function(event){
render.index();
});
});
}
};
$(document).ready(function() {
render.index();
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="span12" id="content">
</div>
</div>
</div>
</body>
</html>
|