diff --git a/docgen.sh b/docgen.sh index e4a38ac0..b4da0cf6 100755 --- a/docgen.sh +++ b/docgen.sh @@ -21,6 +21,7 @@ pydocmd simple jc.parsers.mount+ > ../docs/parsers/mount.md pydocmd simple jc.parsers.netstat+ > ../docs/parsers/netstat.md pydocmd simple jc.parsers.ps+ > ../docs/parsers/ps.md pydocmd simple jc.parsers.route+ > ../docs/parsers/route.md +pydocmd simple jc.parsers.ss+ > ../docs/parsers/ss.md pydocmd simple jc.parsers.uname+ > ../docs/parsers/uname.md pydocmd simple jc.parsers.uptime+ > ../docs/parsers/uptime.md pydocmd simple jc.parsers.w+ > ../docs/parsers/w.md diff --git a/docs/parsers/ss.md b/docs/parsers/ss.md new file mode 100644 index 00000000..8e6a6d1a --- /dev/null +++ b/docs/parsers/ss.md @@ -0,0 +1,184 @@ +# jc.parsers.ss +jc - JSON CLI output utility ss Parser + +Usage: + specify --ss as the first argument if the piped input is coming from ss + +Examples: + + $ sudo ss -a | jc --ss -p + [ + { + "netid": "nl", + "state": "UNCONN", + "recv_q": 0, + "send_q": 0, + "local_address": "rtnl", + "local_port": "kernel", + "peer_address": "*" + }, + { + "netid": "nl", + "state": "UNCONN", + "recv_q": 0, + "send_q": 0, + "local_address": "rtnl", + "local_port": "systemd-resolve/893", + "peer_address": "*" + }, + { + "netid": "nl", + "state": "UNCONN", + "recv_q": 0, + "send_q": 0, + "local_address": "rtnl", + "local_port": "systemd/1", + "peer_address": "*" + }, + ... + { + "netid": "tcp", + "state": "LISTEN", + "recv_q": 0, + "send_q": 128, + "local_address": "127.0.0.1", + "local_port": "35485", + "peer_address": "0.0.0.0", + "peer_port": "*", + "interface": "lo" + }, + { + "netid": "tcp", + "state": "LISTEN", + "recv_q": 0, + "send_q": 128, + "local_address": "[::]", + "local_port": "ssh", + "peer_address": "[::]", + "peer_port": "*" + }, + { + "netid": "v_str", + "state": "ESTAB", + "recv_q": 0, + "send_q": 0, + "local_address": "999900439", + "local_port": "1023", + "peer_address": "0", + "peer_port": "976", + "local_port_num": 1023, + "peer_port_num": 976 + } + ] + + $ sudo ss -a | jc --ss -p -r + [ + { + "netid": "nl", + "state": "UNCONN", + "recv_q": "0", + "send_q": "0", + "local_address": "rtnl", + "local_port": "kernel", + "peer_address": "*" + }, + { + "netid": "nl", + "state": "UNCONN", + "recv_q": "0", + "send_q": "0", + "local_address": "rtnl", + "local_port": "systemd-resolve/893", + "peer_address": "*" + }, + { + "netid": "nl", + "state": "UNCONN", + "recv_q": "0", + "send_q": "0", + "local_address": "rtnl", + "local_port": "systemd/1", + "peer_address": "*" + }, + ... + { + "netid": "tcp", + "state": "LISTEN", + "recv_q": "0", + "send_q": "128", + "local_address": "127.0.0.1", + "local_port": "35485", + "peer_address": "0.0.0.0", + "peer_port": "*", + "interface": "lo" + }, + { + "netid": "tcp", + "state": "LISTEN", + "recv_q": "0", + "send_q": "128", + "local_address": "[::]", + "local_port": "ssh", + "peer_address": "[::]", + "peer_port": "*" + }, + { + "netid": "v_str", + "state": "ESTAB", + "recv_q": "0", + "send_q": "0", + "local_address": "999900439", + "local_port": "1023", + "peer_address": "0", + "peer_port": "976" + } + ] + +## process +```python +process(proc_data) +``` + +Final processing to conform to the schema. + +Parameters: + + proc_data (dictionary) raw structured data to process + +Returns: + + dictionary structured data with the following schema: + + [ + { + "netid": string, + "state": string, + "recv_q": integer, + "send_q": integer, + "local_address": string, + "local_port": string, + "local_port_num": integer, + "peer_address": string, + "peer_port": string, + "peer_port_num": integer, + "interface": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + +Returns: + + dictionary raw or processed structured data + diff --git a/jc/parsers/ss.py b/jc/parsers/ss.py index 534b0f3a..e941c0cf 100644 --- a/jc/parsers/ss.py +++ b/jc/parsers/ss.py @@ -148,7 +148,8 @@ def process(proc_data): Returns: dictionary structured data with the following schema: - + + [ { "netid": string, "state": string,