forked from Griesbacher/histou
-
Notifications
You must be signed in to change notification settings - Fork 2
/
histou.js
233 lines (208 loc) · 6.98 KB
/
histou.js
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
/* global _ */
// accessible variables in this scope
var window, document, ARGS, $, jQuery, moment, kbn;
//parse arguments
parseArgs()
return function (callback) {
if (window.location.href.search('/dashboard-solo/') != -1) {
document.documentElement.style.background = '#FFF';
}
var url = location.protocol+'//'+window.location.hostname+'/histou/';
// add omd site name
var site = window.location.href.match(/(https?:\/\/.*?\/.*?)\/grafana\/.*/);
if(site && site.length > 1){
url = site[1]+'/histou/';
}
var configUrl = url+'index.php?host='+host+'&service='+service+'&height='+height+'&legend='+legend+debug+disablePanelTitle+disablePerfdataLookup+specificTemplate+'&annotations='+annotations;
if(jQuery(".js-histou-flotAddons").length === 0) {
$('head').append('<script class="js-histou-flotAddons" src="'+url+'flotAddons.js"></script>');
}
if (!_.isUndefined(ARGS.customCSSFile)) {
$('head').append('<link rel="stylesheet" href="' + ARGS.customCSSFile + '" type="text/css" />');
}
cssLoaded = false;
jQuery('body').on('DOMNodeInserted', 'DIV.drop-popover', function (e) {
var cssUrl = url+'lightbox/css/light.css'
if (!cssLoaded) {
var link = $('<link type="text/css" rel="stylesheet" />').attr("href", cssUrl);
$('head').append(link);
$.getScript(url+'lightbox/js/light.js', function(){});
cssLoaded = true;
}
var box = $( e.currentTarget ).find( "DIV.sakuli-popup" );
if (box.length > 0 ){
$(box[0]).attr('class', 'sakuli-image');
var sakuliUrl = site[1] + box[0].innerHTML;
var svcoutput;
var imagename;
jQuery.when(
// fetch Sakuli serviceoutput file
$.get( sakuliUrl + "output.txt").always(function(data ,state) {
if (state != "success" ) {
data = "Could not find Sakuli service outputfile at " + sakuliUrl + "output.txt !"
}
console.log(data);
svcoutput = $("<div>").text(data).html().replace(/['"]+/g, '');
console.log("Sakuli service output: " + svcoutput);
}) &&
// fetch Sakuli screenshot (jpg/png)
$.get( sakuliUrl ).always(function(imgdata ,state) {
if (state != "success" ) {
imgdata = "Could not access screenshot list page at " + sakuliUrl + "!"
}
// the 3rd href on the apache index page contains the img name
imagename = $(imgdata).find('a')[2].text.trim();
console.log("Sakuli screenshot image name: " + imagename);
})
).then ( function() {
box[0].innerHTML = '<a href="' + sakuliUrl + imagename + '" data-lightbox="sakuli" data-title="'+ svcoutput +'"><img src="'+ sakuliUrl + imagename +'" alt="Sakuli error image" width=250px /></a>';
});
}
});
$.ajax(
{
method: 'GET',
url: configUrl,
dataType: "jsonp",
}
).done(
function (result) {
console.log(result);
callback(result);
}
).fail(
function (result) {
console.log(result);
console.log(configUrl);
if (result.status == 200) {
callback(createErrorDashboard('# HTTP code: '+result.status+'\n- Message: '+result.statusText+'\n- Url: '+configUrl+'\n- Probably the output is not valid json, because the returncode is 200!'));
} else {
callback(createErrorDashboard('# HTTP code: '+result.status+'\n- Message: '+result.statusText+'\n- Url: '+configUrl));
}
}
);
}
function createErrorDashboard(message)
{
return {
rows : [{
title: 'Chart',
height: '300px',
panels : [{
title: 'Error Message below',
type: 'text',
span: 12,
fill: 1,
content: message,
options: {
content: message,
},
}]
}],
services : {},
title : 'JS Error / HTTP Error'
};
}
function parseArgs()
{
if (!_.isUndefined(ARGS.reduce)) {
$('head').append('<style>.panel-fullscreen {top:0}</style>');
//change ui to our needs
clearUi();
}
if (!_.isUndefined(ARGS.dynUnit)) {
dynUnit = true;
} else {
dynUnit = false;
}
if (!_.isUndefined(ARGS.host)) {
host = ARGS.host;
} else {
host = "";
}
if (!_.isUndefined(ARGS.service)) {
service = ARGS.service;
} else {
service = "";
}
if (!_.isUndefined(ARGS.command)) {
command = ARGS.command;
} else {
command = "";
}
if (!_.isUndefined(ARGS.perf)) {
perf = ARGS.perf;
} else {
perf = "";
}
if (!_.isUndefined(ARGS.height)) {
height = ARGS.height;
} else {
height = "";
}
if (_.isUndefined(ARGS.debug)) {
debug = '';
} else {
debug = "&debug";
}
if (!_.isUndefined(ARGS.legend)) {
legend = ARGS.legend;
} else {
legend = true;
}
if (!_.isUndefined(ARGS.annotations)) {
annotations = ARGS.annotations;
} else {
annotations = false;
}
if(_.isUndefined(ARGS.disablePanelTitle)) {
disablePanelTitle = '';
}else{
disablePanelTitle = "&disablePanelTitle";
}
if(_.isUndefined(ARGS.disablePerfdataLookup)) {
disablePerfdataLookup = '';
}else{
disablePerfdataLookup = "&disablePerfdataLookup";
}
if(_.isUndefined(ARGS.specificTemplate)) {
specificTemplate = '';
}else{
specificTemplate = "&specificTemplate="+ARGS.specificTemplate;
}
}
function clearUi()
{
//removes white space
var checkExist = setInterval(
function () {
if ($('.panel-content').length) {
clearInterval(checkExist);
document.getElementsByClassName("panel-content")[0].style.paddingBottom = '0px';
}
},
100
);
/*
.panel-header removes the headline of the graphs
.navbar-static-top removes the menubar on the top
.row-control-inner removes the row controll button on the left
.span12 removes the add new row button on the bottom
*/
var divs = ['.panel-header','.navbar-static-top','.row-control-inner','.span12']
for (var index = 0; index < divs.length; index++) {
waitForDivAndDeleteIt(divs[index]);
}
function waitForDivAndDeleteIt(div)
{
var checkExist = setInterval(
function () {
if ($(div).length) {
clearInterval(checkExist);
$(div).remove();
}
},
100
);
}
}