Module: check_mk
Branch: master
Commit: c0f1dd848b7151744f9d703327478aa7bc5ae4a9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c0f1dd848b7151…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Aug 23 09:07:17 2016 +0200
Several minor cleanups
---
web/htdocs/index.py | 5 +++--
web/htdocs/lib.py | 19 ++++++-------------
web/htdocs/multitar.py | 4 ++--
web/htdocs/wato.py | 13 ++++---------
web/htdocs/watolib.py | 6 +++---
5 files changed, 18 insertions(+), 29 deletions(-)
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index a99db40..f75d527 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -26,6 +26,8 @@
from mod_python import apache
import sys, os, pprint, __builtin__
+import traceback
+
import i18n
import sites
import livestatus
@@ -66,7 +68,7 @@ def handler(req, fields = None, is_profiling = False):
except Exception, e:
html.write(str(e))
if config.debug:
- html.write(html.attrencode(format_exception()))
+ html.write(html.attrencode(traceback.format_exc()))
raise FinalizeRequest()
# Is the user set by the webserver? otherwise use the cookie based auth
@@ -179,7 +181,6 @@ def handler(req, fields = None, is_profiling = False):
except Exception, e:
html.unplug()
- import traceback
msg = "%s %s: %s" % (html.request_uri(), _('Internal error'),
traceback.format_exc())
if type(msg) == unicode:
msg = msg.encode('utf-8')
diff --git a/web/htdocs/lib.py b/web/htdocs/lib.py
index f737d92..0fef22a 100644
--- a/web/htdocs/lib.py
+++ b/web/htdocs/lib.py
@@ -145,6 +145,8 @@ def remove_user_file(path):
os.remove(path)
+# TODO: Remove this helper function. Replace with explicit checks and covnersion
+# in using code.
def savefloat(f):
try:
return float(f)
@@ -259,8 +261,9 @@ def pnp_cleanup(s):
.replace('\\', '_')
# Quote string for use as arguments on the shell
+# TODO: Move to Check_MK library
def quote_shell_string(s):
- return "'" + s.replace("'",
"'\"'\"'") + "'"
+ return "'" + s.replace("'",
"'\"'\"'") + "'"
ok_marker = '<b class="stmark state0">OK</b>'
warn_marker = '<b class="stmark state1">WARN</b>'
@@ -310,10 +313,6 @@ def format_plugin_output(output, row = None):
return output
-def format_exception():
- import traceback
- return traceback.format_exc()
-
# Debug logging directly to the dedicated web GUI log. The log format is
# equal to the cmc.log format. The format is:
@@ -354,6 +353,8 @@ def lqencode(s):
return s.replace('\n', '')
+# TODO: Remove this helper function. Replace with explicit checks and covnersion
+# in using code.
def saveint(x):
try:
return int(x)
@@ -368,14 +369,6 @@ def tryint(x):
return x
-def isint(i):
- try:
- int(i)
- return True
- except:
- return False
-
-
aquire_lock = store.aquire_lock
release_lock = store.release_lock
have_lock = store.have_lock
diff --git a/web/htdocs/multitar.py b/web/htdocs/multitar.py
index d020186..47b61c2 100644
--- a/web/htdocs/multitar.py
+++ b/web/htdocs/multitar.py
@@ -28,6 +28,7 @@
# of multi-tier tar files (tar files containing tar files)
import os, tarfile, time, shutil, cStringIO, defaults, grp
+import traceback
from lib import *
class fake_file:
@@ -247,7 +248,7 @@ def extract_domains(tar, domains):
errors.extend(dom_errors or [])
except Exception, e:
# This should NEVER happen
- err_info = "Restore-Phase: %s, Domain: %s\nError: %s" %
(what, name, format_exception())
+ err_info = "Restore-Phase: %s, Domain: %s\nError: %s" %
(what, name, traceback.format_exc())
errors.append(err_info)
logger(LOG_CRIT, err_info)
if abort_on_error == False:
@@ -301,7 +302,6 @@ def extract(tar, components):
subtar = tarfile.open(fileobj = subtarstream)
subtar.extractall(target_dir)
except Exception, e:
- import traceback
raise MKGeneralException('Failed to extract subtar %s: %s' % (name,
traceback.format_exc()))
# Try to cleanup everything starting from the root_path
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index b2cde70..172bcb6 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -87,6 +87,7 @@ import sys, pprint, socket, re, time, datetime, \
shutil, tarfile, cStringIO, math, fcntl, random, glob, \
base64, csv
import subprocess
+import traceback
import i18n
import config, table, multitar, userdb, weblib, login
from hashlib import sha256
@@ -265,7 +266,6 @@ def page_handler():
except Exception, e:
html.unplug()
- import traceback
html.show_error(traceback.format_exc().replace('\n', '<br
/>'))
html.write("</div>\n")
@@ -2648,7 +2648,6 @@ def ajax_diag_host():
# Second is treated as text output
html.write("%s %s" % (result[0], html.attrencode(result[1])))
except Exception, e:
- import traceback
html.write("1 %s" % _("Exception: %s") %
html.attrencode(traceback.format_exc()))
#.
@@ -2895,7 +2894,6 @@ def show_service_table(host, firsttime):
paramtext =
rulespec["valuespec"].value_to_text(params)
except Exception, e:
if config.debug:
- import traceback
err = traceback.format_exc()
else:
err = e
@@ -3490,7 +3488,7 @@ def mode_bulk_discovery(phase):
else:
msg = _("Error during inventory of %s<div
class=exc>%s</div>") % (", ".join(hostnames), e)
if config.debug:
- msg += "<br><pre>%s</pre><br>" %
html.attrencode(format_exception().replace("\n", "<br>"))
+ msg += "<br><pre>%s</pre><br>" %
html.attrencode(traceback.format_exc().replace("\n", "<br>"))
result += msg
html.write(result)
return ""
@@ -3909,7 +3907,7 @@ def mode_parentscan(phase):
else:
msg = _("Error during parent scan of %s: %s") % (host_name,
e)
if config.debug:
- msg += "<br><pre>%s</pre>" %
html.attrencode(format_exception().replace("\n", "<br>"))
+ msg += "<br><pre>%s</pre>" %
html.attrencode(traceback.format_exc().replace("\n", "<br>"))
result += msg + "\n<br>"
html.write(result)
return ""
@@ -5147,7 +5145,6 @@ def get_snapshot_status(snapshot, validate_checksums = False):
except Exception, e:
if config.debug:
- import traceback
status["broken_text"] = traceback.format_exc()
status["broken"] = True
else:
@@ -9721,7 +9718,7 @@ def automation_push_profile():
return True
except Exception, e:
if config.debug:
- return _("Internal automation error: %s\n%s") % (str(e),
format_exception())
+ return _("Internal automation error: %s\n%s") % (e,
traceback.format_exc())
else:
return _("Internal automation error: %s") % e
@@ -9941,7 +9938,6 @@ def mode_users(phase):
return None, _('The user synchronization completed
successfully.')
except Exception, e:
if config.debug:
- import traceback
raise MKUserError(None, traceback.format_exc().replace('\n',
'<br>\n'))
else:
raise MKUserError(None, "%s" % e)
@@ -15758,7 +15754,6 @@ def execute_network_scan_job():
"state" : False,
"output" : _("An exception occured: %s") % e,
})
- import traceback
logger(LOG_ERR, "Exception in network scan:\n%s" %
(traceback.format_exc()))
result["end"] = time.time()
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index ef013ab..c758e5c 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -45,6 +45,7 @@
import os, shutil, subprocess, base64, pickle, pwd
import defaults, config, hooks, userdb, multitar
import sites
+import traceback
from lib import *
from valuespec import *
@@ -158,7 +159,6 @@ def activate_changes():
update_replication_status(None, {}, { 'act': duration })
except Exception:
if config.debug:
- import traceback
raise MKUserError(None, "Error executing hooks: %s" %
traceback.format_exc().replace('\n', '<br
/>'))
else:
@@ -285,7 +285,7 @@ def parse_audit_log(what):
for line in file(path):
line = line.rstrip().decode("utf-8")
splitted = line.split(None, 4)
- if len(splitted) == 5 and isint(splitted[0]):
+ if len(splitted) == 5 and splitted[0].isdigit():
splitted[0] = int(splitted[0])
entries.append(splitted)
entries.reverse()
@@ -3723,7 +3723,7 @@ def automation_push_snapshot():
return configuration_warnings
except Exception, e:
if config.debug:
- return _("Internal automation error: %s\n%s") % (str(e),
format_exception())
+ return _("Internal automation error: %s\n%s") % (e,
traceback.format_exc())
else:
return _("Internal automation error: %s") % e