Module: check_mk
Branch: master
Commit: 6c662eb9c219e8b87e8684dfc95431563ada0f0a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6c662eb9c219e8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jul 27 09:07:08 2016 +0200
Backup/Restore job details: page is being updated automatically
---
web/htdocs/backup.py | 12 +++++++
web/htdocs/js/checkmk.js | 80 +++++++++++++++++++++++++++++++++++++++++++++
web/htdocs/wato.py | 7 ++++
web/plugins/pages/wato.py | 1 +
4 files changed, 100 insertions(+)
diff --git a/web/htdocs/backup.py b/web/htdocs/backup.py
index 6952a0f..c9003ee 100644
--- a/web/htdocs/backup.py
+++ b/web/htdocs/backup.py
@@ -860,6 +860,18 @@ class PageBackupJobState(object):
def page(self):
+ html.write("<div id=\"job_details\">")
+ self._show_job_details()
+ html.write("</div>")
+ html.javascript("refresh_job_details('%s', '%s', %s)"
%
+ (self._update_url(), self._ident, "true" if is_site() else
"false"))
+
+
+ def _update_url(self):
+ return "ajax_backup_job_state.py?job=%s" % self._ident
+
+
+ def _show_job_details(self):
job = self._job
state = job.state()
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index a7baec2..aeebbe1 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -3147,3 +3147,83 @@ function hide_crash_report_processing_msg()
var msg = document.getElementById("pending_msg");
msg.parentNode.removeChild(msg);
}
+
+//#.
+//# .-Backup-------------------------------------------------------------.
+//# | ____ _ |
+//# | | __ ) __ _ ___| | ___ _ _ __ |
+//# | | _ \ / _` |/ __| |/ / | | | '_ \ |
+//# | | |_) | (_| | (__| <| |_| | |_) | |
+//# | |____/ \__,_|\___|_|\_\\__,_| .__/ |
+//# | |_| |
+//# +--------------------------------------------------------------------+
+//# | |
+//# '--------------------------------------------------------------------'
+
+function refresh_job_details(url, ident, is_site)
+{
+ setTimeout(function() {
+ do_job_detail_refresh(url, ident, is_site);
+ }, 1000);
+}
+
+function do_job_detail_refresh(url, ident, is_site)
+{
+ call_ajax(url, {
+ method : "GET",
+ post_data : "job=" + encodeURIComponent(ident),
+ response_handler : handle_job_detail_response,
+ error_handler : handle_job_detail_error,
+ handler_data : {
+ "url" : url,
+ "ident" : ident,
+ "is_site" : is_site,
+ }
+ });
+}
+
+function handle_job_detail_response(handler_data, response_body)
+{
+ var container = document.getElementById("job_details");
+ container.innerHTML = response_body;
+
+ refresh_job_details(handler_data["url"], handler_data["ident"],
handler_data["is_site"]);
+}
+
+function handle_job_detail_error(handler_data, status_code, error_msg)
+{
+ hide_job_detail_msg();
+
+ if (status_code == 0)
+ return; // ajax request aborted. Stop refresh.
+
+ var container = document.getElementById("job_details");
+
+ var msg = document.createElement("div");
+ container.insertBefore(msg, container.firstChild);
+ msg.setAttribute("id", "job_detail_msg");
+ msg.className = "message";
+
+ txt = "Could not update the job details.";
+ if (handler_data.is_site)
+ txt += " The site will be started again after the restore.";
+ else
+ txt += " Maybe the device is currently being rebooted.";
+
+ txt += "<br>Will continue trying to refresh the job details.";
+
+ txt += "<br><br>HTTP status code: "+status_code;
+ if (error_msg)
+ txt += ", Error: "+error_msg;
+
+ msg.innerHTML = txt;
+
+ refresh_job_details(handler_data["url"], handler_data["ident"],
handler_data["is_site"]);
+}
+
+function hide_job_detail_msg()
+{
+ var msg = document.getElementById("job_detail_msg");
+ if (msg)
+ msg.parentNode.removeChild(msg);
+}
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 1d41c8c..2c26770 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -5426,6 +5426,13 @@ class ModeBackupJobState(backup.PageBackupJobState, WatoMode):
+class ModeAjaxBackupJobState(ModeBackupJobState):
+ def page(self):
+ config.need_permission("wato.backups")
+ self._show_job_details()
+
+
+
class SiteBackupKeypairStore(backup.BackupKeypairStore):
def __init__(self):
super(SiteBackupKeypairStore, self).__init__(
diff --git a/web/plugins/pages/wato.py b/web/plugins/pages/wato.py
index 10ecf98..f9a702d 100644
--- a/web/plugins/pages/wato.py
+++ b/web/plugins/pages/wato.py
@@ -40,4 +40,5 @@ pagehandlers.update({
"wato_ajax_execute_check" : wato.ajax_execute_check,
"download_agent_output" : wato.page_download_agent_output,
"ajax_popup_move_to_folder" : wato.ajax_popup_move_to_folder,
+ "ajax_backup_job_state" : lambda:
wato.ModeAjaxBackupJobState().page(),
})