summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
authormergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-10-08 23:05:30 +0300
committerGitHub <noreply@github.com>2024-10-08 23:05:30 +0300
commit65991f7f4d79b0c9255776a4160946e52e7da320 (patch)
tree211a23f82138563605f2c703bc100e54ac9b3786 /src/op_mode
parent54f2999a5618d72ebb445c9fe79e0a00a921fe93 (diff)
downloadvyos-1x-65991f7f4d79b0c9255776a4160946e52e7da320.tar.gz
vyos-1x-65991f7f4d79b0c9255776a4160946e52e7da320.zip
op-mode: T6753: Fix json output for mtr / monitor traceroute (#4122) (#4143)
(cherry picked from commit 17c9b444ecc7883f1d8af01fefc8d00f6f1ef49b) Co-authored-by: Nataliia S. <81954790+natali-rs1985@users.noreply.github.com>
Diffstat (limited to 'src/op_mode')
-rw-r--r--src/op_mode/mtr.py14
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}')