From 813794ed46bf5901ab0afdcdd6122bfa04ac1701 Mon Sep 17 00:00:00 2001 From: garyk Date: Thu, 3 Nov 2011 10:59:51 +0200 Subject: [PATCH] Blueprint lasterror Add in a log report to nova-manage Usages: Get the last errors in the nova logs nova-manage logs errors Get the last x nova messages in the syslog. The default is 10 nova-manage logs syslog Change-Id: Id5d3a546051e25175b6523711f437618d07c3f19 --- Authors | 1 + bin/nova-manage | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Authors b/Authors index 8bb8070417db..2f38958ad901 100644 --- a/Authors +++ b/Authors @@ -44,6 +44,7 @@ Eric Day Eric Windisch Ewan Mellor Gabe Westmaas +Gary Kotton Hisaharu Ishii Hisaki Ohara Ilya Alekseyev diff --git a/bin/nova-manage b/bin/nova-manage index 485c93de4e95..f6b86360eeba 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -2158,6 +2158,47 @@ class ConfigCommands(object): print FLAGS.FlagsIntoString() +class GetLogCommands(object): + """Get logging information""" + + def errors(self): + """Get all of the errors from the log files""" + if FLAGS.logdir: + error_found = 0 + logs = [x for x in os.listdir(FLAGS.logdir) if x.endswith('.log')] + for file in logs: + log_file = os.path.join(FLAGS.logdir, file) + lines = [line.strip() for line in open(log_file, "r")] + lines.reverse() + print_name = 0 + for index, line in enumerate(lines): + if line.find(" ERROR ") > 0: + error_found += 1 + if print_name == 0: + print log_file + ":-" + print_name = 1 + print "Line %d : %s" % (len(lines) - index, line) + if error_found == 0: + print "No errors in logfiles!" + + def syslog(self, num_entries=10): + """Get of the nova syslog events""" + entries = int(num_entries) + count = 0 + lines = [line.strip() for line in open('/var/log/syslog', "r")] + lines.reverse() + print "Last %s nova syslog entries:-" % (entries) + for line in lines: + if line.find("nova") > 0: + count += 1 + print "%s" % (line) + if count == entries: + break + + if count == 0: + print "No nova entries in syslog!" + + CATEGORIES = [ ('account', AccountCommands), ('agent', AgentBuildCommands), @@ -2181,7 +2222,8 @@ CATEGORIES = [ ('vm', VmCommands), ('volume', VolumeCommands), ('vpn', VpnCommands), - ('vsa', VsaCommands)] + ('vsa', VsaCommands), + ('logs', GetLogCommands)] def lazy_match(name, key_value_tuples):