From a023001cd350e320ce30f47af214ed7a9bb43185 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 11:10:11 -0700 Subject: [PATCH 01/16] add df, env, and free parsers --- README.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++ changelog.txt | 5 ++++ jc/jc.py | 17 ++++++++++- jc/parsers/df.py | 56 +++++++++++++++++++++++++++++++++++ jc/parsers/env.py | 53 +++++++++++++++++++++++++++++++++ jc/parsers/free.py | 23 +++++++++++++++ 6 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 jc/parsers/df.py create mode 100644 jc/parsers/env.py create mode 100644 jc/parsers/free.py diff --git a/README.md b/README.md index bb7a2806..cfcb99d6 100755 --- a/README.md +++ b/README.md @@ -70,6 +70,79 @@ Options: - `-p` specifies whether to pretty format the JSON output ## Examples +### df +``` +$ df | jc --df -p +[ + { + "Filesystem": "/dev/disk1s1", + "512-blocks": "976490576", + "Used": "268326664", + "Available": "702568152", + "Capacity": "28%", + "iused": "1395740", + "ifree": "9223372036853380067", + "%iused": "0%", + "Mounted": "/" + }, + { + "Filesystem": "devfs", + "512-blocks": "680", + "Used": "680", + "Available": "0", + "Capacity": "100%", + "iused": "1178", + "ifree": "0", + "%iused": "100%", + "Mounted": "/dev" + }, + { + "Filesystem": "map", + "512-blocks": "auto_home", + "Used": "0", + "Available": "0", + "Capacity": "0", + "iused": "100%", + "ifree": "0", + "%iused": "0", + "Mounted": "100%", + "on": "/home" + } +] +``` +### env +``` +$ env | jc --env -p +[ + { + "TERM": "xterm-256color" + }, + { + "SHELL": "/bin/bash" + }, + { + "USER": "root" + }, + { + "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" + }, + { + "PWD": "/bin" + }, + { + "LANG": "en_US.UTF-8" + }, + { + "HOME": "/root" + }, + { + "_": "/usr/bin/env" + } +] +``` +### df +``` +``` ### ifconfig ``` $ ifconfig | jc --ifconfig -p diff --git a/changelog.txt b/changelog.txt index 98ff7973..2c2b9246 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,10 @@ jc changelog +2019xxxx v0.x.x +- Add env parser +- Add df parser +- Add free parser + 20191021 v0.6.4 - Flatten netstat parser output - Clean up argument parsing diff --git a/jc/jc.py b/jc/jc.py index 9adba38c..de436b0b 100755 --- a/jc/jc.py +++ b/jc/jc.py @@ -6,6 +6,9 @@ Main input module import sys import json +import jc.parsers.df +import jc.parsers.env +import jc.parsers.free import jc.parsers.ifconfig import jc.parsers.ls import jc.parsers.netstat @@ -20,7 +23,16 @@ def main(): if '-p' in sys.argv: pretty = True - if '--ifconfig' in sys.argv: + if '--df' in sys.argv: + result = jc.parsers.df.parse(data) + + elif '--env' in sys.argv: + result = jc.parsers.env.parse(data) + + elif '--free' in sys.argv: + result = jc.parsers.free.parse(data) + + elif '--ifconfig' in sys.argv: result = jc.parsers.ifconfig.parse(data) elif '--ls' in sys.argv: @@ -39,6 +51,9 @@ def main(): print('jc: missing arguments', file=sys.stderr) print('Usage: jc [parser] [options]\n', file=sys.stderr) print('Parsers:', file=sys.stderr) + print(' --df df parser', file=sys.stderr) + print(' --env env parser', file=sys.stderr) + print(' --free free parser', file=sys.stderr) print(' --ifconfig iconfig parser', file=sys.stderr) print(' --ls ls parser', file=sys.stderr) print(' --netstat netstat parser', file=sys.stderr) diff --git a/jc/parsers/df.py b/jc/parsers/df.py new file mode 100644 index 00000000..990e982d --- /dev/null +++ b/jc/parsers/df.py @@ -0,0 +1,56 @@ +"""jc - JSON CLI output utility df Parser + +Usage: + specify --df as the first argument if the piped input is coming from df + +Example: + +$ df | jc --df -p +[ + { + "Filesystem": "/dev/disk1s1", + "512-blocks": "976490576", + "Used": "268326664", + "Available": "702568152", + "Capacity": "28%", + "iused": "1395740", + "ifree": "9223372036853380067", + "%iused": "0%", + "Mounted": "/" + }, + { + "Filesystem": "devfs", + "512-blocks": "680", + "Used": "680", + "Available": "0", + "Capacity": "100%", + "iused": "1178", + "ifree": "0", + "%iused": "100%", + "Mounted": "/dev" + }, + { + "Filesystem": "map", + "512-blocks": "auto_home", + "Used": "0", + "Available": "0", + "Capacity": "0", + "iused": "100%", + "ifree": "0", + "%iused": "0", + "Mounted": "100%", + "on": "/home" + } +] +""" + + +def parse(data): + + # code adapted from Conor Heine at: + # https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501 + + cleandata = data.splitlines() + headers = [h for h in ' '.join(cleandata[0].strip().split()).split() if h] + raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:]) + return [dict(zip(headers, r)) for r in raw_data] diff --git a/jc/parsers/env.py b/jc/parsers/env.py new file mode 100644 index 00000000..2cebc027 --- /dev/null +++ b/jc/parsers/env.py @@ -0,0 +1,53 @@ +"""jc - JSON CLI output utility env Parser + +Usage: + specify --env as the first argument if the piped input is coming from env + +Example: +$ env | jc --env -p +[ + { + "TERM": "xterm-256color" + }, + { + "SHELL": "/bin/bash" + }, + { + "USER": "root" + }, + { + "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" + }, + { + "PWD": "/bin" + }, + { + "LANG": "en_US.UTF-8" + }, + { + "HOME": "/root" + }, + { + "_": "/usr/bin/env" + } +] +""" + + +def parse(data): + output = [] + + linedata = data.splitlines() + + # Clear any blank lines + cleandata = list(filter(None, linedata)) + + if cleandata: + + for entry in cleandata: + output_line = {} + parsed_line = entry.split('=', maxsplit=1) + output_line[parsed_line[0]] = parsed_line[1] + output.append(output_line) + + return output diff --git a/jc/parsers/free.py b/jc/parsers/free.py new file mode 100644 index 00000000..72a42d3a --- /dev/null +++ b/jc/parsers/free.py @@ -0,0 +1,23 @@ +"""jc - JSON CLI output utility free Parser + +Usage: + specify --free as the first argument if the piped input is coming from free + +Example: + + +""" + + +def parse(data): + + # code adapted from Conor Heine at: + # https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501 + + cleandata = data.splitlines() + headers = [h for h in ' '.join(cleandata[0].strip().split()).split() if h] + + headers.insert(0, "type") + + raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:]) + return [dict(zip(headers, r)) for r in raw_data] From 36bc55a3109278d663b675a09829200f5474c3d8 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 11:11:41 -0700 Subject: [PATCH 02/16] fix df --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index cfcb99d6..622f4e12 100755 --- a/README.md +++ b/README.md @@ -140,9 +140,6 @@ $ env | jc --env -p } ] ``` -### df -``` -``` ### ifconfig ``` $ ifconfig | jc --ifconfig -p From c2c189f3e6e900e5f3d35df9a9b9d033448baff6 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 11:14:19 -0700 Subject: [PATCH 03/16] readme update --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 622f4e12..2d03da8c 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # JC JSON CLI output utility -`jc` is used to JSONify the output of many standard linux cli tools for easier parsing in scripts. Parsers for `ls`, `ifconfig`, `ps`, `route`, and `netstat` are currently included and more can be added via modules. +`jc` is used to JSONify the output of many standard linux cli tools for easier parsing in scripts. See the Parsers section for supported commands. This allows further command line processing of output with tools like `jq` simply by piping commands: @@ -60,6 +60,9 @@ jc [parser] [options] `jc` accepts piped input from `STDIN` and outputs a JSON representation of the previous command's output to `STDOUT`. The JSON output can be compact or pretty formatted. Parsers: +- `--df` enables the `df` parser +- `--env` enables the `env` parser +- `--free` enables the `free` parser - `--ifconfig` enables the `ifconfig` parser - `--ls` enables the `ls` parser - `--netstat` enables the `netstat` parser From 73a0d70c9294ad392792e690a7bfbcc4f51b0a5b Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 11:15:44 -0700 Subject: [PATCH 04/16] readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2d03da8c..09bd2eda 100755 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ jc [parser] [options] `jc` accepts piped input from `STDIN` and outputs a JSON representation of the previous command's output to `STDOUT`. The JSON output can be compact or pretty formatted. -Parsers: +### Parsers - `--df` enables the `df` parser - `--env` enables the `env` parser - `--free` enables the `free` parser @@ -69,7 +69,7 @@ Parsers: - `--ps` enables the `ps` parser - `--route` enables the `route` parser -Options: +### Options - `-p` specifies whether to pretty format the JSON output ## Examples From 753d5fd9fe5a8e4b67b1a0ec018a9f811e27f8bf Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 11:17:21 -0700 Subject: [PATCH 05/16] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 09bd2eda..2ca5a0bb 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # JC JSON CLI output utility -`jc` is used to JSONify the output of many standard linux cli tools for easier parsing in scripts. See the Parsers section for supported commands. +`jc` is used to JSONify the output of many standard linux cli tools for easier parsing in scripts. See the **Parsers** section for supported commands. This allows further command line processing of output with tools like `jq` simply by piping commands: From ec3d1f84ceccb492b4c968938714fafa2e6a6321 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 11:26:58 -0700 Subject: [PATCH 06/16] fix free parser --- jc/parsers/free.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/jc/parsers/free.py b/jc/parsers/free.py index 72a42d3a..fb206746 100644 --- a/jc/parsers/free.py +++ b/jc/parsers/free.py @@ -5,7 +5,24 @@ Usage: Example: - +$ free | jc --free -p +[ + { + "type": "Mem", + "total": "2017300", + "used": "213104", + "free": "1148452", + "shared": "1176", + "buff/cache": "655744", + "available": "1622204" + }, + { + "type": "Swap", + "total": "2097148", + "used": "0", + "free": "2097148" + } +] """ @@ -20,4 +37,9 @@ def parse(data): headers.insert(0, "type") raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:]) - return [dict(zip(headers, r)) for r in raw_data] + output = [dict(zip(headers, r)) for r in raw_data] + + for entry in output: + entry['type'] = entry['type'].rstrip(':') + + return output From b15227e7ba5377e5fb6799d1b9e4ed5a11c6d92f Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 11:55:11 -0700 Subject: [PATCH 07/16] add lsblk parser --- README.md | 49 +++++++++++++++++++++++++++++++ changelog.txt | 1 + jc/jc.py | 5 ++++ jc/parsers/lsblk.py | 70 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 jc/parsers/lsblk.py diff --git a/README.md b/README.md index 2ca5a0bb..ee37b234 100755 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ jc [parser] [options] - `--free` enables the `free` parser - `--ifconfig` enables the `ifconfig` parser - `--ls` enables the `ls` parser +- `--lsblk` enables the `lsblk` parser - `--netstat` enables the `netstat` parser - `--ps` enables the `ps` parser - `--route` enables the `route` parser @@ -261,6 +262,54 @@ $ ls -l /bin | jc --ls -p ... ] ``` +### lsblk +``` +$ lsblk | jc --lsblk -p +[ + { + "NAME": "loop0", + "MAJ:MIN": "7:0", + "RM": "0", + "SIZE": "54.5M", + "RO": "1", + "TYPE": "loop", + "MOUNTPOINT": "/snap/core18/1223" + }, + { + "NAME": "sda", + "MAJ:MIN": "8:0", + "RM": "0", + "SIZE": "20G", + "RO": "0", + "TYPE": "disk" + }, + { + "NAME": "sda1", + "MAJ:MIN": "8:1", + "RM": "0", + "SIZE": "1M", + "RO": "0", + "TYPE": "part" + }, + { + "NAME": "sda2", + "MAJ:MIN": "8:2", + "RM": "0", + "SIZE": "20G", + "RO": "0", + "TYPE": "part", + "MOUNTPOINT": "/" + }, + { + "NAME": "sr0", + "MAJ:MIN": "11:0", + "RM": "1", + "SIZE": "64.8M", + "RO": "0", + "TYPE": "rom" + } +] +``` ### netstat ``` $ netstat -p | jc --netstat -p diff --git a/changelog.txt b/changelog.txt index 2c2b9246..5c56c507 100644 --- a/changelog.txt +++ b/changelog.txt @@ -4,6 +4,7 @@ jc changelog - Add env parser - Add df parser - Add free parser +- Add lsblk parser 20191021 v0.6.4 - Flatten netstat parser output diff --git a/jc/jc.py b/jc/jc.py index de436b0b..44c66b6c 100755 --- a/jc/jc.py +++ b/jc/jc.py @@ -11,6 +11,7 @@ import jc.parsers.env import jc.parsers.free import jc.parsers.ifconfig import jc.parsers.ls +import jc.parsers.lsblk import jc.parsers.netstat import jc.parsers.ps import jc.parsers.route @@ -38,6 +39,9 @@ def main(): elif '--ls' in sys.argv: result = jc.parsers.ls.parse(data) + elif '--lsblk' in sys.argv: + result = jc.parsers.lsblk.parse(data) + elif '--netstat' in sys.argv: result = jc.parsers.netstat.parse(data) @@ -56,6 +60,7 @@ def main(): print(' --free free parser', file=sys.stderr) print(' --ifconfig iconfig parser', file=sys.stderr) print(' --ls ls parser', file=sys.stderr) + print(' --lsblk lsblk parser', file=sys.stderr) print(' --netstat netstat parser', file=sys.stderr) print(' --ps ps parser', file=sys.stderr) print(' --route route parser\n', file=sys.stderr) diff --git a/jc/parsers/lsblk.py b/jc/parsers/lsblk.py new file mode 100644 index 00000000..eb78975f --- /dev/null +++ b/jc/parsers/lsblk.py @@ -0,0 +1,70 @@ +"""jc - JSON CLI output utility lsblk Parser + +Usage: + specify --lsblk as the first argument if the piped input is coming from lsblk + +Example: + +$ lsblk | jc --lsblk -p +[ + { + "NAME": "loop0", + "MAJ:MIN": "7:0", + "RM": "0", + "SIZE": "54.5M", + "RO": "1", + "TYPE": "loop", + "MOUNTPOINT": "/snap/core18/1223" + }, + { + "NAME": "sda", + "MAJ:MIN": "8:0", + "RM": "0", + "SIZE": "20G", + "RO": "0", + "TYPE": "disk" + }, + { + "NAME": "sda1", + "MAJ:MIN": "8:1", + "RM": "0", + "SIZE": "1M", + "RO": "0", + "TYPE": "part" + }, + { + "NAME": "sda2", + "MAJ:MIN": "8:2", + "RM": "0", + "SIZE": "20G", + "RO": "0", + "TYPE": "part", + "MOUNTPOINT": "/" + }, + { + "NAME": "sr0", + "MAJ:MIN": "11:0", + "RM": "1", + "SIZE": "64.8M", + "RO": "0", + "TYPE": "rom" + } +] +""" + + +def parse(data): + + # code adapted from Conor Heine at: + # https://gist.github.com/cahna/43a1a3ff4d075bcd71f9d7120037a501 + + cleandata = data.splitlines() + headers = [h for h in ' '.join(cleandata[0].strip().split()).split() if h] + + raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), cleandata[1:]) + output = [dict(zip(headers, r)) for r in raw_data] + + for entry in output: + entry['NAME'] = entry['NAME'].encode('ascii', errors='ignore').decode() + + return output From a3e55d97c0fd4397b42e9146afb0ba9558274fdb Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 12:54:41 -0700 Subject: [PATCH 08/16] add mount parser --- README.md | 45 +++++++++++++++++++++++++++ changelog.txt | 1 + jc/jc.py | 7 ++++- jc/parsers/mount.py | 75 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 jc/parsers/mount.py diff --git a/README.md b/README.md index ee37b234..4a99dd4a 100755 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ jc [parser] [options] - `--ifconfig` enables the `ifconfig` parser - `--ls` enables the `ls` parser - `--lsblk` enables the `lsblk` parser +- `--mount` enables the `mount` parser - `--netstat` enables the `netstat` parser - `--ps` enables the `ps` parser - `--route` enables the `route` parser @@ -310,6 +311,50 @@ $ lsblk | jc --lsblk -p } ] ``` +### mount +``` +$ 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" + ] + }, + ... +] +``` ### netstat ``` $ netstat -p | jc --netstat -p diff --git a/changelog.txt b/changelog.txt index 5c56c507..3fbd06a9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,7 @@ jc changelog - Add df parser - Add free parser - Add lsblk parser +- Add mount parser 20191021 v0.6.4 - Flatten netstat parser output diff --git a/jc/jc.py b/jc/jc.py index 44c66b6c..4585292a 100755 --- a/jc/jc.py +++ b/jc/jc.py @@ -12,6 +12,7 @@ import jc.parsers.free import jc.parsers.ifconfig import jc.parsers.ls import jc.parsers.lsblk +import jc.parsers.mount import jc.parsers.netstat import jc.parsers.ps import jc.parsers.route @@ -42,6 +43,9 @@ def main(): elif '--lsblk' in sys.argv: result = jc.parsers.lsblk.parse(data) + elif '--mount' in sys.argv: + result = jc.parsers.mount.parse(data) + elif '--netstat' in sys.argv: result = jc.parsers.netstat.parse(data) @@ -52,7 +56,7 @@ def main(): result = jc.parsers.route.parse(data) else: - print('jc: missing arguments', file=sys.stderr) + print('jc: missing arguments\n', file=sys.stderr) print('Usage: jc [parser] [options]\n', file=sys.stderr) print('Parsers:', file=sys.stderr) print(' --df df parser', file=sys.stderr) @@ -61,6 +65,7 @@ def main(): print(' --ifconfig iconfig parser', file=sys.stderr) print(' --ls ls parser', file=sys.stderr) print(' --lsblk lsblk parser', file=sys.stderr) + print(' --mount mount parser', file=sys.stderr) print(' --netstat netstat parser', file=sys.stderr) print(' --ps ps parser', file=sys.stderr) print(' --route route parser\n', file=sys.stderr) diff --git a/jc/parsers/mount.py b/jc/parsers/mount.py new file mode 100644 index 00000000..650882e8 --- /dev/null +++ b/jc/parsers/mount.py @@ -0,0 +1,75 @@ +"""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" + ] + }, + ... +] +""" + + +def parse(data): + output = [] + + linedata = data.splitlines() + + # Clear any blank lines + cleandata = list(filter(None, linedata)) + + if cleandata: + for entry in cleandata: + output_line = {} + parsed_line = entry.split() + + output_line['filesystem'] = parsed_line[0] + output_line['mount_point'] = parsed_line[2] + output_line['type'] = parsed_line[4] + + access = parsed_line[5].lstrip('(').rstrip(')').split(',') + + output_line['access'] = access + + output.append(output_line) + + return output From 9ac57469967443b195be09d580beaa76ce0e1095 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 13:28:15 -0700 Subject: [PATCH 09/16] add uname parser --- README.md | 15 +++++++++++++++ changelog.txt | 1 + jc/jc.py | 7 ++++++- jc/parsers/uname.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 jc/parsers/uname.py diff --git a/README.md b/README.md index 4a99dd4a..d4a8a8f2 100755 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ jc [parser] [options] - `--netstat` enables the `netstat` parser - `--ps` enables the `ps` parser - `--route` enables the `route` parser +- `--uname` enables the `uname -a` parser ### Options - `-p` specifies whether to pretty format the JSON output @@ -561,6 +562,20 @@ $ route -n | jc --route -p } ] ``` +### uname -a +``` +$ 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" +} +``` ## Contributions Feel free to add/improve code or parsers! diff --git a/changelog.txt b/changelog.txt index 3fbd06a9..3a0e042f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ jc changelog - Add free parser - Add lsblk parser - Add mount parser +- Add uname parser 20191021 v0.6.4 - Flatten netstat parser output diff --git a/jc/jc.py b/jc/jc.py index 4585292a..e242f613 100755 --- a/jc/jc.py +++ b/jc/jc.py @@ -16,6 +16,7 @@ import jc.parsers.mount import jc.parsers.netstat import jc.parsers.ps import jc.parsers.route +import jc.parsers.uname def main(): @@ -55,6 +56,9 @@ def main(): elif '--route' in sys.argv: result = jc.parsers.route.parse(data) + elif '--uname' in sys.argv: + result = jc.parsers.uname.parse(data) + else: print('jc: missing arguments\n', file=sys.stderr) print('Usage: jc [parser] [options]\n', file=sys.stderr) @@ -68,7 +72,8 @@ def main(): print(' --mount mount parser', file=sys.stderr) print(' --netstat netstat parser', file=sys.stderr) print(' --ps ps parser', file=sys.stderr) - print(' --route route parser\n', file=sys.stderr) + print(' --route route parser', file=sys.stderr) + print(' --uname uname parser\n', file=sys.stderr) print('Options:', file=sys.stderr) print(' -p pretty print output\n', file=sys.stderr) print('Example:', file=sys.stderr) diff --git a/jc/parsers/uname.py b/jc/parsers/uname.py new file mode 100644 index 00000000..892ec042 --- /dev/null +++ b/jc/parsers/uname.py @@ -0,0 +1,42 @@ +"""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" +} +""" + + +def parse(data): + output = {} + parsed_line = data.split(maxsplit=3) + + output['kernel_name'] = parsed_line.pop(0) + output['node_name'] = parsed_line.pop(0) + output['kernel_release'] = parsed_line.pop(0) + + parsed_line = parsed_line[-1].rsplit(maxsplit=4) + + output['operating_system'] = parsed_line.pop(-1) + output['hardware_platform'] = parsed_line.pop(-1) + output['processor'] = parsed_line.pop(-1) + output['machine'] = parsed_line.pop(-1) + + output['kernel_version'] = parsed_line.pop(0) + + return output From 776ef2d1be81180b8b295fbc587446a326f2f7a6 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 15:42:29 -0700 Subject: [PATCH 10/16] add iptables parser --- jc/jc.py | 5 ++++ jc/parsers/iptables.py | 56 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 jc/parsers/iptables.py diff --git a/jc/jc.py b/jc/jc.py index e242f613..2dc20eb5 100755 --- a/jc/jc.py +++ b/jc/jc.py @@ -10,6 +10,7 @@ import jc.parsers.df import jc.parsers.env import jc.parsers.free import jc.parsers.ifconfig +import jc.parsers.iptables import jc.parsers.ls import jc.parsers.lsblk import jc.parsers.mount @@ -38,6 +39,9 @@ def main(): elif '--ifconfig' in sys.argv: result = jc.parsers.ifconfig.parse(data) + elif '--iptables' in sys.argv: + result = jc.parsers.iptables.parse(data) + elif '--ls' in sys.argv: result = jc.parsers.ls.parse(data) @@ -67,6 +71,7 @@ def main(): print(' --env env parser', file=sys.stderr) print(' --free free parser', file=sys.stderr) print(' --ifconfig iconfig parser', file=sys.stderr) + print(' --iptables iptables parser', file=sys.stderr) print(' --ls ls parser', file=sys.stderr) print(' --lsblk lsblk parser', file=sys.stderr) print(' --mount mount parser', file=sys.stderr) diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py new file mode 100644 index 00000000..5289abca --- /dev/null +++ b/jc/parsers/iptables.py @@ -0,0 +1,56 @@ +"""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: + +""" + + +class state(): + output = [] + chain = {} + headers = [] + + +def parse(data): + cleandata = data.splitlines() + + for line in cleandata: + + if line.find('Chain') == 0: + state.output.append(state.chain) + state.chain = {} + state.headers = [] + state.chain['rules'] = [] + + parsed_line = line.split() + + state.chain['chain'] = parsed_line[1] + state.chain['references'] = parsed_line[2].lstrip('(').rstrip(')').split()[0] + + continue + + if line.find('target') == 0: + state.headers = [] + + state.headers = [h for h in ' '.join(line.strip().split()).split() if h] + state.headers.append("options") + + continue + + else: + rule = line.split() + temp_rule = {} + for h, r in zip(state.headers, rule): + temp_rule[h] = r + state.chain['rules'].append(temp_rule) + + continue + + state.output = list(filter(None, state.output)) + + return state.output From 414c2ecef88af2d2c098e6acfb507a5fd7bb8eda Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 16:32:55 -0700 Subject: [PATCH 11/16] fix iptables parser --- jc/parsers/iptables.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index 5289abca..9761861a 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -25,32 +25,28 @@ def parse(data): state.output.append(state.chain) state.chain = {} state.headers = [] - state.chain['rules'] = [] parsed_line = line.split() state.chain['chain'] = parsed_line[1] - state.chain['references'] = parsed_line[2].lstrip('(').rstrip(')').split()[0] + # state.chain['references'] = parsed_line[2].lstrip('(').rstrip(')').split()[0] + state.chain['rules'] = [] continue - if line.find('target') == 0: + if line.find('target') == 0 or line.find('pkts') == 1: state.headers = [] - state.headers = [h for h in ' '.join(line.strip().split()).split() if h] state.headers.append("options") continue else: - rule = line.split() - temp_rule = {} - for h, r in zip(state.headers, rule): - temp_rule[h] = r + rule = line.split(maxsplit=len(state.headers) - 1) + temp_rule = dict(zip(state.headers, rule)) + if temp_rule: state.chain['rules'].append(temp_rule) - continue - state.output = list(filter(None, state.output)) return state.output From f3087b8a8ede88834285bb5d0655fc96341c174c Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 16:40:27 -0700 Subject: [PATCH 12/16] update readme and formatting --- README.md | 319 +++++++++++++++++++++++++++++++++++++++++ changelog.txt | 1 + jc/parsers/iptables.py | 316 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 635 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d4a8a8f2..733e4154 100755 --- a/README.md +++ b/README.md @@ -230,6 +230,325 @@ $ ifconfig | jc --ifconfig -p } ] ``` +### iptables +``` +$ sudo iptables -L -t nat | jc --iptables -p +[ + { + "chain": "PREROUTING", + "rules": [ + { + "target": "PREROUTING_direct", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "PREROUTING_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "PREROUTING_ZONES", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "DOCKER", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + { + "chain": "INPUT", + "rules": [] + }, + { + "chain": "OUTPUT", + "rules": [ + { + "target": "OUTPUT_direct", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "DOCKER", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "!loopback/8", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + ... +] +``` +``` +$ sudo iptables -vnL -t filter | jc --iptables -p +[ + { + "chain": "INPUT", + "rules": [ + { + "pkts": "1571", + "bytes": "3394K", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "lo", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_direct", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DROP", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate INVALID" + }, + { + "pkts": "710", + "bytes": "60078", + "target": "REJECT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "reject-with icmp-host-prohibited" + } + ] + }, + { + "chain": "FORWARD", + "rules": [ + { + "pkts": "0", + "bytes": "0", + "target": "DOCKER-ISOLATION", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DOCKER", + "prot": "all", + "opt": "--", + "in": "*", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "docker0", + "out": "!docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "docker0", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "lo", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_direct", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_IN_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_IN_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_OUT_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_OUT_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DROP", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate INVALID" + }, + { + "pkts": "0", + "bytes": "0", + "target": "REJECT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "reject-with icmp-host-prohibited" + } + ] + }, + ... +] +``` ### ls ``` $ ls -l /bin | jc --ls -p diff --git a/changelog.txt b/changelog.txt index 3a0e042f..e01976e1 100644 --- a/changelog.txt +++ b/changelog.txt @@ -7,6 +7,7 @@ jc changelog - Add lsblk parser - Add mount parser - Add uname parser +- Add iptables parser 20191021 v0.6.4 - Flatten netstat parser output diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index 9761861a..2d6756e2 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -7,6 +7,321 @@ Usage: Examples: +$ sudo iptables -L -t nat | jc --iptables -p +[ + { + "chain": "PREROUTING", + "rules": [ + { + "target": "PREROUTING_direct", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "PREROUTING_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "PREROUTING_ZONES", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "DOCKER", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + { + "chain": "INPUT", + "rules": [] + }, + { + "chain": "OUTPUT", + "rules": [ + { + "target": "OUTPUT_direct", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "anywhere" + }, + { + "target": "DOCKER", + "prot": "all", + "opt": "--", + "source": "anywhere", + "destination": "!loopback/8", + "options": "ADDRTYPE match dst-type LOCAL" + } + ] + }, + ... +] + +$ sudo iptables -vnL -t filter | jc --iptables -p +[ + { + "chain": "INPUT", + "rules": [ + { + "pkts": "1571", + "bytes": "3394K", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "lo", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_direct", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "711", + "bytes": "60126", + "target": "INPUT_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DROP", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate INVALID" + }, + { + "pkts": "710", + "bytes": "60078", + "target": "REJECT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "reject-with icmp-host-prohibited" + } + ] + }, + { + "chain": "FORWARD", + "rules": [ + { + "pkts": "0", + "bytes": "0", + "target": "DOCKER-ISOLATION", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DOCKER", + "prot": "all", + "opt": "--", + "in": "*", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "docker0", + "out": "!docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "docker0", + "out": "docker0", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate RELATED,ESTABLISHED" + }, + { + "pkts": "0", + "bytes": "0", + "target": "ACCEPT", + "prot": "all", + "opt": "--", + "in": "lo", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_direct", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_IN_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_IN_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_OUT_ZONES_SOURCE", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "FORWARD_OUT_ZONES", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0" + }, + { + "pkts": "0", + "bytes": "0", + "target": "DROP", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "ctstate INVALID" + }, + { + "pkts": "0", + "bytes": "0", + "target": "REJECT", + "prot": "all", + "opt": "--", + "in": "*", + "out": "*", + "source": "0.0.0.0/0", + "destination": "0.0.0.0/0", + "options": "reject-with icmp-host-prohibited" + } + ] + }, + ... +] """ @@ -29,7 +344,6 @@ def parse(data): parsed_line = line.split() state.chain['chain'] = parsed_line[1] - # state.chain['references'] = parsed_line[2].lstrip('(').rstrip(')').split()[0] state.chain['rules'] = [] continue From 306d539b6bbfb272c7b955e4847adc3a6b4afa5f Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 16:50:01 -0700 Subject: [PATCH 13/16] readme update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 733e4154..d88976ef 100755 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ jc [parser] [options] - `--env` enables the `env` parser - `--free` enables the `free` parser - `--ifconfig` enables the `ifconfig` parser +- `--iptables` enables the `iptables` parser - `--ls` enables the `ls` parser - `--lsblk` enables the `lsblk` parser - `--mount` enables the `mount` parser From 39a8aec77f5134b5b958e3f679910a1c3512e13a Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 17:15:02 -0700 Subject: [PATCH 14/16] v0.8.1 build --- changelog.txt | 2 +- jc/parsers/ls.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/changelog.txt b/changelog.txt index e01976e1..57f7fa74 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,6 @@ jc changelog -2019xxxx v0.x.x +20191022 v0.8.1 - Add env parser - Add df parser - Add free parser diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 24a8d841..318153aa 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -72,7 +72,7 @@ $ ls -al /usr/bin | jc --ls -p ... ] -$ $ ls -l /usr/bin | jc --ls | jq .[] | jq 'select(.bytes > 50000000)' +$ $ ls -l /usr/bin | jc --ls | jq '.[] | 'select(.bytes > 50000000)' { "filename": "emacs", "flags": "-r-xr-xr-x", diff --git a/setup.py b/setup.py index ac5088ab..43fef882 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='0.6.4', + version='0.8.1', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='This tool serializes the output of popular command line tools to structured JSON output.', From d8337870cad042cdcc6a4ff3c61f756c3430fa96 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 17:21:00 -0700 Subject: [PATCH 15/16] update documentation --- jc/parsers/df.py | 57 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/jc/parsers/df.py b/jc/parsers/df.py index 990e982d..32a9af01 100644 --- a/jc/parsers/df.py +++ b/jc/parsers/df.py @@ -8,39 +8,38 @@ Example: $ df | jc --df -p [ { - "Filesystem": "/dev/disk1s1", - "512-blocks": "976490576", - "Used": "268326664", - "Available": "702568152", - "Capacity": "28%", - "iused": "1395740", - "ifree": "9223372036853380067", - "%iused": "0%", - "Mounted": "/" - }, - { - "Filesystem": "devfs", - "512-blocks": "680", - "Used": "680", - "Available": "0", - "Capacity": "100%", - "iused": "1178", - "ifree": "0", - "%iused": "100%", + "Filesystem": "udev", + "1K-blocks": "977500", + "Used": "0", + "Available": "977500", + "Use%": "0%", "Mounted": "/dev" }, { - "Filesystem": "map", - "512-blocks": "auto_home", + "Filesystem": "tmpfs", + "1K-blocks": "201732", + "Used": "1180", + "Available": "200552", + "Use%": "1%", + "Mounted": "/run" + }, + { + "Filesystem": "/dev/sda2", + "1K-blocks": "20508240", + "Used": "5747284", + "Available": "13696152", + "Use%": "30%", + "Mounted": "/" + }, + { + "Filesystem": "tmpfs", + "1K-blocks": "1008648", "Used": "0", - "Available": "0", - "Capacity": "0", - "iused": "100%", - "ifree": "0", - "%iused": "0", - "Mounted": "100%", - "on": "/home" - } + "Available": "1008648", + "Use%": "0%", + "Mounted": "/dev/shm" + }, + ... ] """ From 976fd7d9bd49190a8b28ea5acf5af8979cdec537 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 22 Oct 2019 17:24:56 -0700 Subject: [PATCH 16/16] readme update --- README.md | 57 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index d88976ef..f5cd1281 100755 --- a/README.md +++ b/README.md @@ -82,39 +82,38 @@ jc [parser] [options] $ df | jc --df -p [ { - "Filesystem": "/dev/disk1s1", - "512-blocks": "976490576", - "Used": "268326664", - "Available": "702568152", - "Capacity": "28%", - "iused": "1395740", - "ifree": "9223372036853380067", - "%iused": "0%", - "Mounted": "/" - }, - { - "Filesystem": "devfs", - "512-blocks": "680", - "Used": "680", - "Available": "0", - "Capacity": "100%", - "iused": "1178", - "ifree": "0", - "%iused": "100%", + "Filesystem": "udev", + "1K-blocks": "977500", + "Used": "0", + "Available": "977500", + "Use%": "0%", "Mounted": "/dev" }, { - "Filesystem": "map", - "512-blocks": "auto_home", + "Filesystem": "tmpfs", + "1K-blocks": "201732", + "Used": "1180", + "Available": "200552", + "Use%": "1%", + "Mounted": "/run" + }, + { + "Filesystem": "/dev/sda2", + "1K-blocks": "20508240", + "Used": "5747284", + "Available": "13696152", + "Use%": "30%", + "Mounted": "/" + }, + { + "Filesystem": "tmpfs", + "1K-blocks": "1008648", "Used": "0", - "Available": "0", - "Capacity": "0", - "iused": "100%", - "ifree": "0", - "%iused": "0", - "Mounted": "100%", - "on": "/home" - } + "Available": "1008648", + "Use%": "0%", + "Mounted": "/dev/shm" + }, + ... ] ``` ### env