diff options
author | Bryan Quigley <bryan.quigley@canonical.com> | 2019-10-07 17:36:46 -0700 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2019-12-11 16:40:57 +0000 |
commit | 745b4a236a0255ea76ffd273f3e2028ac46b4a89 (patch) | |
tree | b460b71dc5ae7b2b209ea6b0d7b4d42e7b993e64 | |
parent | 9b81a642baeb5e230a55bab7fc983fc421856298 (diff) | |
download | sos-745b4a236a0255ea76ffd273f3e2028ac46b4a89.tar.gz |
[logs] Substancial rewrite ending RH/U/D differences
--all-logs totally broke due to extra s in get_options, this
resulted in me trying to fix it, but it's simply grown too
complicated IMHO. We're duplicating functionality differently
in the RH and Ubuntu/Debian sections.
Logs.py changes:
Dropped the log_days option as it's confusing with since.
Use journal if persistant, otherwise don't collect it.
If all-logs collect full raw journal insteaf of verbose as it's the
same size but collects more info and is easier to parse.
Still collecting catalog for this/last boot ignoring since. RH request.
Collect message/secure no matter what. Rh specific.
Collect first 3 syslog/kern/auth only if not-journal.
Default to just stop at 100mb limit jounral limit (which is enforced
outside of plugin).
Also implement some basic "did it error" travis checks for the above.
Resolves: #1822
Signed-off-by: Bryan Quigley <bryan.quigley@canonical.com>
-rw-r--r-- | .travis.yml | 3 | ||||
-rw-r--r-- | sos/plugins/logs.py | 117 |
2 files changed, 38 insertions, 82 deletions
diff --git a/.travis.yml b/.travis.yml index 1b54c599..86f5168b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,9 @@ script: - "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport --help" - "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport -l --config-file=sos.conf" - "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport --batch --config-file=sos.conf 2> errors | tee batch_output" + - "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport --batch --all-logs --config-file=sos.conf 2> errors | tee batch_output" + - "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport --batch --since=20191007 --config-file=sos.conf 2> errors | tee batch_output" + - "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport --batch --all-logs --since=20191007 --config-file=sos.conf 2> errors | tee batch_output" - "[[ ! -s errors ]]" - "cat errors" - "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport --batch --build --config-file=sos.conf" diff --git a/sos/plugins/logs.py b/sos/plugins/logs.py index 77e2da85..1f0f163b 100644 --- a/sos/plugins/logs.py +++ b/sos/plugins/logs.py @@ -11,27 +11,18 @@ import glob from sos.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin -class Logs(Plugin): +class Logs(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin): """System logs""" plugin_name = "logs" profiles = ('system', 'hardware', 'storage') def setup(self): - self.add_copy_spec([ - "/etc/syslog.conf", - "/etc/rsyslog.conf", - "/etc/rsyslog.d" - ]) - - self.add_copy_spec("/var/log/boot.log") - self.add_journal(boot="this", catalog=True) - self.add_journal(boot="last", catalog=True) - self.add_cmd_output("journalctl --disk-usage") - confs = ['/etc/syslog.conf', '/etc/rsyslog.conf'] logs = [] + since = self.get_option("since") + if os.path.exists('/etc/rsyslog.conf'): with open('/etc/rsyslog.conf', 'r') as conf: for line in conf.readlines(): @@ -50,91 +41,41 @@ class Logs(Plugin): if os.path.isfile(i): self.add_copy_spec(i) - if self.get_option('all_logs'): - self.add_journal(boot="this", since=self.get_option("since"), - allfields=True, output="verbose") - self.add_journal(boot="last", allfields=True, output="verbose") - - def postproc(self): - self.do_path_regex_sub( - r"/etc/rsyslog*", - r"ActionLibdbiPassword (.*)", - r"ActionLibdbiPassword [********]" - ) - self.do_path_regex_sub( - r"/etc/rsyslog*", - r"pwd=.*", - r"pwd=[******]" - ) - - -class RedHatLogs(Logs, RedHatPlugin): - - option_list = [ - ("log_days", "the number of days logs to collect", "", 3) - ] - - def setup(self): - super(RedHatLogs, self).setup() - # NOTE: for historical reasons the 'messages' and 'secure' log - # paths for the RedHatLogs plugin do not obey the normal --all-logs - # convention. The rotated copies are collected unconditionally - # due to their frequent importance in diagnosing problems. - messages = "/var/log/messages" - secure = "/var/log/secure" - - have_messages = os.path.exists(messages) - - self.add_copy_spec(secure + "*") - self.add_copy_spec(messages + "*") - - # collect three days worth of logs by default if the system is - # configured to use the journal and not /var/log/messages - if not have_messages and self.is_installed("systemd"): - try: - days = int(self.get_option("log_days")) - except ValueError: - days = 3 - if self.get_option("all_logs") and self.get_options("since"): - since = self.get_options("since") - else: - since = "-%ddays" % days - self.add_journal(since=since) - - -class DebianLogs(Logs, DebianPlugin, UbuntuPlugin): - - option_list = [ - ("log_days", "the number of days logs to collect", "", 7) - ] - - def setup(self): - super(DebianLogs, self).setup() - days = int(self.get_option("log_days")) - journal = os.path.exists("/var/log/journal/") self.add_copy_spec([ + "/etc/syslog.conf", + "/etc/rsyslog.conf", + "/etc/rsyslog.d", + "/var/log/boot.log", + "/var/log/installer", + "/var/log/unattended-upgrades", + "/var/log/messages*", + "/var/log/secure*", "/var/log/udev", "/var/log/dist-upgrade", - "/var/log/installer", - "/var/log/unattended-upgrades" - ]) + ]) + + self.add_cmd_output("journalctl --disk-usage") self.add_cmd_output('ls -alRh /var/log/') + journal = os.path.exists("/var/log/journal/") if journal and self.is_installed("systemd"): - if self.get_option("all_logs"): - since = self.get_options("since") - else: - since = "-%ddays" % days self.add_journal(since=since) - else: + self.add_journal(boot="this", catalog=True) + self.add_journal(boot="last", catalog=True) + if self.get_option("all_logs"): + self.add_copy_spec("/var/log/journal/*") + else: # If not using journal if not self.get_option("all_logs"): self.add_copy_spec([ "/var/log/syslog", "/var/log/syslog.1", + "/var/log/syslog.2*", "/var/log/kern.log", "/var/log/kern.log.1", + "/var/log/kern.log.2*", "/var/log/auth.log", "/var/log/auth.log.1", + "/var/log/auth.log.2*", ]) else: self.add_copy_spec([ @@ -143,4 +84,16 @@ class DebianLogs(Logs, DebianPlugin, UbuntuPlugin): "/var/log/auth.log*", ]) + def postproc(self): + self.do_path_regex_sub( + r"/etc/rsyslog*", + r"ActionLibdbiPassword (.*)", + r"ActionLibdbiPassword [********]" + ) + self.do_path_regex_sub( + r"/etc/rsyslog*", + r"pwd=.*", + r"pwd=[******]" + ) + # vim: set et ts=4 sw=4 : |