forked from kepi/IcingaChromedStatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.html
272 lines (220 loc) · 11.2 KB
/
popup.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="inc/jquery-1.4.2.min.js"></script>
<link href="inc/jquery-ui/css/smoothness/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/>
<script src="inc/jquery-ui/js/jquery-ui-1.8.4.custom.min.js"></script>
<link href="icinga.css?0.1.0" rel="stylesheet" type="text/css"/>
<script src="icinga.js"></script>
<script>
function goto(url) {
chrome.tabs.create({url: url});
if ( typeof arguments[1] != "undefined" && arguments[1] === true )
window.close();
}
function refresh()
{
chrome.extension.sendRequest({reqtype: "refresh-data"}, function(response) {
show();
});
}
function z(num)
{
if ( num < 10 ) {
num = '0'+num;
}
return num;
}
function sendCommand(command, hostname, servicename)
{
// basic variables
hostname = hostname.toLowerCase();
cmds = {'ack': 33, 'reschedule': 96};
cmd_url = window.localStorage.url_icinga + '/cmd.cgi';
service_query = '';
// run command for service not for host
if ( servicename != undefined ) {
cmds = {'ack': 34, 'reschedule': 7};
servicename = servicename.replace(/ /, "+");
service_query = '&service='+servicename;
}
// Acknowledge host or service problem
if ( command == 'ack' ) {
goto(cmd_url+'?cmd_typ='+cmds[command]+'&host='+hostname+service_query);
// Reschedule next check of host or service
} else if ( command == 'reschedule' ) {
var t = new Date();
var time = z(t.getDate()) + '-' + z(t.getMonth()+1) + '-' + z(t.getFullYear()) + '+' + z(t.getHours()) + '%3A' + z(t.getMinutes()) + '%3A' + z(t.getSeconds());
var dataString = 'cmd_typ=' + cmds[command] + '&cmd_mod=2&host=' + hostname + service_query + '&start_time=' + time + '&force_check=on&submit=Commit';
$.post(cmd_url, dataString, function(data, textStatus) { debug_log(textStatus); debug_log(data); });
}
}
function show()
{
chrome.extension.sendRequest({reqtype: "get-data"}, function(response) {
if ( response.state == false ) {
debug_log("We received false response from background");
debug_log(response.error);
if ( response.error == 'need-setup' )
msg = 'You need to <a href="#" onclick="javascript:goto(\'options.html\')">setup this extension</a> first.';
else if ( response.error == 'bad-auth' )
msg = 'You need to <a href="#" onclick="javascript:goto(\'options.html\')">setup this extension</a> first.';
else if ( response.error == 'bad-url' )
msg = 'URL to status.cgi doesn\'t exists on server, please <a href="#" onclick="javascript:goto(\'options.html\')">setup correct URL</a> first.';
else if ( response.error == 'bad-regexp' )
msg = 'It appears that you have a syntax error in your regular expression, please <a href="#" onclick="javascript:goto(\'options.html\')">go to options</a> to correct it.';
else if ( response.error = 'unknown' )
msg = 'Unknown error. Please provide more details about your config to github issue page so I can help you.';
else
msg = 'Please wait, data not ready yet.';
$("#output").html(msg);
$("#outputHosts").html(msg);
$("#outputServices").html(msg);
return;
}
debug_log(response.state);
var oo = '';
var oh = '';
var os = '';
var hideAcked = window.localStorage.hideAcked === "true" ? true : false;
// browse all hosts
for (var h in response.hosts) {
var host = response.hosts[h];
var reschedule='<a title="Reschedule check of this host" class="ui-icon ui-icon-refresh" href="#" onclick="sendCommand(\'reschedule\', \''+host.name+'\')">resch</a>';
var ack='<a title="Acknowledge this problem" class="ui-icon ui-icon-wrench" href="#" onclick="sendCommand(\'ack\', \''+host.name+'\')">ack</a>';
var hDowntime = host.downtime ? ' downtime' : '';
var line = '<tr class="host" data-hostname="'+host.name+'"><td colspan="2" class="normal'+hDowntime+'"><a href="#" onclick="goto(\''+window.localStorage.url_icinga+'/'+host.link+'\')">'+host.name+'</a>'+(host.ack?' <span class="ui-icon ui-icon-check" style="float: right;" title="Acknowledged"> </span>':'')+'</td><td class="state '+stateClass(host.state)+'">'+stateClass(host.state, true)+'</td><td class="tools">'+reschedule+(host.ack || host.downtime || host.state == 0 ? '' : ack)+'</td></tr>';
// add to overview only if not ok
var _states = hideAcked ? host.states : host.states_all;
if ( _states['HOST'] > 0 || _states['WRONG'] > 0 )
oo += line;
oh += line;
os += line;
// browse all services of host
for (var s in host.services ) {
var service = host.services[s];
var sDowntime = service.downtime ? ' downtime' : '';
var reschedule='<a title="Reschedule check of this service" class="ui-icon ui-icon-refresh" href="#" onclick="sendCommand(\'reschedule\', \''+host.name+'\',\''+service.name+'\')">resch</a>';
var ack='<a title="Acknowledge this problem" class="ui-icon ui-icon-wrench" href="#" onclick="sendCommand(\'ack\', \''+host.name+'\',\''+service.name+'\')">ack</a>';
var line = '<tr class="service" data-hostname="'+host.name+'" data-servicename="'+service.name+'"><td style="width: 30px;"> </td><td class="normal'+sDowntime+'" style="white-space: nowrap;"><a href="#" onclick="goto(\''+window.localStorage.url_icinga+'/'+service.link+'\')">'+service.name+'</a>'+(service.ack?' <span class="ui-icon ui-icon-check" style="float: right;" title="Acknowledged"> </span>':'')+'</td><td class="state '+stateClass(service.state)+'">'+stateClass(service.state, true)+'</td><td class="tools">'+reschedule+(service.ack || service.downtime || service.state == 0 ? '' : ack)+'</td></tr>';
// add to overview only if not ok
if ( service.state > 0 && ( !hideAcked || ( hideAcked && !service.ack ) ) )
oo += line;
os += line;
}
}
if ( oo == '' ) {
oo = '<p id="all-ok">Everything is OK. Just take your coffee and relax.</p>';
} else {
oo = '<br /><h3>Problems on hosts and services</h3><table id="tableOverview">'+oo+'</table>';
}
var ot = '<div id="totalsHosts"><h3>Host Status</h3><table>'+
'<tr><th>Up</th><th>Down</th><th>Unr</th><th>Pend</th></tr>'+
'<tr>'+
'<td class="ok">'+response.totals_hosts[0]+'/'+response.totals_all_hosts[0]+'</td>'+
'<td class="cri">'+response.totals_hosts[8]+'/'+response.totals_all_hosts[8]+'</td>'+
'<td class="unr">'+response.totals_hosts[4]+'/'+response.totals_all_hosts[4]+'</td>'+
'<td class="pend">'+response.totals_hosts[1]+'/'+response.totals_all_hosts[1]+'</td>'+
'</tr></table></div>';
ot = ot + '<div id="totalsServices"><h3>Service Status</h3><table>'+
'<tr><th>Ok</th><th>Warn</th><th>Unkn</th><th>Crit</th><th>Pend</th></tr>'+
'<tr>'+
'<td class="ok">'+response.totals_services[0]+'/'+response.totals_all_services[0]+'</td>'+
'<td class="warn">'+response.totals_services[4]+'/'+response.totals_all_services[4]+'</td>'+
'<td class="unkn">'+response.totals_services[2]+'/'+response.totals_all_services[2]+'</td>'+
'<td class="cri">'+response.totals_services[8]+'/'+response.totals_all_services[8]+'</td>'+
'<td class="pend">'+response.totals_services[1]+'/'+response.totals_all_services[1]+'</td>'+
'</tr></table></div><br class="clear" />';
$("#output").html(ot+oo)
$("#outputHosts").html('<input type="text" id="searchHosts" onkeyup="filter(this, \'tableHosts\')" placeholder="enter part i.e. part of hostname" /><table id="tableHosts">'+oh+'</table>');
$("#outputServices").html('<input type="text" id="searchServices" onkeyup="filter(this, \'tableServices\')" placeholder="enter part i.e. part of service name or hostname" /><table id="tableServices">'+os+'</table>');
});
}
/* filter host and service table */
function filter(search, table)
{
var reg = new RegExp(search.value, "i");
var enabledHosts = new Array();
$('#'+table+" tr").each(function() {
var row = $(this);
/* normal hostname */
if ( reg.test(row.attr('data-hostname')) ) {
$(this).css('display','table-row')
/* services */
} else if ( table == 'tableServices' && reg.test(row.attr('data-servicename') ) ) {
enabledHosts[row.attr('data-hostname')] = 1;
console.log(row.attr('data-hostname'))
console.log(enabledHosts)
$(this).css('display','table-row')
/* none */
} else {
$(this).css('display','none')
}
});
/* we have to reenable hosts for services that are shown */
if ( table == 'tableServices' && Object.keys(enabledHosts).length > 0 ) {
$('#'+table+" tr").each(function() {
var row = $(this);
if ( enabledHosts[row.attr('data-hostname')] === 1 && row.attr('class') == 'host' ) {
$(this).css('display','table-row');
}
});
}
}
// document is ready, we can start
$(document).ready(function() {
// show tabs
$("#tabs").tabs();
$("a.ext").click(function() { goto(this.href); });
// draw screen
show();
});
</script>
<script type="text/javascript">
/* <![CDATA[ */
(function() {
var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';
t.parentNode.insertBefore(s, t);
})();
/* ]]> */
</script>
</head>
<body id="popup">
<a class="uglyfirstahack" href="#"> </a>
<a title="Refresh data" id="refresh-data" href="#" onclick="javascript:refresh()" border="0"></a>
<div id="tabs">
<ul>
<li><a href="#tab-1"><span>Overview</span></a></li>
<li><a href="#tab-2"><span>Hosts</span></a></li>
<li><a href="#tab-3"><span>Services</span></a></li>
<li><a href="#tab-4"><span>About</span></a></li>
</ul>
<div id="tab-1">
<div id="output"></div>
</div>
<div id="tab-2">
<h3>Hosts status</h3>
<div id="outputHosts"></div>
</div>
<div id="tab-3">
<h3>Services status</h3>
<div id="outputServices"></div>
</div>
<div id="tab-4">
<h3>Icinga Status</h3>
<p><strong>This extension is provided as is, there is no guarantee.</strong></p>
<p>Icinga Status is simple open source extension for Google Chrome™ that helps you watch over your Icinga or Nagios instance.</p>
<p>Author of this extension is <a class="ext" href="http://kepi.cz/">Ondra 'Kepi' Kudlík</a>, part of work on this extension is sponsored by <a class="ext" href="http://www.igloonet.cz/">igloonet.cz</a> company.</p>
<p class="center"><a class="ext" href="http://www.pledgie.com/campaigns/11805"><img alt="Click here to lend your support to: Icinga Status and make a donation at www.pledgie.com !" src="http://www.pledgie.com/campaigns/11805.png?skin_name=chrome" border="0" /></a></p>
</div>
</div>
<div id="footer">
<span id="flattrbutton"><a class="FlattrButton" style="display:none;" rev="flattr;button:compact;" href="https://chrome.google.com/webstore/detail/imaieifkljkcdepgaeommbdgihollphm"></a><noscript><a href="http://flattr.com/thing/381395" target="_blank"><img src="http://api.flattr.com/button/flattr-badge-large.png" alt="Flattr this" title="Flattr this" border="0" /></a></noscript></span>
<a class="ext" href="options.html">Options</a>
</div>
</body>
</html>