diff options
author | Nataliia S. <81954790+natali-rs1985@users.noreply.github.com> | 2024-10-05 22:48:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-05 22:48:43 +0300 |
commit | 17c9b444ecc7883f1d8af01fefc8d00f6f1ef49b (patch) | |
tree | 5704d4faffc109e9dbe9f0eef03fb21f00dd3025 /src/op_mode | |
parent | ed873d845372430a8bd96126ac93da1ad599ceb3 (diff) | |
download | vyos-1x-17c9b444ecc7883f1d8af01fefc8d00f6f1ef49b.tar.gz vyos-1x-17c9b444ecc7883f1d8af01fefc8d00f6f1ef49b.zip |
op-mode: T6753: Fix json output for mtr / monitor traceroute (#4122)
Diffstat (limited to 'src/op_mode')
-rw-r--r-- | src/op_mode/mtr.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/op_mode/mtr.py b/src/op_mode/mtr.py index de139f2fa..baf9672a1 100644 --- a/src/op_mode/mtr.py +++ b/src/op_mode/mtr.py @@ -178,6 +178,7 @@ mtr = { 6: '/bin/mtr -6', } + class List(list): def first(self): return self.pop(0) if self else '' @@ -218,12 +219,15 @@ def complete(prefix): def convert(command, args): + to_json = False while args: shortname = args.first() longnames = complete(shortname) if len(longnames) != 1: expension_failure(shortname, longnames) longname = longnames[0] + if longname == 'json': + to_json = True if options[longname]['type'] == 'noarg': command = options[longname]['mtr'].format( command=command, value='') @@ -232,7 +236,7 @@ def convert(command, args): else: command = options[longname]['mtr'].format( command=command, value=args.first()) - return command + return command, to_json if __name__ == '__main__': @@ -242,7 +246,6 @@ if __name__ == '__main__': if not host: sys.exit("mtr: Missing host") - if host == '--get-options' or host == '--get-options-nested': if host == '--get-options-nested': args.first() # pop monitor @@ -302,5 +305,8 @@ if __name__ == '__main__': except ValueError: sys.exit(f'mtr: Unknown host: {host}') - command = convert(mtr[version], args) - call(f'{command} --curses --displaymode 0 {host}') + command, to_json = convert(mtr[version], args) + if to_json: + call(f'{command} {host}') + else: + call(f'{command} --curses --displaymode 0 {host}') |