1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00

add flags_pretty

This commit is contained in:
Kelly Brazil
2020-05-29 12:55:16 -07:00
parent 6ce18de84c
commit f07b7eaa47

View File

@ -101,7 +101,7 @@ import jc.parsers.universal
class info(): class info():
version = '1.0' version = '1.1'
description = 'route command parser' description = 'route command parser'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -128,17 +128,20 @@ def process(proc_data):
[ [
{ {
"destination": string, "destination": string,
"gateway": string, "gateway": string,
"genmask": string, "genmask": string,
"flags": string, "flags": string,
"metric": integer, "flags_pretty": [
"ref": integer, string,
"use": integer, ]
"mss": integer, "metric": integer,
"window": integer, "ref": integer,
"irtt": integer, "use": integer,
"iface": string "mss": integer,
"window": integer,
"irtt": integer,
"iface": string
} }
] ]
""" """
@ -152,6 +155,29 @@ def process(proc_data):
except (ValueError): except (ValueError):
entry[key] = None entry[key] = None
# add flags_pretty
# Flag mapping from https://www.man7.org/linux/man-pages/man8/route.8.html
if 'flags' in entry:
flag_map = {
'U': 'UP',
'H': 'HOST',
'G': 'GATEWAY',
'R': 'REINSTATE',
'D': 'DYNAMIC',
'M': 'MODIFIED',
'A': 'ADDRCONF',
'C': 'CACHE',
'!': 'REJECT'
}
pretty_flags = []
for flag in entry['flags']:
if flag in flag_map:
pretty_flags.append(flag_map[flag])
entry['flags_pretty'] = pretty_flags
return proc_data return proc_data