From 146e29f7cbc0f396be67dbd7ae971a4ef4dafb7b Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 11 Nov 2019 18:30:46 -0800 Subject: [PATCH] update docs --- docgen.sh | 27 ++ docs/cli.md | 5 + docs/parsers/arp.md | 110 +++++++ docs/parsers/df.md | 97 ++++++ docs/parsers/dig.md | 212 +++++++++++++ docs/parsers/env.md | 72 +++++ docs/parsers/free.md | 77 +++++ docs/parsers/history.md | 64 ++++ docs/parsers/ifconfig.md | 170 ++++++++++ docs/parsers/iptables.md | 168 ++++++++++ docs/parsers/jobs.md | 98 ++++++ docs/parsers/ls.md | 168 ++++++++++ docs/parsers/lsblk.md | 273 ++++++++++++++++ docs/parsers/lsmod.md | 130 ++++++++ docs/parsers/lsof.md | 124 ++++++++ docs/parsers/mount.md | 82 +++++ docs/parsers/netstat.md | 352 +++++++++++++++++++++ docs/parsers/ps.md | 223 +++++++++++++ docs/parsers/route.md | 129 ++++++++ docs/parsers/uname.md | 55 ++++ docs/parsers/uptime.md | 56 ++++ docs/parsers/w.md | 108 +++++++ docs/readme.md | 79 +++++ docs/utils.md | 22 ++ jc/__init__.py | 135 ++++---- jc/parsers/arp.py | 172 +++++----- jc/parsers/df.py | 127 ++++---- jc/parsers/dig.py | 364 ++++++++++----------- jc/parsers/env.py | 99 +++--- jc/parsers/foo.py | 37 ++- jc/parsers/free.py | 109 ++++--- jc/parsers/history.py | 83 ++--- jc/parsers/ifconfig.py | 292 ++++++++--------- jc/parsers/iptables.py | 269 ++++++++-------- jc/parsers/jobs.py | 148 +++++---- jc/parsers/ls.py | 274 ++++++++-------- jc/parsers/lsblk.py | 499 ++++++++++++++--------------- jc/parsers/lsmod.py | 209 +++++++------ jc/parsers/lsof.py | 203 ++++++------ jc/parsers/mount.py | 115 ++++--- jc/parsers/netstat.py | 659 ++++++++++++++++++++------------------- jc/parsers/ps.py | 389 ++++++++++++----------- jc/parsers/route.py | 213 +++++++------ jc/parsers/uname.py | 57 ++-- jc/parsers/uptime.py | 67 ++-- jc/parsers/w.py | 171 +++++----- jc/utils.py | 11 +- 47 files changed, 5370 insertions(+), 2233 deletions(-) create mode 100755 docgen.sh create mode 100644 docs/cli.md create mode 100644 docs/parsers/arp.md create mode 100644 docs/parsers/df.md create mode 100644 docs/parsers/dig.md create mode 100644 docs/parsers/env.md create mode 100644 docs/parsers/free.md create mode 100644 docs/parsers/history.md create mode 100644 docs/parsers/ifconfig.md create mode 100644 docs/parsers/iptables.md create mode 100644 docs/parsers/jobs.md create mode 100644 docs/parsers/ls.md create mode 100644 docs/parsers/lsblk.md create mode 100644 docs/parsers/lsmod.md create mode 100644 docs/parsers/lsof.md create mode 100644 docs/parsers/mount.md create mode 100644 docs/parsers/netstat.md create mode 100644 docs/parsers/ps.md create mode 100644 docs/parsers/route.md create mode 100644 docs/parsers/uname.md create mode 100644 docs/parsers/uptime.md create mode 100644 docs/parsers/w.md create mode 100644 docs/readme.md create mode 100644 docs/utils.md diff --git a/docgen.sh b/docgen.sh new file mode 100755 index 00000000..68e93964 --- /dev/null +++ b/docgen.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Generate docs.md + +cd jc +pydocmd simple jc+ > ../docs/readme.md +pydocmd simple cli+ > ../docs/cli.md +pydocmd simple utils+ > ../docs/utils.md +pydocmd simple jc.parsers.arp+ > ../docs/parsers/arp.md +pydocmd simple jc.parsers.df+ > ../docs/parsers/df.md +pydocmd simple jc.parsers.dig+ > ../docs/parsers/dig.md +pydocmd simple jc.parsers.env+ > ../docs/parsers/env.md +pydocmd simple jc.parsers.free+ > ../docs/parsers/free.md +pydocmd simple jc.parsers.history+ > ../docs/parsers/history.md +pydocmd simple jc.parsers.ifconfig+ > ../docs/parsers/ifconfig.md +pydocmd simple jc.parsers.iptables+ > ../docs/parsers/iptables.md +pydocmd simple jc.parsers.jobs+ > ../docs/parsers/jobs.md +pydocmd simple jc.parsers.ls+ > ../docs/parsers/ls.md +pydocmd simple jc.parsers.lsblk+ > ../docs/parsers/lsblk.md +pydocmd simple jc.parsers.lsmod+ > ../docs/parsers/lsmod.md +pydocmd simple jc.parsers.lsof+ > ../docs/parsers/lsof.md +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.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/cli.md b/docs/cli.md new file mode 100644 index 00000000..a8ea7315 --- /dev/null +++ b/docs/cli.md @@ -0,0 +1,5 @@ +# cli +jc - JSON CLI output utility + +JC cli module + diff --git a/docs/parsers/arp.md b/docs/parsers/arp.md new file mode 100644 index 00000000..bf3c37d1 --- /dev/null +++ b/docs/parsers/arp.md @@ -0,0 +1,110 @@ +# jc.parsers.arp +jc - JSON CLI output utility arp Parser + +Usage: + specify --arp as the first argument if the piped input is coming from arp + +Examples: + + $ arp | jc --arp -p + [ + { + "address": "192.168.71.254", + "hwtype": "ether", + "hwaddress": "00:50:56:f0:98:26", + "flags_mask": "C", + "iface": "ens33" + }, + { + "address": "gateway", + "hwtype": "ether", + "hwaddress": "00:50:56:f7:4a:fc", + "flags_mask": "C", + "iface": "ens33" + } + ] + + $ arp | jc --arp -p -r + [ + { + "address": "gateway", + "hwtype": "ether", + "hwaddress": "00:50:56:f7:4a:fc", + "flags_mask": "C", + "iface": "ens33" + }, + { + "address": "192.168.71.254", + "hwtype": "ether", + "hwaddress": "00:50:56:fe:7a:b4", + "flags_mask": "C", + "iface": "ens33" + } + ] + + $ arp -a | jc --arp -p + [ + { + "name": null, + "address": "192.168.71.254", + "hwtype": "ether", + "hwaddress": "00:50:56:f0:98:26", + "iface": "ens33" + }, + { + "name": "gateway", + "address": "192.168.71.2", + "hwtype": "ether", + "hwaddress": "00:50:56:f7:4a:fc", + "iface": "ens33" + } + ] + + $ arp -a | jc --arp -p -r + [ + { + "name": "?", + "address": "192.168.71.254", + "hwtype": "ether", + "hwaddress": "00:50:56:fe:7a:b4", + "iface": "ens33" + }, + { + "name": "_gateway", + "address": "192.168.71.2", + "hwtype": "ether", + "hwaddress": "00:50:56:f7:4a:fc", + "iface": "ens33" + } + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "name": string, + "address": string, + "hwtype": string, + "hwaddress": string, + "flags_mask": string, + "iface": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/df.md b/docs/parsers/df.md new file mode 100644 index 00000000..c3ff132e --- /dev/null +++ b/docs/parsers/df.md @@ -0,0 +1,97 @@ +# jc.parsers.df +jc - JSON CLI output utility df Parser + +Usage: + specify --df as the first argument if the piped input is coming from df + +Examples: + + $ df | jc --df -p + [ + { + "filesystem": "devtmpfs", + "1k-blocks": 1918820, + "used": 0, + "available": 1918820, + "use_percent": 0, + "mounted_on": "/dev" + }, + { + "filesystem": "tmpfs", + "1k-blocks": 1930668, + "used": 0, + "available": 1930668, + "use_percent": 0, + "mounted_on": "/dev/shm" + }, + { + "filesystem": "tmpfs", + "1k-blocks": 1930668, + "used": 11800, + "available": 1918868, + "use_percent": 1, + "mounted_on": "/run" + }, + ... + ] + + $ df | jc --df -p -r + [ + { + "filesystem": "devtmpfs", + "1k-blocks": "1918820", + "used": "0", + "available": "1918820", + "use_percent": "0%", + "mounted_on": "/dev" + }, + { + "filesystem": "tmpfs", + "1k-blocks": "1930668", + "used": "0", + "available": "1930668", + "use_percent": "0%", + "mounted_on": "/dev/shm" + }, + { + "filesystem": "tmpfs", + "1k-blocks": "1930668", + "used": "11800", + "available": "1918868", + "use_percent": "1%", + "mounted_on": "/run" + }, + ... + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "filesystem": string, + "size": string, + "1k-blocks": integer, + "used": integer, + "available": integer, + "use_percent": integer, + "mounted_on": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/dig.md b/docs/parsers/dig.md new file mode 100644 index 00000000..79266554 --- /dev/null +++ b/docs/parsers/dig.md @@ -0,0 +1,212 @@ +# jc.parsers.dig +jc - JSON CLI output utility dig Parser + +Usage: + Specify --dig as the first argument if the piped input is coming from dig + +Examples: + + $ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p + [ + { + "id": "28182", + "opcode": "QUERY", + "status": "NOERROR", + "flags": "qr rd ra", + "query_num": "1", + "answer_num": "4", + "authority_num": "0", + "additional_num": "1", + "question": { + "name": "cnn.com.", + "class": "IN", + "type": "A" + }, + "answer": [ + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.193.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.1.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.129.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.65.67" + } + ], + "query_time": "45 msec", + "server": "192.168.71.2#53(192.168.71.2)", + "when": "Wed Oct 30 03:11:21 PDT 2019", + "rcvd": "100" + }, + { + "id": "23264", + "opcode": "QUERY", + "status": "NOERROR", + "flags": "qr aa rd", + "query_num": "1", + "answer_num": "1", + "authority_num": "4", + "additional_num": "1", + "question": { + "name": "www.cnn.com.", + "class": "IN", + "type": "A" + }, + "answer": [ + { + "name": "www.cnn.com.", + "class": "IN", + "type": "CNAME", + "ttl": "300", + "data": "turner-tls.map.fastly.net." + } + ], + "authority": [ + { + "name": "cnn.com.", + "class": "IN", + "type": "NS", + "ttl": "3600", + "data": "ns-1086.awsdns-07.org." + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "NS", + "ttl": "3600", + "data": "ns-1630.awsdns-11.co.uk." + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "NS", + "ttl": "3600", + "data": "ns-47.awsdns-05.com." + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "NS", + "ttl": "3600", + "data": "ns-576.awsdns-08.net." + } + ], + "query_time": "33 msec", + "server": "205.251.194.64#53(205.251.194.64)", + "when": "Wed Oct 30 03:11:21 PDT 2019", + "rcvd": "212" + } + ] + + $ dig -x 1.1.1.1 | jc --dig -p + [ + { + "id": "27526", + "opcode": "QUERY", + "status": "NOERROR", + "flags": "qr rd ra", + "query_num": "1", + "answer_num": "1", + "authority_num": "0", + "additional_num": "1", + "question": { + "name": "1.1.1.1.in-addr.arpa.", + "class": "IN", + "type": "PTR" + }, + "answer": [ + { + "name": "1.1.1.1.IN-ADDR.ARPA.", + "class": "IN", + "type": "PTR", + "ttl": "5", + "data": "one.one.one.one." + } + ], + "query_time": "34 msec", + "server": "192.168.71.2#53(192.168.71.2)", + "when": "Wed Oct 30 03:13:48 PDT 2019", + "rcvd": "98" + } + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "id": integer, + "opcode": string, + "status": string, + "flags": [ + string + ], + "query_num": integer, + "answer_num": integer, + "authority_num": integer, + "additional_num": integer, + "question": { + "name": string, + "class": string, + "type": string + }, + "answer": [ + { + "name": string, + "class": string, + "type": string, + "ttl": integer, + "data": string + } + ], + "authority": [ + { + "name": string, + "class": string, + "type": string, + "ttl": integer, + "data": string + } + ], + "query_time": integer, # in msec + "server": string, + "when": string, + "rcvd": integer + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/env.md b/docs/parsers/env.md new file mode 100644 index 00000000..fef5a027 --- /dev/null +++ b/docs/parsers/env.md @@ -0,0 +1,72 @@ +# jc.parsers.env +jc - JSON CLI output utility env Parser + +Usage: + specify --env as the first argument if the piped input is coming from env + +Examples: + + $ env | jc --env -p + [ + { + "name": "XDG_SESSION_ID", + "value": "1" + }, + { + "name": "HOSTNAME", + "value": "localhost.localdomain" + }, + { + "name": "TERM", + "value": "vt220" + }, + { + "name": "SHELL", + "value": "/bin/bash" + }, + { + "name": "HISTSIZE", + "value": "1000" + }, + ... + ] + + $ env | jc --env -p -r + { + "TERM": "xterm-256color", + "SHELL": "/bin/bash", + "USER": "root", + "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", + "PWD": "/root", + "LANG": "en_US.UTF-8", + "HOME": "/root", + "LOGNAME": "root", + "_": "/usr/bin/env" + } + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "name": string, + "value": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/free.md b/docs/parsers/free.md new file mode 100644 index 00000000..5521eb47 --- /dev/null +++ b/docs/parsers/free.md @@ -0,0 +1,77 @@ +# jc.parsers.free +jc - JSON CLI output utility free Parser + +Usage: + specify --free as the first argument if the piped input is coming from free + +Examples: + + $ free | jc --free -p + [ + { + "type": "Mem", + "total": 3861340, + "used": 220508, + "free": 3381972, + "shared": 11800, + "buff_cache": 258860, + "available": 3397784 + }, + { + "type": "Swap", + "total": 2097148, + "used": 0, + "free": 2097148 + } + ] + + $ free | jc --free -p -r + [ + { + "type": "Mem", + "total": "2017300", + "used": "213104", + "free": "1148452", + "shared": "1176", + "buff_cache": "655744", + "available": "1622204" + }, + { + "type": "Swap", + "total": "2097148", + "used": "0", + "free": "2097148" + } + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "type": string, + "total": integer, + "used": integer, + "free": integer, + "shared": integer, + "buff_cache": integer, + "available": integer + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/history.md b/docs/parsers/history.md new file mode 100644 index 00000000..086703c0 --- /dev/null +++ b/docs/parsers/history.md @@ -0,0 +1,64 @@ +# jc.parsers.history +jc - JSON CLI output utility history Parser + +Usage: + specify --history as the first argument if the piped input is coming from history + +Examples: + + $ history | jc --history -p + [ + { + "line": "118", + "command": "sleep 100" + }, + { + "line": "119", + "command": "ls /bin" + }, + { + "line": "120", + "command": "echo "hello"" + }, + { + "line": "121", + "command": "docker images" + }, + ... + ] + + $ history | jc --history -p -r + { + "118": "sleep 100", + "119": "ls /bin", + "120": "echo "hello"", + "121": "docker images", + ... + } + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "line": string, + "command": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/ifconfig.md b/docs/parsers/ifconfig.md new file mode 100644 index 00000000..16ff7043 --- /dev/null +++ b/docs/parsers/ifconfig.md @@ -0,0 +1,170 @@ +# jc.parsers.ifconfig +jc - JSON CLI output utility ifconfig Parser + +Usage: + specify --ifconfig as the first argument if the piped input is coming from ifconfig + + no ifconfig options are supported. + +Examples: + + $ ifconfig | jc --ifconfig -p + [ + { + "name": "ens33", + "flags": 4163, + "state": "UP,BROADCAST,RUNNING,MULTICAST", + "mtu": 1500, + "ipv4_addr": "192.168.71.138", + "ipv4_mask": "255.255.255.0", + "ipv4_bcast": "192.168.71.255", + "ipv6_addr": "fe80::c1cb:715d:bc3e:b8a0", + "ipv6_mask": 64, + "ipv6_scope": "link", + "mac_addr": "00:0c:29:3b:58:0e", + "type": "Ethernet", + "rx_packets": 6374, + "rx_errors": 0, + "rx_dropped": 0, + "rx_overruns": 0, + "rx_frame": 0, + "tx_packets": 3707, + "tx_errors": 0, + "tx_dropped": 0, + "tx_overruns": 0, + "tx_carrier": 0, + "tx_collisions": 0, + "metric": null + }, + { + "name": "lo", + "flags": 73, + "state": "UP,LOOPBACK,RUNNING", + "mtu": 65536, + "ipv4_addr": "127.0.0.1", + "ipv4_mask": "255.0.0.0", + "ipv4_bcast": null, + "ipv6_addr": "::1", + "ipv6_mask": 128, + "ipv6_scope": "host", + "mac_addr": null, + "type": "Local Loopback", + "rx_packets": 81, + "rx_errors": 0, + "rx_dropped": 0, + "rx_overruns": 0, + "rx_frame": 0, + "tx_packets": 81, + "tx_errors": 0, + "tx_dropped": 0, + "tx_overruns": 0, + "tx_carrier": 0, + "tx_collisions": 0, + "metric": null + } + ] + + $ ifconfig | jc --ifconfig -p -r + [ + { + "name": "ens33", + "flags": "4163", + "state": "UP,BROADCAST,RUNNING,MULTICAST", + "mtu": "1500", + "ipv4_addr": "192.168.71.135", + "ipv4_mask": "255.255.255.0", + "ipv4_bcast": "192.168.71.255", + "ipv6_addr": "fe80::c1cb:715d:bc3e:b8a0", + "ipv6_mask": "64", + "ipv6_scope": "link", + "mac_addr": "00:0c:29:3b:58:0e", + "type": "Ethernet", + "rx_packets": "26348", + "rx_errors": "0", + "rx_dropped": "0", + "rx_overruns": "0", + "rx_frame": "0", + "tx_packets": "5308", + "tx_errors": "0", + "tx_dropped": "0", + "tx_overruns": "0", + "tx_carrier": "0", + "tx_collisions": "0", + "metric": null + }, + { + "name": "lo", + "flags": "73", + "state": "UP,LOOPBACK,RUNNING", + "mtu": "65536", + "ipv4_addr": "127.0.0.1", + "ipv4_mask": "255.0.0.0", + "ipv4_bcast": null, + "ipv6_addr": "::1", + "ipv6_mask": "128", + "ipv6_scope": "host", + "mac_addr": null, + "type": "Local Loopback", + "rx_packets": "64", + "rx_errors": "0", + "rx_dropped": "0", + "rx_overruns": "0", + "rx_frame": "0", + "tx_packets": "64", + "tx_errors": "0", + "tx_dropped": "0", + "tx_overruns": "0", + "tx_carrier": "0", + "tx_collisions": "0", + "metric": null + } + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "name": string, + "flags": integer, + "state": string, + "mtu": integer, + "ipv4_addr": string, + "ipv4_mask": string, + "ipv4_bcast": string, + "ipv6_addr": string, + "ipv6_mask": integer, + "ipv6_scope": string, + "mac_addr": string, + "type": string, + "rx_packets": integer, + "rx_errors": integer, + "rx_dropped": integer, + "rx_overruns": integer, + "rx_frame": integer, + "tx_packets": integer, + "tx_errors": integer, + "tx_dropped": integer, + "tx_overruns": integer, + "tx_carrier": integer, + "tx_collisions": integer, + "metric": integer + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/iptables.md b/docs/parsers/iptables.md new file mode 100644 index 00000000..3fea4ce7 --- /dev/null +++ b/docs/parsers/iptables.md @@ -0,0 +1,168 @@ +# jc.parsers.iptables +jc - JSON CLI output utility ipables Parser + +Usage: + Specify --iptables as the first argument if the piped input is coming from iptables + + Supports -vLn for all tables + +Examples: + + $ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p + [ + { + "chain": "PREROUTING", + "rules": [ + { + "num": 1, + "pkts": 2183, + "bytes": 186000, + "target": "PREROUTING_direct", + "prot": "all", + "opt": null, + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": 2, + "pkts": 2183, + "bytes": 186000, + "target": "PREROUTING_ZONES_SOURCE", + "prot": "all", + "opt": null, + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": 3, + "pkts": 2183, + "bytes": 186000, + "target": "PREROUTING_ZONES", + "prot": "all", + "opt": null, + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": 4, + "pkts": 0, + "bytes": 0, + "target": "DOCKER", + "prot": "all", + "opt": null, + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + ... + ] + + $ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p -r + [ + { + "chain": "PREROUTING", + "rules": [ + { + "num": "1", + "pkts": "2183", + "bytes": "186K", + "target": "PREROUTING_direct", + "prot": "all", + "opt": "--", + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": "2", + "pkts": "2183", + "bytes": "186K", + "target": "PREROUTING_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": "3", + "pkts": "2183", + "bytes": "186K", + "target": "PREROUTING_ZONES", + "prot": "all", + "opt": "--", + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": "4", + "pkts": "0", + "bytes": "0", + "target": "DOCKER", + "prot": "all", + "opt": "--", + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + ... + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "chain": string, + "rules": [ + { + "num" integer, + "pkts": integer, + "bytes": integer, # converted based on suffix + "target": string, + "prot": string, + "opt": string, # "--" = Null + "in": string, + "out": string, + "source": string, + "destination": string, + "options": string + } + ] + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/jobs.md b/docs/parsers/jobs.md new file mode 100644 index 00000000..fc8ca228 --- /dev/null +++ b/docs/parsers/jobs.md @@ -0,0 +1,98 @@ +# jc.parsers.jobs +jc - JSON CLI output utility jobs Parser + +Usage: + specify --jobs as the first argument if the piped input is coming from jobs + + Also supports the -l option + +Example: + + $ jobs -l | jc --jobs -p + [ + { + "job_number": 1, + "pid": 5283, + "status": "Running", + "command": "sleep 10000 &" + }, + { + "job_number": 2, + "pid": 5284, + "status": "Running", + "command": "sleep 10100 &" + }, + { + "job_number": 3, + "pid": 5285, + "history": "previous", + "status": "Running", + "command": "sleep 10001 &" + }, + { + "job_number": 4, + "pid": 5286, + "history": "current", + "status": "Running", + "command": "sleep 10112 &" + } + ] + + $ jobs -l | jc --jobs -p -r + [ + { + "job_number": "1", + "pid": "19510", + "status": "Running", + "command": "sleep 1000 &" + }, + { + "job_number": "2", + "pid": "19511", + "status": "Running", + "command": "sleep 1001 &" + }, + { + "job_number": "3", + "pid": "19512", + "history": "previous", + "status": "Running", + "command": "sleep 1002 &" + }, + { + "job_number": "4", + "pid": "19513", + "history": "current", + "status": "Running", + "command": "sleep 1003 &" + } + ] + +## process +```python +process(proc_data) +``` + +schema: + [ + { + "job_number": integer, + "pid": integer, + "history": string, + "status": string, + "command": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/ls.md b/docs/parsers/ls.md new file mode 100644 index 00000000..7c3a27a2 --- /dev/null +++ b/docs/parsers/ls.md @@ -0,0 +1,168 @@ +# jc.parsers.ls +jc - JSON CLI output utility ls Parser + +Usage: + specify --ls as the first argument if the piped input is coming from ls + + ls options supported: + - None + - la + - h file sizes will be available in text form with -r but larger file sizes + with human readable suffixes will be converted to Null in default view + since the parser attempts to convert this field to an integer. + +Examples: + + $ ls /usr/bin | jc --ls -p + [ + { + "filename": "apropos" + }, + { + "filename": "arch" + }, + { + "filename": "awk" + }, + { + "filename": "base64" + }, + ... + ] + + $ ls -l /usr/bin | jc --ls -p + [ + { + "filename": "apropos", + "link_to": "whatis", + "flags": "lrwxrwxrwx.", + "links": 1, + "owner": "root", + "group": "root", + "size": 6, + "date": "Aug 15 10:53" + }, + { + "filename": "ar", + "flags": "-rwxr-xr-x.", + "links": 1, + "owner": "root", + "group": "root", + "size": 62744, + "date": "Aug 8 16:14" + }, + { + "filename": "arch", + "flags": "-rwxr-xr-x.", + "links": 1, + "owner": "root", + "group": "root", + "size": 33080, + "date": "Aug 19 23:25" + }, + ... + ] + + $ ls -l /usr/bin | jc --ls -p -r + [ + { + "filename": "apropos", + "link_to": "whatis", + "flags": "lrwxrwxrwx.", + "links": "1", + "owner": "root", + "group": "root", + "size": "6", + "date": "Aug 15 10:53" + }, + { + "filename": "arch", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "33080", + "date": "Aug 19 23:25" + }, + { + "filename": "awk", + "link_to": "gawk", + "flags": "lrwxrwxrwx.", + "links": "1", + "owner": "root", + "group": "root", + "size": "4", + "date": "Aug 15 10:53" + }, + { + "filename": "base64", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "37360", + "date": "Aug 19 23:25" + }, + { + "filename": "basename", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "29032", + "date": "Aug 19 23:25" + }, + { + "filename": "bash", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "964600", + "date": "Aug 8 05:06" + }, + ... + ] + + $ ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)' + { + "filename": "emacs", + "flags": "-r-xr-xr-x", + "links": 1, + "owner": "root", + "group": "wheel", + "size": 117164432, + "date": "May 3 2019" + } + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "filename": string, + "flags": string, + "links": integer, + "owner": string, + "group": string, + "size": integer, + "date": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/lsblk.md b/docs/parsers/lsblk.md new file mode 100644 index 00000000..56d150ff --- /dev/null +++ b/docs/parsers/lsblk.md @@ -0,0 +1,273 @@ +# jc.parsers.lsblk +jc - JSON CLI output utility lsblk Parser + +Usage: + specify --lsblk as the first argument if the piped input is coming from lsblk + +Examples: + + $ lsblk | jc --lsblk -p + [ + { + "name": "sda", + "maj_min": "8:0", + "rm": false, + "size": "20G", + "ro": false, + "type": "disk", + "mountpoint": null + }, + { + "name": "sda1", + "maj_min": "8:1", + "rm": false, + "size": "1G", + "ro": false, + "type": "part", + "mountpoint": "/boot" + }, + ... + ] + + $ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p + [ + { + "name": "sda", + "maj_min": "8:0", + "rm": false, + "size": "20G", + "ro": false, + "type": "disk", + "mountpoint": null, + "kname": "sda", + "fstype": null, + "label": null, + "uuid": null, + "partlabel": null, + "partuuid": null, + "ra": 4096, + "model": "VMware Virtual S", + "serial": null, + "state": "running", + "owner": "root", + "group": "disk", + "mode": "brw-rw----", + "alignment": 0, + "min_io": 512, + "opt_io": 0, + "phy_sec": 512, + "log_sec": 512, + "rota": true, + "sched": "deadline", + "rq_size": 128, + "disc_aln": 0, + "disc_gran": "0B", + "disc_max": "0B", + "disc_zero": false, + "wsame": "32M", + "wwn": null, + "rand": true, + "pkname": null, + "hctl": "0:0:0:0", + "tran": "spi", + "rev": "1.0", + "vendor": "VMware," + }, + { + "name": "sda1", + "maj_min": "8:1", + "rm": false, + "size": "1G", + "ro": false, + "type": "part", + "mountpoint": "/boot", + "kname": "sda1", + "fstype": "xfs", + "label": null, + "uuid": "05d927bb-5875-49e3-ada1-7f46cb31c932", + "partlabel": null, + "partuuid": null, + "ra": 4096, + "model": null, + "serial": null, + "state": null, + "owner": "root", + "group": "disk", + "mode": "brw-rw----", + "alignment": 0, + "min_io": 512, + "opt_io": 0, + "phy_sec": 512, + "log_sec": 512, + "rota": true, + "sched": "deadline", + "rq_size": 128, + "disc_aln": 0, + "disc_gran": "0B", + "disc_max": "0B", + "disc_zero": false, + "wsame": "32M", + "wwn": null, + "rand": true, + "pkname": "sda", + "hctl": null, + "tran": null, + "rev": null, + "vendor": null + }, + ... + ] + + $ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p -r + [ + { + "name": "sda", + "maj_min": "8:0", + "rm": "0", + "size": "20G", + "ro": "0", + "type": "disk", + "mountpoint": null, + "kname": "sda", + "fstype": null, + "label": null, + "uuid": null, + "partlabel": null, + "partuuid": null, + "ra": "4096", + "model": "VMware Virtual S", + "serial": null, + "state": "running", + "owner": "root", + "group": "disk", + "mode": "brw-rw----", + "alignment": "0", + "min_io": "512", + "opt_io": "0", + "phy_sec": "512", + "log_sec": "512", + "rota": "1", + "sched": "deadline", + "rq_size": "128", + "disc_aln": "0", + "disc_gran": "0B", + "disc_max": "0B", + "disc_zero": "0", + "wsame": "32M", + "wwn": null, + "rand": "1", + "pkname": null, + "hctl": "0:0:0:0", + "tran": "spi", + "rev": "1.0", + "vendor": "VMware," + }, + { + "name": "sda1", + "maj_min": "8:1", + "rm": "0", + "size": "1G", + "ro": "0", + "type": "part", + "mountpoint": "/boot", + "kname": "sda1", + "fstype": "xfs", + "label": null, + "uuid": "05d927bb-5875-49e3-ada1-7f46cb31c932", + "partlabel": null, + "partuuid": null, + "ra": "4096", + "model": null, + "serial": null, + "state": null, + "owner": "root", + "group": "disk", + "mode": "brw-rw----", + "alignment": "0", + "min_io": "512", + "opt_io": "0", + "phy_sec": "512", + "log_sec": "512", + "rota": "1", + "sched": "deadline", + "rq_size": "128", + "disc_aln": "0", + "disc_gran": "0B", + "disc_max": "0B", + "disc_zero": "0", + "wsame": "32M", + "wwn": null, + "rand": "1", + "pkname": "sda", + "hctl": null, + "tran": null, + "rev": null, + "vendor": null + }, + ... + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "name": string, + "maj_min": string, + "rm": boolean, + "size": string, + "ro": boolean, + "type": string, + "mountpoint": string, + "kname": string, + "fstype": string, + "label": string, + "uuid": string, + "partlabel": string, + "partuuid": string, + "ra": integer, + "model": string, + "serial": string, + "state": string, + "owner": string, + "group": string, + "mode": string, + "alignment": integer, + "min_io": integer, + "opt_io": integer, + "phy_sec": integer, + "log_sec": integer, + "rota": boolean, + "sched": string, + "rq_size": integer, + "disc_aln": integer, + "disc_gran": string, + "disc_max": string, + "disc_zero": boolean, + "wsame": string, + "wwn": string, + "rand": boolean, + "pkname": string, + "hctl": string, + "tran": string, + "rev": string, + "vendor": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/lsmod.md b/docs/parsers/lsmod.md new file mode 100644 index 00000000..a19a7e9d --- /dev/null +++ b/docs/parsers/lsmod.md @@ -0,0 +1,130 @@ +# jc.parsers.lsmod +jc - JSON CLI output utility lsmod Parser + +Usage: + specify --lsmod as the first argument if the piped input is coming from lsmod + +Examples: + + $ lsmod | jc --lsmod -p + [ + ... + { + "module": "nf_nat", + "size": 26583, + "used": 3, + "by": [ + "nf_nat_ipv4", + "nf_nat_ipv6", + "nf_nat_masquerade_ipv4" + ] + }, + { + "module": "iptable_mangle", + "size": 12695, + "used": 1 + }, + { + "module": "iptable_security", + "size": 12705, + "used": 1 + }, + { + "module": "iptable_raw", + "size": 12678, + "used": 1 + }, + { + "module": "nf_conntrack", + "size": 139224, + "used": 7, + "by": [ + "nf_nat", + "nf_nat_ipv4", + "nf_nat_ipv6", + "xt_conntrack", + "nf_nat_masquerade_ipv4", + "nf_conntrack_ipv4", + "nf_conntrack_ipv6" + ] + }, + ... + ] + + $ lsmod | jc --lsmod -p -r + [ + ... + { + "module": "nf_conntrack", + "size": "139224", + "used": "7", + "by": [ + "nf_nat", + "nf_nat_ipv4", + "nf_nat_ipv6", + "xt_conntrack", + "nf_nat_masquerade_ipv4", + "nf_conntrack_ipv4", + "nf_conntrack_ipv6" + ] + }, + { + "module": "ip_set", + "size": "45799", + "used": "0" + }, + { + "module": "nfnetlink", + "size": "14519", + "used": "1", + "by": [ + "ip_set" + ] + }, + { + "module": "ebtable_filter", + "size": "12827", + "used": "1" + }, + { + "module": "ebtables", + "size": "35009", + "used": "2", + "by": [ + "ebtable_nat", + "ebtable_filter" + ] + }, + ... + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "module": string, + "size": integer, + "used": integer, + "by": [ + string + ] + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/lsof.md b/docs/parsers/lsof.md new file mode 100644 index 00000000..08b11123 --- /dev/null +++ b/docs/parsers/lsof.md @@ -0,0 +1,124 @@ +# jc.parsers.lsof +jc - JSON CLI output utility lsof Parser + +Usage: + specify --lsof as the first argument if the piped input is coming from lsof + +Examples: + + $ sudo lsof | jc --lsof -p + [ + { + "command": "systemd", + "pid": 1, + "tid": null, + "user": "root", + "fd": "cwd", + "type": "DIR", + "device": "253,0", + "size_off": 224, + "node": 64, + "name": "/" + }, + { + "command": "systemd", + "pid": 1, + "tid": null, + "user": "root", + "fd": "rtd", + "type": "DIR", + "device": "253,0", + "size_off": 224, + "node": 64, + "name": "/" + }, + { + "command": "systemd", + "pid": 1, + "tid": null, + "user": "root", + "fd": "txt", + "type": "REG", + "device": "253,0", + "size_off": 1624520, + "node": 50360451, + "name": "/usr/lib/systemd/systemd" + }, + ... + ] + + $ sudo lsof | jc --lsof -p -r + [ + { + "command": "systemd", + "pid": "1", + "tid": null, + "user": "root", + "fd": "cwd", + "type": "DIR", + "device": "8,2", + "size_off": "4096", + "node": "2", + "name": "/" + }, + { + "command": "systemd", + "pid": "1", + "tid": null, + "user": "root", + "fd": "rtd", + "type": "DIR", + "device": "8,2", + "size_off": "4096", + "node": "2", + "name": "/" + }, + { + "command": "systemd", + "pid": "1", + "tid": null, + "user": "root", + "fd": "txt", + "type": "REG", + "device": "8,2", + "size_off": "1595792", + "node": "668802", + "name": "/lib/systemd/systemd" + }, + ... + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "command": string, + "pid": integer, + "tid": integer, + "user": string, + "fd": string, + "type": string, + "device": string, + "size_off": integer, + "node": integer, + "name": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/mount.md b/docs/parsers/mount.md new file mode 100644 index 00000000..ce54bdb2 --- /dev/null +++ b/docs/parsers/mount.md @@ -0,0 +1,82 @@ +# jc.parsers.mount +jc - JSON CLI output utility mount Parser + +Usage: + specify --mount as the first argument if the piped input is coming from mount + +Example: + + $ mount | jc --mount -p + [ + { + "filesystem": "sysfs", + "mount_point": "/sys", + "type": "sysfs", + "access": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ] + }, + { + "filesystem": "proc", + "mount_point": "/proc", + "type": "proc", + "access": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ] + }, + { + "filesystem": "udev", + "mount_point": "/dev", + "type": "devtmpfs", + "access": [ + "rw", + "nosuid", + "relatime", + "size=977500k", + "nr_inodes=244375", + "mode=755" + ] + }, + ... + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "filesystem": string, + "mount_point": string, + "type": string, + "access": [ + string + ] + } + ] + + nothing to process + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/netstat.md b/docs/parsers/netstat.md new file mode 100644 index 00000000..8f573830 --- /dev/null +++ b/docs/parsers/netstat.md @@ -0,0 +1,352 @@ +# jc.parsers.netstat +jc - JSON CLI output utility netstat Parser + +Usage: + Specify --netstat as the first argument if the piped input is coming from netstat + +Examples: + + $ sudo netstat -apee | jc --netstat -p + [ + { + "proto": "tcp", + "recv_q": 0, + "send_q": 0, + "local_address": "localhost", + "foreign_address": "0.0.0.0", + "state": "LISTEN", + "user": "systemd-resolve", + "inode": 26958, + "program_name": "systemd-resolve", + "kind": "network", + "pid": 887, + "local_port": "domain", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": 0, + "send_q": 0, + "local_address": "0.0.0.0", + "foreign_address": "0.0.0.0", + "state": "LISTEN", + "user": "root", + "inode": 30499, + "program_name": "sshd", + "kind": "network", + "pid": 1186, + "local_port": "ssh", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": 0, + "send_q": 0, + "local_address": "localhost", + "foreign_address": "localhost", + "state": "ESTABLISHED", + "user": "root", + "inode": 46829, + "program_name": "sshd: root", + "kind": "network", + "pid": 2242, + "local_port": "ssh", + "foreign_port": "52186", + "transport_protocol": "tcp", + "network_protocol": "ipv4", + "foreign_port_num": 52186 + }, + { + "proto": "tcp", + "recv_q": 0, + "send_q": 0, + "local_address": "localhost", + "foreign_address": "localhost", + "state": "ESTABLISHED", + "user": "root", + "inode": 46828, + "program_name": "ssh", + "kind": "network", + "pid": 2241, + "local_port": "52186", + "foreign_port": "ssh", + "transport_protocol": "tcp", + "network_protocol": "ipv4", + "local_port_num": 52186 + }, + { + "proto": "tcp6", + "recv_q": 0, + "send_q": 0, + "local_address": "[::]", + "foreign_address": "[::]", + "state": "LISTEN", + "user": "root", + "inode": 30510, + "program_name": "sshd", + "kind": "network", + "pid": 1186, + "local_port": "ssh", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv6" + }, + { + "proto": "udp", + "recv_q": 0, + "send_q": 0, + "local_address": "localhost", + "foreign_address": "0.0.0.0", + "state": null, + "user": "systemd-resolve", + "inode": 26957, + "program_name": "systemd-resolve", + "kind": "network", + "pid": 887, + "local_port": "domain", + "foreign_port": "*", + "transport_protocol": "udp", + "network_protocol": "ipv4" + }, + { + "proto": "raw6", + "recv_q": 0, + "send_q": 0, + "local_address": "[::]", + "foreign_address": "[::]", + "state": "7", + "user": "systemd-network", + "inode": 27001, + "program_name": "systemd-network", + "kind": "network", + "pid": 867, + "local_port": "ipv6-icmp", + "foreign_port": "*", + "transport_protocol": null, + "network_protocol": "ipv6" + }, + { + "proto": "unix", + "refcnt": 2, + "flags": null, + "type": "DGRAM", + "state": null, + "inode": 33322, + "program_name": "systemd", + "path": "/run/user/1000/systemd/notify", + "kind": "socket", + "pid": 1607 + }, + { + "proto": "unix", + "refcnt": 2, + "flags": "ACC", + "type": "SEQPACKET", + "state": "LISTENING", + "inode": 20835, + "program_name": "init", + "path": "/run/udev/control", + "kind": "socket", + "pid": 1 + }, + ... + ] + + $ sudo netstat -apee | jc --netstat -p -r + [ + { + "proto": "tcp", + "recv_q": "0", + "send_q": "0", + "local_address": "localhost", + "foreign_address": "0.0.0.0", + "state": "LISTEN", + "user": "systemd-resolve", + "inode": "26958", + "program_name": "systemd-resolve", + "kind": "network", + "pid": "887", + "local_port": "domain", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": "0", + "send_q": "0", + "local_address": "0.0.0.0", + "foreign_address": "0.0.0.0", + "state": "LISTEN", + "user": "root", + "inode": "30499", + "program_name": "sshd", + "kind": "network", + "pid": "1186", + "local_port": "ssh", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": "0", + "send_q": "0", + "local_address": "localhost", + "foreign_address": "localhost", + "state": "ESTABLISHED", + "user": "root", + "inode": "46829", + "program_name": "sshd: root", + "kind": "network", + "pid": "2242", + "local_port": "ssh", + "foreign_port": "52186", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": "0", + "send_q": "0", + "local_address": "localhost", + "foreign_address": "localhost", + "state": "ESTABLISHED", + "user": "root", + "inode": "46828", + "program_name": "ssh", + "kind": "network", + "pid": "2241", + "local_port": "52186", + "foreign_port": "ssh", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp6", + "recv_q": "0", + "send_q": "0", + "local_address": "[::]", + "foreign_address": "[::]", + "state": "LISTEN", + "user": "root", + "inode": "30510", + "program_name": "sshd", + "kind": "network", + "pid": "1186", + "local_port": "ssh", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv6" + }, + { + "proto": "udp", + "recv_q": "0", + "send_q": "0", + "local_address": "localhost", + "foreign_address": "0.0.0.0", + "state": null, + "user": "systemd-resolve", + "inode": "26957", + "program_name": "systemd-resolve", + "kind": "network", + "pid": "887", + "local_port": "domain", + "foreign_port": "*", + "transport_protocol": "udp", + "network_protocol": "ipv4" + }, + { + "proto": "raw6", + "recv_q": "0", + "send_q": "0", + "local_address": "[::]", + "foreign_address": "[::]", + "state": "7", + "user": "systemd-network", + "inode": "27001", + "program_name": "systemd-network", + "kind": "network", + "pid": "867", + "local_port": "ipv6-icmp", + "foreign_port": "*", + "transport_protocol": null, + "network_protocol": "ipv6" + }, + { + "proto": "unix", + "refcnt": "2", + "flags": null, + "type": "DGRAM", + "state": null, + "inode": "33322", + "program_name": "systemd", + "path": "/run/user/1000/systemd/notify", + "kind": "socket", + "pid": " 1607" + }, + { + "proto": "unix", + "refcnt": "2", + "flags": "ACC", + "type": "SEQPACKET", + "state": "LISTENING", + "inode": "20835", + "program_name": "init", + "path": "/run/udev/control", + "kind": "socket", + "pid": " 1" + }, + ... + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "proto": string, + "recv_q": integer, + "send_q": integer, + "transport_protocol" string, + "network_protocol": string, + "local_address": string, + "local_port": string, + "local_port_num": integer, + "foreign_address": string, + "foreign_port": string, + "foreign_port_num": integer, + "state": string, + "program_name": string, + "pid": integer, + "user": string, + "security_context": string, + "refcnt": integer, + "flags": string, + "type": string, + "inode": integer, + "path": string, + "kind": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/ps.md b/docs/parsers/ps.md new file mode 100644 index 00000000..29fe4292 --- /dev/null +++ b/docs/parsers/ps.md @@ -0,0 +1,223 @@ +# jc.parsers.ps +jc - JSON CLI output utility ps Parser + +Usage: + specify --ps as the first argument if the piped input is coming from ps + + ps options supported: + - ef + - axu + +Examples: + + $ ps -ef | jc --ps -p + [ + { + "uid": "root", + "pid": 1, + "ppid": 0, + "c": 0, + "stime": "Nov01", + "tty": null, + "time": "00:00:11", + "cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" + }, + { + "uid": "root", + "pid": 2, + "ppid": 0, + "c": 0, + "stime": "Nov01", + "tty": null, + "time": "00:00:00", + "cmd": "[kthreadd]" + }, + { + "uid": "root", + "pid": 4, + "ppid": 2, + "c": 0, + "stime": "Nov01", + "tty": null, + "time": "00:00:00", + "cmd": "[kworker/0:0H]" + }, + ... + ] + + $ ps -ef | jc --ps -p -r + [ + { + "uid": "root", + "pid": "1", + "ppid": "0", + "c": "0", + "stime": "Nov01", + "tty": "?", + "time": "00:00:11", + "cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" + }, + { + "uid": "root", + "pid": "2", + "ppid": "0", + "c": "0", + "stime": "Nov01", + "tty": "?", + "time": "00:00:00", + "cmd": "[kthreadd]" + }, + { + "uid": "root", + "pid": "4", + "ppid": "2", + "c": "0", + "stime": "Nov01", + "tty": "?", + "time": "00:00:00", + "cmd": "[kworker/0:0H]" + }, + ... + ] + + $ ps axu | jc --ps -p + [ + { + "user": "root", + "pid": 1, + "cpu_percent": "0.0", + "mem_percent": "0.1", + "vsz": "128072", + "rss": "6676", + "tty": null, + "stat": "Ss", + "start": "Nov09", + "time": "0:06", + "command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" + }, + { + "user": "root", + "pid": 2, + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": null, + "stat": "S", + "start": "Nov09", + "time": "0:00", + "command": "[kthreadd]" + }, + { + "user": "root", + "pid": 4, + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": null, + "stat": "S<", + "start": "Nov09", + "time": "0:00", + "command": "[kworker/0:0H]" + }, + ... + ] + + $ ps axu | jc --ps -p -r + [ + { + "user": "root", + "pid": "1", + "cpu_percent": "0.0", + "mem_percent": "0.1", + "vsz": "128072", + "rss": "6676", + "tty": "?", + "stat": "Ss", + "start": "Nov09", + "time": "0:06", + "command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" + }, + { + "user": "root", + "pid": "2", + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": "?", + "stat": "S", + "start": "Nov09", + "time": "0:00", + "command": "[kthreadd]" + }, + { + "user": "root", + "pid": "4", + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": "?", + "stat": "S<", + "start": "Nov09", + "time": "0:00", + "command": "[kworker/0:0H]" + }, + { + "user": "root", + "pid": "6", + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": "?", + "stat": "S", + "start": "Nov09", + "time": "0:00", + "command": "[ksoftirqd/0]" + }, + ... + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "uid": string, + "pid": integer, + "ppid": integer, + "c": integer, + "stime": string, + "tty": string, # ? = Null + "time": string, + "cmd": string, + "user": string, + "cpu_percent": float, + "mem_percent": float, + "vsz": integer, + "rss": integer, + "stat": string, + "start": string, + "command": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/route.md b/docs/parsers/route.md new file mode 100644 index 00000000..b3952c0f --- /dev/null +++ b/docs/parsers/route.md @@ -0,0 +1,129 @@ +# jc.parsers.route +jc - JSON CLI output utility route Parser + +Usage: + specify --route as the first argument if the piped input is coming from route + +Examples: + + $ route -ee | jc --route -p + [ + { + "destination": "default", + "gateway": "gateway", + "genmask": "0.0.0.0", + "flags": "UG", + "metric": 100, + "ref": 0, + "use": 0, + "iface": "ens33", + "mss": 0, + "window": 0, + "irtt": 0 + }, + { + "destination": "172.17.0.0", + "gateway": "0.0.0.0", + "genmask": "255.255.0.0", + "flags": "U", + "metric": 0, + "ref": 0, + "use": 0, + "iface": "docker", + "mss": 0, + "window": 0, + "irtt": 0 + }, + { + "destination": "192.168.71.0", + "gateway": "0.0.0.0", + "genmask": "255.255.255.0", + "flags": "U", + "metric": 100, + "ref": 0, + "use": 0, + "iface": "ens33", + "mss": 0, + "window": 0, + "irtt": 0 + } + ] + + $ route -ee | jc --route -p -r + [ + { + "destination": "default", + "gateway": "gateway", + "genmask": "0.0.0.0", + "flags": "UG", + "metric": "100", + "ref": "0", + "use": "0", + "iface": "ens33", + "mss": "0", + "window": "0", + "irtt": "0" + }, + { + "destination": "172.17.0.0", + "gateway": "0.0.0.0", + "genmask": "255.255.0.0", + "flags": "U", + "metric": "0", + "ref": "0", + "use": "0", + "iface": "docker", + "mss": "0", + "window": "0", + "irtt": "0" + }, + { + "destination": "192.168.71.0", + "gateway": "0.0.0.0", + "genmask": "255.255.255.0", + "flags": "U", + "metric": "100", + "ref": "0", + "use": "0", + "iface": "ens33", + "mss": "0", + "window": "0", + "irtt": "0" + } + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "destination": string, + "gateway": string, + "genmask": string, + "flags": string, + "metric": integer, + "ref": integer, + "use": integer, + "mss": integer, + "window": integer, + "irtt": integer, + "iface": string + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/uname.md b/docs/parsers/uname.md new file mode 100644 index 00000000..93fc79ac --- /dev/null +++ b/docs/parsers/uname.md @@ -0,0 +1,55 @@ +# jc.parsers.uname +jc - JSON CLI output utility uname Parser + +Usage: + specify --uname as the first argument if the piped input is coming from uname + +Limitations: + must use 'uname -a' + +Example: + + $ uname -a | jc --uname -p + { + "kernel_name": "Linux", + "node_name": "user-ubuntu", + "kernel_release": "4.15.0-65-generic", + "operating_system": "GNU/Linux", + "hardware_platform": "x86_64", + "processor": "x86_64", + "machine": "x86_64", + "kernel_version": "#74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019" + } + +## process +```python +process(proc_data) +``` + +schema: + + { + "kernel_name": string, + "node_name": string, + "kernel_release": string, + "operating_system": string, + "hardware_platform": string, + "processor": string, + "machine": string, + "kernel_version": string + } + +no extra processing + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/uptime.md b/docs/parsers/uptime.md new file mode 100644 index 00000000..f037cafd --- /dev/null +++ b/docs/parsers/uptime.md @@ -0,0 +1,56 @@ +# jc.parsers.uptime +jc - JSON CLI output utility uptime Parser + +Usage: + specify --uptime as the first argument if the piped input is coming from uptime + +Example: + + $ uptime | jc --uptime -p + { + "time": "11:30:44", + "uptime": "1 day, 21:17", + "users": 1, + "load_1m": 0.01, + "load_5m": 0.04, + "load_15m": 0.05 + } + + $ uptime | jc --uptime -p -r + { + "time": "11:31:09", + "uptime": "1 day, 21:17", + "users": "1", + "load_1m": "0.00", + "load_5m": "0.04", + "load_15m": "0.05" + } + +## process +```python +process(proc_data) +``` + +schema: + + { + "time": string, + "uptime": string, + "users": integer, + "load_1m": float, + "load_5m": float, + "load_15m": float + } + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/parsers/w.md b/docs/parsers/w.md new file mode 100644 index 00000000..3e97ef8a --- /dev/null +++ b/docs/parsers/w.md @@ -0,0 +1,108 @@ +# jc.parsers.w +jc - JSON CLI output utility w Parser + +Usage: + specify --w as the first argument if the piped input is coming from w + +Examples: + + $ w | jc --w -p + [ + { + "user": "root", + "tty": "tty1", + "from": null, + "login_at": "07:49", + "idle": "1:15m", + "jcpu": "0.00s", + "pcpu": "0.00s", + "what": "-bash" + }, + { + "user": "root", + "tty": "ttyS0", + "from": null, + "login_at": "06:24", + "idle": "0.00s", + "jcpu": "0.43s", + "pcpu": "0.00s", + "what": "w" + }, + { + "user": "root", + "tty": "pts/0", + "from": "192.168.71.1", + "login_at": "06:29", + "idle": "2:35m", + "jcpu": "0.00s", + "pcpu": "0.00s", + "what": "-bash" + } + ] + + $ w | jc --w -p -r + [ + { + "user": "kbrazil", + "tty": "tty1", + "from": "-", + "login_at": "07:49", + "idle": "1:16m", + "jcpu": "0.00s", + "pcpu": "0.00s", + "what": "-bash" + }, + { + "user": "kbrazil", + "tty": "ttyS0", + "from": "-", + "login_at": "06:24", + "idle": "2.00s", + "jcpu": "0.46s", + "pcpu": "0.00s", + "what": "w" + }, + { + "user": "kbrazil", + "tty": "pts/0", + "from": "192.168.71.1", + "login_at": "06:29", + "idle": "2:36m", + "jcpu": "0.00s", + "pcpu": "0.00s", + "what": "-bash" + } + ] + +## process +```python +process(proc_data) +``` + +schema: + + [ + { + "user": string, # '-'' = null + "tty": string, # '-'' = null + "from": string, # '-'' = null + "login_at": string, # '-'' = null + "idle": string, # '-'' = null + "jcpu": string, + "pcpu": string, + "what": string # '-'' = null + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main parsing function + +Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 00000000..c223632a --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,79 @@ +# jc +JC - JSON CLI output utility + +* kellyjonbrazil@gmail.com + +This package serializes the output of many standard unix command line tools to JSON format. + +CLI Example: + + $ ls -l /usr/bin | jc --ls -p + [ + { + "filename": "apropos", + "link_to": "whatis", + "flags": "lrwxrwxrwx.", + "links": "1", + "owner": "root", + "group": "root", + "size": "6", + "date": "Aug 15 10:53" + }, + { + "filename": "arch", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "33080", + "date": "Aug 19 23:25" + }, + { + "filename": "awk", + "link_to": "gawk", + "flags": "lrwxrwxrwx.", + "links": "1", + "owner": "root", + "group": "root", + "size": "4", + "date": "Aug 15 10:53" + }, + { + "filename": "base64", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "37360", + "date": "Aug 19 23:25" + }, + ... + ] + +Module Example: + + >>> import jc.parsers.ls + >>> + >>> data='''-rwxr-xr-x 1 root wheel 23648 May 3 22:26 cat + ... -rwxr-xr-x 1 root wheel 30016 May 3 22:26 chmod + ... -rwxr-xr-x 1 root wheel 29024 May 3 22:26 cp + ... -rwxr-xr-x 1 root wheel 375824 May 3 22:26 csh + ... -rwxr-xr-x 1 root wheel 28608 May 3 22:26 date + ... -rwxr-xr-x 1 root wheel 32000 May 3 22:26 dd + ... -rwxr-xr-x 1 root wheel 23392 May 3 22:26 df + ... -rwxr-xr-x 1 root wheel 18128 May 3 22:26 echo''' + >>> + >>> jc.parsers.ls.parse(data) + [{'filename': 'cat', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', + 'size': '23648', 'date': 'May 3 22:26'}, {'filename': 'chmod', 'flags': '-rwxr-xr-x', + 'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '30016', 'date': 'May 3 22:26'}, + {'filename': 'cp', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', + 'size': '29024', 'date': 'May 3 22:26'}, {'filename': 'csh', 'flags': '-rwxr-xr-x', 'links': '1', + 'owner': 'root', 'group': 'wheel', 'size': '375824', 'date': 'May 3 22:26'}, {'filename': 'date', + 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '28608', + 'date': 'May 3 22:26'}, {'filename': 'dd', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', + 'group': 'wheel', 'size': '32000', 'date': 'May 3 22:26'}, {'filename': 'df', 'flags': '-rwxr-xr-x', + 'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '23392', 'date': 'May 3 22:26'}, + {'filename': 'echo', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', + 'size': '18128', 'date': 'May 3 22:26'}] + diff --git a/docs/utils.md b/docs/utils.md new file mode 100644 index 00000000..815a8f3c --- /dev/null +++ b/docs/utils.md @@ -0,0 +1,22 @@ +# utils +jc - JSON CLI output utility utils +## warning_message +```python +warning_message(message) +``` +Prints a warning message for non-fatal issues +## error_message +```python +error_message(message) +``` +Prints an error message for fatal issues +## compatibility +```python +compatibility(mod_name, compatible) +``` +Checks for the parser's compatibility with the running OS platform. + +compatible options: + + linux, darwin, cygwin, win32, aix, freebsd + diff --git a/jc/__init__.py b/jc/__init__.py index 3413a0c5..a219ab3b 100644 --- a/jc/__init__.py +++ b/jc/__init__.py @@ -2,80 +2,79 @@ * kellyjonbrazil@gmail.com -This module serializes standard unix command line output to structured JSON -output. +This package serializes the output of many standard unix command line tools to JSON format. CLI Example: -$ ls -l /usr/bin | jc --ls -p -[ - { - "filename": "apropos", - "link_to": "whatis", - "flags": "lrwxrwxrwx.", - "links": "1", - "owner": "root", - "group": "root", - "size": "6", - "date": "Aug 15 10:53" - }, - { - "filename": "arch", - "flags": "-rwxr-xr-x.", - "links": "1", - "owner": "root", - "group": "root", - "size": "33080", - "date": "Aug 19 23:25" - }, - { - "filename": "awk", - "link_to": "gawk", - "flags": "lrwxrwxrwx.", - "links": "1", - "owner": "root", - "group": "root", - "size": "4", - "date": "Aug 15 10:53" - }, - { - "filename": "base64", - "flags": "-rwxr-xr-x.", - "links": "1", - "owner": "root", - "group": "root", - "size": "37360", - "date": "Aug 19 23:25" - }, - ... -] + $ ls -l /usr/bin | jc --ls -p + [ + { + "filename": "apropos", + "link_to": "whatis", + "flags": "lrwxrwxrwx.", + "links": "1", + "owner": "root", + "group": "root", + "size": "6", + "date": "Aug 15 10:53" + }, + { + "filename": "arch", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "33080", + "date": "Aug 19 23:25" + }, + { + "filename": "awk", + "link_to": "gawk", + "flags": "lrwxrwxrwx.", + "links": "1", + "owner": "root", + "group": "root", + "size": "4", + "date": "Aug 15 10:53" + }, + { + "filename": "base64", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "37360", + "date": "Aug 19 23:25" + }, + ... + ] Module Example: ->>> import jc.parsers.ls ->>> ->>> data='''-rwxr-xr-x 1 root wheel 23648 May 3 22:26 cat -... -rwxr-xr-x 1 root wheel 30016 May 3 22:26 chmod -... -rwxr-xr-x 1 root wheel 29024 May 3 22:26 cp -... -rwxr-xr-x 1 root wheel 375824 May 3 22:26 csh -... -rwxr-xr-x 1 root wheel 28608 May 3 22:26 date -... -rwxr-xr-x 1 root wheel 32000 May 3 22:26 dd -... -rwxr-xr-x 1 root wheel 23392 May 3 22:26 df -... -rwxr-xr-x 1 root wheel 18128 May 3 22:26 echo''' ->>> ->>> jc.parsers.ls.parse(data) -[{'filename': 'cat', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', -'size': '23648', 'date': 'May 3 22:26'}, {'filename': 'chmod', 'flags': '-rwxr-xr-x', -'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '30016', 'date': 'May 3 22:26'}, -{'filename': 'cp', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', -'size': '29024', 'date': 'May 3 22:26'}, {'filename': 'csh', 'flags': '-rwxr-xr-x', 'links': '1', -'owner': 'root', 'group': 'wheel', 'size': '375824', 'date': 'May 3 22:26'}, {'filename': 'date', -'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '28608', -'date': 'May 3 22:26'}, {'filename': 'dd', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', -'group': 'wheel', 'size': '32000', 'date': 'May 3 22:26'}, {'filename': 'df', 'flags': '-rwxr-xr-x', -'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '23392', 'date': 'May 3 22:26'}, -{'filename': 'echo', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', -'size': '18128', 'date': 'May 3 22:26'}] + >>> import jc.parsers.ls + >>> + >>> data='''-rwxr-xr-x 1 root wheel 23648 May 3 22:26 cat + ... -rwxr-xr-x 1 root wheel 30016 May 3 22:26 chmod + ... -rwxr-xr-x 1 root wheel 29024 May 3 22:26 cp + ... -rwxr-xr-x 1 root wheel 375824 May 3 22:26 csh + ... -rwxr-xr-x 1 root wheel 28608 May 3 22:26 date + ... -rwxr-xr-x 1 root wheel 32000 May 3 22:26 dd + ... -rwxr-xr-x 1 root wheel 23392 May 3 22:26 df + ... -rwxr-xr-x 1 root wheel 18128 May 3 22:26 echo''' + >>> + >>> jc.parsers.ls.parse(data) + [{'filename': 'cat', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', + 'size': '23648', 'date': 'May 3 22:26'}, {'filename': 'chmod', 'flags': '-rwxr-xr-x', + 'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '30016', 'date': 'May 3 22:26'}, + {'filename': 'cp', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', + 'size': '29024', 'date': 'May 3 22:26'}, {'filename': 'csh', 'flags': '-rwxr-xr-x', 'links': '1', + 'owner': 'root', 'group': 'wheel', 'size': '375824', 'date': 'May 3 22:26'}, {'filename': 'date', + 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '28608', + 'date': 'May 3 22:26'}, {'filename': 'dd', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', + 'group': 'wheel', 'size': '32000', 'date': 'May 3 22:26'}, {'filename': 'df', 'flags': '-rwxr-xr-x', + 'links': '1', 'owner': 'root', 'group': 'wheel', 'size': '23392', 'date': 'May 3 22:26'}, + {'filename': 'echo', 'flags': '-rwxr-xr-x', 'links': '1', 'owner': 'root', 'group': 'wheel', + 'size': '18128', 'date': 'May 3 22:26'}] """ name = 'jc' diff --git a/jc/parsers/arp.py b/jc/parsers/arp.py index 6e2191cc..4ca7c2b1 100644 --- a/jc/parsers/arp.py +++ b/jc/parsers/arp.py @@ -5,95 +5,96 @@ Usage: Examples: -$ arp | jc --arp -p -[ - { - "address": "192.168.71.254", - "hwtype": "ether", - "hwaddress": "00:50:56:f0:98:26", - "flags_mask": "C", - "iface": "ens33" - }, - { - "address": "gateway", - "hwtype": "ether", - "hwaddress": "00:50:56:f7:4a:fc", - "flags_mask": "C", - "iface": "ens33" - } -] + $ arp | jc --arp -p + [ + { + "address": "192.168.71.254", + "hwtype": "ether", + "hwaddress": "00:50:56:f0:98:26", + "flags_mask": "C", + "iface": "ens33" + }, + { + "address": "gateway", + "hwtype": "ether", + "hwaddress": "00:50:56:f7:4a:fc", + "flags_mask": "C", + "iface": "ens33" + } + ] -$ arp | jc --arp -p -r -[ - { - "address": "gateway", - "hwtype": "ether", - "hwaddress": "00:50:56:f7:4a:fc", - "flags_mask": "C", - "iface": "ens33" - }, - { - "address": "192.168.71.254", - "hwtype": "ether", - "hwaddress": "00:50:56:fe:7a:b4", - "flags_mask": "C", - "iface": "ens33" - } -] + $ arp | jc --arp -p -r + [ + { + "address": "gateway", + "hwtype": "ether", + "hwaddress": "00:50:56:f7:4a:fc", + "flags_mask": "C", + "iface": "ens33" + }, + { + "address": "192.168.71.254", + "hwtype": "ether", + "hwaddress": "00:50:56:fe:7a:b4", + "flags_mask": "C", + "iface": "ens33" + } + ] -$ arp -a | jc --arp -p -[ - { - "name": null, - "address": "192.168.71.254", - "hwtype": "ether", - "hwaddress": "00:50:56:f0:98:26", - "iface": "ens33" - }, - { - "name": "gateway", - "address": "192.168.71.2", - "hwtype": "ether", - "hwaddress": "00:50:56:f7:4a:fc", - "iface": "ens33" - } -] + $ arp -a | jc --arp -p + [ + { + "name": null, + "address": "192.168.71.254", + "hwtype": "ether", + "hwaddress": "00:50:56:f0:98:26", + "iface": "ens33" + }, + { + "name": "gateway", + "address": "192.168.71.2", + "hwtype": "ether", + "hwaddress": "00:50:56:f7:4a:fc", + "iface": "ens33" + } + ] - -$ arp -a | jc --arp -p -r -[ - { - "name": "?", - "address": "192.168.71.254", - "hwtype": "ether", - "hwaddress": "00:50:56:fe:7a:b4", - "iface": "ens33" - }, - { - "name": "_gateway", - "address": "192.168.71.2", - "hwtype": "ether", - "hwaddress": "00:50:56:f7:4a:fc", - "iface": "ens33" - } -] + $ arp -a | jc --arp -p -r + [ + { + "name": "?", + "address": "192.168.71.254", + "hwtype": "ether", + "hwaddress": "00:50:56:fe:7a:b4", + "iface": "ens33" + }, + { + "name": "_gateway", + "address": "192.168.71.2", + "hwtype": "ether", + "hwaddress": "00:50:56:f7:4a:fc", + "iface": "ens33" + } + ] """ import jc.utils def process(proc_data): - '''schema: - [ - { - "name": string, - "address": string, - "hwtype": string, - "hwaddress": string, - "flags_mask": string, - "iface": string - } - ] - ''' + """ + schema: + + [ + { + "name": string, + "address": string, + "hwtype": string, + "hwaddress": string, + "flags_mask": string, + "iface": string + } + ] + """ # in BSD style, change name to null if it is a question mark for entry in proc_data: @@ -104,6 +105,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'aix', 'freebsd'] diff --git a/jc/parsers/df.py b/jc/parsers/df.py index ab460779..541597d0 100644 --- a/jc/parsers/df.py +++ b/jc/parsers/df.py @@ -5,69 +5,71 @@ Usage: Examples: -$ df | jc --df -p -[ - { - "filesystem": "devtmpfs", - "1k-blocks": 1918820, - "used": 0, - "available": 1918820, - "use_percent": 0, - "mounted_on": "/dev" - }, - { - "filesystem": "tmpfs", - "1k-blocks": 1930668, - "used": 0, - "available": 1930668, - "use_percent": 0, - "mounted_on": "/dev/shm" - }, - { - "filesystem": "tmpfs", - "1k-blocks": 1930668, - "used": 11800, - "available": 1918868, - "use_percent": 1, - "mounted_on": "/run" - }, - ... -] + $ df | jc --df -p + [ + { + "filesystem": "devtmpfs", + "1k-blocks": 1918820, + "used": 0, + "available": 1918820, + "use_percent": 0, + "mounted_on": "/dev" + }, + { + "filesystem": "tmpfs", + "1k-blocks": 1930668, + "used": 0, + "available": 1930668, + "use_percent": 0, + "mounted_on": "/dev/shm" + }, + { + "filesystem": "tmpfs", + "1k-blocks": 1930668, + "used": 11800, + "available": 1918868, + "use_percent": 1, + "mounted_on": "/run" + }, + ... + ] -$ df | jc --df -p -r -[ - { - "filesystem": "devtmpfs", - "1k-blocks": "1918820", - "used": "0", - "available": "1918820", - "use_percent": "0%", - "mounted_on": "/dev" - }, - { - "filesystem": "tmpfs", - "1k-blocks": "1930668", - "used": "0", - "available": "1930668", - "use_percent": "0%", - "mounted_on": "/dev/shm" - }, - { - "filesystem": "tmpfs", - "1k-blocks": "1930668", - "used": "11800", - "available": "1918868", - "use_percent": "1%", - "mounted_on": "/run" - }, - ... -] + $ df | jc --df -p -r + [ + { + "filesystem": "devtmpfs", + "1k-blocks": "1918820", + "used": "0", + "available": "1918820", + "use_percent": "0%", + "mounted_on": "/dev" + }, + { + "filesystem": "tmpfs", + "1k-blocks": "1930668", + "used": "0", + "available": "1930668", + "use_percent": "0%", + "mounted_on": "/dev/shm" + }, + { + "filesystem": "tmpfs", + "1k-blocks": "1930668", + "used": "11800", + "available": "1918868", + "use_percent": "1%", + "mounted_on": "/run" + }, + ... + ] """ import jc.utils def process(proc_data): - ''' schema: + """ + schema: + [ { "filesystem": string, @@ -79,7 +81,7 @@ def process(proc_data): "mounted_on": string } ] - ''' + """ for entry in proc_data: # change any entry for key with '-blocks' in the name to int for k in entry: @@ -108,6 +110,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/dig.py b/jc/parsers/dig.py index 7827fbfc..3f1108d0 100644 --- a/jc/parsers/dig.py +++ b/jc/parsers/dig.py @@ -5,196 +5,199 @@ Usage: Examples: -$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p -[ - { - "id": "28182", - "opcode": "QUERY", - "status": "NOERROR", - "flags": "qr rd ra", - "query_num": "1", - "answer_num": "4", - "authority_num": "0", - "additional_num": "1", - "question": { - "name": "cnn.com.", - "class": "IN", - "type": "A" - }, - "answer": [ + $ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p + [ { - "name": "cnn.com.", - "class": "IN", - "type": "A", - "ttl": "5", - "data": "151.101.193.67" + "id": "28182", + "opcode": "QUERY", + "status": "NOERROR", + "flags": "qr rd ra", + "query_num": "1", + "answer_num": "4", + "authority_num": "0", + "additional_num": "1", + "question": { + "name": "cnn.com.", + "class": "IN", + "type": "A" + }, + "answer": [ + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.193.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.1.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.129.67" + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "A", + "ttl": "5", + "data": "151.101.65.67" + } + ], + "query_time": "45 msec", + "server": "192.168.71.2#53(192.168.71.2)", + "when": "Wed Oct 30 03:11:21 PDT 2019", + "rcvd": "100" }, { - "name": "cnn.com.", - "class": "IN", - "type": "A", - "ttl": "5", - "data": "151.101.1.67" - }, - { - "name": "cnn.com.", - "class": "IN", - "type": "A", - "ttl": "5", - "data": "151.101.129.67" - }, - { - "name": "cnn.com.", - "class": "IN", - "type": "A", - "ttl": "5", - "data": "151.101.65.67" + "id": "23264", + "opcode": "QUERY", + "status": "NOERROR", + "flags": "qr aa rd", + "query_num": "1", + "answer_num": "1", + "authority_num": "4", + "additional_num": "1", + "question": { + "name": "www.cnn.com.", + "class": "IN", + "type": "A" + }, + "answer": [ + { + "name": "www.cnn.com.", + "class": "IN", + "type": "CNAME", + "ttl": "300", + "data": "turner-tls.map.fastly.net." + } + ], + "authority": [ + { + "name": "cnn.com.", + "class": "IN", + "type": "NS", + "ttl": "3600", + "data": "ns-1086.awsdns-07.org." + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "NS", + "ttl": "3600", + "data": "ns-1630.awsdns-11.co.uk." + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "NS", + "ttl": "3600", + "data": "ns-47.awsdns-05.com." + }, + { + "name": "cnn.com.", + "class": "IN", + "type": "NS", + "ttl": "3600", + "data": "ns-576.awsdns-08.net." + } + ], + "query_time": "33 msec", + "server": "205.251.194.64#53(205.251.194.64)", + "when": "Wed Oct 30 03:11:21 PDT 2019", + "rcvd": "212" } - ], - "query_time": "45 msec", - "server": "192.168.71.2#53(192.168.71.2)", - "when": "Wed Oct 30 03:11:21 PDT 2019", - "rcvd": "100" - }, - { - "id": "23264", - "opcode": "QUERY", - "status": "NOERROR", - "flags": "qr aa rd", - "query_num": "1", - "answer_num": "1", - "authority_num": "4", - "additional_num": "1", - "question": { - "name": "www.cnn.com.", - "class": "IN", - "type": "A" - }, - "answer": [ - { - "name": "www.cnn.com.", - "class": "IN", - "type": "CNAME", - "ttl": "300", - "data": "turner-tls.map.fastly.net." - } - ], - "authority": [ - { - "name": "cnn.com.", - "class": "IN", - "type": "NS", - "ttl": "3600", - "data": "ns-1086.awsdns-07.org." - }, - { - "name": "cnn.com.", - "class": "IN", - "type": "NS", - "ttl": "3600", - "data": "ns-1630.awsdns-11.co.uk." - }, - { - "name": "cnn.com.", - "class": "IN", - "type": "NS", - "ttl": "3600", - "data": "ns-47.awsdns-05.com." - }, - { - "name": "cnn.com.", - "class": "IN", - "type": "NS", - "ttl": "3600", - "data": "ns-576.awsdns-08.net." - } - ], - "query_time": "33 msec", - "server": "205.251.194.64#53(205.251.194.64)", - "when": "Wed Oct 30 03:11:21 PDT 2019", - "rcvd": "212" - } -] + ] -$ dig -x 1.1.1.1 | jc --dig -p -[ - { - "id": "27526", - "opcode": "QUERY", - "status": "NOERROR", - "flags": "qr rd ra", - "query_num": "1", - "answer_num": "1", - "authority_num": "0", - "additional_num": "1", - "question": { - "name": "1.1.1.1.in-addr.arpa.", - "class": "IN", - "type": "PTR" - }, - "answer": [ + $ dig -x 1.1.1.1 | jc --dig -p + [ { - "name": "1.1.1.1.IN-ADDR.ARPA.", - "class": "IN", - "type": "PTR", - "ttl": "5", - "data": "one.one.one.one." + "id": "27526", + "opcode": "QUERY", + "status": "NOERROR", + "flags": "qr rd ra", + "query_num": "1", + "answer_num": "1", + "authority_num": "0", + "additional_num": "1", + "question": { + "name": "1.1.1.1.in-addr.arpa.", + "class": "IN", + "type": "PTR" + }, + "answer": [ + { + "name": "1.1.1.1.IN-ADDR.ARPA.", + "class": "IN", + "type": "PTR", + "ttl": "5", + "data": "one.one.one.one." + } + ], + "query_time": "34 msec", + "server": "192.168.71.2#53(192.168.71.2)", + "when": "Wed Oct 30 03:13:48 PDT 2019", + "rcvd": "98" } - ], - "query_time": "34 msec", - "server": "192.168.71.2#53(192.168.71.2)", - "when": "Wed Oct 30 03:13:48 PDT 2019", - "rcvd": "98" - } -] + ] """ import jc.utils def process(proc_data): - ''' schema: - [ - { - "id": integer, - "opcode": string, - "status": string, - "flags": [ - string - ], - "query_num": integer, - "answer_num": integer, - "authority_num": integer, - "additional_num": integer, - "question": { - "name": string, - "class": string, - "type": string - }, - "answer": [ + """ + schema: + + [ { - "name": string, - "class": string, - "type": string, - "ttl": integer, - "data": string + "id": integer, + "opcode": string, + "status": string, + "flags": [ + string + ], + "query_num": integer, + "answer_num": integer, + "authority_num": integer, + "additional_num": integer, + "question": { + "name": string, + "class": string, + "type": string + }, + "answer": [ + { + "name": string, + "class": string, + "type": string, + "ttl": integer, + "data": string + } + ], + "authority": [ + { + "name": string, + "class": string, + "type": string, + "ttl": integer, + "data": string + } + ], + "query_time": integer, # in msec + "server": string, + "when": string, + "rcvd": integer } - ], - "authority": [ - { - "name": string, - "class": string, - "type": string, - "ttl": integer, - "data": string - } - ], - "query_time": integer, # in msec - "server": string, - "when": string, - "rcvd": integer - } - ] - ''' + ] + """ + for entry in proc_data: int_list = ['id', 'query_num', 'answer_num', 'authority_num', 'additional_num', 'rcvd'] for key in int_list: @@ -312,6 +315,15 @@ def parse_answer(answer): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'] diff --git a/jc/parsers/env.py b/jc/parsers/env.py index 28a0dca7..dca766b5 100644 --- a/jc/parsers/env.py +++ b/jc/parsers/env.py @@ -5,56 +5,58 @@ Usage: Examples: -$ env | jc --env -p -[ - { - "name": "XDG_SESSION_ID", - "value": "1" - }, - { - "name": "HOSTNAME", - "value": "localhost.localdomain" - }, - { - "name": "TERM", - "value": "vt220" - }, - { - "name": "SHELL", - "value": "/bin/bash" - }, - { - "name": "HISTSIZE", - "value": "1000" - }, - ... -] + $ env | jc --env -p + [ + { + "name": "XDG_SESSION_ID", + "value": "1" + }, + { + "name": "HOSTNAME", + "value": "localhost.localdomain" + }, + { + "name": "TERM", + "value": "vt220" + }, + { + "name": "SHELL", + "value": "/bin/bash" + }, + { + "name": "HISTSIZE", + "value": "1000" + }, + ... + ] -$ env | jc --env -p -r -{ - "TERM": "xterm-256color", - "SHELL": "/bin/bash", - "USER": "root", - "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", - "PWD": "/root", - "LANG": "en_US.UTF-8", - "HOME": "/root", - "LOGNAME": "root", - "_": "/usr/bin/env" -} + $ env | jc --env -p -r + { + "TERM": "xterm-256color", + "SHELL": "/bin/bash", + "USER": "root", + "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", + "PWD": "/root", + "LANG": "en_US.UTF-8", + "HOME": "/root", + "LOGNAME": "root", + "_": "/usr/bin/env" + } """ import jc.utils def process(proc_data): - '''schema: - [ - { - "name": string, - "value": string - } - ] - ''' + """ + schema: + + [ + { + "name": string, + "value": string + } + ] + """ # rebuild output for added semantic information processed = [] @@ -68,6 +70,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'] diff --git a/jc/parsers/foo.py b/jc/parsers/foo.py index 0bad5c84..b9111d2c 100644 --- a/jc/parsers/foo.py +++ b/jc/parsers/foo.py @@ -5,31 +5,42 @@ Usage: Examples: -$ foo | jc --foo -p -[] + $ foo | jc --foo -p + [] -$ foo | jc --foo -p -r -[] + $ foo | jc --foo -p -r + [] """ import jc.utils def process(proc_data): - '''schema: - [ - { - "foo": string, - "bar": boolean, - "baz": integer - } - ] - ''' + """ + schema: + + [ + { + "foo": string, + "bar": boolean, + "baz": integer + } + ] + """ # rebuild output for added semantic information return proc_data def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'] diff --git a/jc/parsers/free.py b/jc/parsers/free.py index adce04e5..89978671 100644 --- a/jc/parsers/free.py +++ b/jc/parsers/free.py @@ -5,61 +5,63 @@ Usage: Examples: -$ free | jc --free -p -[ - { - "type": "Mem", - "total": 3861340, - "used": 220508, - "free": 3381972, - "shared": 11800, - "buff_cache": 258860, - "available": 3397784 - }, - { - "type": "Swap", - "total": 2097148, - "used": 0, - "free": 2097148 - } -] + $ free | jc --free -p + [ + { + "type": "Mem", + "total": 3861340, + "used": 220508, + "free": 3381972, + "shared": 11800, + "buff_cache": 258860, + "available": 3397784 + }, + { + "type": "Swap", + "total": 2097148, + "used": 0, + "free": 2097148 + } + ] -$ free | jc --free -p -r -[ - { - "type": "Mem", - "total": "2017300", - "used": "213104", - "free": "1148452", - "shared": "1176", - "buff_cache": "655744", - "available": "1622204" - }, - { - "type": "Swap", - "total": "2097148", - "used": "0", - "free": "2097148" - } -] + $ free | jc --free -p -r + [ + { + "type": "Mem", + "total": "2017300", + "used": "213104", + "free": "1148452", + "shared": "1176", + "buff_cache": "655744", + "available": "1622204" + }, + { + "type": "Swap", + "total": "2097148", + "used": "0", + "free": "2097148" + } + ] """ import jc.utils def process(proc_data): - '''schema: - [ - { - "type": string, - "total": integer, - "used": integer, - "free": integer, - "shared": integer, - "buff_cache": integer, - "available": integer - } - ] - ''' + """ + schema: + + [ + { + "type": string, + "total": integer, + "used": integer, + "free": integer, + "shared": integer, + "buff_cache": integer, + "available": integer + } + ] + """ for entry in proc_data: int_list = ['total', 'used', 'free', 'shared', 'buff_cache', 'available'] @@ -75,6 +77,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/history.py b/jc/parsers/history.py index 76c3a4ba..79758c0f 100644 --- a/jc/parsers/history.py +++ b/jc/parsers/history.py @@ -5,48 +5,50 @@ Usage: Examples: -$ history | jc --history -p -[ - { - "line": "118", - "command": "sleep 100" - }, - { - "line": "119", - "command": "ls /bin" - }, - { - "line": "120", - "command": "echo \"hello\"" - }, - { - "line": "121", - "command": "docker images" - }, - ... -] + $ history | jc --history -p + [ + { + "line": "118", + "command": "sleep 100" + }, + { + "line": "119", + "command": "ls /bin" + }, + { + "line": "120", + "command": "echo \"hello\"" + }, + { + "line": "121", + "command": "docker images" + }, + ... + ] -$ history | jc --history -p -r -{ - "118": "sleep 100", - "119": "ls /bin", - "120": "echo \"hello\"", - "121": "docker images", - ... -} + $ history | jc --history -p -r + { + "118": "sleep 100", + "119": "ls /bin", + "120": "echo \"hello\"", + "121": "docker images", + ... + } """ import jc def process(proc_data): - '''schema: - [ - { - "line": string, - "command": string - } - ] - ''' + """ + schema: + + [ + { + "line": string, + "command": string + } + ] + """ # rebuild output for added semantic information processed = [] @@ -60,6 +62,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'] diff --git a/jc/parsers/ifconfig.py b/jc/parsers/ifconfig.py index 6cbf0351..512b0e1a 100644 --- a/jc/parsers/ifconfig.py +++ b/jc/parsers/ifconfig.py @@ -7,154 +7,155 @@ Usage: Examples: -$ ifconfig | jc --ifconfig -p -[ - { - "name": "ens33", - "flags": 4163, - "state": "UP,BROADCAST,RUNNING,MULTICAST", - "mtu": 1500, - "ipv4_addr": "192.168.71.138", - "ipv4_mask": "255.255.255.0", - "ipv4_bcast": "192.168.71.255", - "ipv6_addr": "fe80::c1cb:715d:bc3e:b8a0", - "ipv6_mask": 64, - "ipv6_scope": "link", - "mac_addr": "00:0c:29:3b:58:0e", - "type": "Ethernet", - "rx_packets": 6374, - "rx_errors": 0, - "rx_dropped": 0, - "rx_overruns": 0, - "rx_frame": 0, - "tx_packets": 3707, - "tx_errors": 0, - "tx_dropped": 0, - "tx_overruns": 0, - "tx_carrier": 0, - "tx_collisions": 0, - "metric": null - }, - { - "name": "lo", - "flags": 73, - "state": "UP,LOOPBACK,RUNNING", - "mtu": 65536, - "ipv4_addr": "127.0.0.1", - "ipv4_mask": "255.0.0.0", - "ipv4_bcast": null, - "ipv6_addr": "::1", - "ipv6_mask": 128, - "ipv6_scope": "host", - "mac_addr": null, - "type": "Local Loopback", - "rx_packets": 81, - "rx_errors": 0, - "rx_dropped": 0, - "rx_overruns": 0, - "rx_frame": 0, - "tx_packets": 81, - "tx_errors": 0, - "tx_dropped": 0, - "tx_overruns": 0, - "tx_carrier": 0, - "tx_collisions": 0, - "metric": null - } -] + $ ifconfig | jc --ifconfig -p + [ + { + "name": "ens33", + "flags": 4163, + "state": "UP,BROADCAST,RUNNING,MULTICAST", + "mtu": 1500, + "ipv4_addr": "192.168.71.138", + "ipv4_mask": "255.255.255.0", + "ipv4_bcast": "192.168.71.255", + "ipv6_addr": "fe80::c1cb:715d:bc3e:b8a0", + "ipv6_mask": 64, + "ipv6_scope": "link", + "mac_addr": "00:0c:29:3b:58:0e", + "type": "Ethernet", + "rx_packets": 6374, + "rx_errors": 0, + "rx_dropped": 0, + "rx_overruns": 0, + "rx_frame": 0, + "tx_packets": 3707, + "tx_errors": 0, + "tx_dropped": 0, + "tx_overruns": 0, + "tx_carrier": 0, + "tx_collisions": 0, + "metric": null + }, + { + "name": "lo", + "flags": 73, + "state": "UP,LOOPBACK,RUNNING", + "mtu": 65536, + "ipv4_addr": "127.0.0.1", + "ipv4_mask": "255.0.0.0", + "ipv4_bcast": null, + "ipv6_addr": "::1", + "ipv6_mask": 128, + "ipv6_scope": "host", + "mac_addr": null, + "type": "Local Loopback", + "rx_packets": 81, + "rx_errors": 0, + "rx_dropped": 0, + "rx_overruns": 0, + "rx_frame": 0, + "tx_packets": 81, + "tx_errors": 0, + "tx_dropped": 0, + "tx_overruns": 0, + "tx_carrier": 0, + "tx_collisions": 0, + "metric": null + } + ] - -$ ifconfig | jc --ifconfig -p -r -[ - { - "name": "ens33", - "flags": "4163", - "state": "UP,BROADCAST,RUNNING,MULTICAST", - "mtu": "1500", - "ipv4_addr": "192.168.71.135", - "ipv4_mask": "255.255.255.0", - "ipv4_bcast": "192.168.71.255", - "ipv6_addr": "fe80::c1cb:715d:bc3e:b8a0", - "ipv6_mask": "64", - "ipv6_scope": "link", - "mac_addr": "00:0c:29:3b:58:0e", - "type": "Ethernet", - "rx_packets": "26348", - "rx_errors": "0", - "rx_dropped": "0", - "rx_overruns": "0", - "rx_frame": "0", - "tx_packets": "5308", - "tx_errors": "0", - "tx_dropped": "0", - "tx_overruns": "0", - "tx_carrier": "0", - "tx_collisions": "0", - "metric": null - }, - { - "name": "lo", - "flags": "73", - "state": "UP,LOOPBACK,RUNNING", - "mtu": "65536", - "ipv4_addr": "127.0.0.1", - "ipv4_mask": "255.0.0.0", - "ipv4_bcast": null, - "ipv6_addr": "::1", - "ipv6_mask": "128", - "ipv6_scope": "host", - "mac_addr": null, - "type": "Local Loopback", - "rx_packets": "64", - "rx_errors": "0", - "rx_dropped": "0", - "rx_overruns": "0", - "rx_frame": "0", - "tx_packets": "64", - "tx_errors": "0", - "tx_dropped": "0", - "tx_overruns": "0", - "tx_carrier": "0", - "tx_collisions": "0", - "metric": null - } -] + $ ifconfig | jc --ifconfig -p -r + [ + { + "name": "ens33", + "flags": "4163", + "state": "UP,BROADCAST,RUNNING,MULTICAST", + "mtu": "1500", + "ipv4_addr": "192.168.71.135", + "ipv4_mask": "255.255.255.0", + "ipv4_bcast": "192.168.71.255", + "ipv6_addr": "fe80::c1cb:715d:bc3e:b8a0", + "ipv6_mask": "64", + "ipv6_scope": "link", + "mac_addr": "00:0c:29:3b:58:0e", + "type": "Ethernet", + "rx_packets": "26348", + "rx_errors": "0", + "rx_dropped": "0", + "rx_overruns": "0", + "rx_frame": "0", + "tx_packets": "5308", + "tx_errors": "0", + "tx_dropped": "0", + "tx_overruns": "0", + "tx_carrier": "0", + "tx_collisions": "0", + "metric": null + }, + { + "name": "lo", + "flags": "73", + "state": "UP,LOOPBACK,RUNNING", + "mtu": "65536", + "ipv4_addr": "127.0.0.1", + "ipv4_mask": "255.0.0.0", + "ipv4_bcast": null, + "ipv6_addr": "::1", + "ipv6_mask": "128", + "ipv6_scope": "host", + "mac_addr": null, + "type": "Local Loopback", + "rx_packets": "64", + "rx_errors": "0", + "rx_dropped": "0", + "rx_overruns": "0", + "rx_frame": "0", + "tx_packets": "64", + "tx_errors": "0", + "tx_dropped": "0", + "tx_overruns": "0", + "tx_carrier": "0", + "tx_collisions": "0", + "metric": null + } + ] """ import jc.utils from ifconfigparser import IfconfigParser def process(proc_data): - '''schema: - [ - { - "name": string, - "flags": integer, - "state": string, - "mtu": integer, - "ipv4_addr": string, - "ipv4_mask": string, - "ipv4_bcast": string, - "ipv6_addr": string, - "ipv6_mask": integer, - "ipv6_scope": string, - "mac_addr": string, - "type": string, - "rx_packets": integer, - "rx_errors": integer, - "rx_dropped": integer, - "rx_overruns": integer, - "rx_frame": integer, - "tx_packets": integer, - "tx_errors": integer, - "tx_dropped": integer, - "tx_overruns": integer, - "tx_carrier": integer, - "tx_collisions": integer, - "metric": integer - } - ] - ''' + """ + schema: + + [ + { + "name": string, + "flags": integer, + "state": string, + "mtu": integer, + "ipv4_addr": string, + "ipv4_mask": string, + "ipv4_bcast": string, + "ipv6_addr": string, + "ipv6_mask": integer, + "ipv6_scope": string, + "mac_addr": string, + "type": string, + "rx_packets": integer, + "rx_errors": integer, + "rx_dropped": integer, + "rx_overruns": integer, + "rx_frame": integer, + "tx_packets": integer, + "tx_errors": integer, + "tx_dropped": integer, + "tx_overruns": integer, + "tx_carrier": integer, + "tx_collisions": integer, + "metric": integer + } + ] + """ for entry in proc_data: int_list = ['flags', 'mtu', 'ipv6_mask', 'rx_packets', 'rx_errors', 'rx_dropped', 'rx_overruns', 'rx_frame', 'tx_packets', 'tx_errors', 'tx_dropped', 'tx_overruns', 'tx_carrier', @@ -171,6 +172,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'aix', 'freebsd'] diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index fb643374..4529a47c 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -7,150 +7,152 @@ Usage: Examples: -$ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p -[ - { - "chain": "PREROUTING", - "rules": [ + $ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p + [ { - "num": 1, - "pkts": 2183, - "bytes": 186000, - "target": "PREROUTING_direct", - "prot": "all", - "opt": null, - "in": "any", - "out": "any", - "source": "anywhere", - "destination": "anywhere" + "chain": "PREROUTING", + "rules": [ + { + "num": 1, + "pkts": 2183, + "bytes": 186000, + "target": "PREROUTING_direct", + "prot": "all", + "opt": null, + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": 2, + "pkts": 2183, + "bytes": 186000, + "target": "PREROUTING_ZONES_SOURCE", + "prot": "all", + "opt": null, + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": 3, + "pkts": 2183, + "bytes": 186000, + "target": "PREROUTING_ZONES", + "prot": "all", + "opt": null, + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": 4, + "pkts": 0, + "bytes": 0, + "target": "DOCKER", + "prot": "all", + "opt": null, + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] }, - { - "num": 2, - "pkts": 2183, - "bytes": 186000, - "target": "PREROUTING_ZONES_SOURCE", - "prot": "all", - "opt": null, - "in": "any", - "out": "any", - "source": "anywhere", - "destination": "anywhere" - }, - { - "num": 3, - "pkts": 2183, - "bytes": 186000, - "target": "PREROUTING_ZONES", - "prot": "all", - "opt": null, - "in": "any", - "out": "any", - "source": "anywhere", - "destination": "anywhere" - }, - { - "num": 4, - "pkts": 0, - "bytes": 0, - "target": "DOCKER", - "prot": "all", - "opt": null, - "in": "any", - "out": "any", - "source": "anywhere", - "destination": "anywhere", - "options": "ADDRTYPE match dst-type LOCAL" - } + ... ] - }, - ... -] -$ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p -r -[ - { - "chain": "PREROUTING", - "rules": [ + $ sudo iptables --line-numbers -v -L -t nat | jc --iptables -p -r + [ { - "num": "1", - "pkts": "2183", - "bytes": "186K", - "target": "PREROUTING_direct", - "prot": "all", - "opt": "--", - "in": "any", - "out": "any", - "source": "anywhere", - "destination": "anywhere" + "chain": "PREROUTING", + "rules": [ + { + "num": "1", + "pkts": "2183", + "bytes": "186K", + "target": "PREROUTING_direct", + "prot": "all", + "opt": "--", + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": "2", + "pkts": "2183", + "bytes": "186K", + "target": "PREROUTING_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": "3", + "pkts": "2183", + "bytes": "186K", + "target": "PREROUTING_ZONES", + "prot": "all", + "opt": "--", + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere" + }, + { + "num": "4", + "pkts": "0", + "bytes": "0", + "target": "DOCKER", + "prot": "all", + "opt": "--", + "in": "any", + "out": "any", + "source": "anywhere", + "destination": "anywhere", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] }, - { - "num": "2", - "pkts": "2183", - "bytes": "186K", - "target": "PREROUTING_ZONES_SOURCE", - "prot": "all", - "opt": "--", - "in": "any", - "out": "any", - "source": "anywhere", - "destination": "anywhere" - }, - { - "num": "3", - "pkts": "2183", - "bytes": "186K", - "target": "PREROUTING_ZONES", - "prot": "all", - "opt": "--", - "in": "any", - "out": "any", - "source": "anywhere", - "destination": "anywhere" - }, - { - "num": "4", - "pkts": "0", - "bytes": "0", - "target": "DOCKER", - "prot": "all", - "opt": "--", - "in": "any", - "out": "any", - "source": "anywhere", - "destination": "anywhere", - "options": "ADDRTYPE match dst-type LOCAL" - } + ... ] - }, - ... -] """ import jc.utils def process(proc_data): - '''schema: - [ - { - "chain": string, - "rules": [ + """ + schema: + + [ { - "num" integer, - "pkts": integer, - "bytes": integer, # converted based on suffix - "target": string, - "prot": string, - "opt": string, # "--" = Null - "in": string, - "out": string, - "source": string, - "destination": string, - "options": string + "chain": string, + "rules": [ + { + "num" integer, + "pkts": integer, + "bytes": integer, # converted based on suffix + "target": string, + "prot": string, + "opt": string, # "--" = Null + "in": string, + "out": string, + "source": string, + "destination": string, + "options": string + } + ] } ] - } - ] - ''' + """ for entry in proc_data: for rule in entry['rules']: int_list = ['num', 'pkts'] @@ -194,6 +196,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/jobs.py b/jc/parsers/jobs.py index 0a5e3a1c..6885776f 100644 --- a/jc/parsers/jobs.py +++ b/jc/parsers/jobs.py @@ -7,82 +7,83 @@ Usage: Example: -$ jobs -l | jc --jobs -p -[ - { - "job_number": 1, - "pid": 5283, - "status": "Running", - "command": "sleep 10000 &" - }, - { - "job_number": 2, - "pid": 5284, - "status": "Running", - "command": "sleep 10100 &" - }, - { - "job_number": 3, - "pid": 5285, - "history": "previous", - "status": "Running", - "command": "sleep 10001 &" - }, - { - "job_number": 4, - "pid": 5286, - "history": "current", - "status": "Running", - "command": "sleep 10112 &" - } -] + $ jobs -l | jc --jobs -p + [ + { + "job_number": 1, + "pid": 5283, + "status": "Running", + "command": "sleep 10000 &" + }, + { + "job_number": 2, + "pid": 5284, + "status": "Running", + "command": "sleep 10100 &" + }, + { + "job_number": 3, + "pid": 5285, + "history": "previous", + "status": "Running", + "command": "sleep 10001 &" + }, + { + "job_number": 4, + "pid": 5286, + "history": "current", + "status": "Running", + "command": "sleep 10112 &" + } + ] -$ jobs -l | jc --jobs -p -r -[ - { - "job_number": "1", - "pid": "19510", - "status": "Running", - "command": "sleep 1000 &" - }, - { - "job_number": "2", - "pid": "19511", - "status": "Running", - "command": "sleep 1001 &" - }, - { - "job_number": "3", - "pid": "19512", - "history": "previous", - "status": "Running", - "command": "sleep 1002 &" - }, - { - "job_number": "4", - "pid": "19513", - "history": "current", - "status": "Running", - "command": "sleep 1003 &" - } -] + $ jobs -l | jc --jobs -p -r + [ + { + "job_number": "1", + "pid": "19510", + "status": "Running", + "command": "sleep 1000 &" + }, + { + "job_number": "2", + "pid": "19511", + "status": "Running", + "command": "sleep 1001 &" + }, + { + "job_number": "3", + "pid": "19512", + "history": "previous", + "status": "Running", + "command": "sleep 1002 &" + }, + { + "job_number": "4", + "pid": "19513", + "history": "current", + "status": "Running", + "command": "sleep 1003 &" + } + ] """ import string import jc.utils def process(proc_data): - '''schema: - [ - { - "job_number": integer, - "pid": integer, - "history": string, - "status": string, - "command": string - } - ] - ''' + """ + schema: + [ + { + "job_number": integer, + "pid": integer, + "history": string, + "status": string, + "command": string + } + ] + """ for entry in proc_data: int_list = ['job_number', 'pid'] for key in int_list: @@ -97,6 +98,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd'] diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index bff95ae4..066cbeb7 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -12,146 +12,149 @@ Usage: Examples: -$ ls /usr/bin | jc --ls -p -[ - { - "filename": "apropos" - }, - { - "filename": "arch" - }, - { - "filename": "awk" - }, - { - "filename": "base64" - }, - ... -] + $ ls /usr/bin | jc --ls -p + [ + { + "filename": "apropos" + }, + { + "filename": "arch" + }, + { + "filename": "awk" + }, + { + "filename": "base64" + }, + ... + ] -$ ls -l /usr/bin | jc --ls -p -[ - { - "filename": "apropos", - "link_to": "whatis", - "flags": "lrwxrwxrwx.", - "links": 1, - "owner": "root", - "group": "root", - "size": 6, - "date": "Aug 15 10:53" - }, - { - "filename": "ar", - "flags": "-rwxr-xr-x.", - "links": 1, - "owner": "root", - "group": "root", - "size": 62744, - "date": "Aug 8 16:14" - }, - { - "filename": "arch", - "flags": "-rwxr-xr-x.", - "links": 1, - "owner": "root", - "group": "root", - "size": 33080, - "date": "Aug 19 23:25" - }, - ... -] + $ ls -l /usr/bin | jc --ls -p + [ + { + "filename": "apropos", + "link_to": "whatis", + "flags": "lrwxrwxrwx.", + "links": 1, + "owner": "root", + "group": "root", + "size": 6, + "date": "Aug 15 10:53" + }, + { + "filename": "ar", + "flags": "-rwxr-xr-x.", + "links": 1, + "owner": "root", + "group": "root", + "size": 62744, + "date": "Aug 8 16:14" + }, + { + "filename": "arch", + "flags": "-rwxr-xr-x.", + "links": 1, + "owner": "root", + "group": "root", + "size": 33080, + "date": "Aug 19 23:25" + }, + ... + ] -$ ls -l /usr/bin | jc --ls -p -r -[ - { - "filename": "apropos", - "link_to": "whatis", - "flags": "lrwxrwxrwx.", - "links": "1", - "owner": "root", - "group": "root", - "size": "6", - "date": "Aug 15 10:53" - }, - { - "filename": "arch", - "flags": "-rwxr-xr-x.", - "links": "1", - "owner": "root", - "group": "root", - "size": "33080", - "date": "Aug 19 23:25" - }, - { - "filename": "awk", - "link_to": "gawk", - "flags": "lrwxrwxrwx.", - "links": "1", - "owner": "root", - "group": "root", - "size": "4", - "date": "Aug 15 10:53" - }, - { - "filename": "base64", - "flags": "-rwxr-xr-x.", - "links": "1", - "owner": "root", - "group": "root", - "size": "37360", - "date": "Aug 19 23:25" - }, - { - "filename": "basename", - "flags": "-rwxr-xr-x.", - "links": "1", - "owner": "root", - "group": "root", - "size": "29032", - "date": "Aug 19 23:25" - }, - { - "filename": "bash", - "flags": "-rwxr-xr-x.", - "links": "1", - "owner": "root", - "group": "root", - "size": "964600", - "date": "Aug 8 05:06" - }, - ... -] + $ ls -l /usr/bin | jc --ls -p -r + [ + { + "filename": "apropos", + "link_to": "whatis", + "flags": "lrwxrwxrwx.", + "links": "1", + "owner": "root", + "group": "root", + "size": "6", + "date": "Aug 15 10:53" + }, + { + "filename": "arch", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "33080", + "date": "Aug 19 23:25" + }, + { + "filename": "awk", + "link_to": "gawk", + "flags": "lrwxrwxrwx.", + "links": "1", + "owner": "root", + "group": "root", + "size": "4", + "date": "Aug 15 10:53" + }, + { + "filename": "base64", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "37360", + "date": "Aug 19 23:25" + }, + { + "filename": "basename", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "29032", + "date": "Aug 19 23:25" + }, + { + "filename": "bash", + "flags": "-rwxr-xr-x.", + "links": "1", + "owner": "root", + "group": "root", + "size": "964600", + "date": "Aug 8 05:06" + }, + ... + ] -$ ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)' -{ - "filename": "emacs", - "flags": "-r-xr-xr-x", - "links": 1, - "owner": "root", - "group": "wheel", - "size": 117164432, - "date": "May 3 2019" -} + $ ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)' + { + "filename": "emacs", + "flags": "-r-xr-xr-x", + "links": 1, + "owner": "root", + "group": "wheel", + "size": 117164432, + "date": "May 3 2019" + } """ import re import jc.utils def process(proc_data): - '''schema: - [ - { - "filename": string, - "flags": string, - "links": integer, - "owner": string, - "group": string, - "size": integer, - "date": string - } - ] - ''' + """ + schema: + + [ + { + "filename": string, + "flags": string, + "links": integer, + "owner": string, + "group": string, + "size": integer, + "date": string + } + ] + """ + for entry in proc_data: int_list = ['links', 'size'] for key in int_list: @@ -166,6 +169,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd'] diff --git a/jc/parsers/lsblk.py b/jc/parsers/lsblk.py index 2e6378de..34393b34 100644 --- a/jc/parsers/lsblk.py +++ b/jc/parsers/lsblk.py @@ -5,258 +5,260 @@ Usage: Examples: -$ lsblk | jc --lsblk -p -[ - { - "name": "sda", - "maj_min": "8:0", - "rm": false, - "size": "20G", - "ro": false, - "type": "disk", - "mountpoint": null - }, - { - "name": "sda1", - "maj_min": "8:1", - "rm": false, - "size": "1G", - "ro": false, - "type": "part", - "mountpoint": "/boot" - }, - ... -] + $ lsblk | jc --lsblk -p + [ + { + "name": "sda", + "maj_min": "8:0", + "rm": false, + "size": "20G", + "ro": false, + "type": "disk", + "mountpoint": null + }, + { + "name": "sda1", + "maj_min": "8:1", + "rm": false, + "size": "1G", + "ro": false, + "type": "part", + "mountpoint": "/boot" + }, + ... + ] -$ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p -[ - { - "name": "sda", - "maj_min": "8:0", - "rm": false, - "size": "20G", - "ro": false, - "type": "disk", - "mountpoint": null, - "kname": "sda", - "fstype": null, - "label": null, - "uuid": null, - "partlabel": null, - "partuuid": null, - "ra": 4096, - "model": "VMware Virtual S", - "serial": null, - "state": "running", - "owner": "root", - "group": "disk", - "mode": "brw-rw----", - "alignment": 0, - "min_io": 512, - "opt_io": 0, - "phy_sec": 512, - "log_sec": 512, - "rota": true, - "sched": "deadline", - "rq_size": 128, - "disc_aln": 0, - "disc_gran": "0B", - "disc_max": "0B", - "disc_zero": false, - "wsame": "32M", - "wwn": null, - "rand": true, - "pkname": null, - "hctl": "0:0:0:0", - "tran": "spi", - "rev": "1.0", - "vendor": "VMware," - }, - { - "name": "sda1", - "maj_min": "8:1", - "rm": false, - "size": "1G", - "ro": false, - "type": "part", - "mountpoint": "/boot", - "kname": "sda1", - "fstype": "xfs", - "label": null, - "uuid": "05d927bb-5875-49e3-ada1-7f46cb31c932", - "partlabel": null, - "partuuid": null, - "ra": 4096, - "model": null, - "serial": null, - "state": null, - "owner": "root", - "group": "disk", - "mode": "brw-rw----", - "alignment": 0, - "min_io": 512, - "opt_io": 0, - "phy_sec": 512, - "log_sec": 512, - "rota": true, - "sched": "deadline", - "rq_size": 128, - "disc_aln": 0, - "disc_gran": "0B", - "disc_max": "0B", - "disc_zero": false, - "wsame": "32M", - "wwn": null, - "rand": true, - "pkname": "sda", - "hctl": null, - "tran": null, - "rev": null, - "vendor": null - }, - ... -] + $ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p + [ + { + "name": "sda", + "maj_min": "8:0", + "rm": false, + "size": "20G", + "ro": false, + "type": "disk", + "mountpoint": null, + "kname": "sda", + "fstype": null, + "label": null, + "uuid": null, + "partlabel": null, + "partuuid": null, + "ra": 4096, + "model": "VMware Virtual S", + "serial": null, + "state": "running", + "owner": "root", + "group": "disk", + "mode": "brw-rw----", + "alignment": 0, + "min_io": 512, + "opt_io": 0, + "phy_sec": 512, + "log_sec": 512, + "rota": true, + "sched": "deadline", + "rq_size": 128, + "disc_aln": 0, + "disc_gran": "0B", + "disc_max": "0B", + "disc_zero": false, + "wsame": "32M", + "wwn": null, + "rand": true, + "pkname": null, + "hctl": "0:0:0:0", + "tran": "spi", + "rev": "1.0", + "vendor": "VMware," + }, + { + "name": "sda1", + "maj_min": "8:1", + "rm": false, + "size": "1G", + "ro": false, + "type": "part", + "mountpoint": "/boot", + "kname": "sda1", + "fstype": "xfs", + "label": null, + "uuid": "05d927bb-5875-49e3-ada1-7f46cb31c932", + "partlabel": null, + "partuuid": null, + "ra": 4096, + "model": null, + "serial": null, + "state": null, + "owner": "root", + "group": "disk", + "mode": "brw-rw----", + "alignment": 0, + "min_io": 512, + "opt_io": 0, + "phy_sec": 512, + "log_sec": 512, + "rota": true, + "sched": "deadline", + "rq_size": 128, + "disc_aln": 0, + "disc_gran": "0B", + "disc_max": "0B", + "disc_zero": false, + "wsame": "32M", + "wwn": null, + "rand": true, + "pkname": "sda", + "hctl": null, + "tran": null, + "rev": null, + "vendor": null + }, + ... + ] -$ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p -r -[ - { - "name": "sda", - "maj_min": "8:0", - "rm": "0", - "size": "20G", - "ro": "0", - "type": "disk", - "mountpoint": null, - "kname": "sda", - "fstype": null, - "label": null, - "uuid": null, - "partlabel": null, - "partuuid": null, - "ra": "4096", - "model": "VMware Virtual S", - "serial": null, - "state": "running", - "owner": "root", - "group": "disk", - "mode": "brw-rw----", - "alignment": "0", - "min_io": "512", - "opt_io": "0", - "phy_sec": "512", - "log_sec": "512", - "rota": "1", - "sched": "deadline", - "rq_size": "128", - "disc_aln": "0", - "disc_gran": "0B", - "disc_max": "0B", - "disc_zero": "0", - "wsame": "32M", - "wwn": null, - "rand": "1", - "pkname": null, - "hctl": "0:0:0:0", - "tran": "spi", - "rev": "1.0", - "vendor": "VMware," - }, - { - "name": "sda1", - "maj_min": "8:1", - "rm": "0", - "size": "1G", - "ro": "0", - "type": "part", - "mountpoint": "/boot", - "kname": "sda1", - "fstype": "xfs", - "label": null, - "uuid": "05d927bb-5875-49e3-ada1-7f46cb31c932", - "partlabel": null, - "partuuid": null, - "ra": "4096", - "model": null, - "serial": null, - "state": null, - "owner": "root", - "group": "disk", - "mode": "brw-rw----", - "alignment": "0", - "min_io": "512", - "opt_io": "0", - "phy_sec": "512", - "log_sec": "512", - "rota": "1", - "sched": "deadline", - "rq_size": "128", - "disc_aln": "0", - "disc_gran": "0B", - "disc_max": "0B", - "disc_zero": "0", - "wsame": "32M", - "wwn": null, - "rand": "1", - "pkname": "sda", - "hctl": null, - "tran": null, - "rev": null, - "vendor": null - }, - ... -] + $ lsblk -o +KNAME,FSTYPE,LABEL,UUID,PARTLABEL,PARTUUID,RA,MODEL,SERIAL,STATE,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,DISC-ALN,DISC-GRAN,DISC-MAX,DISC-ZERO,WSAME,WWN,RAND,PKNAME,HCTL,TRAN,REV,VENDOR | jc --lsblk -p -r + [ + { + "name": "sda", + "maj_min": "8:0", + "rm": "0", + "size": "20G", + "ro": "0", + "type": "disk", + "mountpoint": null, + "kname": "sda", + "fstype": null, + "label": null, + "uuid": null, + "partlabel": null, + "partuuid": null, + "ra": "4096", + "model": "VMware Virtual S", + "serial": null, + "state": "running", + "owner": "root", + "group": "disk", + "mode": "brw-rw----", + "alignment": "0", + "min_io": "512", + "opt_io": "0", + "phy_sec": "512", + "log_sec": "512", + "rota": "1", + "sched": "deadline", + "rq_size": "128", + "disc_aln": "0", + "disc_gran": "0B", + "disc_max": "0B", + "disc_zero": "0", + "wsame": "32M", + "wwn": null, + "rand": "1", + "pkname": null, + "hctl": "0:0:0:0", + "tran": "spi", + "rev": "1.0", + "vendor": "VMware," + }, + { + "name": "sda1", + "maj_min": "8:1", + "rm": "0", + "size": "1G", + "ro": "0", + "type": "part", + "mountpoint": "/boot", + "kname": "sda1", + "fstype": "xfs", + "label": null, + "uuid": "05d927bb-5875-49e3-ada1-7f46cb31c932", + "partlabel": null, + "partuuid": null, + "ra": "4096", + "model": null, + "serial": null, + "state": null, + "owner": "root", + "group": "disk", + "mode": "brw-rw----", + "alignment": "0", + "min_io": "512", + "opt_io": "0", + "phy_sec": "512", + "log_sec": "512", + "rota": "1", + "sched": "deadline", + "rq_size": "128", + "disc_aln": "0", + "disc_gran": "0B", + "disc_max": "0B", + "disc_zero": "0", + "wsame": "32M", + "wwn": null, + "rand": "1", + "pkname": "sda", + "hctl": null, + "tran": null, + "rev": null, + "vendor": null + }, + ... + ] """ import string import jc.utils def process(proc_data): - '''schema: - [ - { - "name": string, - "maj_min": string, - "rm": boolean, - "size": string, - "ro": boolean, - "type": string, - "mountpoint": string, - "kname": string, - "fstype": string, - "label": string, - "uuid": string, - "partlabel": string, - "partuuid": string, - "ra": integer, - "model": string, - "serial": string, - "state": string, - "owner": string, - "group": string, - "mode": string, - "alignment": integer, - "min_io": integer, - "opt_io": integer, - "phy_sec": integer, - "log_sec": integer, - "rota": boolean, - "sched": string, - "rq_size": integer, - "disc_aln": integer, - "disc_gran": string, - "disc_max": string, - "disc_zero": boolean, - "wsame": string, - "wwn": string, - "rand": boolean, - "pkname": string, - "hctl": string, - "tran": string, - "rev": string, - "vendor": string - } - ] - ''' + """ + schema: + + [ + { + "name": string, + "maj_min": string, + "rm": boolean, + "size": string, + "ro": boolean, + "type": string, + "mountpoint": string, + "kname": string, + "fstype": string, + "label": string, + "uuid": string, + "partlabel": string, + "partuuid": string, + "ra": integer, + "model": string, + "serial": string, + "state": string, + "owner": string, + "group": string, + "mode": string, + "alignment": integer, + "min_io": integer, + "opt_io": integer, + "phy_sec": integer, + "log_sec": integer, + "rota": boolean, + "sched": string, + "rq_size": integer, + "disc_aln": integer, + "disc_gran": string, + "disc_max": string, + "disc_zero": boolean, + "wsame": string, + "wwn": string, + "rand": boolean, + "pkname": string, + "hctl": string, + "tran": string, + "rev": string, + "vendor": string + } + ] + """ for entry in proc_data: # boolean changes bool_list = ['rm', 'ro', 'rota', 'disc_zero', 'rand'] @@ -282,6 +284,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/lsmod.py b/jc/parsers/lsmod.py index 3264183b..44a96fef 100644 --- a/jc/parsers/lsmod.py +++ b/jc/parsers/lsmod.py @@ -5,114 +5,116 @@ Usage: Examples: -$ lsmod | jc --lsmod -p -[ - ... - { - "module": "nf_nat", - "size": 26583, - "used": 3, - "by": [ - "nf_nat_ipv4", - "nf_nat_ipv6", - "nf_nat_masquerade_ipv4" + $ lsmod | jc --lsmod -p + [ + ... + { + "module": "nf_nat", + "size": 26583, + "used": 3, + "by": [ + "nf_nat_ipv4", + "nf_nat_ipv6", + "nf_nat_masquerade_ipv4" + ] + }, + { + "module": "iptable_mangle", + "size": 12695, + "used": 1 + }, + { + "module": "iptable_security", + "size": 12705, + "used": 1 + }, + { + "module": "iptable_raw", + "size": 12678, + "used": 1 + }, + { + "module": "nf_conntrack", + "size": 139224, + "used": 7, + "by": [ + "nf_nat", + "nf_nat_ipv4", + "nf_nat_ipv6", + "xt_conntrack", + "nf_nat_masquerade_ipv4", + "nf_conntrack_ipv4", + "nf_conntrack_ipv6" + ] + }, + ... ] - }, - { - "module": "iptable_mangle", - "size": 12695, - "used": 1 - }, - { - "module": "iptable_security", - "size": 12705, - "used": 1 - }, - { - "module": "iptable_raw", - "size": 12678, - "used": 1 - }, - { - "module": "nf_conntrack", - "size": 139224, - "used": 7, - "by": [ - "nf_nat", - "nf_nat_ipv4", - "nf_nat_ipv6", - "xt_conntrack", - "nf_nat_masquerade_ipv4", - "nf_conntrack_ipv4", - "nf_conntrack_ipv6" - ] - }, - ... -] -$ lsmod | jc --lsmod -p -r -[ - ... - { - "module": "nf_conntrack", - "size": "139224", - "used": "7", - "by": [ - "nf_nat", - "nf_nat_ipv4", - "nf_nat_ipv6", - "xt_conntrack", - "nf_nat_masquerade_ipv4", - "nf_conntrack_ipv4", - "nf_conntrack_ipv6" + $ lsmod | jc --lsmod -p -r + [ + ... + { + "module": "nf_conntrack", + "size": "139224", + "used": "7", + "by": [ + "nf_nat", + "nf_nat_ipv4", + "nf_nat_ipv6", + "xt_conntrack", + "nf_nat_masquerade_ipv4", + "nf_conntrack_ipv4", + "nf_conntrack_ipv6" + ] + }, + { + "module": "ip_set", + "size": "45799", + "used": "0" + }, + { + "module": "nfnetlink", + "size": "14519", + "used": "1", + "by": [ + "ip_set" + ] + }, + { + "module": "ebtable_filter", + "size": "12827", + "used": "1" + }, + { + "module": "ebtables", + "size": "35009", + "used": "2", + "by": [ + "ebtable_nat", + "ebtable_filter" + ] + }, + ... ] - }, - { - "module": "ip_set", - "size": "45799", - "used": "0" - }, - { - "module": "nfnetlink", - "size": "14519", - "used": "1", - "by": [ - "ip_set" - ] - }, - { - "module": "ebtable_filter", - "size": "12827", - "used": "1" - }, - { - "module": "ebtables", - "size": "35009", - "used": "2", - "by": [ - "ebtable_nat", - "ebtable_filter" - ] - }, - ... -] """ import jc.utils def process(proc_data): - '''schema: - [ - { - "module": string, - "size": integer, - "used": integer, - "by": [ - string + """ + schema: + + [ + { + "module": string, + "size": integer, + "used": integer, + "by": [ + string + ] + } ] - } - ] - ''' + """ for entry in proc_data: # integer changes int_list = ['size', 'used'] @@ -128,6 +130,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/lsof.py b/jc/parsers/lsof.py index 27689990..22cb0b82 100644 --- a/jc/parsers/lsof.py +++ b/jc/parsers/lsof.py @@ -5,109 +5,111 @@ Usage: Examples: -$ sudo lsof | jc --lsof -p -[ - { - "command": "systemd", - "pid": 1, - "tid": null, - "user": "root", - "fd": "cwd", - "type": "DIR", - "device": "253,0", - "size_off": 224, - "node": 64, - "name": "/" - }, - { - "command": "systemd", - "pid": 1, - "tid": null, - "user": "root", - "fd": "rtd", - "type": "DIR", - "device": "253,0", - "size_off": 224, - "node": 64, - "name": "/" - }, - { - "command": "systemd", - "pid": 1, - "tid": null, - "user": "root", - "fd": "txt", - "type": "REG", - "device": "253,0", - "size_off": 1624520, - "node": 50360451, - "name": "/usr/lib/systemd/systemd" - }, - ... -] + $ sudo lsof | jc --lsof -p + [ + { + "command": "systemd", + "pid": 1, + "tid": null, + "user": "root", + "fd": "cwd", + "type": "DIR", + "device": "253,0", + "size_off": 224, + "node": 64, + "name": "/" + }, + { + "command": "systemd", + "pid": 1, + "tid": null, + "user": "root", + "fd": "rtd", + "type": "DIR", + "device": "253,0", + "size_off": 224, + "node": 64, + "name": "/" + }, + { + "command": "systemd", + "pid": 1, + "tid": null, + "user": "root", + "fd": "txt", + "type": "REG", + "device": "253,0", + "size_off": 1624520, + "node": 50360451, + "name": "/usr/lib/systemd/systemd" + }, + ... + ] -$ sudo lsof | jc --lsof -p -r -[ - { - "command": "systemd", - "pid": "1", - "tid": null, - "user": "root", - "fd": "cwd", - "type": "DIR", - "device": "8,2", - "size_off": "4096", - "node": "2", - "name": "/" - }, - { - "command": "systemd", - "pid": "1", - "tid": null, - "user": "root", - "fd": "rtd", - "type": "DIR", - "device": "8,2", - "size_off": "4096", - "node": "2", - "name": "/" - }, - { - "command": "systemd", - "pid": "1", - "tid": null, - "user": "root", - "fd": "txt", - "type": "REG", - "device": "8,2", - "size_off": "1595792", - "node": "668802", - "name": "/lib/systemd/systemd" - }, - ... -] + $ sudo lsof | jc --lsof -p -r + [ + { + "command": "systemd", + "pid": "1", + "tid": null, + "user": "root", + "fd": "cwd", + "type": "DIR", + "device": "8,2", + "size_off": "4096", + "node": "2", + "name": "/" + }, + { + "command": "systemd", + "pid": "1", + "tid": null, + "user": "root", + "fd": "rtd", + "type": "DIR", + "device": "8,2", + "size_off": "4096", + "node": "2", + "name": "/" + }, + { + "command": "systemd", + "pid": "1", + "tid": null, + "user": "root", + "fd": "txt", + "type": "REG", + "device": "8,2", + "size_off": "1595792", + "node": "668802", + "name": "/lib/systemd/systemd" + }, + ... + ] """ import string import jc.utils def process(proc_data): - '''schema: - [ - { - "command": string, - "pid": integer, - "tid": integer, - "user": string, - "fd": string, - "type": string, - "device": string, - "size_off": integer, - "node": integer, - "name": string - } - ] - ''' + """ + schema: + + [ + { + "command": string, + "pid": integer, + "tid": integer, + "user": string, + "fd": string, + "type": string, + "device": string, + "size_off": integer, + "node": integer, + "name": string + } + ] + """ for entry in proc_data: # integer changes int_list = ['pid', 'tid', 'size_off', 'node'] @@ -122,6 +124,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/mount.py b/jc/parsers/mount.py index 001165ad..68762b46 100644 --- a/jc/parsers/mount.py +++ b/jc/parsers/mount.py @@ -5,70 +5,81 @@ Usage: Example: -$ mount | jc --mount -p -[ - { - "filesystem": "sysfs", - "mount_point": "/sys", - "type": "sysfs", - "access": [ - "rw", - "nosuid", - "nodev", - "noexec", - "relatime" + $ mount | jc --mount -p + [ + { + "filesystem": "sysfs", + "mount_point": "/sys", + "type": "sysfs", + "access": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ] + }, + { + "filesystem": "proc", + "mount_point": "/proc", + "type": "proc", + "access": [ + "rw", + "nosuid", + "nodev", + "noexec", + "relatime" + ] + }, + { + "filesystem": "udev", + "mount_point": "/dev", + "type": "devtmpfs", + "access": [ + "rw", + "nosuid", + "relatime", + "size=977500k", + "nr_inodes=244375", + "mode=755" + ] + }, + ... ] - }, - { - "filesystem": "proc", - "mount_point": "/proc", - "type": "proc", - "access": [ - "rw", - "nosuid", - "nodev", - "noexec", - "relatime" - ] - }, - { - "filesystem": "udev", - "mount_point": "/dev", - "type": "devtmpfs", - "access": [ - "rw", - "nosuid", - "relatime", - "size=977500k", - "nr_inodes=244375", - "mode=755" - ] - }, - ... -] """ import jc.utils def process(proc_data): - '''schema: - [ - { - "filesystem": string, - "mount_point": string, - "type": string, - "access": [ - string + """ + schema: + + [ + { + "filesystem": string, + "mount_point": string, + "type": string, + "access": [ + string + ] + } ] - } - ] - nothing to process - ''' + nothing to process + """ return proc_data def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/netstat.py b/jc/parsers/netstat.py index a52400a3..67be8e19 100644 --- a/jc/parsers/netstat.py +++ b/jc/parsers/netstat.py @@ -5,337 +5,339 @@ Usage: Examples: -$ sudo netstat -apee | jc --netstat -p -[ - { - "proto": "tcp", - "recv_q": 0, - "send_q": 0, - "local_address": "localhost", - "foreign_address": "0.0.0.0", - "state": "LISTEN", - "user": "systemd-resolve", - "inode": 26958, - "program_name": "systemd-resolve", - "kind": "network", - "pid": 887, - "local_port": "domain", - "foreign_port": "*", - "transport_protocol": "tcp", - "network_protocol": "ipv4" - }, - { - "proto": "tcp", - "recv_q": 0, - "send_q": 0, - "local_address": "0.0.0.0", - "foreign_address": "0.0.0.0", - "state": "LISTEN", - "user": "root", - "inode": 30499, - "program_name": "sshd", - "kind": "network", - "pid": 1186, - "local_port": "ssh", - "foreign_port": "*", - "transport_protocol": "tcp", - "network_protocol": "ipv4" - }, - { - "proto": "tcp", - "recv_q": 0, - "send_q": 0, - "local_address": "localhost", - "foreign_address": "localhost", - "state": "ESTABLISHED", - "user": "root", - "inode": 46829, - "program_name": "sshd: root", - "kind": "network", - "pid": 2242, - "local_port": "ssh", - "foreign_port": "52186", - "transport_protocol": "tcp", - "network_protocol": "ipv4", - "foreign_port_num": 52186 - }, - { - "proto": "tcp", - "recv_q": 0, - "send_q": 0, - "local_address": "localhost", - "foreign_address": "localhost", - "state": "ESTABLISHED", - "user": "root", - "inode": 46828, - "program_name": "ssh", - "kind": "network", - "pid": 2241, - "local_port": "52186", - "foreign_port": "ssh", - "transport_protocol": "tcp", - "network_protocol": "ipv4", - "local_port_num": 52186 - }, - { - "proto": "tcp6", - "recv_q": 0, - "send_q": 0, - "local_address": "[::]", - "foreign_address": "[::]", - "state": "LISTEN", - "user": "root", - "inode": 30510, - "program_name": "sshd", - "kind": "network", - "pid": 1186, - "local_port": "ssh", - "foreign_port": "*", - "transport_protocol": "tcp", - "network_protocol": "ipv6" - }, - { - "proto": "udp", - "recv_q": 0, - "send_q": 0, - "local_address": "localhost", - "foreign_address": "0.0.0.0", - "state": null, - "user": "systemd-resolve", - "inode": 26957, - "program_name": "systemd-resolve", - "kind": "network", - "pid": 887, - "local_port": "domain", - "foreign_port": "*", - "transport_protocol": "udp", - "network_protocol": "ipv4" - }, - { - "proto": "raw6", - "recv_q": 0, - "send_q": 0, - "local_address": "[::]", - "foreign_address": "[::]", - "state": "7", - "user": "systemd-network", - "inode": 27001, - "program_name": "systemd-network", - "kind": "network", - "pid": 867, - "local_port": "ipv6-icmp", - "foreign_port": "*", - "transport_protocol": null, - "network_protocol": "ipv6" - }, - { - "proto": "unix", - "refcnt": 2, - "flags": null, - "type": "DGRAM", - "state": null, - "inode": 33322, - "program_name": "systemd", - "path": "/run/user/1000/systemd/notify", - "kind": "socket", - "pid": 1607 - }, - { - "proto": "unix", - "refcnt": 2, - "flags": "ACC", - "type": "SEQPACKET", - "state": "LISTENING", - "inode": 20835, - "program_name": "init", - "path": "/run/udev/control", - "kind": "socket", - "pid": 1 - }, - ... -] + $ sudo netstat -apee | jc --netstat -p + [ + { + "proto": "tcp", + "recv_q": 0, + "send_q": 0, + "local_address": "localhost", + "foreign_address": "0.0.0.0", + "state": "LISTEN", + "user": "systemd-resolve", + "inode": 26958, + "program_name": "systemd-resolve", + "kind": "network", + "pid": 887, + "local_port": "domain", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": 0, + "send_q": 0, + "local_address": "0.0.0.0", + "foreign_address": "0.0.0.0", + "state": "LISTEN", + "user": "root", + "inode": 30499, + "program_name": "sshd", + "kind": "network", + "pid": 1186, + "local_port": "ssh", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": 0, + "send_q": 0, + "local_address": "localhost", + "foreign_address": "localhost", + "state": "ESTABLISHED", + "user": "root", + "inode": 46829, + "program_name": "sshd: root", + "kind": "network", + "pid": 2242, + "local_port": "ssh", + "foreign_port": "52186", + "transport_protocol": "tcp", + "network_protocol": "ipv4", + "foreign_port_num": 52186 + }, + { + "proto": "tcp", + "recv_q": 0, + "send_q": 0, + "local_address": "localhost", + "foreign_address": "localhost", + "state": "ESTABLISHED", + "user": "root", + "inode": 46828, + "program_name": "ssh", + "kind": "network", + "pid": 2241, + "local_port": "52186", + "foreign_port": "ssh", + "transport_protocol": "tcp", + "network_protocol": "ipv4", + "local_port_num": 52186 + }, + { + "proto": "tcp6", + "recv_q": 0, + "send_q": 0, + "local_address": "[::]", + "foreign_address": "[::]", + "state": "LISTEN", + "user": "root", + "inode": 30510, + "program_name": "sshd", + "kind": "network", + "pid": 1186, + "local_port": "ssh", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv6" + }, + { + "proto": "udp", + "recv_q": 0, + "send_q": 0, + "local_address": "localhost", + "foreign_address": "0.0.0.0", + "state": null, + "user": "systemd-resolve", + "inode": 26957, + "program_name": "systemd-resolve", + "kind": "network", + "pid": 887, + "local_port": "domain", + "foreign_port": "*", + "transport_protocol": "udp", + "network_protocol": "ipv4" + }, + { + "proto": "raw6", + "recv_q": 0, + "send_q": 0, + "local_address": "[::]", + "foreign_address": "[::]", + "state": "7", + "user": "systemd-network", + "inode": 27001, + "program_name": "systemd-network", + "kind": "network", + "pid": 867, + "local_port": "ipv6-icmp", + "foreign_port": "*", + "transport_protocol": null, + "network_protocol": "ipv6" + }, + { + "proto": "unix", + "refcnt": 2, + "flags": null, + "type": "DGRAM", + "state": null, + "inode": 33322, + "program_name": "systemd", + "path": "/run/user/1000/systemd/notify", + "kind": "socket", + "pid": 1607 + }, + { + "proto": "unix", + "refcnt": 2, + "flags": "ACC", + "type": "SEQPACKET", + "state": "LISTENING", + "inode": 20835, + "program_name": "init", + "path": "/run/udev/control", + "kind": "socket", + "pid": 1 + }, + ... + ] -$ sudo netstat -apee | jc --netstat -p -r -[ - { - "proto": "tcp", - "recv_q": "0", - "send_q": "0", - "local_address": "localhost", - "foreign_address": "0.0.0.0", - "state": "LISTEN", - "user": "systemd-resolve", - "inode": "26958", - "program_name": "systemd-resolve", - "kind": "network", - "pid": "887", - "local_port": "domain", - "foreign_port": "*", - "transport_protocol": "tcp", - "network_protocol": "ipv4" - }, - { - "proto": "tcp", - "recv_q": "0", - "send_q": "0", - "local_address": "0.0.0.0", - "foreign_address": "0.0.0.0", - "state": "LISTEN", - "user": "root", - "inode": "30499", - "program_name": "sshd", - "kind": "network", - "pid": "1186", - "local_port": "ssh", - "foreign_port": "*", - "transport_protocol": "tcp", - "network_protocol": "ipv4" - }, - { - "proto": "tcp", - "recv_q": "0", - "send_q": "0", - "local_address": "localhost", - "foreign_address": "localhost", - "state": "ESTABLISHED", - "user": "root", - "inode": "46829", - "program_name": "sshd: root", - "kind": "network", - "pid": "2242", - "local_port": "ssh", - "foreign_port": "52186", - "transport_protocol": "tcp", - "network_protocol": "ipv4" - }, - { - "proto": "tcp", - "recv_q": "0", - "send_q": "0", - "local_address": "localhost", - "foreign_address": "localhost", - "state": "ESTABLISHED", - "user": "root", - "inode": "46828", - "program_name": "ssh", - "kind": "network", - "pid": "2241", - "local_port": "52186", - "foreign_port": "ssh", - "transport_protocol": "tcp", - "network_protocol": "ipv4" - }, - { - "proto": "tcp6", - "recv_q": "0", - "send_q": "0", - "local_address": "[::]", - "foreign_address": "[::]", - "state": "LISTEN", - "user": "root", - "inode": "30510", - "program_name": "sshd", - "kind": "network", - "pid": "1186", - "local_port": "ssh", - "foreign_port": "*", - "transport_protocol": "tcp", - "network_protocol": "ipv6" - }, - { - "proto": "udp", - "recv_q": "0", - "send_q": "0", - "local_address": "localhost", - "foreign_address": "0.0.0.0", - "state": null, - "user": "systemd-resolve", - "inode": "26957", - "program_name": "systemd-resolve", - "kind": "network", - "pid": "887", - "local_port": "domain", - "foreign_port": "*", - "transport_protocol": "udp", - "network_protocol": "ipv4" - }, - { - "proto": "raw6", - "recv_q": "0", - "send_q": "0", - "local_address": "[::]", - "foreign_address": "[::]", - "state": "7", - "user": "systemd-network", - "inode": "27001", - "program_name": "systemd-network", - "kind": "network", - "pid": "867", - "local_port": "ipv6-icmp", - "foreign_port": "*", - "transport_protocol": null, - "network_protocol": "ipv6" - }, - { - "proto": "unix", - "refcnt": "2", - "flags": null, - "type": "DGRAM", - "state": null, - "inode": "33322", - "program_name": "systemd", - "path": "/run/user/1000/systemd/notify", - "kind": "socket", - "pid": " 1607" - }, - { - "proto": "unix", - "refcnt": "2", - "flags": "ACC", - "type": "SEQPACKET", - "state": "LISTENING", - "inode": "20835", - "program_name": "init", - "path": "/run/udev/control", - "kind": "socket", - "pid": " 1" - }, - ... -] + $ sudo netstat -apee | jc --netstat -p -r + [ + { + "proto": "tcp", + "recv_q": "0", + "send_q": "0", + "local_address": "localhost", + "foreign_address": "0.0.0.0", + "state": "LISTEN", + "user": "systemd-resolve", + "inode": "26958", + "program_name": "systemd-resolve", + "kind": "network", + "pid": "887", + "local_port": "domain", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": "0", + "send_q": "0", + "local_address": "0.0.0.0", + "foreign_address": "0.0.0.0", + "state": "LISTEN", + "user": "root", + "inode": "30499", + "program_name": "sshd", + "kind": "network", + "pid": "1186", + "local_port": "ssh", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": "0", + "send_q": "0", + "local_address": "localhost", + "foreign_address": "localhost", + "state": "ESTABLISHED", + "user": "root", + "inode": "46829", + "program_name": "sshd: root", + "kind": "network", + "pid": "2242", + "local_port": "ssh", + "foreign_port": "52186", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp", + "recv_q": "0", + "send_q": "0", + "local_address": "localhost", + "foreign_address": "localhost", + "state": "ESTABLISHED", + "user": "root", + "inode": "46828", + "program_name": "ssh", + "kind": "network", + "pid": "2241", + "local_port": "52186", + "foreign_port": "ssh", + "transport_protocol": "tcp", + "network_protocol": "ipv4" + }, + { + "proto": "tcp6", + "recv_q": "0", + "send_q": "0", + "local_address": "[::]", + "foreign_address": "[::]", + "state": "LISTEN", + "user": "root", + "inode": "30510", + "program_name": "sshd", + "kind": "network", + "pid": "1186", + "local_port": "ssh", + "foreign_port": "*", + "transport_protocol": "tcp", + "network_protocol": "ipv6" + }, + { + "proto": "udp", + "recv_q": "0", + "send_q": "0", + "local_address": "localhost", + "foreign_address": "0.0.0.0", + "state": null, + "user": "systemd-resolve", + "inode": "26957", + "program_name": "systemd-resolve", + "kind": "network", + "pid": "887", + "local_port": "domain", + "foreign_port": "*", + "transport_protocol": "udp", + "network_protocol": "ipv4" + }, + { + "proto": "raw6", + "recv_q": "0", + "send_q": "0", + "local_address": "[::]", + "foreign_address": "[::]", + "state": "7", + "user": "systemd-network", + "inode": "27001", + "program_name": "systemd-network", + "kind": "network", + "pid": "867", + "local_port": "ipv6-icmp", + "foreign_port": "*", + "transport_protocol": null, + "network_protocol": "ipv6" + }, + { + "proto": "unix", + "refcnt": "2", + "flags": null, + "type": "DGRAM", + "state": null, + "inode": "33322", + "program_name": "systemd", + "path": "/run/user/1000/systemd/notify", + "kind": "socket", + "pid": " 1607" + }, + { + "proto": "unix", + "refcnt": "2", + "flags": "ACC", + "type": "SEQPACKET", + "state": "LISTENING", + "inode": "20835", + "program_name": "init", + "path": "/run/udev/control", + "kind": "socket", + "pid": " 1" + }, + ... + ] """ import string import jc.utils def process(proc_data): - '''schema: - [ - { - "proto": string, - "recv_q": integer, - "send_q": integer, - "transport_protocol" string, - "network_protocol": string, - "local_address": string, - "local_port": string, - "local_port_num": integer, - "foreign_address": string, - "foreign_port": string, - "foreign_port_num": integer, - "state": string, - "program_name": string, - "pid": integer, - "user": string, - "security_context": string, - "refcnt": integer, - "flags": string, - "type": string, - "inode": integer, - "path": string, - "kind": string - } - ] - ''' + """ + schema: + + [ + { + "proto": string, + "recv_q": integer, + "send_q": integer, + "transport_protocol" string, + "network_protocol": string, + "local_address": string, + "local_port": string, + "local_port_num": integer, + "foreign_address": string, + "foreign_port": string, + "foreign_port_num": integer, + "state": string, + "program_name": string, + "pid": integer, + "user": string, + "security_context": string, + "refcnt": integer, + "flags": string, + "type": string, + "inode": integer, + "path": string, + "kind": string + } + ] + """ for entry in proc_data: # integer changes int_list = ['recv_q', 'send_q', 'pid', 'refcnt', 'inode'] @@ -485,6 +487,15 @@ def parse_post(raw_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/ps.py b/jc/parsers/ps.py index 98390b05..e1e4b948 100644 --- a/jc/parsers/ps.py +++ b/jc/parsers/ps.py @@ -9,203 +9,205 @@ Usage: Examples: -$ ps -ef | jc --ps -p -[ - { - "uid": "root", - "pid": 1, - "ppid": 0, - "c": 0, - "stime": "Nov01", - "tty": null, - "time": "00:00:11", - "cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" - }, - { - "uid": "root", - "pid": 2, - "ppid": 0, - "c": 0, - "stime": "Nov01", - "tty": null, - "time": "00:00:00", - "cmd": "[kthreadd]" - }, - { - "uid": "root", - "pid": 4, - "ppid": 2, - "c": 0, - "stime": "Nov01", - "tty": null, - "time": "00:00:00", - "cmd": "[kworker/0:0H]" - }, - ... -] + $ ps -ef | jc --ps -p + [ + { + "uid": "root", + "pid": 1, + "ppid": 0, + "c": 0, + "stime": "Nov01", + "tty": null, + "time": "00:00:11", + "cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" + }, + { + "uid": "root", + "pid": 2, + "ppid": 0, + "c": 0, + "stime": "Nov01", + "tty": null, + "time": "00:00:00", + "cmd": "[kthreadd]" + }, + { + "uid": "root", + "pid": 4, + "ppid": 2, + "c": 0, + "stime": "Nov01", + "tty": null, + "time": "00:00:00", + "cmd": "[kworker/0:0H]" + }, + ... + ] -$ ps -ef | jc --ps -p -r -[ - { - "uid": "root", - "pid": "1", - "ppid": "0", - "c": "0", - "stime": "Nov01", - "tty": "?", - "time": "00:00:11", - "cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" - }, - { - "uid": "root", - "pid": "2", - "ppid": "0", - "c": "0", - "stime": "Nov01", - "tty": "?", - "time": "00:00:00", - "cmd": "[kthreadd]" - }, - { - "uid": "root", - "pid": "4", - "ppid": "2", - "c": "0", - "stime": "Nov01", - "tty": "?", - "time": "00:00:00", - "cmd": "[kworker/0:0H]" - }, - ... -] + $ ps -ef | jc --ps -p -r + [ + { + "uid": "root", + "pid": "1", + "ppid": "0", + "c": "0", + "stime": "Nov01", + "tty": "?", + "time": "00:00:11", + "cmd": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" + }, + { + "uid": "root", + "pid": "2", + "ppid": "0", + "c": "0", + "stime": "Nov01", + "tty": "?", + "time": "00:00:00", + "cmd": "[kthreadd]" + }, + { + "uid": "root", + "pid": "4", + "ppid": "2", + "c": "0", + "stime": "Nov01", + "tty": "?", + "time": "00:00:00", + "cmd": "[kworker/0:0H]" + }, + ... + ] -$ ps axu | jc --ps -p -[ - { - "user": "root", - "pid": 1, - "cpu_percent": "0.0", - "mem_percent": "0.1", - "vsz": "128072", - "rss": "6676", - "tty": null, - "stat": "Ss", - "start": "Nov09", - "time": "0:06", - "command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" - }, - { - "user": "root", - "pid": 2, - "cpu_percent": "0.0", - "mem_percent": "0.0", - "vsz": "0", - "rss": "0", - "tty": null, - "stat": "S", - "start": "Nov09", - "time": "0:00", - "command": "[kthreadd]" - }, - { - "user": "root", - "pid": 4, - "cpu_percent": "0.0", - "mem_percent": "0.0", - "vsz": "0", - "rss": "0", - "tty": null, - "stat": "S<", - "start": "Nov09", - "time": "0:00", - "command": "[kworker/0:0H]" - }, - ... -] + $ ps axu | jc --ps -p + [ + { + "user": "root", + "pid": 1, + "cpu_percent": "0.0", + "mem_percent": "0.1", + "vsz": "128072", + "rss": "6676", + "tty": null, + "stat": "Ss", + "start": "Nov09", + "time": "0:06", + "command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" + }, + { + "user": "root", + "pid": 2, + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": null, + "stat": "S", + "start": "Nov09", + "time": "0:00", + "command": "[kthreadd]" + }, + { + "user": "root", + "pid": 4, + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": null, + "stat": "S<", + "start": "Nov09", + "time": "0:00", + "command": "[kworker/0:0H]" + }, + ... + ] -$ ps axu | jc --ps -p -r -[ - { - "user": "root", - "pid": "1", - "cpu_percent": "0.0", - "mem_percent": "0.1", - "vsz": "128072", - "rss": "6676", - "tty": "?", - "stat": "Ss", - "start": "Nov09", - "time": "0:06", - "command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" - }, - { - "user": "root", - "pid": "2", - "cpu_percent": "0.0", - "mem_percent": "0.0", - "vsz": "0", - "rss": "0", - "tty": "?", - "stat": "S", - "start": "Nov09", - "time": "0:00", - "command": "[kthreadd]" - }, - { - "user": "root", - "pid": "4", - "cpu_percent": "0.0", - "mem_percent": "0.0", - "vsz": "0", - "rss": "0", - "tty": "?", - "stat": "S<", - "start": "Nov09", - "time": "0:00", - "command": "[kworker/0:0H]" - }, - { - "user": "root", - "pid": "6", - "cpu_percent": "0.0", - "mem_percent": "0.0", - "vsz": "0", - "rss": "0", - "tty": "?", - "stat": "S", - "start": "Nov09", - "time": "0:00", - "command": "[ksoftirqd/0]" - }, - ... -] + $ ps axu | jc --ps -p -r + [ + { + "user": "root", + "pid": "1", + "cpu_percent": "0.0", + "mem_percent": "0.1", + "vsz": "128072", + "rss": "6676", + "tty": "?", + "stat": "Ss", + "start": "Nov09", + "time": "0:06", + "command": "/usr/lib/systemd/systemd --switched-root --system --deserialize 22" + }, + { + "user": "root", + "pid": "2", + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": "?", + "stat": "S", + "start": "Nov09", + "time": "0:00", + "command": "[kthreadd]" + }, + { + "user": "root", + "pid": "4", + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": "?", + "stat": "S<", + "start": "Nov09", + "time": "0:00", + "command": "[kworker/0:0H]" + }, + { + "user": "root", + "pid": "6", + "cpu_percent": "0.0", + "mem_percent": "0.0", + "vsz": "0", + "rss": "0", + "tty": "?", + "stat": "S", + "start": "Nov09", + "time": "0:00", + "command": "[ksoftirqd/0]" + }, + ... + ] """ import jc.utils def process(proc_data): - '''schema: - [ - { - "uid": string, - "pid": integer, - "ppid": integer, - "c": integer, - "stime": string, - "tty": string, # ? = Null - "time": string, - "cmd": string, - "user": string, - "cpu_percent": float, - "mem_percent": float, - "vsz": integer, - "rss": integer, - "stat": string, - "start": string, - "command": string - } - ] - ''' + """ + schema: + + [ + { + "uid": string, + "pid": integer, + "ppid": integer, + "c": integer, + "stime": string, + "tty": string, # ? = Null + "time": string, + "cmd": string, + "user": string, + "cpu_percent": float, + "mem_percent": float, + "vsz": integer, + "rss": integer, + "stat": string, + "start": string, + "command": string + } + ] + """ for entry in proc_data: # change to int int_list = ['pid', 'ppid', 'c', 'vsz', 'rss'] @@ -235,6 +237,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd'] diff --git a/jc/parsers/route.py b/jc/parsers/route.py index 888fbb41..8d0c042e 100644 --- a/jc/parsers/route.py +++ b/jc/parsers/route.py @@ -5,113 +5,115 @@ Usage: Examples: -$ route -ee | jc --route -p -[ - { - "destination": "default", - "gateway": "gateway", - "genmask": "0.0.0.0", - "flags": "UG", - "metric": 100, - "ref": 0, - "use": 0, - "iface": "ens33", - "mss": 0, - "window": 0, - "irtt": 0 - }, - { - "destination": "172.17.0.0", - "gateway": "0.0.0.0", - "genmask": "255.255.0.0", - "flags": "U", - "metric": 0, - "ref": 0, - "use": 0, - "iface": "docker", - "mss": 0, - "window": 0, - "irtt": 0 - }, - { - "destination": "192.168.71.0", - "gateway": "0.0.0.0", - "genmask": "255.255.255.0", - "flags": "U", - "metric": 100, - "ref": 0, - "use": 0, - "iface": "ens33", - "mss": 0, - "window": 0, - "irtt": 0 - } -] + $ route -ee | jc --route -p + [ + { + "destination": "default", + "gateway": "gateway", + "genmask": "0.0.0.0", + "flags": "UG", + "metric": 100, + "ref": 0, + "use": 0, + "iface": "ens33", + "mss": 0, + "window": 0, + "irtt": 0 + }, + { + "destination": "172.17.0.0", + "gateway": "0.0.0.0", + "genmask": "255.255.0.0", + "flags": "U", + "metric": 0, + "ref": 0, + "use": 0, + "iface": "docker", + "mss": 0, + "window": 0, + "irtt": 0 + }, + { + "destination": "192.168.71.0", + "gateway": "0.0.0.0", + "genmask": "255.255.255.0", + "flags": "U", + "metric": 100, + "ref": 0, + "use": 0, + "iface": "ens33", + "mss": 0, + "window": 0, + "irtt": 0 + } + ] -$ route -ee | jc --route -p -r -[ - { - "destination": "default", - "gateway": "gateway", - "genmask": "0.0.0.0", - "flags": "UG", - "metric": "100", - "ref": "0", - "use": "0", - "iface": "ens33", - "mss": "0", - "window": "0", - "irtt": "0" - }, - { - "destination": "172.17.0.0", - "gateway": "0.0.0.0", - "genmask": "255.255.0.0", - "flags": "U", - "metric": "0", - "ref": "0", - "use": "0", - "iface": "docker", - "mss": "0", - "window": "0", - "irtt": "0" - }, - { - "destination": "192.168.71.0", - "gateway": "0.0.0.0", - "genmask": "255.255.255.0", - "flags": "U", - "metric": "100", - "ref": "0", - "use": "0", - "iface": "ens33", - "mss": "0", - "window": "0", - "irtt": "0" - } -] + $ route -ee | jc --route -p -r + [ + { + "destination": "default", + "gateway": "gateway", + "genmask": "0.0.0.0", + "flags": "UG", + "metric": "100", + "ref": "0", + "use": "0", + "iface": "ens33", + "mss": "0", + "window": "0", + "irtt": "0" + }, + { + "destination": "172.17.0.0", + "gateway": "0.0.0.0", + "genmask": "255.255.0.0", + "flags": "U", + "metric": "0", + "ref": "0", + "use": "0", + "iface": "docker", + "mss": "0", + "window": "0", + "irtt": "0" + }, + { + "destination": "192.168.71.0", + "gateway": "0.0.0.0", + "genmask": "255.255.255.0", + "flags": "U", + "metric": "100", + "ref": "0", + "use": "0", + "iface": "ens33", + "mss": "0", + "window": "0", + "irtt": "0" + } + ] """ import jc.utils def process(proc_data): - '''schema: - [ - { - "destination": string, - "gateway": string, - "genmask": string, - "flags": string, - "metric": integer, - "ref": integer, - "use": integer, - "mss": integer, - "window": integer, - "irtt": integer, - "iface": string - } - ] - ''' + """ + schema: + + [ + { + "destination": string, + "gateway": string, + "genmask": string, + "flags": string, + "metric": integer, + "ref": integer, + "use": integer, + "mss": integer, + "window": integer, + "irtt": integer, + "iface": string + } + ] + """ for entry in proc_data: int_list = ['metric', 'ref', 'use', 'mss', 'window', 'irtt'] for key in int_list: @@ -126,6 +128,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'aix', 'freebsd'] diff --git a/jc/parsers/uname.py b/jc/parsers/uname.py index a247a94a..7d83edfd 100644 --- a/jc/parsers/uname.py +++ b/jc/parsers/uname.py @@ -8,40 +8,51 @@ Limitations: Example: -$ uname -a | jc --uname -p -{ - "kernel_name": "Linux", - "node_name": "user-ubuntu", - "kernel_release": "4.15.0-65-generic", - "operating_system": "GNU/Linux", - "hardware_platform": "x86_64", - "processor": "x86_64", - "machine": "x86_64", - "kernel_version": "#74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019" -} + $ uname -a | jc --uname -p + { + "kernel_name": "Linux", + "node_name": "user-ubuntu", + "kernel_release": "4.15.0-65-generic", + "operating_system": "GNU/Linux", + "hardware_platform": "x86_64", + "processor": "x86_64", + "machine": "x86_64", + "kernel_version": "#74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019" + } """ import jc.utils def process(proc_data): - '''schema: - { - "kernel_name": string, - "node_name": string, - "kernel_release": string, - "operating_system": string, - "hardware_platform": string, - "processor": string, - "machine": string, - "kernel_version": string - } + """ + schema: + + { + "kernel_name": string, + "node_name": string, + "kernel_release": string, + "operating_system": string, + "hardware_platform": string, + "processor": string, + "machine": string, + "kernel_version": string + } no extra processing - ''' + """ return proc_data def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux'] diff --git a/jc/parsers/uptime.py b/jc/parsers/uptime.py index 314b75d1..ba7c2b61 100644 --- a/jc/parsers/uptime.py +++ b/jc/parsers/uptime.py @@ -5,40 +5,42 @@ Usage: Example: -$ uptime | jc --uptime -p -{ - "time": "11:30:44", - "uptime": "1 day, 21:17", - "users": 1, - "load_1m": 0.01, - "load_5m": 0.04, - "load_15m": 0.05 -} + $ uptime | jc --uptime -p + { + "time": "11:30:44", + "uptime": "1 day, 21:17", + "users": 1, + "load_1m": 0.01, + "load_5m": 0.04, + "load_15m": 0.05 + } -$ uptime | jc --uptime -p -r -{ - "time": "11:31:09", - "uptime": "1 day, 21:17", - "users": "1", - "load_1m": "0.00", - "load_5m": "0.04", - "load_15m": "0.05" -} + $ uptime | jc --uptime -p -r + { + "time": "11:31:09", + "uptime": "1 day, 21:17", + "users": "1", + "load_1m": "0.00", + "load_5m": "0.04", + "load_15m": "0.05" + } """ import jc.utils def process(proc_data): - '''schema: - { - "time": string, - "uptime": string, - "users": integer, - "load_1m": float, - "load_5m": float, - "load_15m": float - } - ''' + """ + schema: + + { + "time": string, + "uptime": string, + "users": integer, + "load_1m": float, + "load_5m": float, + "load_15m": float + } + """ int_list = ['users'] for key in int_list: if key in proc_data: @@ -61,6 +63,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd'] diff --git a/jc/parsers/w.py b/jc/parsers/w.py index f49f2138..9583e428 100644 --- a/jc/parsers/w.py +++ b/jc/parsers/w.py @@ -5,93 +5,95 @@ Usage: Examples: -$ w | jc --w -p -[ - { - "user": "root", - "tty": "tty1", - "from": null, - "login_at": "07:49", - "idle": "1:15m", - "jcpu": "0.00s", - "pcpu": "0.00s", - "what": "-bash" - }, - { - "user": "root", - "tty": "ttyS0", - "from": null, - "login_at": "06:24", - "idle": "0.00s", - "jcpu": "0.43s", - "pcpu": "0.00s", - "what": "w" - }, - { - "user": "root", - "tty": "pts/0", - "from": "192.168.71.1", - "login_at": "06:29", - "idle": "2:35m", - "jcpu": "0.00s", - "pcpu": "0.00s", - "what": "-bash" - } -] + $ w | jc --w -p + [ + { + "user": "root", + "tty": "tty1", + "from": null, + "login_at": "07:49", + "idle": "1:15m", + "jcpu": "0.00s", + "pcpu": "0.00s", + "what": "-bash" + }, + { + "user": "root", + "tty": "ttyS0", + "from": null, + "login_at": "06:24", + "idle": "0.00s", + "jcpu": "0.43s", + "pcpu": "0.00s", + "what": "w" + }, + { + "user": "root", + "tty": "pts/0", + "from": "192.168.71.1", + "login_at": "06:29", + "idle": "2:35m", + "jcpu": "0.00s", + "pcpu": "0.00s", + "what": "-bash" + } + ] -$ w | jc --w -p -r -[ - { - "user": "kbrazil", - "tty": "tty1", - "from": "-", - "login_at": "07:49", - "idle": "1:16m", - "jcpu": "0.00s", - "pcpu": "0.00s", - "what": "-bash" - }, - { - "user": "kbrazil", - "tty": "ttyS0", - "from": "-", - "login_at": "06:24", - "idle": "2.00s", - "jcpu": "0.46s", - "pcpu": "0.00s", - "what": "w" - }, - { - "user": "kbrazil", - "tty": "pts/0", - "from": "192.168.71.1", - "login_at": "06:29", - "idle": "2:36m", - "jcpu": "0.00s", - "pcpu": "0.00s", - "what": "-bash" - } -] + $ w | jc --w -p -r + [ + { + "user": "kbrazil", + "tty": "tty1", + "from": "-", + "login_at": "07:49", + "idle": "1:16m", + "jcpu": "0.00s", + "pcpu": "0.00s", + "what": "-bash" + }, + { + "user": "kbrazil", + "tty": "ttyS0", + "from": "-", + "login_at": "06:24", + "idle": "2.00s", + "jcpu": "0.46s", + "pcpu": "0.00s", + "what": "w" + }, + { + "user": "kbrazil", + "tty": "pts/0", + "from": "192.168.71.1", + "login_at": "06:29", + "idle": "2:36m", + "jcpu": "0.00s", + "pcpu": "0.00s", + "what": "-bash" + } + ] """ import string import jc.utils def process(proc_data): - '''schema: - [ - { - "user": string, # '-'' = null - "tty": string, # '-'' = null - "from": string, # '-'' = null - "login_at": string, # '-'' = null - "idle": string, # '-'' = null - "jcpu": string, - "pcpu": string, - "what": string # '-'' = null - } - ] - ''' + """ + schema: + + [ + { + "user": string, # '-'' = null + "tty": string, # '-'' = null + "from": string, # '-'' = null + "login_at": string, # '-'' = null + "idle": string, # '-'' = null + "jcpu": string, + "pcpu": string, + "what": string # '-'' = null + } + ] + """ for entry in proc_data: null_list = ['user', 'tty', 'from', 'login_at', 'idle', 'what'] for key in null_list: @@ -103,6 +105,15 @@ def process(proc_data): def parse(data, raw=False, quiet=False): + """ + Main parsing function + + Arguments: + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + """ + # compatible options: linux, darwin, cygwin, win32, aix, freebsd compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd'] diff --git a/jc/utils.py b/jc/utils.py index add06752..73c3aed1 100644 --- a/jc/utils.py +++ b/jc/utils.py @@ -4,6 +4,8 @@ import sys def warning_message(message): + """Prints a warning message for non-fatal issues""" + error_string = f''' jc: Warning - {message} ''' @@ -11,6 +13,8 @@ def warning_message(message): def error_message(message): + """Prints an error message for fatal issues""" + error_string = f''' jc: Error - {message} ''' @@ -18,8 +22,11 @@ def error_message(message): def compatibility(mod_name, compatible): - """ - compatible options: linux, darwin, cygwin, win32, aix, freebsd + """Checks for the parser's compatibility with the running OS platform. + + compatible options: + + linux, darwin, cygwin, win32, aix, freebsd """ if sys.platform not in compatible: mod = mod_name.split('.')[-1]