Module: check_mk
Branch: master
Commit: 7969597fc635194c26c5700d7571976c3e1c0c99
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7969597fc63519…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Apr 12 12:06:06 2018 +0200
Refactoring: Made agent output download page a class
Change-Id: I959cb6e9c9d3e66be33c6bdb33db422fcaa417a3
---
web/htdocs/wato.py | 67 ++++++++++++++++++++++++++---------------------
web/plugins/pages/wato.py | 2 +-
2 files changed, 38 insertions(+), 31 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 2ac9a31..65ee95f 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -15079,42 +15079,49 @@ def page_user_profile(change_pw=False):
# | Page for downloading the current agent output / SNMP walk of a host |
# '----------------------------------------------------------------------'
-def page_download_agent_output():
- config.user.need_permission("wato.download_agent_output")
+class PageDownloadAgentOutput(object):
+ def page(self):
+ self._from_vars()
- host_name = html.var("host")
- if not host_name:
- raise MKGeneralException(_("The host is missing."))
+ import htmllib
+ try:
+ success, output, agent_data =
watolib.check_mk_automation(self._host.site_id(), "get-agent-output",
+ [self._host.name(), self._ty])
+ except htmllib.RequestTimeout, e:
+ success, output, agent_data = False, "%s" % e, ""
+
+ if success:
+ html.set_output_format("text")
+ html.set_http_header("Content-Disposition", "Attachment;
filename=" + self._host.name())
+ html.write(agent_data)
+ else:
+ html.header(_("Failed to fetch agent data"),
stylesheets=["status", "pages"])
+ html.p(_("There was a problem fetching data from the host."))
+ if output:
+ html.show_error(output)
+ html.pre(agent_data)
+ html.footer()
- ty = html.var("type")
- if ty not in [ "walk", "agent" ]:
- raise MKGeneralException(_("Invalid type specified."))
- init_wato_datastructures(with_wato_lock=True)
+ def _from_vars(self):
+ config.user.need_permission("wato.download_agent_output")
- host = watolib.Folder.current().host(host_name)
- if not host:
- raise MKGeneralException(_("Invalid host."))
- host.need_permission("read")
+ host_name = html.var("host")
+ if not host_name:
+ raise MKGeneralException(_("The host is missing."))
- import htmllib
- try:
- success, output, agent_data = watolib.check_mk_automation(host.site_id(),
"get-agent-output",
- [host_name, ty])
- except htmllib.RequestTimeout, e:
- success, output, agent_data = False, "%s" % e, ""
+ ty = html.var("type")
+ if ty not in [ "walk", "agent" ]:
+ raise MKGeneralException(_("Invalid type specified."))
+ self._ty = ty
- if success:
- html.set_output_format("text")
- html.set_http_header("Content-Disposition", "Attachment;
filename=" + host_name)
- html.write(agent_data)
- else:
- html.header(_("Failed to fetch agent data"),
stylesheets=["status", "pages"])
- html.p(_("There was a problem fetching data from the host."))
- if output:
- html.show_error(output)
- html.pre(agent_data)
- html.footer()
+ init_wato_datastructures(with_wato_lock=True)
+
+ host = watolib.Folder.current().host(host_name)
+ if not host:
+ raise MKGeneralException(_("Invalid host."))
+ host.need_permission("read")
+ self._host = host
#.
# .--Sampleconfig--------------------------------------------------------.
diff --git a/web/plugins/pages/wato.py b/web/plugins/pages/wato.py
index e2c660c..cdcbc18 100644
--- a/web/plugins/pages/wato.py
+++ b/web/plugins/pages/wato.py
@@ -41,7 +41,7 @@ register_handlers({
"wato_ajax_diag_host" : lambda:
wato.ModeAjaxDiagHost().handle_page(),
"wato_ajax_profile_repl" : watolib.ajax_profile_repl,
"wato_ajax_execute_check" : lambda:
wato.ModeAjaxExecuteCheck().handle_page(),
- "download_agent_output" : wato.page_download_agent_output,
+ "download_agent_output" : lambda:
wato.PageDownloadAgentOutput().page(),
"ajax_popup_move_to_folder" : wato.ajax_popup_move_to_folder,
"ajax_backup_job_state" : lambda:
wato.ModeAjaxBackupJobState().page(),
})