Module: check_mk
Branch: master
Commit: fe12899a691ec17d364d0f9226836a125c6ea7bc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fe12899a691ec1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Oct 1 16:44:43 2012 +0200
FIX: Implemented basic non HTTP 200 status code response handling in
interactive progress dialogs (e.g. bulk inventory mode)
---
ChangeLog | 4 +++
web/htdocs/js/wato.js | 59 ++++++++++++++++++++++++++++++++++++------------
web/htdocs/wato.py | 11 ++++++--
3 files changed, 56 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c361152..73a9dac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,10 @@
* FIX: Fixed releasing of locks and livestatus connections when logging out
* FIX: Fixed login/login confusions with index page caching
+ WATO:
+ * FIX: Implemented basic non HTTP 200 status code response handling in interactive
+ progress dialogs (e.g. bulk inventory mode)
+
1.2.0p3:
Mulitisite
* Added "view" parameter to dashlet_pnpgraph webservice
diff --git a/web/htdocs/js/wato.js b/web/htdocs/js/wato.js
index 76bf3be..e3da0f4 100644
--- a/web/htdocs/js/wato.js
+++ b/web/htdocs/js/wato.js
@@ -240,6 +240,8 @@ var progress_found = 0;
// The fields which signal that something has been successfully processed.
// this is used together with progress_found to find out the correct redirect url
var progress_success_stats = [];
+// The fields which signal that something has failed
+var progress_fail_stats = [];
// The URL to redirect to after finish/abort button pressed
var progress_end_url = '';
// The URL to redirect to after finish/abort button pressed when nothing found
@@ -253,23 +255,46 @@ var progress_paused = false;
// Is set to true when the user hit aborted/finished
var progress_ended = false;
-function progress_handle_response(data, code) {
+function progress_handle_error(data, code) {
+ // code contains no parsable response but the http code
+ progress_handle_response(data, '', code);
+}
+
+function progress_handle_response(data, code, http_code) {
var mode = data[0];
var item = data[1];
var header = null;
- try {
- var header = eval(code.split("\n", 1)[0]);
- if (header === null)
- alert('Header is null!');
- } catch(err) {
- alert('Invalid response: ' + code);
- }
+ var body = null;
+ if(http_code !== undefined) {
+ // If the request failed report the item as failed
+ // - Report failed state
+ // - Update the total count (item 0 = 1)
+ // - Update the failed stats
+ header = [ 'failed', 1 ];
+ for(var i = 1; i <= Math.max.apply(Math, progress_fail_stats); i++) {
+ if(progress_fail_stats.indexOf(i) !== -1) {
+ header.push(1);
+ } else {
+ header.push(0);
+ }
+ }
+ body = 'HTTP-Request failed (' + http_code + ', ' + data +
')'
+ } else {
+ // Regular response processing
+ try {
+ var header = eval(code.split("\n", 1)[0]);
+ if (header === null)
+ alert('Header is null!');
+ } catch(err) {
+ alert('Invalid response: ' + code);
+ }
- // Extract the body from the response
- var body = code.split('\n');
- body.splice(0,1);
- body = body.join('');
+ // Extract the body from the response
+ var body = code.split('\n');
+ body.splice(0,1);
+ body = body.join('');
+ }
// Process statistics
update_progress_stats(header);
@@ -404,7 +429,7 @@ function progress_clean_log() {
log = null;
}
-function progress_scheduler(mode, url_prefix, timeout, items, end_url, success_stats,
term_url, finished_txt) {
+function progress_scheduler(mode, url_prefix, timeout, items, end_url, success_stats,
fail_stats, term_url, finished_txt) {
// Initialize
if (progress_items === null) {
progress_items = items;
@@ -413,6 +438,7 @@ function progress_scheduler(mode, url_prefix, timeout, items, end_url,
success_s
progress_end_url = end_url;
progress_term_url = term_url;
progress_success_stats = success_stats;
+ progress_fail_stats = fail_stats;
progress_fin_txt = finished_txt;
progress_mode = mode;
progress_url = url_prefix;
@@ -430,8 +456,11 @@ function progress_scheduler(mode, url_prefix, timeout, items,
end_url, success_s
progress_running = true;
// Remove leading pipe signs (when having no folder set)
update_progress_title(progress_items[0].replace(/^\|*/g, ''));
- 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, // regular handler (http code 200)
+ [ mode, progress_items[0] ], // data to hand over to handlers
+ progress_handle_error // error handler
+ );
} else {
progress_finished();
return;
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index b8624c2..8541e6a 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -2530,6 +2530,7 @@ def mode_bulk_inventory(phase):
(_("Total services"), 0) ], # stats table
[ ("mode", "folder") ], # URL for "Stop/Finish"
button
50, # ms to sleep between two steps
+ fail_stats = [ 1 ],
)
else:
@@ -2900,6 +2901,7 @@ def mode_parentscan(phase):
],
[ ("mode", "folder") ], # URL for "Stop/Finish"
button
50, # ms to sleep between two steps
+ fail_stats = [ 1 ],
)
else:
@@ -4019,7 +4021,9 @@ def hilite_errors(outdata):
# | buttons for aborting and pausing. |
# '----------------------------------------------------------------------'
-def interactive_progress(items, title, stats, finishvars, timewait, success_stats = [],
termvars = []):
+# success_stats: Fields from the stats list to use for checking if something has been
found
+# fail_stats: Fields from the stats list to used to count failed elements
+def interactive_progress(items, title, stats, finishvars, timewait, success_stats = [],
termvars = [], fail_stats = []):
if not termvars:
termvars = finishvars;
html.write("<center>")
@@ -4050,6 +4054,7 @@ def interactive_progress(items, title, stats, finishvars, timewait,
success_stat
html.write("</center>")
json_items = '[ %s ]' % ',\n'.join([ "'" + h +
"'" for h in items ])
success_stats = '[ %s ]' % ','.join(map(str, success_stats))
+ fail_stats = '[ %s ]' % ','.join(map(str, fail_stats))
# Remove all sel_* variables. We do not need them for our ajax-calls.
# They are just needed for the Abort/Finish links. Those must be converted
# to POST.
@@ -4057,9 +4062,9 @@ def interactive_progress(items, title, stats, finishvars, timewait,
success_stat
finish_url = make_link([("mode", "folder")] + finishvars)
term_url = make_link([("mode", "folder")] + termvars)
- html.javascript(('progress_scheduler("%s", "%s", 50, %s,
"%s", %s, "%s", "' + _("FINISHED.") +
'");') %
+ html.javascript(('progress_scheduler("%s", "%s", 50, %s,
"%s", %s, %s, "%s", "' + _("FINISHED.") +
'");') %
(html.var('mode'), base_url, json_items, finish_url,
- success_stats, term_url))
+ success_stats, fail_stats, term_url))
#.