Skip to content

Commit 4309ca6

Browse files
authored
[storyteller] sort output by time and improve lag support (sonic-net#1430)
What I did sort output by time improve lag support according to event format changes add an option to sort the log files by a field of file name (after log files got moved or copied, sorting by timestamp is no longer reliable). Signed-off-by: Ying Xie [email protected] How to verify it run 'sudo storyteller --since "2021-2-10" -c lag' on a dut
1 parent c7e46c9 commit 4309ca6

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

scripts/storyteller

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ regex_dict = {
1717
'bgp' : 'bgpcfgd',
1818
'crash' : r'what\|unexpected exception\|notify_OA_about_syncd_exception\|SIG\|not expected',
1919
'interface' : r'updatePortOperStatus\|Configure .* to',
20-
'lag' : r'link becomes\|addLag',
20+
'lag' : r'link becomes\|addLag\|PortChannel.*oper state',
2121
'reboot' : r'BOOT\|rc.local\|old_config\|minigraph.xml\|Rebooting\|reboot\|executeOperationsOnAsic\|getAsicView\|dumpVidToAsicOperatioId\|neighbor_adv\|Pausing\|shutdown\|warm',
2222
'service' : r'Starting\|Stopping\|Started\|Stopped',
2323
}
@@ -44,9 +44,13 @@ def build_options(after=0, before=0, context=0):
4444
return ' '.join(x for x in options)
4545

4646

47-
def find_log(logpath, log, regex, after=0, before=0, context=0):
47+
def find_log(logpath, log, regex, after=0, before=0, context=0, field=0):
4848
options = build_options(after, before, context)
49-
cmd = 'find -L {}/{}* -newer {} | xargs zgrep -a {} "{}"'.format(logpath, log, reference_file, options, regex)
49+
if field <= 0:
50+
cmd = 'find -L {}/{}* -newer {} | xargs ls -rt | xargs zgrep -a {} "{}"'.format(logpath, log, reference_file, options, regex)
51+
else:
52+
cmd = 'find -L {0}/{1}* -newer {2} | sort -rn -t . -k {3},{3} | xargs zgrep -a {4} "{5}"'.format(logpath, log, reference_file, field, options, regex)
53+
5054
_, out, _ = exec_cmd(cmd)
5155
'''
5256
Opportunity to improve:
@@ -92,8 +96,10 @@ def main():
9296
type=int, required=False, default=0)
9397
parser.add_argument('-C', '--context', help='Show N lines before and after match',
9498
type=int, required=False, default=0)
95-
parser.add_argument('-S', '--since', help='Filter logs since the given date',
99+
parser.add_argument('-s', '--since', help='Filter logs since the given date',
96100
type=str, required=False, default="@0")
101+
parser.add_argument('-f', '--sortfield', help='Use Nth field separted by "." in file name to sort. e.g. syslog.1.gz: -f 2, swss.rec.2.gz: -f 3, default 0: sort by timestamp',
102+
type=int, required=False, default=0)
97103

98104
args = parser.parse_args()
99105

@@ -106,7 +112,7 @@ def main():
106112
reg = build_regex(category)
107113
configure_time_filter(since)
108114

109-
find_log(log_path, log, reg, args.after, args.before, args.context)
115+
find_log(log_path, log, reg, args.after, args.before, args.context, args.sortfield)
110116

111117

112118
if __name__ == '__main__':

0 commit comments

Comments
 (0)