Module: check_mk
Branch: master
Commit: c341df84fe5253a2aafe6145423d120ed81c0704
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c341df84fe5253…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue May 24 15:24:30 2011 +0200
WATO: bulk inventory: allow to just retry failed hosts
---
web/htdocs/js/wato.js | 75 ++++++++++++++++++++++++++++++++++++++++--------
web/htdocs/wato.py | 19 ++++++------
2 files changed, 72 insertions(+), 22 deletions(-)
diff --git a/web/htdocs/js/wato.js b/web/htdocs/js/wato.js
index 2ed080a..66f8a81 100644
--- a/web/htdocs/js/wato.js
+++ b/web/htdocs/js/wato.js
@@ -30,7 +30,7 @@ function getElementsByClass(cl) {
var items = new Array();
var elements = document.getElementsByTagName('*');
for(var i = 0; i < elements.length; i++)
- if(elements[i].className == cl)
+ if (elements[i].className == cl)
items.push(elements[i]);
return items;
}
@@ -42,7 +42,7 @@ function wato_check_all(css_class) {
// First check if all boxes are checked
var all_checked = true;
for(var i = 0; i < items.length && all_checked == true; i++)
- if(items[i].checked == false)
+ if (items[i].checked == false)
all_checked = false;
// Now set the new state
@@ -55,8 +55,16 @@ function wato_check_all(css_class) {
// ----------------------------------------------------------------------------
+// WATO mode during progress
+var progress_mode = null;
+// WATO url belonging to progress
+var progress_url = null;
+// timeout for progress
+var progress_timeout = null;
// Keeps the items to be fetched
var progress_items = null;
+// items failed, needed for retry
+var failed_items = null;
// Number of total items to handle
var progress_total_num = 0;
// The URL to redirect to after finish/abort button pressed
@@ -81,7 +89,7 @@ function progress_handle_response(data, code) {
alert('Invalid response: ' + code);
}
- if(header === null) {
+ if (header === null) {
alert('Header is null!');
}
@@ -97,14 +105,15 @@ function progress_handle_response(data, code) {
update_progress_bar(header);
// Process optional body
- if(typeof(body) !== 'undefined' && body != '')
+ if (typeof(body) !== 'undefined' && body != '')
progress_attach_log(body);
- if(header[0] === 'pause') {
+ if (header[0] === 'pause')
progress_pause();
- } else if(header[0] === 'abort') {
+ else if (header[0] == 'failed')
+ failed_items.push(item);
+ else if (header[0] === 'abort')
return;
- }
progress_items.shift();
progress_running = false;
@@ -126,6 +135,19 @@ function progress_proceed() {
document.getElementById('progress_proceed').style.display = 'none';
}
+function progress_retry() {
+ document.getElementById('progress_retry').style.display = 'none';
+ document.getElementById('progress_pause').style.display = '';
+ document.getElementById('progress_abort').style.display = '';
+ progress_clean_log();
+ clear_progress_stats();
+ progress_items = failed_items;
+ failed_items = Array();
+ progress_scheduler(progress_mode, progress_url, progress_timeout, [], "",
"");
+}
+
+
+
/* Is called when the processing is completely finished */
function progress_finished() {
update_progress_title(progress_fin_txt);
@@ -135,6 +157,9 @@ function progress_finished() {
document.getElementById('progress_pause').style.display = 'none';
document.getElementById('progress_proceed').style.display = 'none';
document.getElementById('progress_abort').style.display = 'none';
+ if (failed_items.length > 0)
+ document.getElementById('progress_retry').style.display = '';
+
}
/* Is called by the users abort/finish button click */
@@ -144,10 +169,22 @@ function progress_end() {
location.href = progress_end_url;
}
+function clear_progress_stats() {
+ for(var i = 1; i < 100; i++) {
+ var o = document.getElementById('progress_stat' + (i - 1));
+ if (o) {
+ o.innerHTML = "0";
+ o = null;
+ }
+ else
+ break;
+ }
+}
+
function update_progress_stats(header) {
for(var i = 1; i < header.length; i++) {
var o = document.getElementById('progress_stat' + (i - 1));
- if(o) {
+ if (o) {
o.innerHTML = parseInt(o.innerHTML) + parseInt(header[i]);
o = null;
}
@@ -178,26 +215,38 @@ function progress_attach_log(t) {
log = null;
}
+function progress_clean_log() {
+ var log = document.getElementById('progress_log');
+ log.innerHTML = '';
+ log.scrollTop = 0;
+ log = null;
+}
+
function progress_scheduler(mode, url_prefix, timeout, items, end_url, finished_txt) {
// Initialize
- if(progress_items === null) {
+ if (progress_items === null) {
progress_items = items;
+ failed_items = Array();
progress_total_num = items.length;
progress_end_url = end_url;
progress_fin_txt = finished_txt;
+ progress_mode = mode;
+ progress_url = url_prefix;
+ progress_timeout = timeout;
}
// Escape the loop when ended
- if(progress_ended)
+ if (progress_ended)
return false;
// Regular processing when not paused and not already running
- if(!progress_paused && !progress_running) {
- if(progress_items.length > 0) {
+ if (!progress_paused && !progress_running) {
+ if (progress_items.length > 0) {
// Progressing
progress_running = true;
update_progress_title(progress_items[0]);
- get_url(url_prefix + '&_transid=-1&_item=' +
escape(progress_items[0]), progress_handle_response, [ mode, progress_items[0] ]);
+ get_url(url_prefix + '&_transid=-1&_item=' +
+ escape(progress_items[0]), progress_handle_response, [ mode,
progress_items[0] ]);
} else {
progress_finished();
return;
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 2ae6451..1cb4687 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -954,14 +954,14 @@ def mode_bulk_inventory(phase):
elif phase == "action":
if html.var("_item"):
how = html.var("how")
- hostname = html.var("_item").encode("utf-8")
+ hostname = html.var("_item")
try:
counts = check_mk_automation("inventory", [how, hostname])
- result = repr([ 'continue' ] + list(counts)) + "\n"
+ result = repr([ 'continue', 0 ] + list(counts)) + "\n"
result += "Inventorized %s<br>\n" % hostname
log_pending(hostname, "bulk-inventory", "Inventorized
host: %d added, %d removed, %d kept, %d total services" % counts)
except Exception, e:
- result = repr([ 'pause', 0, 0, 0, 0, ]) + "\n"
+ result = repr([ 'failed', 1, 0, 0, 0, 0, ]) + "\n"
result += "Error during inventory of %s: %s<br>\n" %
(hostname, e)
html.write(result)
return ""
@@ -976,7 +976,7 @@ def mode_bulk_inventory(phase):
interactive_progress(
hostnames, # list of items
"Bulk inventory", # title
- [ ("Services added", 0), ("Services removed", 0),
("Services kept", 0), ("Total services", 0) ], # stats table
+ [ ("Failed hosts", 0), ("Services added", 0),
("Services removed", 0), ("Services kept", 0), ("Total
services", 0) ], # stats table
[ ("mode", "file") ], # URL for "Stop/Finish"
button
50, # ms to sleep between two steps
)
@@ -1986,11 +1986,12 @@ def interactive_progress(items, title, stats, finishvars,
timewait):
html.write(" </table>")
html.write("</td>")
html.write("<td class=buttons>")
- html.jsbutton('progress_pause', 'Pause',
'javascript:progress_pause()')
- html.jsbutton('progress_proceed', 'Proceed',
'javascript:progress_proceed()', 'display:none')
- html.jsbutton('progress_finished', 'Finish',
'javascript:progress_end()', 'display:none')
- html.jsbutton('progress_restart', 'Restart',
'javascript:location.reload()')
- html.jsbutton('progress_abort', 'Abort',
'javascript:progress_end()')
+ html.jsbutton('progress_pause', _('Pause'),
'javascript:progress_pause()')
+ html.jsbutton('progress_proceed', _('Proceed'),
'javascript:progress_proceed()', 'display:none')
+ html.jsbutton('progress_finished', _('Finish'),
'javascript:progress_end()', 'display:none')
+ html.jsbutton('progress_retry', _('Retry Failed Hosts'),
'javascript:progress_retry()', 'display:none')
+ html.jsbutton('progress_restart', _('Restart'),
'javascript:location.reload()')
+ html.jsbutton('progress_abort', _('Abort'),
'javascript:progress_end()')
html.write("</td></tr>")
html.write("</table>")
html.write("</center>")