@@ -14,13 +14,14 @@ regex_dict = {
14
14
'crash' : 'what\|unexpected exception\|notify_OA_about_syncd_exception\|SIG\|not expected' ,
15
15
'interface' : 'updatePortOperStatus\|Configure .* to' ,
16
16
'lag' : 'link becomes\|addLag' ,
17
- 'reboot' : 'BOOT\|rc.local\|old_config\|minigraph.xml\|Rebooting\|reboot\|executeOperationsOnAsic\|getAsicView\|dumpVidToAsicOperatioId' ,
17
+ 'reboot' : 'BOOT\|rc.local\|old_config\|minigraph.xml\|Rebooting\|reboot\|executeOperationsOnAsic\|getAsicView\|dumpVidToAsicOperatioId\|neighbor_adv\|Pausing\|shutdown\|warm ' ,
18
18
'service' : 'Starting\|Stopping\|Started\|Stopped' ,
19
19
}
20
20
21
21
22
22
def exec_cmd (cmd ):
23
- out = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT , shell = True , text = True )
23
+ # Use universal_newlines (instead of text) so that this tool can work with any python versions.
24
+ out = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT , shell = True , universal_newlines = True )
24
25
stdout , stderr = out .communicate ()
25
26
return out .returncode , stdout , stderr
26
27
@@ -37,9 +38,9 @@ def build_options(after=0, before=0, context=0):
37
38
return ' ' .join (x for x in options )
38
39
39
40
40
- def find_log (log , regex , after = 0 , before = 0 , context = 0 ):
41
+ def find_log (logpath , log , regex , after = 0 , before = 0 , context = 0 ):
41
42
options = build_options (after , before , context )
42
- cmd = 'ls -rt /var/log/ {}* | xargs zgrep -a {} "{}"' .format (log , options , regex )
43
+ cmd = 'ls -rt {}/ {}* | xargs zgrep -a {} "{}"' .format (logpath , log , options , regex )
43
44
_ , out , _ = exec_cmd (cmd )
44
45
'''
45
46
Opportunity to improve:
@@ -66,6 +67,8 @@ def main():
66
67
type = str , required = False , default = 'syslog' )
67
68
parser .add_argument ('-c' , '--category' , help = 'Categories: bgp, crash, interface, lag, reboot, service Specify multiple categories as c1,c2,c3; default: reboot' ,
68
69
type = str , required = False , default = 'reboot' )
70
+ parser .add_argument ('-p' , '--logpath' , help = 'log file path, e.g. /var/log; default: /var/log' ,
71
+ type = str , required = False , default = '/var/log' )
69
72
parser .add_argument ('-A' , '--after' , help = 'Show N lines after match' ,
70
73
type = int , required = False , default = 0 )
71
74
parser .add_argument ('-B' , '--before' , help = 'Show N lines before match' ,
@@ -78,7 +81,7 @@ def main():
78
81
log = args .log
79
82
reg = build_regex (args .category )
80
83
81
- find_log (log , reg , args .after , args .before , args .context )
84
+ find_log (args . logpath , log , reg , args .after , args .before , args .context )
82
85
83
86
84
87
if __name__ == '__main__' :
0 commit comments