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:
@ -264,74 +264,77 @@ def process(proc_data):
|
|||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"proto": string,
|
"proto": string,
|
||||||
"recv_q": integer,
|
"recv_q": integer,
|
||||||
"send_q": integer,
|
"send_q": integer,
|
||||||
"transport_protocol" string,
|
"transport_protocol" string,
|
||||||
"network_protocol": string,
|
"network_protocol": string,
|
||||||
"local_address": string,
|
"local_address": string,
|
||||||
"local_port": string,
|
"local_port": string,
|
||||||
"local_port_num": integer,
|
"local_port_num": integer,
|
||||||
"foreign_address": string,
|
"foreign_address": string,
|
||||||
"foreign_port": string,
|
"foreign_port": string,
|
||||||
"foreign_port_num": integer,
|
"foreign_port_num": integer,
|
||||||
"state": string,
|
"state": string,
|
||||||
"program_name": string,
|
"program_name": string,
|
||||||
"pid": integer,
|
"pid": integer,
|
||||||
"user": string,
|
"user": string,
|
||||||
"security_context": string,
|
"security_context": string,
|
||||||
"refcnt": integer,
|
"refcnt": integer,
|
||||||
"flags": string,
|
"flags": string,
|
||||||
"type": string,
|
"type": string,
|
||||||
"inode": integer,
|
"inode": integer,
|
||||||
"path": string,
|
"path": string,
|
||||||
"kind": string,
|
"kind": string,
|
||||||
"address": string,
|
"address": string,
|
||||||
"osx_inode": string,
|
"osx_inode": string,
|
||||||
"conn": string,
|
"conn": string,
|
||||||
"refs": string,
|
"refs": string,
|
||||||
"nextref": string,
|
"nextref": string,
|
||||||
"name": string,
|
"name": string,
|
||||||
"unit": integer,
|
"unit": integer,
|
||||||
"vendor": integer,
|
"vendor": integer,
|
||||||
"class": integer,
|
"class": integer,
|
||||||
"subcla": integer,
|
"subcla": integer,
|
||||||
"osx_flags": integer,
|
"osx_flags": integer,
|
||||||
"pcbcount": integer,
|
"pcbcount": integer,
|
||||||
"rcvbuf": integer,
|
"rcvbuf": integer,
|
||||||
"sndbuf": integer,
|
"sndbuf": integer,
|
||||||
"rxbytes": integer,
|
"rxbytes": integer,
|
||||||
"txbytes": integer,
|
"txbytes": integer,
|
||||||
"destination": string,
|
"destination": string,
|
||||||
"gateway": string,
|
"gateway": string,
|
||||||
"route_flags": string,
|
"route_flags": string,
|
||||||
"route_refs": integer,
|
"route_flags_pretty": [
|
||||||
"use": integer,
|
string,
|
||||||
"mtu": integer,
|
]
|
||||||
"expire": string,
|
"route_refs": integer,
|
||||||
"genmask": string,
|
"use": integer,
|
||||||
"mss": integer,
|
"mtu": integer,
|
||||||
"window": integer,
|
"expire": string,
|
||||||
"irtt": integer,
|
"genmask": string,
|
||||||
"iface": string,
|
"mss": integer,
|
||||||
"metric": integer,
|
"window": integer,
|
||||||
"network": string,
|
"irtt": integer,
|
||||||
"address": string,
|
"iface": string,
|
||||||
"ipkts": integer, - = null
|
"metric": integer,
|
||||||
"ierrs": integer, - = null
|
"network": string,
|
||||||
"idrop": integer, - = null
|
"address": string,
|
||||||
"opkts": integer, - = null
|
"ipkts": integer, - = null
|
||||||
"oerrs": integer, - = null
|
"ierrs": integer, - = null
|
||||||
"coll": integer, - = null
|
"idrop": integer, - = null
|
||||||
"rx_ok": integer,
|
"opkts": integer, - = null
|
||||||
"rx_err": integer,
|
"oerrs": integer, - = null
|
||||||
"rx_drp": integer,
|
"coll": integer, - = null
|
||||||
"rx_ovr": integer,
|
"rx_ok": integer,
|
||||||
"tx_ok": integer,
|
"rx_err": integer,
|
||||||
"tx_err": integer,
|
"rx_drp": integer,
|
||||||
"tx_drp": integer,
|
"rx_ovr": integer,
|
||||||
"tx_ovr": integer,
|
"tx_ok": integer,
|
||||||
"flg": string
|
"tx_err": integer,
|
||||||
|
"tx_drp": integer,
|
||||||
|
"tx_ovr": integer,
|
||||||
|
"flg": string
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
"""
|
"""
|
||||||
|
@ -152,6 +152,29 @@ def parse_post(raw_data):
|
|||||||
else:
|
else:
|
||||||
entry['network_protocol'] = 'ipv4'
|
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
|
return raw_data
|
||||||
|
|
||||||
|
|
||||||
|
@ -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):
|
def normalize_headers(header):
|
||||||
@ -86,6 +86,41 @@ def parse_post(raw_data):
|
|||||||
else:
|
else:
|
||||||
entry['network_protocol'] = 'ipv4'
|
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
|
return raw_data
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user