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

add route_flags_pretty

This commit is contained in:
Kelly Brazil
2020-05-29 12:51:04 -07:00
parent 8631b756e7
commit 6ce18de84c
3 changed files with 130 additions and 69 deletions

View File

@ -305,6 +305,9 @@ def process(proc_data):
"destination": string,
"gateway": string,
"route_flags": string,
"route_flags_pretty": [
string,
]
"route_refs": integer,
"use": integer,
"mtu": integer,

View File

@ -152,6 +152,29 @@ def parse_post(raw_data):
else:
entry['network_protocol'] = 'ipv4'
# add route_flags_pretty
# Flag mapping from https://www.man7.org/linux/man-pages/man8/route.8.html
if 'route_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['route_flags']:
if flag in flag_map:
pretty_flags.append(flag_map[flag])
entry['route_flags_pretty'] = pretty_flags
return raw_data

View File

@ -1,4 +1,4 @@
"""jc - JSON CLI output utility OSX netstat Parser"""
"""jc - JSON CLI output utility OSX and FreeBSD netstat Parser"""
def normalize_headers(header):
@ -86,6 +86,41 @@ def parse_post(raw_data):
else:
entry['network_protocol'] = 'ipv4'
# add route_flags_pretty field
if 'route_flags' in entry:
flag_map = {
'1': 'PROTO1',
'2': 'PROTO2',
'3': 'PROTO3',
'B': 'BLACKHOLE',
'b': 'BROADCAST',
'C': 'CLONING',
'c': 'PRCLONING',
'D': 'DYNAMIC',
'G': 'GATEWAY',
'H': 'HOST',
'I': 'IFSCOPE',
'i': 'IFREF',
'L': 'LLINFO',
'M': 'MODIFIED',
'm': 'MULTICAST',
'R': 'REJECT',
'r': 'ROUTER',
'S': 'STATIC',
'U': 'UP',
'W': 'WASCLONED',
'X': 'XRESOLVE',
'Y': 'PROXY',
}
pretty_flags = []
for flag in entry['route_flags']:
if flag in flag_map:
pretty_flags.append(flag_map[flag])
entry['route_flags_pretty'] = pretty_flags
return raw_data