Skip to content

Commit

Permalink
[storyteller] allow storyteller to work on downloaded logs (sonic-net…
Browse files Browse the repository at this point in the history
…#1388)

- What I did

Add log path parameter to allow storyteller to work on logs downloaded from sonic devices.
Improve reboot regex to capture more warm reboot related logs.

- How to verify it
Use storyteller against a sonic dump.
  • Loading branch information
yxieca authored Feb 3, 2021
1 parent a6ae218 commit aa7b90e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions scripts/storyteller
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ regex_dict = {
'crash' : 'what\|unexpected exception\|notify_OA_about_syncd_exception\|SIG\|not expected',
'interface' : 'updatePortOperStatus\|Configure .* to',
'lag' : 'link becomes\|addLag',
'reboot' : 'BOOT\|rc.local\|old_config\|minigraph.xml\|Rebooting\|reboot\|executeOperationsOnAsic\|getAsicView\|dumpVidToAsicOperatioId',
'reboot' : 'BOOT\|rc.local\|old_config\|minigraph.xml\|Rebooting\|reboot\|executeOperationsOnAsic\|getAsicView\|dumpVidToAsicOperatioId\|neighbor_adv\|Pausing\|shutdown\|warm',
'service' : 'Starting\|Stopping\|Started\|Stopped',
}


def exec_cmd(cmd):
out = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, text=True)
# Use universal_newlines (instead of text) so that this tool can work with any python versions.
out = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, universal_newlines=True)
stdout, stderr = out.communicate()
return out.returncode, stdout, stderr

Expand All @@ -37,9 +38,9 @@ def build_options(after=0, before=0, context=0):
return ' '.join(x for x in options)


def find_log(log, regex, after=0, before=0, context=0):
def find_log(logpath, log, regex, after=0, before=0, context=0):
options = build_options(after, before, context)
cmd = 'ls -rt /var/log/{}* | xargs zgrep -a {} "{}"'.format(log, options, regex)
cmd = 'ls -rt {}/{}* | xargs zgrep -a {} "{}"'.format(logpath, log, options, regex)
_, out, _ = exec_cmd(cmd)
'''
Opportunity to improve:
Expand All @@ -66,6 +67,8 @@ def main():
type=str, required=False, default='syslog')
parser.add_argument('-c', '--category', help='Categories: bgp, crash, interface, lag, reboot, service Specify multiple categories as c1,c2,c3; default: reboot',
type=str, required=False, default='reboot')
parser.add_argument('-p', '--logpath', help='log file path, e.g. /var/log; default: /var/log',
type=str, required=False, default='/var/log')
parser.add_argument('-A', '--after', help='Show N lines after match',
type=int, required=False, default=0)
parser.add_argument('-B', '--before', help='Show N lines before match',
Expand All @@ -78,7 +81,7 @@ def main():
log = args.log
reg = build_regex(args.category)

find_log(log, reg, args.after, args.before, args.context)
find_log(args.logpath, log, reg, args.after, args.before, args.context)


if __name__ == '__main__':
Expand Down

0 comments on commit aa7b90e

Please sign in to comment.