From b8b8dfead4fdc4285585c44c2ebce3bdd42b2e7c Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 8 Apr 2021 15:52:49 -0700 Subject: [PATCH] update docs --- docs/parsers/ini.md | 39 +++--- docs/parsers/iptables.md | 62 ++++------ docs/parsers/iw_scan.md | 35 ++---- docs/parsers/jobs.md | 40 ++----- docs/parsers/kv.md | 12 +- docs/parsers/last.md | 48 +++----- docs/parsers/ls.md | 50 +++----- docs/parsers/lsblk.md | 110 ++++++++--------- docs/parsers/lsmod.md | 42 +++---- docs/parsers/lsof.md | 50 +++----- docs/parsers/mount.md | 42 +++---- docs/parsers/netstat.md | 218 ++++++++++++++++------------------ docs/parsers/ntpq.md | 53 +++------ docs/parsers/passwd.md | 44 +++---- docs/parsers/ping.md | 76 +++++------- docs/parsers/pip_list.md | 36 ++---- docs/parsers/pip_show.md | 51 +++----- docs/parsers/ps.md | 64 ++++------ docs/parsers/route.md | 58 ++++----- docs/parsers/rpm_qi.md | 72 +++++------ docs/parsers/shadow.md | 46 +++---- docs/parsers/ss.md | 66 ++++------ docs/parsers/stat.md | 92 ++++++-------- docs/parsers/sysctl.md | 32 ++--- docs/parsers/systemctl.md | 40 ++----- docs/parsers/systemctl_lj.md | 39 ++---- docs/parsers/systemctl_ls.md | 36 ++---- docs/parsers/systemctl_luf.md | 34 ++---- docs/parsers/time.md | 100 +++++++--------- docs/parsers/timedatectl.md | 48 +++----- docs/parsers/tracepath.md | 55 ++++----- docs/parsers/traceroute.md | 64 ++++------ jc/parsers/jobs.py | 31 ++--- jc/parsers/kv.py | 13 +- jc/parsers/last.py | 39 +++--- jc/parsers/ls.py | 41 ++++--- jc/parsers/lsblk.py | 101 ++++++++-------- jc/parsers/lsmod.py | 33 ++--- jc/parsers/lsof.py | 41 ++++--- jc/parsers/mount.py | 41 ++++--- jc/parsers/netstat.py | 209 ++++++++++++++++---------------- jc/parsers/ntpq.py | 44 +++---- jc/parsers/passwd.py | 35 +++--- jc/parsers/ping.py | 75 ++++++------ jc/parsers/pip_list.py | 27 +++-- jc/parsers/pip_show.py | 42 +++---- jc/parsers/ps.py | 55 +++++---- jc/parsers/route.py | 49 ++++---- jc/parsers/rpm_qi.py | 63 +++++----- jc/parsers/shadow.py | 37 +++--- jc/parsers/ss.py | 57 ++++----- jc/parsers/stat.py | 83 ++++++------- jc/parsers/sysctl.py | 23 ++-- jc/parsers/systemctl.py | 31 ++--- jc/parsers/systemctl_lj.py | 30 ++--- jc/parsers/systemctl_ls.py | 27 +++-- jc/parsers/systemctl_luf.py | 25 ++-- jc/parsers/time.py | 91 +++++++------- jc/parsers/timedatectl.py | 39 +++--- jc/parsers/tracepath.py | 46 +++---- jc/parsers/traceroute.py | 65 +++++----- 61 files changed, 1500 insertions(+), 1847 deletions(-) diff --git a/docs/parsers/ini.md b/docs/parsers/ini.md index 0d38e819..382371c1 100644 --- a/docs/parsers/ini.md +++ b/docs/parsers/ini.md @@ -15,6 +15,19 @@ Usage (module): import jc.parsers.ini result = jc.parsers.ini.parse(ini_file_output) +Schema: + + ini or key/value document converted to a dictionary - see configparser standard + library documentation for more details. + + Note: Values starting and ending with quotation marks will have the marks removed. + If you would like to keep the quotation marks, use the -r or raw=True argument. + + { + "key1": string, + "key2": string + } + Compatibility: 'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd' @@ -58,31 +71,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (Dictionary) raw structured data to process - -Returns: - - Dictionary representing an ini or simple key/value pair document: - - { - ini or key/value document converted to a dictionary - see configparser standard - library documentation for more details. - - Note: Values starting and ending with quotation marks will have the marks removed. - If you would like to keep the quotation marks, use the -r or raw=True argument. - } - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/iptables.md b/docs/parsers/iptables.md index e4b9467e..30c08a4a 100644 --- a/docs/parsers/iptables.md +++ b/docs/parsers/iptables.md @@ -17,6 +17,29 @@ Usage (module): import jc.parsers.iptables result = jc.parsers.iptables.parse(iptables_command_output) +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 + } + ] + } + ] + Compatibility: 'linux' @@ -146,44 +169,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following 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 - } - ] - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/iw_scan.md b/docs/parsers/iw_scan.md index 58268fae..6173ab04 100644 --- a/docs/parsers/iw_scan.md +++ b/docs/parsers/iw_scan.md @@ -17,6 +17,16 @@ Usage (module): import jc.parsers.iw-scan result = jc.parsers.iw-scan.parse(iw-scan_command_output) +Schema: + + [ + { + "foo": string/integer/float, # best guess based on value + "bar": string/integer/float, + "baz": string/integer/float + } + ] + Compatibility: 'linux' @@ -116,30 +126,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - [ - { - "foo": string/integer/float, # best guess based on value - "bar": string/integer/float, - "baz": string/integer/float - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/jobs.md b/docs/parsers/jobs.md index de3cb74e..d3df7349 100644 --- a/docs/parsers/jobs.md +++ b/docs/parsers/jobs.md @@ -17,6 +17,18 @@ Usage (module): import jc.parsers.jobs result = jc.parsers.jobs.parse(jobs_command_output) +Schema: + + [ + { + "job_number": integer, + "pid": integer, + "history": string, + "status": string, + "command": string + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'aix', 'freebsd' @@ -88,33 +100,7 @@ Example: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "job_number": integer, - "pid": integer, - "history": string, - "status": string, - "command": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/kv.md b/docs/parsers/kv.md index 2ba6e825..8348ab06 100644 --- a/docs/parsers/kv.md +++ b/docs/parsers/kv.md @@ -6,7 +6,6 @@ Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. M Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`. - Usage (cli): $ cat foo.txt | jc --kv @@ -16,6 +15,15 @@ Usage (module): import jc.parsers.kv result = jc.parsers.kv.parse(kv_file_output) +Schema: + + key/value document converted to a dictionary - see configparser standard library documentation for more details. + + { + "key1": string, + "key2": string + } + Compatibility: 'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd' @@ -46,7 +54,7 @@ Examples: ```python info() ``` - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/last.md b/docs/parsers/last.md index 8267a3e1..5df05d03 100644 --- a/docs/parsers/last.md +++ b/docs/parsers/last.md @@ -19,6 +19,22 @@ Usage (module): import jc.parsers.last result = jc.parsers.last.parse(last_command_output) +Schema: + + [ + { + "user": string, + "tty": string, + "hostname": string, + "login": string, + "logout": string, + "duration": string, + "login_epoch": integer, # (naive) available with last -F option + "logout_epoch": integer, # (naive) available with last -F option + "duration_seconds": integer # available with last -F option + } + ] + Compatibility: 'linux', 'darwin', 'aix', 'freebsd' @@ -93,37 +109,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "user": string, - "tty": string, - "hostname": string, - "login": string, - "logout": string, - "duration": string, - "login_epoch": integer, # (naive) available with last -F option - "logout_epoch": integer, # (naive) available with last -F option - "duration_seconds": integer # available with last -F option - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/ls.md b/docs/parsers/ls.md index 1af78f01..c70c3d42 100644 --- a/docs/parsers/ls.md +++ b/docs/parsers/ls.md @@ -26,6 +26,23 @@ Usage (module): import jc.parsers.ls result = jc.parsers.ls.parse(ls_command_output) +Schema: + + [ + { + "filename": string, + "flags": string, + "links": integer, + "parent": string, + "owner": string, + "group": string, + "size": integer, + "date": string, + "epoch": integer, # naive timestamp if date field exists and can be converted + "epoch_utc": integer # timezone aware timestamp if date field is in UTC and can be converted + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'aix', 'freebsd' @@ -159,38 +176,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "filename": string, - "flags": string, - "links": integer, - "parent": string, - "owner": string, - "group": string, - "size": integer, - "date": string, - "epoch": integer, # naive timestamp if date field exists and can be converted - "epoch_utc": integer # timezone aware timestamp if date field is in UTC and can be converted - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/lsblk.md b/docs/parsers/lsblk.md index 016e6dc3..d45c17ff 100644 --- a/docs/parsers/lsblk.md +++ b/docs/parsers/lsblk.md @@ -15,6 +15,53 @@ Usage (module): import jc.parsers.lsblk result = jc.parsers.lsblk.parse(lsblk_command_output) +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 + } + ] + Compatibility: 'linux' @@ -227,68 +274,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following 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 - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/lsmod.md b/docs/parsers/lsmod.md index 9b0e27df..32360f9a 100644 --- a/docs/parsers/lsmod.md +++ b/docs/parsers/lsmod.md @@ -15,6 +15,19 @@ Usage (module): import jc.parsers.lsmod result = jc.parsers.lsmod.parse(lsmod_command_output) +Schema: + + [ + { + "module": string, + "size": integer, + "used": integer, + "by": [ + string + ] + } + ] + Compatibility: 'linux' @@ -118,34 +131,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "module": string, - "size": integer, - "used": integer, - "by": [ - string - ] - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/lsof.md b/docs/parsers/lsof.md index 543abcec..a3772527 100644 --- a/docs/parsers/lsof.md +++ b/docs/parsers/lsof.md @@ -15,6 +15,23 @@ Usage (module): import jc.parsers.lsof result = jc.parsers.lsof.parse(lsof_command_output) +Schema: + + [ + { + "command": string, + "pid": integer, + "tid": integer, + "user": string, + "fd": string, + "type": string, + "device": string, + "size_off": integer, + "node": integer, + "name": string + } + ] + Compatibility: 'linux' @@ -108,38 +125,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "command": string, - "pid": integer, - "tid": integer, - "user": string, - "fd": string, - "type": string, - "device": string, - "size_off": integer, - "node": integer, - "name": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/mount.md b/docs/parsers/mount.md index 57cd3400..29dbd26c 100644 --- a/docs/parsers/mount.md +++ b/docs/parsers/mount.md @@ -15,6 +15,19 @@ Usage (module): import jc.parsers.mount result = jc.parsers.mount.parse(mount_command_output) +Schema: + + [ + { + "filesystem": string, + "mount_point": string, + "type": string, + "access": [ + string + ] + } + ] + Compatibility: 'linux', 'darwin', 'freebsd' @@ -68,34 +81,7 @@ Example: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "filesystem": string, - "mount_point": string, - "type": string, - "access": [ - string - ] - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/netstat.md b/docs/parsers/netstat.md index bb5c0763..55e51356 100644 --- a/docs/parsers/netstat.md +++ b/docs/parsers/netstat.md @@ -19,6 +19,107 @@ Usage (module): import jc.parsers.netstat result = jc.parsers.netstat.parse(netstat_command_output) +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, + "address": string, + "unix_inode": string, + "conn": string, + "refs": string, + "nextref": string, + "name": string, + "unit": integer, + "vendor": integer, + "class": integer, + "subcla": integer, + "unix_flags": integer, + "pcbcount": integer, + "rcvbuf": integer, + "sndbuf": integer, + "rxbytes": integer, + "txbytes": integer, + "destination": string, + "gateway": string, + "route_flags": string, + "route_flags_pretty": [ + string, + ] + "route_refs": integer, + "use": integer, + "mtu": integer, + "expire": string, + "genmask": string, + "mss": integer, + "window": integer, + "irtt": integer, + "iface": string, + "metric": integer, + "network": string, + "address": string, + "ipkts": integer, # - = null + "ierrs": integer, # - = null + "idrop": integer, # - = null + "opkts": integer, # - = null + "oerrs": integer, # - = null + "coll": integer, # - = null + "rx_ok": integer, + "rx_err": integer, + "rx_drp": integer, + "rx_ovr": integer, + "tx_ok": integer, + "tx_err": integer, + "tx_drp": integer, + "tx_ovr": integer, + "flg": string, + "ibytes": integer, + "obytes": integer, + "r_mbuf": integer, + "s_mbuf": integer, + "r_clus": integer, + "s_clus": integer, + "r_hiwa": integer, + "s_hiwa": integer, + "r_lowa": integer, + "s_lowa": integer, + "r_bcnt": integer, + "s_bcnt": integer, + "r_bmax": integer, + "s_bmax": integer, + "rexmit": integer, + "ooorcv": integer, + "0_win": integer, + "rexmt": float, + "persist": float, + "keep": float, + "2msl": float, + "delack": float, + "rcvtime": float, + } + ] + Compatibility: 'linux', 'darwin', 'freebsd' @@ -259,122 +360,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following 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, - "address": string, - "unix_inode": string, - "conn": string, - "refs": string, - "nextref": string, - "name": string, - "unit": integer, - "vendor": integer, - "class": integer, - "subcla": integer, - "unix_flags": integer, - "pcbcount": integer, - "rcvbuf": integer, - "sndbuf": integer, - "rxbytes": integer, - "txbytes": integer, - "destination": string, - "gateway": string, - "route_flags": string, - "route_flags_pretty": [ - string, - ] - "route_refs": integer, - "use": integer, - "mtu": integer, - "expire": string, - "genmask": string, - "mss": integer, - "window": integer, - "irtt": integer, - "iface": string, - "metric": integer, - "network": string, - "address": string, - "ipkts": integer, - = null - "ierrs": integer, - = null - "idrop": integer, - = null - "opkts": integer, - = null - "oerrs": integer, - = null - "coll": integer, - = null - "rx_ok": integer, - "rx_err": integer, - "rx_drp": integer, - "rx_ovr": integer, - "tx_ok": integer, - "tx_err": integer, - "tx_drp": integer, - "tx_ovr": integer, - "flg": string, - "ibytes": integer, - "obytes": integer, - "r_mbuf": integer, - "s_mbuf": integer, - "r_clus": integer, - "s_clus": integer, - "r_hiwa": integer, - "s_hiwa": integer, - "r_lowa": integer, - "s_lowa": integer, - "r_bcnt": integer, - "s_bcnt": integer, - "r_bmax": integer, - "s_bmax": integer, - "rexmit": integer, - "ooorcv": integer, - "0_win": integer, - "rexmt": float, - "persist": float, - "keep": float, - "2msl": float, - "delack": float, - "rcvtime": float, - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/ntpq.md b/docs/parsers/ntpq.md index 313d8b6e..01ed563c 100644 --- a/docs/parsers/ntpq.md +++ b/docs/parsers/ntpq.md @@ -15,6 +15,24 @@ Usage (module): import jc.parsers.ntpq result = jc.parsers.ntpq.parse(ntpq_command_output) +Schema: + + [ + { + "state": string, # space/~ converted to null + "remote": string, + "refid": string, + "st": integer, + "t": string, + "when": integer, # - converted to null + "poll": integer, + "reach": integer, + "delay": float, + "offset": float, + "jitter": float + }, + ] + Compatibility: 'linux', 'freebsd' @@ -194,40 +212,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "state": string, # space/~ converted to null - "remote": string, - "refid": string, - "st": integer, - "t": string, - "when": integer, # - converted to null - "poll": integer, - "reach": integer, - "delay": float, - "offset": float, - "jitter": float - }, - ] - - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/passwd.md b/docs/parsers/passwd.md index 42ee12bf..45b5caee 100644 --- a/docs/parsers/passwd.md +++ b/docs/parsers/passwd.md @@ -11,6 +11,20 @@ Usage (module): import jc.parsers.passwd result = jc.parsers.passwd.parse(passwd_file_output) +Schema: + + [ + { + "username": string, + "password": string, + "uid": integer, + "gid": integer, + "comment": string, + "home": string, + "shell": string + } + ] + Compatibility: 'linux', 'darwin', 'aix', 'freebsd' @@ -86,35 +100,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "username": string, - "password": string, - "uid": integer, - "gid": integer, - "comment": string, - "home": string, - "shell": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/ping.md b/docs/parsers/ping.md index b2f83a8c..d0906766 100644 --- a/docs/parsers/ping.md +++ b/docs/parsers/ping.md @@ -19,6 +19,36 @@ Usage (module): import jc.parsers.ping result = jc.parsers.ping.parse(ping_command_output) +Schema: + + { + "source_ip": string, + "destination_ip": string, + "data_bytes": integer, + "pattern": string, # (null if not set) + "destination": string, + "packets_transmitted": integer, + "packets_received": integer, + "packet_loss_percent": float, + "duplicates": integer, + "round_trip_ms_min": float, + "round_trip_ms_avg": float, + "round_trip_ms_max": float, + "round_trip_ms_stddev": float, + "responses": [ + { + "type": string, # ('reply' or 'timeout') + "timestamp": float, + "bytes": integer, + "response_ip": string, + "icmp_seq": integer, + "ttl": integer, + "time_ms": float, + "duplicate": boolean + } + ] + } + Compatibility: 'linux', 'darwin', 'freebsd' @@ -121,51 +151,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (Dictionary) raw structured data to process - -Returns: - - Dictionary. Structured data with the following schema: - - { - "source_ip": string, - "destination_ip": string, - "data_bytes": integer, - "pattern": string, (null if not set) - "destination": string, - "packets_transmitted": integer, - "packets_received": integer, - "packet_loss_percent": float, - "duplicates": integer, - "round_trip_ms_min": float, - "round_trip_ms_avg": float, - "round_trip_ms_max": float, - "round_trip_ms_stddev": float, - "responses": [ - { - "type": string, ('reply' or 'timeout') - "timestamp": float, - "bytes": integer, - "response_ip": string, - "icmp_seq": integer, - "ttl": integer, - "time_ms": float, - "duplicate": boolean - } - ] - } - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/pip_list.md b/docs/parsers/pip_list.md index 3e4a24c6..2026ed2b 100644 --- a/docs/parsers/pip_list.md +++ b/docs/parsers/pip_list.md @@ -15,6 +15,16 @@ Usage (module): import jc.parsers.pip_list result = jc.parsers.pip_list.parse(pip_list_command_output) +Schema: + + [ + { + "package": string, + "version": string, + "location": string + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd' @@ -43,31 +53,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "package": string, - "version": string, - "location": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/pip_show.md b/docs/parsers/pip_show.md index 04ea0cec..3b2b78c2 100644 --- a/docs/parsers/pip_show.md +++ b/docs/parsers/pip_show.md @@ -15,6 +15,23 @@ Usage (module): import jc.parsers.pip_show result = jc.parsers.pip_show.parse(pip_show_command_output) +Schema: + + [ + { + "name": string, + "version": string, + "summary": string, + "home_page": string, + "author": string, + "author_email": string, + "license": string, + "location": string, + "requires": string, + "required_by": string + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd' @@ -54,39 +71,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "name": string, - "version": string, - "summary": string, - "home_page": string, - "author": string, - "author_email": string, - "license": string, - "location": string, - "requires": string, - "required_by": string - } - ] - - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/ps.md b/docs/parsers/ps.md index 2d854823..b1003e8f 100644 --- a/docs/parsers/ps.md +++ b/docs/parsers/ps.md @@ -19,6 +19,30 @@ Usage (module): import jc.parsers.ps result = jc.parsers.ps.parse(ps_command_output) +Schema: + + [ + { + "uid": string, + "pid": integer, + "ppid": integer, + "c": integer, + "stime": string, + "tty": string, # ? or ?? = Null + "tt": string, # ?? = Null + "time": string, + "cmd": string, + "user": string, + "cpu_percent": float, + "mem_percent": float, + "vsz": integer, + "rss": integer, + "stat": string, + "start": string, + "command": string + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'aix', 'freebsd' @@ -188,45 +212,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "uid": string, - "pid": integer, - "ppid": integer, - "c": integer, - "stime": string, - "tty": string, # ? or ?? = Null - "tt": string, # ?? = Null - "time": string, - "cmd": string, - "user": string, - "cpu_percent": float, - "mem_percent": float, - "vsz": integer, - "rss": integer, - "stat": string, - "start": string, - "command": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/route.md b/docs/parsers/route.md index d1d2e5da..1c2bd1b0 100644 --- a/docs/parsers/route.md +++ b/docs/parsers/route.md @@ -15,6 +15,27 @@ Usage (module): import jc.parsers.route result = jc.parsers.route.parse(route_command_output) +Schema: + + [ + { + "destination": string, + "gateway": string, + "genmask": string, + "flags": string, + "flags_pretty": [ + string, + ] + "metric": integer, + "ref": integer, + "use": integer, + "mss": integer, + "window": integer, + "irtt": integer, + "iface": string + } + ] + Compatibility: 'linux' @@ -95,42 +116,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "destination": string, - "gateway": string, - "genmask": string, - "flags": string, - "flags_pretty": [ - string, - ] - "metric": integer, - "ref": integer, - "use": integer, - "mss": integer, - "window": integer, - "irtt": integer, - "iface": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/rpm_qi.md b/docs/parsers/rpm_qi.md index c2e59b4f..00f37825 100644 --- a/docs/parsers/rpm_qi.md +++ b/docs/parsers/rpm_qi.md @@ -21,6 +21,34 @@ Usage (module): import jc.parsers.rpm_qi result = jc.parsers.rpm_qi.parse(rpm_qi_command_output) +Schema: + + [ + { + "name": string, + "epoch": integer, + "version": string, + "release": string, + "architecture": string, + "install_date": string, + "group": string, + "size": integer, + "license": string, + "signature": string, + "source_rpm": string, + "build_date": string, + "build_epoch": integer, # naive timestamp + "build_epoch_utc": integer, # Aware timestamp if timezone is UTC + "build_host": string, + "relocations": string, + "packager": string, + "vendor": string, + "url": string, + "summary": string, + "description": string + } + ] + Compatibility: 'linux' @@ -128,49 +156,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "name": string, - "epoch": integer, - "version": string, - "release": string, - "architecture": string, - "install_date": string, - "group": string, - "size": integer, - "license": string, - "signature": string, - "source_rpm": string, - "build_date": string, - "build_epoch": integer, # naive timestamp - "build_epoch_utc": integer, # Aware timestamp if timezone is UTC - "build_host": string, - "relocations": string, - "packager": string, - "vendor": string, - "url": string, - "summary": string, - "description": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/shadow.md b/docs/parsers/shadow.md index 60196aa1..1678d2d8 100644 --- a/docs/parsers/shadow.md +++ b/docs/parsers/shadow.md @@ -11,6 +11,21 @@ Usage (module): import jc.parsers.shadow result = jc.parsers.shadow.parse(shadow_file_output) +Schema: + + [ + { + "username": string, + "password": string, + "last_changed": integer, + "minimum": integer, + "maximum": integer, + "warn": integer, + "inactive": integer, + "expire": integer + } + ] + Compatibility: 'linux', 'darwin', 'aix', 'freebsd' @@ -92,36 +107,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "username": string, - "password": string, - "last_changed": integer, - "minimum": integer, - "maximum": integer, - "warn": integer, - "inactive": integer, - "expire": integer - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/ss.md b/docs/parsers/ss.md index 4f081e1e..a4d5d4e4 100644 --- a/docs/parsers/ss.md +++ b/docs/parsers/ss.md @@ -2,6 +2,8 @@ # jc.parsers.ss jc - JSON CLI output utility `ss` command output parser +Extended information options like -e and -p are not supported and may cause parsing irregularities. + Usage (cli): $ ss | jc --ss @@ -15,9 +17,29 @@ Usage (module): import jc.parsers.ss result = jc.parsers.ss.parse(ss_command_output) -Limitations: +Schema: - Extended information options like -e and -p are not supported and may cause parsing irregularities + Information from https://www.cyberciti.biz/files/ss.html used to define field names + + [ + { + "netid": string, + "state": string, + "recv_q": integer, + "send_q": integer, + "local_address": string, + "local_port": string, + "local_port_num": integer, + "peer_address": string, + "peer_port": string, + "peer_port_num": integer, + "interface": string, + "link_layer" string, + "channel": string, + "path": string, + "pid": integer + } + ] Compatibility: @@ -262,45 +284,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "netid": string, - "state": string, - "recv_q": integer, - "send_q": integer, - "local_address": string, - "local_port": string, - "local_port_num": integer, - "peer_address": string, - "peer_port": string, - "peer_port_num": integer, - "interface": string, - "link_layer" string, - "channel": string, - "path": string, - "pid": integer - } - ] - - Information from https://www.cyberciti.biz/files/ss.html used to define field names - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/stat.md b/docs/parsers/stat.md index 99d8cc11..6b323e77 100644 --- a/docs/parsers/stat.md +++ b/docs/parsers/stat.md @@ -19,6 +19,44 @@ Usage (module): import jc.parsers.stat result = jc.parsers.stat.parse(stat_command_output) +Schema: + + [ + { + "file": string, + "link_to" string, + "size": integer, + "blocks": integer, + "io_blocks": integer, + "type": string, + "device": string, + "inode": integer, + "links": integer, + "access": string, + "flags": string, + "uid": integer, + "user": string, + "gid": integer, + "group": string, + "access_time": string, # - = null + "access_time_epoch": integer, # naive timestamp + "access_time_epoch_utc": integer, # timezone-aware timestamp + "modify_time": string, # - = null + "modify_time_epoch": integer, # naive timestamp + "modify_time_epoch_utc": integer, # timezone-aware timestamp + "change_time": string, # - = null + "change_time_epoch": integer, # naive timestamp + "change_time_epoch_utc": integer, # timezone-aware timestamp + "birth_time": string, # - = null + "birth_time_epoch": integer, # naive timestamp + "birth_time_epoch_utc": integer, # timezone-aware timestamp + "unix_device": integer, + "rdev": integer, + "block_size": integer, + "unix_flags": string + } + ] + Compatibility: 'linux', 'darwin', 'freebsd' @@ -136,59 +174,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "file": string, - "link_to" string, - "size": integer, - "blocks": integer, - "io_blocks": integer, - "type": string, - "device": string, - "inode": integer, - "links": integer, - "access": string, - "flags": string, - "uid": integer, - "user": string, - "gid": integer, - "group": string, - "access_time": string, # - = null - "access_time_epoch": integer, # naive timestamp - "access_time_epoch_utc": integer, # timezone-aware timestamp - "modify_time": string, # - = null - "modify_time_epoch": integer, # naive timestamp - "modify_time_epoch_utc": integer, # timezone-aware timestamp - "change_time": string, # - = null - "change_time_epoch": integer, # naive timestamp - "change_time_epoch_utc": integer, # timezone-aware timestamp - "birth_time": string, # - = null - "birth_time_epoch": integer, # naive timestamp - "birth_time_epoch_utc": integer, # timezone-aware timestamp - "unix_device": integer, - "rdev": integer, - "block_size": integer, - "unix_flags": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/sysctl.md b/docs/parsers/sysctl.md index e167c0c8..2ad42e4e 100644 --- a/docs/parsers/sysctl.md +++ b/docs/parsers/sysctl.md @@ -17,6 +17,14 @@ Usage (module): import jc.parsers.sysctl result = jc.parsers.sysctl.parse(sysctl_command_output) +Schema: + + { + "key1": string/integer/float, # best guess based on value + "key2": string/integer/float, + "key3": string/integer/float + } + Compatibility: 'linux', 'darwin', 'freebsd' @@ -52,29 +60,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (Dictionary) raw structured data to process - -Returns: - - Dictionary. Structured data with the following schema: - - { - "foo": string/integer/float, # best guess based on value - "bar": string/integer/float, - "baz": string/integer/float - } - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/systemctl.md b/docs/parsers/systemctl.md index af747f2e..1f7aa9f9 100644 --- a/docs/parsers/systemctl.md +++ b/docs/parsers/systemctl.md @@ -15,6 +15,18 @@ Usage (module): import jc.parsers.systemctl result = jc.parsers.systemctl.parse(systemctl_command_output) +Schema: + + [ + { + "unit": string, + "load": string, + "active": string, + "sub": string, + "description": string + } + ] + Compatibility: 'linux' @@ -52,33 +64,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "unit": string, - "load": string, - "active": string, - "sub": string, - "description": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/systemctl_lj.md b/docs/parsers/systemctl_lj.md index 4975256a..b92e3c5c 100644 --- a/docs/parsers/systemctl_lj.md +++ b/docs/parsers/systemctl_lj.md @@ -15,6 +15,17 @@ Usage (module): import jc.parsers.systemctl_lj result = jc.parsers.systemctl_lj.parse(systemctl_lj_command_output) +Schema: + + [ + { + "job": integer, + "unit": string, + "type": string, + "state": string + } + ] + Compatibility: 'linux' @@ -66,37 +77,11 @@ Examples: ] - ## info ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "job": integer, - "unit": string, - "type": string, - "state": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/systemctl_ls.md b/docs/parsers/systemctl_ls.md index 7c61eea2..a89dc2dc 100644 --- a/docs/parsers/systemctl_ls.md +++ b/docs/parsers/systemctl_ls.md @@ -15,6 +15,16 @@ Usage (module): import jc.parsers.systemctl_ls result = jc.parsers.systemctl_ls.parse(systemctl_ls_command_output) +Schema: + + [ + { + "listen": string, + "unit": string, + "activates": string + } + ] + Compatibility: 'linux' @@ -46,31 +56,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "listen": string, - "unit": string, - "activates": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/systemctl_luf.md b/docs/parsers/systemctl_luf.md index a7253569..412bc70f 100644 --- a/docs/parsers/systemctl_luf.md +++ b/docs/parsers/systemctl_luf.md @@ -15,6 +15,15 @@ Usage (module): import jc.parsers.systemctl_luf result = jc.parsers.systemctl_luf.parse(systemctl_luf_command_output) +Schema: + + [ + { + "unit_file": string, + "state": string + } + ] + Compatibility: 'linux' @@ -43,30 +52,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - List of Dictionaries. Structured data with the following schema: - - [ - { - "unit_file": string, - "state": string - } - ] - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/time.md b/docs/parsers/time.md index eb58f8d7..680296d2 100644 --- a/docs/parsers/time.md +++ b/docs/parsers/time.md @@ -17,6 +17,48 @@ Usage (module): import jc.parsers.time result = jc.parsers.time.parse(time_command_output) +Schema: + + Source: https://www.freebsd.org/cgi/man.cgi?query=getrusage + https://man7.org/linux/man-pages/man1/time.1.html + + { + "real_time": float, + "user_time": float, + "system_time": float, + "elapsed_time": string, + "elapsed_time_hours": integer, + "elapsed_time_minutes": integer, + "elapsed_time_seconds": integer, + "elapsed_time_centiseconds": integer, + "elapsed_time_total_seconds": float, + "cpu_percent": integer, # null if ? + "average_shared_text_size": integer, + "average_unshared_data_size": integer, + "average_unshared_stack_size": integer, + "average_shared_memory_size": integer, + "maximum_resident_set_size": integer, + "block_input_operations": integer, # aka File system inputs + "block_output_operations": integer, # aka File system outputs + "major_pagefaults": integer, + "minor_pagefaults": integer, + "swaps": integer, + "page_reclaims": integer, + "page_faults": integer, + "messages_sent": integer, + "messages_received": integer, + "signals_received": integer, + "voluntary_context_switches": integer, + "involuntary_context_switches": integer + "command_being_timed": string, + "average_stack_size": integer, + "average_total_size": integer, + "average_resident_set_size": integer, + "signals_delivered": integer, + "page_size": integer, + "exit_status": integer + } + Compatibility: 'linux', 'darwin', 'cygwin', 'aix', 'freebsd' @@ -87,63 +129,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (List of Dictionaries) raw structured data to process - -Returns: - - Dictionary. Structured data with the following schema: - - Source: https://www.freebsd.org/cgi/man.cgi?query=getrusage - https://man7.org/linux/man-pages/man1/time.1.html - - { - "real_time": float, - "user_time": float, - "system_time": float, - "elapsed_time": string, - "elapsed_time_hours": integer, - "elapsed_time_minutes": integer, - "elapsed_time_seconds": integer, - "elapsed_time_centiseconds": integer, - "elapsed_time_total_seconds": float, - "cpu_percent": integer, # null if ? - "average_shared_text_size": integer, - "average_unshared_data_size": integer, - "average_unshared_stack_size": integer, - "average_shared_memory_size": integer, - "maximum_resident_set_size": integer, - "block_input_operations": integer, # aka File system inputs - "block_output_operations": integer, # aka File system outputs - "major_pagefaults": integer, - "minor_pagefaults": integer, - "swaps": integer, - "page_reclaims": integer, - "page_faults": integer, - "messages_sent": integer, - "messages_received": integer, - "signals_received": integer, - "voluntary_context_switches": integer, - "involuntary_context_switches": integer - "command_being_timed": string, - "average_stack_size": integer, - "average_total_size": integer, - "average_resident_set_size": integer, - "signals_delivered": integer, - "page_size": integer, - "exit_status": integer - } - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/timedatectl.md b/docs/parsers/timedatectl.md index 3b6583c4..85689b52 100644 --- a/docs/parsers/timedatectl.md +++ b/docs/parsers/timedatectl.md @@ -17,6 +17,22 @@ Usage (module): import jc.parsers.timedatectl result = jc.parsers.timedatectl.parse(timedatectl_command_output) +Schema: + + { + "local_time": string, + "universal_time": string, + "epoch_utc": integer, # timezone-aware timestamp + "rtc_time": string, + "time_zone": string, + "ntp_enabled": boolean, + "ntp_synchronized": boolean, + "system_clock_synchronized": boolean, + "systemd-timesyncd.service_active": boolean, + "rtc_in_local_tz": boolean, + "dst_active": boolean + } + Compatibility: 'linux' @@ -53,37 +69,7 @@ Examples: ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (Dictionary) raw structured data to process - -Returns: - - Dictionary. Structured data with the following schema: - - { - "local_time": string, - "universal_time": string, - "epoch_utc": integer, # timezone-aware timestamp - "rtc_time": string, - "time_zone": string, - "ntp_enabled": boolean, - "ntp_synchronized": boolean, - "system_clock_synchronized": boolean, - "systemd-timesyncd.service_active": boolean, - "rtc_in_local_tz": boolean, - "dst_active": boolean - } - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/tracepath.md b/docs/parsers/tracepath.md index 68ea3a1c..a8fa5659 100644 --- a/docs/parsers/tracepath.md +++ b/docs/parsers/tracepath.md @@ -17,6 +17,25 @@ Usage (module): import jc.parsers.tracepath result = jc.parsers.tracepath.parse(tracepath_command_output) +Schema: + + { + "pmtu": integer, + "forward_hops": integer, + "return_hops": integer, + "hops": [ + { + "ttl": integer, + "guess": boolean, + "host": string, + "reply_ms": float, + "pmtu": integer, + "asymmetric_difference": integer, + "reached": boolean + } + ] + } + Compatibility: 'linux' @@ -114,45 +133,11 @@ Examples: } - ## info ```python info() ``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (Dictionary) raw structured data to process - -Returns: - - Dictionary. Structured data with the following schema: - - { - "pmtu": integer, - "forward_hops": integer, - "return_hops": integer, - "hops": [ - { - "ttl": integer, - "guess": boolean, - "host": string, - "reply_ms": float, - "pmtu": integer, - "asymmetric_difference": integer, - "reached": boolean - } - ] - } - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/docs/parsers/traceroute.md b/docs/parsers/traceroute.md index 0b67eda0..b3e0356a 100644 --- a/docs/parsers/traceroute.md +++ b/docs/parsers/traceroute.md @@ -21,6 +21,27 @@ Usage (module): import jc.parsers.traceroute result = jc.parsers.traceroute.parse(traceroute_command_output) +Schema: + + { + "destination_ip": string, + "destination_name": string, + "hops": [ + { + "hop": integer, + "probes": [ + { + "annotation": string, + "asn": integer, + "ip": string, + "name": string, + "rtt": float + } + ] + } + ] + } + Compatibility: 'linux', 'darwin', 'freebsd' @@ -102,48 +123,7 @@ Examples: ```python info() ``` - - -## Hop -```python -Hop(idx) -``` - - -## process -```python -process(proc_data) -``` - -Final processing to conform to the schema. - -Parameters: - - proc_data: (Dictionary) raw structured data to process - -Returns: - - Dictionary. Structured data with the following schema: - - { - "destination_ip": string, - "destination_name": string, - "hops": [ - { - "hop": integer, - "probes": [ - { - "annotation": string, - "asn": integer, - "ip": string, - "name": string, - "rtt": float - } - ] - } - ] - } - +Provides parser metadata (version, author, etc.) ## parse ```python diff --git a/jc/parsers/jobs.py b/jc/parsers/jobs.py index e277f46e..48aedabd 100644 --- a/jc/parsers/jobs.py +++ b/jc/parsers/jobs.py @@ -15,6 +15,18 @@ Usage (module): import jc.parsers.jobs result = jc.parsers.jobs.parse(jobs_command_output) +Schema: + + [ + { + "job_number": integer, + "pid": integer, + "history": string, + "status": string, + "command": string + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'aix', 'freebsd' @@ -86,7 +98,8 @@ import jc.utils class info(): - version = '1.2' + """Provides parser metadata (version, author, etc.)""" + version = '1.3' description = '`jobs` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -99,7 +112,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -109,17 +122,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "job_number": integer, - "pid": integer, - "history": string, - "status": string, - "command": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: int_list = ['job_number', 'pid'] @@ -208,4 +211,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/kv.py b/jc/parsers/kv.py index a884cc09..d536d0d0 100644 --- a/jc/parsers/kv.py +++ b/jc/parsers/kv.py @@ -4,7 +4,6 @@ Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. M Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`. - Usage (cli): $ cat foo.txt | jc --kv @@ -14,6 +13,15 @@ Usage (module): import jc.parsers.kv result = jc.parsers.kv.parse(kv_file_output) +Schema: + + key/value document converted to a dictionary - see configparser standard library documentation for more details. + + { + "key1": string, + "key2": string + } + Compatibility: 'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd' @@ -42,7 +50,8 @@ Examples: class info(): - version = '1.0' + """Provides parser metadata (version, author, etc.)""" + version = '1.1' description = 'Key/Value file parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' diff --git a/jc/parsers/last.py b/jc/parsers/last.py index ff77ff11..dfb8349d 100644 --- a/jc/parsers/last.py +++ b/jc/parsers/last.py @@ -17,6 +17,22 @@ Usage (module): import jc.parsers.last result = jc.parsers.last.parse(last_command_output) +Schema: + + [ + { + "user": string, + "tty": string, + "hostname": string, + "login": string, + "logout": string, + "duration": string, + "login_epoch": integer, # (naive) available with last -F option + "logout_epoch": integer, # (naive) available with last -F option + "duration_seconds": integer # available with last -F option + } + ] + Compatibility: 'linux', 'darwin', 'aix', 'freebsd' @@ -91,7 +107,8 @@ import jc.utils class info(): - version = '1.5' + """Provides parser metadata (version, author, etc.)""" + version = '1.6' description = '`last` and `lastb` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -105,7 +122,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -115,21 +132,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "user": string, - "tty": string, - "hostname": string, - "login": string, - "logout": string, - "duration": string, - "login_epoch": integer, # (naive) available with last -F option - "logout_epoch": integer, # (naive) available with last -F option - "duration_seconds": integer # available with last -F option - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: if 'user' in entry and entry['user'] == 'boot_time': @@ -253,4 +256,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index 425a7361..e5d8b979 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -24,6 +24,23 @@ Usage (module): import jc.parsers.ls result = jc.parsers.ls.parse(ls_command_output) +Schema: + + [ + { + "filename": string, + "flags": string, + "links": integer, + "parent": string, + "owner": string, + "group": string, + "size": integer, + "date": string, + "epoch": integer, # naive timestamp if date field exists and can be converted + "epoch_utc": integer # timezone aware timestamp if date field is in UTC and can be converted + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'aix', 'freebsd' @@ -157,7 +174,8 @@ import jc.utils class info(): - version = '1.7' + """Provides parser metadata (version, author, etc.)""" + version = '1.8' description = '`ls` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -170,7 +188,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -180,22 +198,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "filename": string, - "flags": string, - "links": integer, - "parent": string, - "owner": string, - "group": string, - "size": integer, - "date": string, - "epoch": integer, # naive timestamp if date field exists and can be converted - "epoch_utc": integer # timezone aware timestamp if date field is in UTC and can be converted - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: int_list = ['links', 'size'] @@ -337,4 +340,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/lsblk.py b/jc/parsers/lsblk.py index 1bebb1f0..ae96d527 100644 --- a/jc/parsers/lsblk.py +++ b/jc/parsers/lsblk.py @@ -13,6 +13,53 @@ Usage (module): import jc.parsers.lsblk result = jc.parsers.lsblk.parse(lsblk_command_output) +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 + } + ] + Compatibility: 'linux' @@ -225,7 +272,8 @@ import jc.parsers.universal class info(): - version = '1.5' + """Provides parser metadata (version, author, etc.)""" + version = '1.6' description = '`lsblk` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -238,7 +286,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -248,52 +296,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following 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 - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: # boolean changes @@ -357,4 +360,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/lsmod.py b/jc/parsers/lsmod.py index 5669971d..c7f1c4a3 100644 --- a/jc/parsers/lsmod.py +++ b/jc/parsers/lsmod.py @@ -13,6 +13,19 @@ Usage (module): import jc.parsers.lsmod result = jc.parsers.lsmod.parse(lsmod_command_output) +Schema: + + [ + { + "module": string, + "size": integer, + "used": integer, + "by": [ + string + ] + } + ] + Compatibility: 'linux' @@ -116,7 +129,8 @@ import jc.parsers.universal class info(): - version = '1.3' + """Provides parser metadata (version, author, etc.)""" + version = '1.4' description = '`lsmod` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -129,7 +143,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -139,18 +153,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "module": string, - "size": integer, - "used": integer, - "by": [ - string - ] - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: # integer changes @@ -199,4 +202,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/lsof.py b/jc/parsers/lsof.py index f360a47c..3157dfb8 100644 --- a/jc/parsers/lsof.py +++ b/jc/parsers/lsof.py @@ -13,6 +13,23 @@ Usage (module): import jc.parsers.lsof result = jc.parsers.lsof.parse(lsof_command_output) +Schema: + + [ + { + "command": string, + "pid": integer, + "tid": integer, + "user": string, + "fd": string, + "type": string, + "device": string, + "size_off": integer, + "node": integer, + "name": string + } + ] + Compatibility: 'linux' @@ -106,7 +123,8 @@ import jc.parsers.universal class info(): - version = '1.2' + """Provides parser metadata (version, author, etc.)""" + version = '1.3' description = '`lsof` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -119,7 +137,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -129,22 +147,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "command": string, - "pid": integer, - "tid": integer, - "user": string, - "fd": string, - "type": string, - "device": string, - "size_off": integer, - "node": integer, - "name": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: # integer changes @@ -191,4 +194,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/mount.py b/jc/parsers/mount.py index ee11f075..cc5710e8 100644 --- a/jc/parsers/mount.py +++ b/jc/parsers/mount.py @@ -13,6 +13,19 @@ Usage (module): import jc.parsers.mount result = jc.parsers.mount.parse(mount_command_output) +Schema: + + [ + { + "filesystem": string, + "mount_point": string, + "type": string, + "access": [ + string + ] + } + ] + Compatibility: 'linux', 'darwin', 'freebsd' @@ -65,7 +78,8 @@ import jc.utils class info(): - version = '1.5' + """Provides parser metadata (version, author, etc.)""" + version = '1.6' description = '`mount` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -78,7 +92,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -88,24 +102,13 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "filesystem": string, - "mount_point": string, - "type": string, - "access": [ - string - ] - } - ] + List of Dictionaries. Structured data to conform to the schema. """ # nothing to process return proc_data -def osx_parse(data): +def _osx_parse(data): output = [] for entry in data: @@ -130,7 +133,7 @@ def osx_parse(data): return output -def linux_parse(data): +def _linux_parse(data): output = [] for entry in data: @@ -175,12 +178,12 @@ def parse(data, raw=False, quiet=False): # check for OSX output if ' type ' not in cleandata[0]: - raw_output = osx_parse(cleandata) + raw_output = _osx_parse(cleandata) else: - raw_output = linux_parse(cleandata) + raw_output = _linux_parse(cleandata) if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/netstat.py b/jc/parsers/netstat.py index 51d2ed25..393f1d73 100644 --- a/jc/parsers/netstat.py +++ b/jc/parsers/netstat.py @@ -17,6 +17,107 @@ Usage (module): import jc.parsers.netstat result = jc.parsers.netstat.parse(netstat_command_output) +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, + "address": string, + "unix_inode": string, + "conn": string, + "refs": string, + "nextref": string, + "name": string, + "unit": integer, + "vendor": integer, + "class": integer, + "subcla": integer, + "unix_flags": integer, + "pcbcount": integer, + "rcvbuf": integer, + "sndbuf": integer, + "rxbytes": integer, + "txbytes": integer, + "destination": string, + "gateway": string, + "route_flags": string, + "route_flags_pretty": [ + string, + ] + "route_refs": integer, + "use": integer, + "mtu": integer, + "expire": string, + "genmask": string, + "mss": integer, + "window": integer, + "irtt": integer, + "iface": string, + "metric": integer, + "network": string, + "address": string, + "ipkts": integer, # - = null + "ierrs": integer, # - = null + "idrop": integer, # - = null + "opkts": integer, # - = null + "oerrs": integer, # - = null + "coll": integer, # - = null + "rx_ok": integer, + "rx_err": integer, + "rx_drp": integer, + "rx_ovr": integer, + "tx_ok": integer, + "tx_err": integer, + "tx_drp": integer, + "tx_ovr": integer, + "flg": string, + "ibytes": integer, + "obytes": integer, + "r_mbuf": integer, + "s_mbuf": integer, + "r_clus": integer, + "s_clus": integer, + "r_hiwa": integer, + "s_hiwa": integer, + "r_lowa": integer, + "s_lowa": integer, + "r_bcnt": integer, + "s_bcnt": integer, + "r_bmax": integer, + "s_bmax": integer, + "rexmit": integer, + "ooorcv": integer, + "0_win": integer, + "rexmt": float, + "persist": float, + "keep": float, + "2msl": float, + "delack": float, + "rcvtime": float, + } + ] + Compatibility: 'linux', 'darwin', 'freebsd' @@ -255,7 +356,8 @@ Examples: class info(): - version = '1.8' + """Provides parser metadata (version, author, etc.)""" + version = '1.9' description = '`netstat` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -268,7 +370,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -278,106 +380,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following 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, - "address": string, - "unix_inode": string, - "conn": string, - "refs": string, - "nextref": string, - "name": string, - "unit": integer, - "vendor": integer, - "class": integer, - "subcla": integer, - "unix_flags": integer, - "pcbcount": integer, - "rcvbuf": integer, - "sndbuf": integer, - "rxbytes": integer, - "txbytes": integer, - "destination": string, - "gateway": string, - "route_flags": string, - "route_flags_pretty": [ - string, - ] - "route_refs": integer, - "use": integer, - "mtu": integer, - "expire": string, - "genmask": string, - "mss": integer, - "window": integer, - "irtt": integer, - "iface": string, - "metric": integer, - "network": string, - "address": string, - "ipkts": integer, - = null - "ierrs": integer, - = null - "idrop": integer, - = null - "opkts": integer, - = null - "oerrs": integer, - = null - "coll": integer, - = null - "rx_ok": integer, - "rx_err": integer, - "rx_drp": integer, - "rx_ovr": integer, - "tx_ok": integer, - "tx_err": integer, - "tx_drp": integer, - "tx_ovr": integer, - "flg": string, - "ibytes": integer, - "obytes": integer, - "r_mbuf": integer, - "s_mbuf": integer, - "r_clus": integer, - "s_clus": integer, - "r_hiwa": integer, - "s_hiwa": integer, - "r_lowa": integer, - "s_lowa": integer, - "r_bcnt": integer, - "s_bcnt": integer, - "r_bmax": integer, - "s_bmax": integer, - "rexmit": integer, - "ooorcv": integer, - "0_win": integer, - "rexmt": float, - "persist": float, - "keep": float, - "2msl": float, - "delack": float, - "rcvtime": float, - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: # integer changes @@ -467,4 +470,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/ntpq.py b/jc/parsers/ntpq.py index 50091c20..ff086c34 100644 --- a/jc/parsers/ntpq.py +++ b/jc/parsers/ntpq.py @@ -13,6 +13,24 @@ Usage (module): import jc.parsers.ntpq result = jc.parsers.ntpq.parse(ntpq_command_output) +Schema: + + [ + { + "state": string, # space/~ converted to null + "remote": string, + "refid": string, + "st": integer, + "t": string, + "when": integer, # - converted to null + "poll": integer, + "reach": integer, + "delay": float, + "offset": float, + "jitter": float + }, + ] + Compatibility: 'linux', 'freebsd' @@ -192,7 +210,8 @@ import jc.parsers.universal class info(): - version = '1.3' + """Provides parser metadata (version, author, etc.)""" + version = '1.4' description = '`ntpq -p` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -205,7 +224,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -215,24 +234,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "state": string, # space/~ converted to null - "remote": string, - "refid": string, - "st": integer, - "t": string, - "when": integer, # - converted to null - "poll": integer, - "reach": integer, - "delay": float, - "offset": float, - "jitter": float - }, - ] - + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: @@ -305,4 +307,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/passwd.py b/jc/parsers/passwd.py index 9ebe3130..7742e5e1 100644 --- a/jc/parsers/passwd.py +++ b/jc/parsers/passwd.py @@ -9,6 +9,20 @@ Usage (module): import jc.parsers.passwd result = jc.parsers.passwd.parse(passwd_file_output) +Schema: + + [ + { + "username": string, + "password": string, + "uid": integer, + "gid": integer, + "comment": string, + "home": string, + "shell": string + } + ] + Compatibility: 'linux', 'darwin', 'aix', 'freebsd' @@ -83,7 +97,8 @@ import jc.utils class info(): - version = '1.1' + """Provides parser metadata (version, author, etc.)""" + version = '1.2' description = '`/etc/passwd` file parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -96,7 +111,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -106,19 +121,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "username": string, - "password": string, - "uid": integer, - "gid": integer, - "comment": string, - "home": string, - "shell": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: int_list = ['uid', 'gid'] @@ -177,4 +180,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/ping.py b/jc/parsers/ping.py index ce8fd0a3..1d31396b 100644 --- a/jc/parsers/ping.py +++ b/jc/parsers/ping.py @@ -17,6 +17,36 @@ Usage (module): import jc.parsers.ping result = jc.parsers.ping.parse(ping_command_output) +Schema: + + { + "source_ip": string, + "destination_ip": string, + "data_bytes": integer, + "pattern": string, # (null if not set) + "destination": string, + "packets_transmitted": integer, + "packets_received": integer, + "packet_loss_percent": float, + "duplicates": integer, + "round_trip_ms_min": float, + "round_trip_ms_avg": float, + "round_trip_ms_max": float, + "round_trip_ms_stddev": float, + "responses": [ + { + "type": string, # ('reply' or 'timeout') + "timestamp": float, + "bytes": integer, + "response_ip": string, + "icmp_seq": integer, + "ttl": integer, + "time_ms": float, + "duplicate": boolean + } + ] + } + Compatibility: 'linux', 'darwin', 'freebsd' @@ -119,7 +149,8 @@ import jc.utils class info(): - version = '1.2' + """Provides parser metadata (version, author, etc.)""" + version = '1.3' description = '`ping` and `ping6` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -132,7 +163,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -142,35 +173,7 @@ def process(proc_data): Returns: - Dictionary. Structured data with the following schema: - - { - "source_ip": string, - "destination_ip": string, - "data_bytes": integer, - "pattern": string, (null if not set) - "destination": string, - "packets_transmitted": integer, - "packets_received": integer, - "packet_loss_percent": float, - "duplicates": integer, - "round_trip_ms_min": float, - "round_trip_ms_avg": float, - "round_trip_ms_max": float, - "round_trip_ms_stddev": float, - "responses": [ - { - "type": string, ('reply' or 'timeout') - "timestamp": float, - "bytes": integer, - "response_ip": string, - "icmp_seq": integer, - "ttl": integer, - "time_ms": float, - "duplicate": boolean - } - ] - } + Dictionary. Structured data to conform to the schema. """ int_list = ['data_bytes', 'packets_transmitted', 'packets_received', 'bytes', 'icmp_seq', 'ttl', 'duplicates'] float_list = ['packet_loss_percent', 'round_trip_ms_min', 'round_trip_ms_avg', 'round_trip_ms_max', @@ -208,7 +211,7 @@ def process(proc_data): return proc_data -def linux_parse(data): +def _linux_parse(data): raw_output = {} ping_responses = [] pattern = None @@ -357,7 +360,7 @@ def linux_parse(data): return raw_output -def bsd_parse(data): +def _bsd_parse(data): raw_output = {} ping_responses = [] pattern = None @@ -508,11 +511,11 @@ def parse(data, raw=False, quiet=False): if jc.utils.has_data(data): if ' time ' in data.splitlines()[-2] or ' time ' in data.splitlines()[-3]: - raw_output = linux_parse(data) + raw_output = _linux_parse(data) else: - raw_output = bsd_parse(data) + raw_output = _bsd_parse(data) if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/pip_list.py b/jc/parsers/pip_list.py index 273f4aee..e0f0492a 100644 --- a/jc/parsers/pip_list.py +++ b/jc/parsers/pip_list.py @@ -13,6 +13,16 @@ Usage (module): import jc.parsers.pip_list result = jc.parsers.pip_list.parse(pip_list_command_output) +Schema: + + [ + { + "package": string, + "version": string, + "location": string + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd' @@ -41,7 +51,8 @@ import jc.parsers.universal class info(): - version = '1.3' + """Provides parser metadata (version, author, etc.)""" + version = '1.4' description = '`pip list` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -54,7 +65,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -64,15 +75,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "package": string, - "version": string, - "location": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ # no further processing return proc_data @@ -123,4 +126,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/pip_show.py b/jc/parsers/pip_show.py index 8e0949cc..7a547d61 100644 --- a/jc/parsers/pip_show.py +++ b/jc/parsers/pip_show.py @@ -13,6 +13,23 @@ Usage (module): import jc.parsers.pip_show result = jc.parsers.pip_show.parse(pip_show_command_output) +Schema: + + [ + { + "name": string, + "version": string, + "summary": string, + "home_page": string, + "author": string, + "author_email": string, + "license": string, + "location": string, + "requires": string, + "required_by": string + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd' @@ -51,7 +68,8 @@ import jc.utils class info(): - version = '1.1' + """Provides parser metadata (version, author, etc.)""" + version = '1.2' description = '`pip show` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -64,7 +82,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -74,23 +92,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "name": string, - "version": string, - "summary": string, - "home_page": string, - "author": string, - "author_email": string, - "license": string, - "location": string, - "requires": string, - "required_by": string - } - ] - + List of Dictionaries. Structured data to conform to the schema. """ # no further processing return proc_data @@ -140,4 +142,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/ps.py b/jc/parsers/ps.py index b6cb82fd..fab06d21 100644 --- a/jc/parsers/ps.py +++ b/jc/parsers/ps.py @@ -17,6 +17,30 @@ Usage (module): import jc.parsers.ps result = jc.parsers.ps.parse(ps_command_output) +Schema: + + [ + { + "uid": string, + "pid": integer, + "ppid": integer, + "c": integer, + "stime": string, + "tty": string, # ? or ?? = Null + "tt": string, # ?? = Null + "time": string, + "cmd": string, + "user": string, + "cpu_percent": float, + "mem_percent": float, + "vsz": integer, + "rss": integer, + "stat": string, + "start": string, + "command": string + } + ] + Compatibility: 'linux', 'darwin', 'cygwin', 'aix', 'freebsd' @@ -186,7 +210,8 @@ import jc.parsers.universal class info(): - version = '1.3' + """Provides parser metadata (version, author, etc.)""" + version = '1.4' description = '`ps` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -199,7 +224,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -209,29 +234,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "uid": string, - "pid": integer, - "ppid": integer, - "c": integer, - "stime": string, - "tty": string, # ? or ?? = Null - "tt": string, # ?? = Null - "time": string, - "cmd": string, - "user": string, - "cpu_percent": float, - "mem_percent": float, - "vsz": integer, - "rss": integer, - "stat": string, - "start": string, - "command": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: # change key name '%cpu' to 'cpu_percent' @@ -301,4 +304,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/route.py b/jc/parsers/route.py index 5cf59bb5..057134c7 100644 --- a/jc/parsers/route.py +++ b/jc/parsers/route.py @@ -13,6 +13,27 @@ Usage (module): import jc.parsers.route result = jc.parsers.route.parse(route_command_output) +Schema: + + [ + { + "destination": string, + "gateway": string, + "genmask": string, + "flags": string, + "flags_pretty": [ + string, + ] + "metric": integer, + "ref": integer, + "use": integer, + "mss": integer, + "window": integer, + "irtt": integer, + "iface": string + } + ] + Compatibility: 'linux' @@ -93,7 +114,8 @@ import jc.parsers.universal class info(): - version = '1.4' + """Provides parser metadata (version, author, etc.)""" + version = '1.5' description = '`route` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -106,7 +128,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -116,26 +138,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "destination": string, - "gateway": string, - "genmask": string, - "flags": string, - "flags_pretty": [ - string, - ] - "metric": integer, - "ref": integer, - "use": integer, - "mss": integer, - "window": integer, - "irtt": integer, - "iface": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: int_list = ['metric', 'ref', 'use', 'mss', 'window', 'irtt'] @@ -207,4 +210,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/rpm_qi.py b/jc/parsers/rpm_qi.py index 12901562..695d5e1d 100644 --- a/jc/parsers/rpm_qi.py +++ b/jc/parsers/rpm_qi.py @@ -19,6 +19,34 @@ Usage (module): import jc.parsers.rpm_qi result = jc.parsers.rpm_qi.parse(rpm_qi_command_output) +Schema: + + [ + { + "name": string, + "epoch": integer, + "version": string, + "release": string, + "architecture": string, + "install_date": string, + "group": string, + "size": integer, + "license": string, + "signature": string, + "source_rpm": string, + "build_date": string, + "build_epoch": integer, # naive timestamp + "build_epoch_utc": integer, # Aware timestamp if timezone is UTC + "build_host": string, + "relocations": string, + "packager": string, + "vendor": string, + "url": string, + "summary": string, + "description": string + } + ] + Compatibility: 'linux' @@ -125,7 +153,8 @@ import jc.utils class info(): - version = '1.0' + """Provides parser metadata (version, author, etc.)""" + version = '1.1' description = '`rpm -qi` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -139,7 +168,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -149,33 +178,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "name": string, - "epoch": integer, - "version": string, - "release": string, - "architecture": string, - "install_date": string, - "group": string, - "size": integer, - "license": string, - "signature": string, - "source_rpm": string, - "build_date": string, - "build_epoch": integer, # naive timestamp - "build_epoch_utc": integer, # Aware timestamp if timezone is UTC - "build_host": string, - "relocations": string, - "packager": string, - "vendor": string, - "url": string, - "summary": string, - "description": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: @@ -255,4 +258,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/shadow.py b/jc/parsers/shadow.py index 06a69276..ea7b4fe3 100644 --- a/jc/parsers/shadow.py +++ b/jc/parsers/shadow.py @@ -9,6 +9,21 @@ Usage (module): import jc.parsers.shadow result = jc.parsers.shadow.parse(shadow_file_output) +Schema: + + [ + { + "username": string, + "password": string, + "last_changed": integer, + "minimum": integer, + "maximum": integer, + "warn": integer, + "inactive": integer, + "expire": integer + } + ] + Compatibility: 'linux', 'darwin', 'aix', 'freebsd' @@ -89,7 +104,8 @@ import jc.utils class info(): - version = '1.1' + """Provides parser metadata (version, author, etc.)""" + version = '1.2' description = '`/etc/shadow` file parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -102,7 +118,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -112,20 +128,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "username": string, - "password": string, - "last_changed": integer, - "minimum": integer, - "maximum": integer, - "warn": integer, - "inactive": integer, - "expire": integer - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: int_list = ['last_changed', 'minimum', 'maximum', 'warn', 'inactive', 'expire'] @@ -185,4 +188,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/ss.py b/jc/parsers/ss.py index a4eece7f..2014f19c 100644 --- a/jc/parsers/ss.py +++ b/jc/parsers/ss.py @@ -1,5 +1,7 @@ """jc - JSON CLI output utility `ss` command output parser +Extended information options like -e and -p are not supported and may cause parsing irregularities. + Usage (cli): $ ss | jc --ss @@ -13,9 +15,29 @@ Usage (module): import jc.parsers.ss result = jc.parsers.ss.parse(ss_command_output) -Limitations: +Schema: - Extended information options like -e and -p are not supported and may cause parsing irregularities + Information from https://www.cyberciti.biz/files/ss.html used to define field names + + [ + { + "netid": string, + "state": string, + "recv_q": integer, + "send_q": integer, + "local_address": string, + "local_port": string, + "local_port_num": integer, + "peer_address": string, + "peer_port": string, + "peer_port_num": integer, + "interface": string, + "link_layer" string, + "channel": string, + "path": string, + "pid": integer + } + ] Compatibility: @@ -260,7 +282,8 @@ import jc.utils class info(): - version = '1.2' + """Provides parser metadata (version, author, etc.)""" + version = '1.3' description = '`ss` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -273,7 +296,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -283,29 +306,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "netid": string, - "state": string, - "recv_q": integer, - "send_q": integer, - "local_address": string, - "local_port": string, - "local_port_num": integer, - "peer_address": string, - "peer_port": string, - "peer_port_num": integer, - "interface": string, - "link_layer" string, - "channel": string, - "path": string, - "pid": integer - } - ] - - Information from https://www.cyberciti.biz/files/ss.html used to define field names + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: int_list = ['recv_q', 'send_q', 'pid'] @@ -419,4 +420,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/stat.py b/jc/parsers/stat.py index df2f684c..b877b0ee 100644 --- a/jc/parsers/stat.py +++ b/jc/parsers/stat.py @@ -17,6 +17,44 @@ Usage (module): import jc.parsers.stat result = jc.parsers.stat.parse(stat_command_output) +Schema: + + [ + { + "file": string, + "link_to" string, + "size": integer, + "blocks": integer, + "io_blocks": integer, + "type": string, + "device": string, + "inode": integer, + "links": integer, + "access": string, + "flags": string, + "uid": integer, + "user": string, + "gid": integer, + "group": string, + "access_time": string, # - = null + "access_time_epoch": integer, # naive timestamp + "access_time_epoch_utc": integer, # timezone-aware timestamp + "modify_time": string, # - = null + "modify_time_epoch": integer, # naive timestamp + "modify_time_epoch_utc": integer, # timezone-aware timestamp + "change_time": string, # - = null + "change_time_epoch": integer, # naive timestamp + "change_time_epoch_utc": integer, # timezone-aware timestamp + "birth_time": string, # - = null + "birth_time_epoch": integer, # naive timestamp + "birth_time_epoch_utc": integer, # timezone-aware timestamp + "unix_device": integer, + "rdev": integer, + "block_size": integer, + "unix_flags": string + } + ] + Compatibility: 'linux', 'darwin', 'freebsd' @@ -134,7 +172,8 @@ import jc.utils class info(): - version = '1.6' + """Provides parser metadata (version, author, etc.)""" + version = '1.7' description = '`stat` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -147,7 +186,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -157,43 +196,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "file": string, - "link_to" string, - "size": integer, - "blocks": integer, - "io_blocks": integer, - "type": string, - "device": string, - "inode": integer, - "links": integer, - "access": string, - "flags": string, - "uid": integer, - "user": string, - "gid": integer, - "group": string, - "access_time": string, # - = null - "access_time_epoch": integer, # naive timestamp - "access_time_epoch_utc": integer, # timezone-aware timestamp - "modify_time": string, # - = null - "modify_time_epoch": integer, # naive timestamp - "modify_time_epoch_utc": integer, # timezone-aware timestamp - "change_time": string, # - = null - "change_time_epoch": integer, # naive timestamp - "change_time_epoch_utc": integer, # timezone-aware timestamp - "birth_time": string, # - = null - "birth_time_epoch": integer, # naive timestamp - "birth_time_epoch_utc": integer, # timezone-aware timestamp - "unix_device": integer, - "rdev": integer, - "block_size": integer, - "unix_flags": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: int_list = ['size', 'blocks', 'io_blocks', 'inode', 'links', 'uid', 'gid', 'unix_device', 'rdev', 'block_size'] @@ -349,4 +352,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/sysctl.py b/jc/parsers/sysctl.py index 7095b42e..daeac720 100644 --- a/jc/parsers/sysctl.py +++ b/jc/parsers/sysctl.py @@ -15,6 +15,14 @@ Usage (module): import jc.parsers.sysctl result = jc.parsers.sysctl.parse(sysctl_command_output) +Schema: + + { + "key1": string/integer/float, # best guess based on value + "key2": string/integer/float, + "key3": string/integer/float + } + Compatibility: 'linux', 'darwin', 'freebsd' @@ -49,7 +57,8 @@ import jc.utils class info(): - version = '1.0' + """Provides parser metadata (version, author, etc.)""" + version = '1.1' description = '`sysctl` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -63,7 +72,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -73,13 +82,7 @@ def process(proc_data): Returns: - Dictionary. Structured data with the following schema: - - { - "foo": string/integer/float, # best guess based on value - "bar": string/integer/float, - "baz": string/integer/float - } + Dictionary. Structured data to conform to the schema. """ for key in proc_data: try: @@ -158,4 +161,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/systemctl.py b/jc/parsers/systemctl.py index c91b34d1..5718f3ca 100644 --- a/jc/parsers/systemctl.py +++ b/jc/parsers/systemctl.py @@ -13,6 +13,18 @@ Usage (module): import jc.parsers.systemctl result = jc.parsers.systemctl.parse(systemctl_command_output) +Schema: + + [ + { + "unit": string, + "load": string, + "active": string, + "sub": string, + "description": string + } + ] + Compatibility: 'linux' @@ -49,7 +61,8 @@ import jc.utils class info(): - version = '1.3' + """Provides parser metadata (version, author, etc.)""" + version = '1.4' description = '`systemctl` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -62,7 +75,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -72,17 +85,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "unit": string, - "load": string, - "active": string, - "sub": string, - "description": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ # nothing more to process return proc_data @@ -133,4 +136,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/systemctl_lj.py b/jc/parsers/systemctl_lj.py index 4e3d9da0..b8480b04 100644 --- a/jc/parsers/systemctl_lj.py +++ b/jc/parsers/systemctl_lj.py @@ -13,6 +13,17 @@ Usage (module): import jc.parsers.systemctl_lj result = jc.parsers.systemctl_lj.parse(systemctl_lj_command_output) +Schema: + + [ + { + "job": integer, + "unit": string, + "type": string, + "state": string + } + ] + Compatibility: 'linux' @@ -62,13 +73,13 @@ Examples: "state": "waiting" } ] - """ import jc.utils class info(): - version = '1.3' + """Provides parser metadata (version, author, etc.)""" + version = '1.4' description = '`systemctl list-jobs` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -81,7 +92,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -91,16 +102,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "job": integer, - "unit": string, - "type": string, - "state": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ for entry in proc_data: int_list = ['job'] @@ -161,4 +163,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/systemctl_ls.py b/jc/parsers/systemctl_ls.py index 74fe5a28..c437f8c7 100644 --- a/jc/parsers/systemctl_ls.py +++ b/jc/parsers/systemctl_ls.py @@ -13,6 +13,16 @@ Usage (module): import jc.parsers.systemctl_ls result = jc.parsers.systemctl_ls.parse(systemctl_ls_command_output) +Schema: + + [ + { + "listen": string, + "unit": string, + "activates": string + } + ] + Compatibility: 'linux' @@ -43,7 +53,8 @@ import jc.utils class info(): - version = '1.3' + """Provides parser metadata (version, author, etc.)""" + version = '1.4' description = '`systemctl list-sockets` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -56,7 +67,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -66,15 +77,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "listen": string, - "unit": string, - "activates": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ # nothing more to process return proc_data @@ -125,4 +128,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/systemctl_luf.py b/jc/parsers/systemctl_luf.py index cb671f96..8fafefbc 100644 --- a/jc/parsers/systemctl_luf.py +++ b/jc/parsers/systemctl_luf.py @@ -13,6 +13,15 @@ Usage (module): import jc.parsers.systemctl_luf result = jc.parsers.systemctl_luf.parse(systemctl_luf_command_output) +Schema: + + [ + { + "unit_file": string, + "state": string + } + ] + Compatibility: 'linux' @@ -40,7 +49,8 @@ import jc.utils class info(): - version = '1.3' + """Provides parser metadata (version, author, etc.)""" + version = '1.4' description = '`systemctl list-unit-files` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -53,7 +63,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -63,14 +73,7 @@ def process(proc_data): Returns: - List of Dictionaries. Structured data with the following schema: - - [ - { - "unit_file": string, - "state": string - } - ] + List of Dictionaries. Structured data to conform to the schema. """ # nothing more to process return proc_data @@ -122,4 +125,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/time.py b/jc/parsers/time.py index 6d88378f..b43b7bc2 100644 --- a/jc/parsers/time.py +++ b/jc/parsers/time.py @@ -15,6 +15,48 @@ Usage (module): import jc.parsers.time result = jc.parsers.time.parse(time_command_output) +Schema: + + Source: https://www.freebsd.org/cgi/man.cgi?query=getrusage + https://man7.org/linux/man-pages/man1/time.1.html + + { + "real_time": float, + "user_time": float, + "system_time": float, + "elapsed_time": string, + "elapsed_time_hours": integer, + "elapsed_time_minutes": integer, + "elapsed_time_seconds": integer, + "elapsed_time_centiseconds": integer, + "elapsed_time_total_seconds": float, + "cpu_percent": integer, # null if ? + "average_shared_text_size": integer, + "average_unshared_data_size": integer, + "average_unshared_stack_size": integer, + "average_shared_memory_size": integer, + "maximum_resident_set_size": integer, + "block_input_operations": integer, # aka File system inputs + "block_output_operations": integer, # aka File system outputs + "major_pagefaults": integer, + "minor_pagefaults": integer, + "swaps": integer, + "page_reclaims": integer, + "page_faults": integer, + "messages_sent": integer, + "messages_received": integer, + "signals_received": integer, + "voluntary_context_switches": integer, + "involuntary_context_switches": integer + "command_being_timed": string, + "average_stack_size": integer, + "average_total_size": integer, + "average_resident_set_size": integer, + "signals_delivered": integer, + "page_size": integer, + "exit_status": integer + } + Compatibility: 'linux', 'darwin', 'cygwin', 'aix', 'freebsd' @@ -84,7 +126,8 @@ import jc.utils class info(): - version = '1.0' + """Provides parser metadata (version, author, etc.)""" + version = '1.1' description = '`/usr/bin/time` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -97,7 +140,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -107,47 +150,7 @@ def process(proc_data): Returns: - Dictionary. Structured data with the following schema: - - Source: https://www.freebsd.org/cgi/man.cgi?query=getrusage - https://man7.org/linux/man-pages/man1/time.1.html - - { - "real_time": float, - "user_time": float, - "system_time": float, - "elapsed_time": string, - "elapsed_time_hours": integer, - "elapsed_time_minutes": integer, - "elapsed_time_seconds": integer, - "elapsed_time_centiseconds": integer, - "elapsed_time_total_seconds": float, - "cpu_percent": integer, # null if ? - "average_shared_text_size": integer, - "average_unshared_data_size": integer, - "average_unshared_stack_size": integer, - "average_shared_memory_size": integer, - "maximum_resident_set_size": integer, - "block_input_operations": integer, # aka File system inputs - "block_output_operations": integer, # aka File system outputs - "major_pagefaults": integer, - "minor_pagefaults": integer, - "swaps": integer, - "page_reclaims": integer, - "page_faults": integer, - "messages_sent": integer, - "messages_received": integer, - "signals_received": integer, - "voluntary_context_switches": integer, - "involuntary_context_switches": integer - "command_being_timed": string, - "average_stack_size": integer, - "average_total_size": integer, - "average_resident_set_size": integer, - "signals_delivered": integer, - "page_size": integer, - "exit_status": integer - } + Dictionary. Structured data to conform to the schema. """ if 'command_being_timed' in proc_data: proc_data['command_being_timed'] = proc_data['command_being_timed'][1:-1] @@ -330,4 +333,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/timedatectl.py b/jc/parsers/timedatectl.py index c7574a54..24620bc0 100644 --- a/jc/parsers/timedatectl.py +++ b/jc/parsers/timedatectl.py @@ -15,6 +15,22 @@ Usage (module): import jc.parsers.timedatectl result = jc.parsers.timedatectl.parse(timedatectl_command_output) +Schema: + + { + "local_time": string, + "universal_time": string, + "epoch_utc": integer, # timezone-aware timestamp + "rtc_time": string, + "time_zone": string, + "ntp_enabled": boolean, + "ntp_synchronized": boolean, + "system_clock_synchronized": boolean, + "systemd-timesyncd.service_active": boolean, + "rtc_in_local_tz": boolean, + "dst_active": boolean + } + Compatibility: 'linux' @@ -50,7 +66,8 @@ import jc.utils class info(): - version = '1.2' + """Provides parser metadata (version, author, etc.)""" + version = '1.3' description = '`timedatectl status` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -64,7 +81,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -74,21 +91,7 @@ def process(proc_data): Returns: - Dictionary. Structured data with the following schema: - - { - "local_time": string, - "universal_time": string, - "epoch_utc": integer, # timezone-aware timestamp - "rtc_time": string, - "time_zone": string, - "ntp_enabled": boolean, - "ntp_synchronized": boolean, - "system_clock_synchronized": boolean, - "systemd-timesyncd.service_active": boolean, - "rtc_in_local_tz": boolean, - "dst_active": boolean - } + Dictionary. Structured data to conform to the schema. """ # boolean changes bool_list = ['ntp_enabled', 'ntp_synchronized', 'rtc_in_local_tz', 'dst_active', @@ -138,4 +141,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/tracepath.py b/jc/parsers/tracepath.py index 4353ad52..94e7a066 100644 --- a/jc/parsers/tracepath.py +++ b/jc/parsers/tracepath.py @@ -15,6 +15,25 @@ Usage (module): import jc.parsers.tracepath result = jc.parsers.tracepath.parse(tracepath_command_output) +Schema: + + { + "pmtu": integer, + "forward_hops": integer, + "return_hops": integer, + "hops": [ + { + "ttl": integer, + "guess": boolean, + "host": string, + "reply_ms": float, + "pmtu": integer, + "asymmetric_difference": integer, + "reached": boolean + } + ] + } + Compatibility: 'linux' @@ -110,14 +129,14 @@ Examples: } ] } - """ import re import jc.utils class info(): - version = '1.0' + """Provides parser metadata (version, author, etc.)""" + version = '1.1' description = '`tracepath` and `tracepath6` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -130,7 +149,7 @@ class info(): __version__ = info.version -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -140,24 +159,7 @@ def process(proc_data): Returns: - Dictionary. Structured data with the following schema: - - { - "pmtu": integer, - "forward_hops": integer, - "return_hops": integer, - "hops": [ - { - "ttl": integer, - "guess": boolean, - "host": string, - "reply_ms": float, - "pmtu": integer, - "asymmetric_difference": integer, - "reached": boolean - } - ] - } + Dictionary. Structured data to conform to the schema. """ int_list = ['pmtu', 'forward_hops', 'return_hops', 'ttl', 'asymmetric_difference'] float_list = ['reply_ms'] @@ -259,4 +261,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output) diff --git a/jc/parsers/traceroute.py b/jc/parsers/traceroute.py index cbdf0a93..73a20979 100644 --- a/jc/parsers/traceroute.py +++ b/jc/parsers/traceroute.py @@ -19,6 +19,27 @@ Usage (module): import jc.parsers.traceroute result = jc.parsers.traceroute.parse(traceroute_command_output) +Schema: + + { + "destination_ip": string, + "destination_name": string, + "hops": [ + { + "hop": integer, + "probes": [ + { + "annotation": string, + "asn": integer, + "ip": string, + "name": string, + "rtt": float + } + ] + } + ] + } + Compatibility: 'linux', 'darwin', 'freebsd' @@ -101,7 +122,8 @@ import jc.utils class info(): - version = '1.1' + """Provides parser metadata (version, author, etc.)""" + version = '1.2' description = '`traceroute` and `traceroute6` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -151,7 +173,7 @@ RE_PROBE_ASN = re.compile(r'\[AS(\d+)\]') RE_PROBE_RTT_ANNOTATION = re.compile(r'(?:(\d+(?:\.?\d+)?)\s+ms|(\s+\*\s+))\s*(!\S*)?') -class Traceroute(object): +class _Traceroute(object): def __init__(self, dest_name, dest_ip): self.dest_name = dest_name self.dest_ip = dest_ip @@ -167,7 +189,7 @@ class Traceroute(object): return text -class Hop(object): +class _Hop(object): def __init__(self, idx): self.idx = idx # Hop count, starting at 1 (usually) self.probes = [] # Series of Probe instances @@ -194,7 +216,7 @@ class Hop(object): return text -class Probe(object): +class _Probe(object): def __init__(self, name=None, ip=None, asn=None, rtt=None, annotation=None): self.name = name self.ip = ip @@ -216,7 +238,7 @@ class Probe(object): return text -def loads(data): +def _loads(data): lines = data.splitlines() # Get headers @@ -227,7 +249,7 @@ def loads(data): dest_ip = match_dest.group(2) # The Traceroute node is the root of the tree - traceroute = Traceroute(dest_name, dest_ip) + traceroute = _Traceroute(dest_name, dest_ip) # Parse the remaining lines, they should be only hops/probes for line in lines[1:]: @@ -243,7 +265,7 @@ def loads(data): hop_index = None if hop_index is not None: - hop = Hop(hop_index) + hop = _Hop(hop_index) traceroute.add_hop(hop) hop_string = hop_match.group(2) @@ -279,7 +301,7 @@ def loads(data): probe_annotation = probe_rtt_annotation[2] or None - probe = Probe( + probe = _Probe( name=probe_name, ip=probe_ip, asn=probe_asn, @@ -300,7 +322,7 @@ class ParseError(Exception): ######################################################################################## -def process(proc_data): +def _process(proc_data): """ Final processing to conform to the schema. @@ -310,26 +332,7 @@ def process(proc_data): Returns: - Dictionary. Structured data with the following schema: - - { - "destination_ip": string, - "destination_name": string, - "hops": [ - { - "hop": integer, - "probes": [ - { - "annotation": string, - "asn": integer, - "ip": string, - "name": string, - "rtt": float - } - ] - } - ] - } + Dictionary. Structured to conform to the schema. """ int_list = ['hop', 'asn'] float_list = ['rtt'] @@ -408,7 +411,7 @@ def parse(data, raw=False, quiet=False): data = '\n'.join(new_data) - tr = loads(data) + tr = _loads(data) hops = tr.hops hops_list = [] @@ -441,4 +444,4 @@ def parse(data, raw=False, quiet=False): if raw: return raw_output else: - return process(raw_output) + return _process(raw_output)