diff --git a/CHANGELOG b/CHANGELOG index 89997433..7aa053f6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ jc changelog +20220304 v1.18.4 +- Add nmcli command parser tested on linux +- Enhance parse error messages at the cli +- Add standard and streaming parser list functions to the public API +- Enhance python developer documentation formatting + 20220214 v1.18.3 - Add rsync command and log file parser tested on linux and macOS - Add rsync command and log file streaming parser tested on linux and macOS diff --git a/EXAMPLES.md b/EXAMPLES.md index a2f57254..943933db 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -2387,6 +2387,47 @@ netstat -i | jc --netstat -p # or: jc -p netstat -i } ] ``` +### nmcli +```bash +nmcli connection show ens33 | jc --nmcli -p # or jc -p nmcli connection show ens33 +``` +```json +[ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": 100 + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": 100 + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": 100 + } + } + ] +``` ### ntpq ```bash ntpq -p | jc --ntpq -p # or: jc -p ntpq -p diff --git a/README.md b/README.md index f9743e0d..1d804634 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ ![Tests](https://github.com/kellyjonbrazil/jc/workflows/Tests/badge.svg?branch=master) ![Pypi](https://img.shields.io/pypi/v/jc.svg) -> `jc` was recently featured in the [Console Open Source Newsletter](https://console.substack.com/p/console-89) - > Check out the `jc` Python [package documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs) for developers > Try the `jc` [web demo](https://jc-web-demo.herokuapp.com/) @@ -13,7 +11,7 @@ Ansible filter plugin in the `community.general` collection. See this for an example. # JC -JSON CLI output utility +JSON Convert `jc` JSONifies the output of many CLI tools and file-types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and @@ -55,16 +53,9 @@ will be a python dictionary, or list of dictionaries, instead of JSON: >>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) >>> data = jc.parse('dig', cmd_output) >>> ->>> data -[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', -'ra'], 'query_num': 1, 'answer_num': 1, 'authority_num': 0, 'additional_num': -1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp': 4096}}, -'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': +>>> data[0]['answer'] [{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': -'93.184.216.34'}], 'query_time': 52, 'server': -'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': -'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56, 'when_epoch': 1618614780, -'when_epoch_utc': None}] +'93.184.216.34'}] ``` > For `jc` Python package documentation, use `help('jc')`, `help('jc.lib')`, or @@ -199,6 +190,7 @@ option. - `--lsusb` enables the `lsusb` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb)) - `--mount` enables the `mount` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mount)) - `--netstat` enables the `netstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat)) +- `--nmcli` enables the `nmcli` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli)) - `--ntpq` enables the `ntpq -p` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq)) - `--passwd` enables the `/etc/passwd` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd)) - `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping)) diff --git a/docgen.sh b/docgen.sh index 38495775..812d8aed 100755 --- a/docgen.sh +++ b/docgen.sh @@ -1,6 +1,6 @@ #!/bin/bash # Generate docs.md -# requires pydoc-markdown 4.5.0 +# requires pydoc-markdown 4.6.1 readme_config=$(cat <<'EOF' { "processors": [ @@ -18,7 +18,7 @@ readme_config=$(cat <<'EOF' "Class": 3, "Method": 3, "Function": 3, - "Data": 3 + "Variable": 3 } } } @@ -43,7 +43,7 @@ toc_config=$(cat <<'EOF' "Class": 3, "Method": 3, "Function": 3, - "Data": 3 + "Variable": 3 } } } @@ -68,7 +68,7 @@ parser_config=$(cat <<'EOF' "Class": 3, "Method": 3, "Function": 3, - "Data": 3 + "Variable": 3 } } } diff --git a/docs/lib.md b/docs/lib.md index 6b79fe1d..ae714f9e 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -4,6 +4,8 @@ * [parse](#jc.lib.parse) * [parser\_mod\_list](#jc.lib.parser_mod_list) * [plugin\_parser\_mod\_list](#jc.lib.plugin_parser_mod_list) + * [standard\_parser\_mod\_list](#jc.lib.standard_parser_mod_list) + * [streaming\_parser\_mod\_list](#jc.lib.streaming_parser_mod_list) * [parser\_info](#jc.lib.parser_info) * [all\_parser\_info](#jc.lib.all_parser_info) * [get\_help](#jc.lib.get_help) @@ -12,7 +14,7 @@ # jc.lib -jc - JSON CLI output utility +jc - JSON Convert JC lib module @@ -20,7 +22,12 @@ JC lib module ### parse ```python -def parse(parser_mod_name: str, data: Union[str, Iterable[str]], quiet: bool = False, raw: bool = False, ignore_exceptions: bool = None, **kwargs) -> Union[Dict, List[Dict], Iterator[Dict]] +def parse(parser_mod_name: str, + data: Union[str, Iterable[str]], + quiet: bool = False, + raw: bool = False, + ignore_exceptions: bool = None, + **kwargs) -> Union[Dict, List[Dict], Iterator[Dict]] ``` Parse the string data using the supplied parser module. @@ -34,9 +41,7 @@ Example: >>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022') {'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...} -To get a list of available parser module names, use `parser_mod_list()` -or `plugin_parser_mod_list()`. `plugin_parser_mod_list()` is a subset -of `parser_mod_list()`. +To get a list of available parser module names, use `parser_mod_list()`. You can also use the lower-level parser modules directly: @@ -100,6 +105,29 @@ def plugin_parser_mod_list() -> List[str] Returns a list of plugin parser module names. This function is a subset of `parser_mod_list()`. + + +### standard\_parser\_mod\_list + +```python +def standard_parser_mod_list() -> List[str] +``` + +Returns a list of standard parser module names. This function is a +subset of `parser_mod_list()` and does not contain any streaming +parsers. + + + +### streaming\_parser\_mod\_list + +```python +def streaming_parser_mod_list() -> List[str] +``` + +Returns a list of streaming parser module names. This function is a +subset of `parser_mod_list()`. + ### parser\_info diff --git a/docs/parsers/acpi.md b/docs/parsers/acpi.md index d6adf5a8..98202760 100644 --- a/docs/parsers/acpi.md +++ b/docs/parsers/acpi.md @@ -3,7 +3,7 @@ # jc.parsers.acpi -jc - JSON CLI output utility `acpi` command output parser +jc - JSON Convert `acpi` command output parser Usage (cli): diff --git a/docs/parsers/airport.md b/docs/parsers/airport.md index 24abb893..4ec9bad3 100644 --- a/docs/parsers/airport.md +++ b/docs/parsers/airport.md @@ -3,7 +3,7 @@ # jc.parsers.airport -jc - JSON CLI output utility `airport -I` command output parser +jc - JSON Convert `airport -I` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. diff --git a/docs/parsers/airport_s.md b/docs/parsers/airport_s.md index ae9afae4..b4354c45 100644 --- a/docs/parsers/airport_s.md +++ b/docs/parsers/airport_s.md @@ -3,7 +3,7 @@ # jc.parsers.airport\_s -jc - JSON CLI output utility `airport -s` command output parser +jc - JSON Convert `airport -s` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. diff --git a/docs/parsers/arp.md b/docs/parsers/arp.md index 09ca6d08..ad76015f 100644 --- a/docs/parsers/arp.md +++ b/docs/parsers/arp.md @@ -3,7 +3,7 @@ # jc.parsers.arp -jc - JSON CLI output utility `arp` command output parser +jc - JSON Convert `arp` command output parser Supports `arp` and `arp -a` output. diff --git a/docs/parsers/blkid.md b/docs/parsers/blkid.md index b94411f2..09fb8abe 100644 --- a/docs/parsers/blkid.md +++ b/docs/parsers/blkid.md @@ -3,7 +3,7 @@ # jc.parsers.blkid -jc - JSON CLI output utility `blkid` command output parser +jc - JSON Convert `blkid` command output parser Usage (cli): diff --git a/docs/parsers/cksum.md b/docs/parsers/cksum.md index 0ba7468e..2ab0ecf6 100644 --- a/docs/parsers/cksum.md +++ b/docs/parsers/cksum.md @@ -3,7 +3,7 @@ # jc.parsers.cksum -jc - JSON CLI output utility `cksum` command output parser +jc - JSON Convert `cksum` command output parser This parser works with the following checksum calculation utilities: - `sum` diff --git a/docs/parsers/crontab.md b/docs/parsers/crontab.md index d4f518b6..dfd27bf6 100644 --- a/docs/parsers/crontab.md +++ b/docs/parsers/crontab.md @@ -3,7 +3,7 @@ # jc.parsers.crontab -jc - JSON CLI output utility `crontab -l` command output and crontab +jc - JSON Convert `crontab -l` command output and crontab file parser Supports `crontab -l` command output and crontab files. diff --git a/docs/parsers/crontab_u.md b/docs/parsers/crontab_u.md index 718cb49a..0ae1817d 100644 --- a/docs/parsers/crontab_u.md +++ b/docs/parsers/crontab_u.md @@ -3,7 +3,7 @@ # jc.parsers.crontab\_u -jc - JSON CLI output utility `crontab -l` command output and crontab +jc - JSON Convert `crontab -l` command output and crontab file parser This version of the `crontab -l` parser supports output that contains user diff --git a/docs/parsers/csv.md b/docs/parsers/csv.md index 95656d8e..16c65905 100644 --- a/docs/parsers/csv.md +++ b/docs/parsers/csv.md @@ -3,7 +3,7 @@ # jc.parsers.csv -jc - JSON CLI output utility `csv` file parser +jc - JSON Convert `csv` file parser The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. diff --git a/docs/parsers/csv_s.md b/docs/parsers/csv_s.md index 6362a7a1..4515a77b 100644 --- a/docs/parsers/csv_s.md +++ b/docs/parsers/csv_s.md @@ -3,7 +3,7 @@ # jc.parsers.csv\_s -jc - JSON CLI output utility `csv` file streaming parser +jc - JSON Convert `csv` file streaming parser > This streaming parser outputs JSON Lines diff --git a/docs/parsers/date.md b/docs/parsers/date.md index e4966ba9..6da56dc5 100644 --- a/docs/parsers/date.md +++ b/docs/parsers/date.md @@ -3,7 +3,7 @@ # jc.parsers.date -jc - JSON CLI output utility `date` command output parser +jc - JSON Convert `date` command output parser The `epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) diff --git a/docs/parsers/df.md b/docs/parsers/df.md index 4e787857..717a9637 100644 --- a/docs/parsers/df.md +++ b/docs/parsers/df.md @@ -3,7 +3,7 @@ # jc.parsers.df -jc - JSON CLI output utility `df` command output parser +jc - JSON Convert `df` command output parser Usage (cli): diff --git a/docs/parsers/dig.md b/docs/parsers/dig.md index d1459682..4903fc82 100644 --- a/docs/parsers/dig.md +++ b/docs/parsers/dig.md @@ -3,7 +3,7 @@ # jc.parsers.dig -jc - JSON CLI output utility `dig` command output parser +jc - JSON Convert `dig` command output parser Options supported: - `+noall +answer` options are supported in cases where only the answer diff --git a/docs/parsers/dir.md b/docs/parsers/dir.md index 02e08ac5..c04e4de6 100644 --- a/docs/parsers/dir.md +++ b/docs/parsers/dir.md @@ -3,7 +3,7 @@ # jc.parsers.dir -jc - JSON CLI output utility `dir` command output parser +jc - JSON Convert `dir` command output parser Options supported: - `/T timefield` diff --git a/docs/parsers/dmidecode.md b/docs/parsers/dmidecode.md index 8591a534..8c7072ac 100644 --- a/docs/parsers/dmidecode.md +++ b/docs/parsers/dmidecode.md @@ -3,7 +3,7 @@ # jc.parsers.dmidecode -jc - JSON CLI output utility `dmidecode` command output parser +jc - JSON Convert `dmidecode` command output parser Usage (cli): diff --git a/docs/parsers/dpkg_l.md b/docs/parsers/dpkg_l.md index 0daa5f96..97ed8209 100644 --- a/docs/parsers/dpkg_l.md +++ b/docs/parsers/dpkg_l.md @@ -3,7 +3,7 @@ # jc.parsers.dpkg\_l -jc - JSON CLI output utility `dpkg -l` command output parser +jc - JSON Convert `dpkg -l` command output parser Set the `COLUMNS` environment variable to a large value to avoid field truncation. For example: diff --git a/docs/parsers/du.md b/docs/parsers/du.md index 6168bfda..fe2f5511 100644 --- a/docs/parsers/du.md +++ b/docs/parsers/du.md @@ -3,7 +3,7 @@ # jc.parsers.du -jc - JSON CLI output utility `du` command output parser +jc - JSON Convert `du` command output parser Usage (cli): diff --git a/docs/parsers/env.md b/docs/parsers/env.md index 428f02d1..1b951549 100644 --- a/docs/parsers/env.md +++ b/docs/parsers/env.md @@ -3,7 +3,7 @@ # jc.parsers.env -jc - JSON CLI output utility `env` and `printenv` command output parser +jc - JSON Convert `env` and `printenv` command output parser This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the diff --git a/docs/parsers/file.md b/docs/parsers/file.md index aefb2165..25895fe7 100644 --- a/docs/parsers/file.md +++ b/docs/parsers/file.md @@ -3,7 +3,7 @@ # jc.parsers.file -jc - JSON CLI output utility `file` command output parser +jc - JSON Convert `file` command output parser Usage (cli): diff --git a/docs/parsers/finger.md b/docs/parsers/finger.md index a48edaa9..b9445add 100644 --- a/docs/parsers/finger.md +++ b/docs/parsers/finger.md @@ -3,7 +3,7 @@ # jc.parsers.finger -jc - JSON CLI output utility `finger` command output parser +jc - JSON Convert `finger` command output parser Supports `-s` output option. Does not support the `-l` detail option. diff --git a/docs/parsers/free.md b/docs/parsers/free.md index 4e3fa757..5f540ace 100644 --- a/docs/parsers/free.md +++ b/docs/parsers/free.md @@ -3,7 +3,7 @@ # jc.parsers.free -jc - JSON CLI output utility `free` command output parser +jc - JSON Convert `free` command output parser Usage (cli): diff --git a/docs/parsers/fstab.md b/docs/parsers/fstab.md index 4d4707ec..60c6555e 100644 --- a/docs/parsers/fstab.md +++ b/docs/parsers/fstab.md @@ -3,7 +3,7 @@ # jc.parsers.fstab -jc - JSON CLI output utility `fstab` file parser +jc - JSON Convert `fstab` file parser Usage (cli): diff --git a/docs/parsers/group.md b/docs/parsers/group.md index 14037ccc..33ca0cdf 100644 --- a/docs/parsers/group.md +++ b/docs/parsers/group.md @@ -3,7 +3,7 @@ # jc.parsers.group -jc - JSON CLI output utility `/etc/group` file parser +jc - JSON Convert `/etc/group` file parser Usage (cli): diff --git a/docs/parsers/gshadow.md b/docs/parsers/gshadow.md index d70b01ca..e48012f9 100644 --- a/docs/parsers/gshadow.md +++ b/docs/parsers/gshadow.md @@ -3,7 +3,7 @@ # jc.parsers.gshadow -jc - JSON CLI output utility `/etc/gshadow` file parser +jc - JSON Convert `/etc/gshadow` file parser Usage (cli): diff --git a/docs/parsers/hash.md b/docs/parsers/hash.md index 319591d2..74cde8f5 100644 --- a/docs/parsers/hash.md +++ b/docs/parsers/hash.md @@ -3,7 +3,7 @@ # jc.parsers.hash -jc - JSON CLI output utility `hash` command output parser +jc - JSON Convert `hash` command output parser Usage (cli): diff --git a/docs/parsers/hashsum.md b/docs/parsers/hashsum.md index a2ca926c..b8b76634 100644 --- a/docs/parsers/hashsum.md +++ b/docs/parsers/hashsum.md @@ -3,7 +3,7 @@ # jc.parsers.hashsum -jc - JSON CLI output utility `hash sum` command output parser +jc - JSON Convert `hash sum` command output parser This parser works with the following hash calculation utilities: - `md5` diff --git a/docs/parsers/hciconfig.md b/docs/parsers/hciconfig.md index 7a486eb6..240cc50c 100644 --- a/docs/parsers/hciconfig.md +++ b/docs/parsers/hciconfig.md @@ -3,7 +3,7 @@ # jc.parsers.hciconfig -jc - JSON CLI output utility `hciconfig` command output parser +jc - JSON Convert `hciconfig` command output parser Usage (cli): diff --git a/docs/parsers/history.md b/docs/parsers/history.md index 54ce0dea..5edd0ce6 100644 --- a/docs/parsers/history.md +++ b/docs/parsers/history.md @@ -3,7 +3,7 @@ # jc.parsers.history -jc - JSON CLI output utility `history` command output parser +jc - JSON Convert `history` command output parser This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the diff --git a/docs/parsers/hosts.md b/docs/parsers/hosts.md index 9b9d165b..dd77a886 100644 --- a/docs/parsers/hosts.md +++ b/docs/parsers/hosts.md @@ -3,7 +3,7 @@ # jc.parsers.hosts -jc - JSON CLI output utility `/etc/hosts` file parser +jc - JSON Convert `/etc/hosts` file parser Usage (cli): diff --git a/docs/parsers/id.md b/docs/parsers/id.md index f231d485..b37a97d7 100644 --- a/docs/parsers/id.md +++ b/docs/parsers/id.md @@ -3,7 +3,7 @@ # jc.parsers.id -jc - JSON CLI output utility `id` command output parser +jc - JSON Convert `id` command output parser Usage (cli): diff --git a/docs/parsers/ifconfig.md b/docs/parsers/ifconfig.md index b742d594..de99c8db 100644 --- a/docs/parsers/ifconfig.md +++ b/docs/parsers/ifconfig.md @@ -3,7 +3,7 @@ # jc.parsers.ifconfig -jc - JSON CLI output utility `ifconfig` command output parser +jc - JSON Convert `ifconfig` command output parser Note: No `ifconfig` options are supported. diff --git a/docs/parsers/ini.md b/docs/parsers/ini.md index f5d7892d..5e2dc174 100644 --- a/docs/parsers/ini.md +++ b/docs/parsers/ini.md @@ -3,7 +3,7 @@ # jc.parsers.ini -jc - JSON CLI output utility `INI` file parser +jc - JSON Convert `INI` file parser Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix diff --git a/docs/parsers/iostat.md b/docs/parsers/iostat.md index e0843778..b8e5fae5 100644 --- a/docs/parsers/iostat.md +++ b/docs/parsers/iostat.md @@ -3,7 +3,7 @@ # jc.parsers.iostat -jc - JSON CLI output utility `iostat` command output parser +jc - JSON Convert `iostat` command output parser Note: `iostat` version 11 and higher include a JSON output option diff --git a/docs/parsers/iostat_s.md b/docs/parsers/iostat_s.md index 1fc68dac..8e598bbc 100644 --- a/docs/parsers/iostat_s.md +++ b/docs/parsers/iostat_s.md @@ -3,7 +3,7 @@ # jc.parsers.iostat\_s -jc - JSON CLI output utility `iostat` command output streaming parser +jc - JSON Convert `iostat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/docs/parsers/iptables.md b/docs/parsers/iptables.md index 3066c881..c51d6d13 100644 --- a/docs/parsers/iptables.md +++ b/docs/parsers/iptables.md @@ -3,7 +3,7 @@ # jc.parsers.iptables -jc - JSON CLI output utility `iptables` command output parser +jc - JSON Convert `iptables` command output parser Supports `-vLn` and `--line-numbers` for all tables. diff --git a/docs/parsers/iw_scan.md b/docs/parsers/iw_scan.md index df0ed6df..b39de09e 100644 --- a/docs/parsers/iw_scan.md +++ b/docs/parsers/iw_scan.md @@ -3,7 +3,7 @@ # jc.parsers.iw\_scan -jc - JSON CLI output utility `iw dev scan` command output parser +jc - JSON Convert `iw dev scan` command output parser This parser is considered beta quality. Not all fields are parsed and there are not enough samples to test. diff --git a/docs/parsers/jar_manifest.md b/docs/parsers/jar_manifest.md index 7e2b44d2..91964220 100644 --- a/docs/parsers/jar_manifest.md +++ b/docs/parsers/jar_manifest.md @@ -3,7 +3,7 @@ # jc.parsers.jar\_manifest -jc - JSON CLI output utility `MANIFEST.MF` file parser +jc - JSON Convert `MANIFEST.MF` file parser Usage (cli): diff --git a/docs/parsers/jobs.md b/docs/parsers/jobs.md index d24d7e2b..ab7da0dd 100644 --- a/docs/parsers/jobs.md +++ b/docs/parsers/jobs.md @@ -3,7 +3,7 @@ # jc.parsers.jobs -jc - JSON CLI output utility `jobs` command output parser +jc - JSON Convert `jobs` command output parser Also supports the `-l` option. diff --git a/docs/parsers/kv.md b/docs/parsers/kv.md index 024e1a88..9959671a 100644 --- a/docs/parsers/kv.md +++ b/docs/parsers/kv.md @@ -3,7 +3,7 @@ # jc.parsers.kv -jc - JSON CLI output utility `Key/Value` file parser +jc - JSON Convert `Key/Value` file parser Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. diff --git a/docs/parsers/last.md b/docs/parsers/last.md index aa9de406..910e405f 100644 --- a/docs/parsers/last.md +++ b/docs/parsers/last.md @@ -3,7 +3,7 @@ # jc.parsers.last -jc - JSON CLI output utility `last` and `lastb` command output parser +jc - JSON Convert `last` and `lastb` command output parser Supports `-w` and `-F` options. diff --git a/docs/parsers/ls.md b/docs/parsers/ls.md index 2ae42823..578b3dfb 100644 --- a/docs/parsers/ls.md +++ b/docs/parsers/ls.md @@ -3,7 +3,7 @@ # jc.parsers.ls -jc - JSON CLI output utility `ls` and `vdir` command output parser +jc - JSON Convert `ls` and `vdir` command output parser Options supported: - `lbaR1` diff --git a/docs/parsers/ls_s.md b/docs/parsers/ls_s.md index bd0e5979..20bc6a90 100644 --- a/docs/parsers/ls_s.md +++ b/docs/parsers/ls_s.md @@ -3,7 +3,7 @@ # jc.parsers.ls\_s -jc - JSON CLI output utility `ls` and `vdir` command output streaming +jc - JSON Convert `ls` and `vdir` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/docs/parsers/lsblk.md b/docs/parsers/lsblk.md index 137bb66b..0e8ba14e 100644 --- a/docs/parsers/lsblk.md +++ b/docs/parsers/lsblk.md @@ -3,7 +3,7 @@ # jc.parsers.lsblk -jc - JSON CLI output utility `lsblk` command output parser +jc - JSON Convert `lsblk` command output parser Usage (cli): diff --git a/docs/parsers/lsmod.md b/docs/parsers/lsmod.md index 918196c2..705f45ff 100644 --- a/docs/parsers/lsmod.md +++ b/docs/parsers/lsmod.md @@ -3,7 +3,7 @@ # jc.parsers.lsmod -jc - JSON CLI output utility `lsmod` command output parser +jc - JSON Convert `lsmod` command output parser Usage (cli): diff --git a/docs/parsers/lsof.md b/docs/parsers/lsof.md index 91d8b439..bff7b40c 100644 --- a/docs/parsers/lsof.md +++ b/docs/parsers/lsof.md @@ -3,7 +3,7 @@ # jc.parsers.lsof -jc - JSON CLI output utility `lsof` command output parser +jc - JSON Convert `lsof` command output parser Usage (cli): diff --git a/docs/parsers/lsusb.md b/docs/parsers/lsusb.md index 4243593c..fa27c836 100644 --- a/docs/parsers/lsusb.md +++ b/docs/parsers/lsusb.md @@ -3,7 +3,7 @@ # jc.parsers.lsusb -jc - JSON CLI output utility `lsusb` command output parser +jc - JSON Convert `lsusb` command output parser Supports the `-v` option or no options. diff --git a/docs/parsers/mount.md b/docs/parsers/mount.md index 4eb3ba20..e5bbea98 100644 --- a/docs/parsers/mount.md +++ b/docs/parsers/mount.md @@ -3,7 +3,7 @@ # jc.parsers.mount -jc - JSON CLI output utility `mount` command output parser +jc - JSON Convert `mount` command output parser Usage (cli): diff --git a/docs/parsers/netstat.md b/docs/parsers/netstat.md index c48fbcfc..01d0782b 100644 --- a/docs/parsers/netstat.md +++ b/docs/parsers/netstat.md @@ -3,7 +3,7 @@ # jc.parsers.netstat -jc - JSON CLI output utility `netstat` command output parser +jc - JSON Convert `netstat` command output parser Caveats: - Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`) diff --git a/docs/parsers/nmcli.md b/docs/parsers/nmcli.md new file mode 100644 index 00000000..3df6a3de --- /dev/null +++ b/docs/parsers/nmcli.md @@ -0,0 +1,176 @@ +[Home](https://kellyjonbrazil.github.io/jc/) + + +# jc.parsers.nmcli + +jc - JSON Convert `nmcli` command output parser + +Supports the following `nmcli` subcommands: +- `nmcli general` +- `nmcli general permissions` +- `nmcli connection` +- `nmcli connection show ` +- `nmcli device` +- `nmcli device show` +- `nmcli device show ` + +Usage (cli): + + $ nmcli device show lo | jc --nmcli + + or + + $ jc nmcli device show lo + +Usage (module): + + import jc + result = jc.parse('nmcli', nmcli_command_output) + + or + + import jc.parsers.nmcli + result = jc.parsers.nmcli.parse(nmcli_command_output) + +Schema: + + Because there are so many options, the schema is not strictly defined. + Integer and Float value conversions are attempted and the original + values are kept if they fail. If you don't want automatic conversion, + then use the -r or raw=True option to disable it. + + The structure is flat, for the most part, but there are a couple of + "well-known" keys that are further parsed into objects for convenience. + These are documented below. + + [ + { + "": string/integer/float, [0] + "dhcp4_option_x": { + "name": string, + "value": string/integer/float, + }, + "dhcp6_option_x": { + "name": string, + "value": string/integer/float, + }, + "ip4_route_x": { + "dst": string, + "nh": string, + "mt": integer + }, + "ip6_route_x": { + "dst": string, + "nh": string, + "mt": integer, + "table": integer + } + } + ] + + [0] all values of `---` are converted to null + +Examples: + + $ nmcli connection show ens33 | jc --nmcli -p + [ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + ... + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": 100 + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": 100 + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + ... + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": 100 + } + } + ] + + $ nmcli connection show ens33 | jc --nmcli -p -r + [ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + ... + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": "100" + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": "100" + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + ... + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": "100" + } + } + ] + + + +### parse + +```python +def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict] +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) unprocessed output if True + quiet: (boolean) suppress warning messages if True + +Returns: + + List of Dictionaries. Raw or processed structured data. + +### Parser Information +Compatibility: linux + +Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/ntpq.md b/docs/parsers/ntpq.md index 15ca65db..ff043328 100644 --- a/docs/parsers/ntpq.md +++ b/docs/parsers/ntpq.md @@ -3,7 +3,7 @@ # jc.parsers.ntpq -jc - JSON CLI output utility `ntpq -p` command output parser +jc - JSON Convert `ntpq -p` command output parser Usage (cli): diff --git a/docs/parsers/passwd.md b/docs/parsers/passwd.md index e0682d55..498c1cfb 100644 --- a/docs/parsers/passwd.md +++ b/docs/parsers/passwd.md @@ -3,7 +3,7 @@ # jc.parsers.passwd -jc - JSON CLI output utility `/etc/passwd` file Parser +jc - JSON Convert `/etc/passwd` file Parser Usage (cli): diff --git a/docs/parsers/ping.md b/docs/parsers/ping.md index 3ffce210..a5e1f2cd 100644 --- a/docs/parsers/ping.md +++ b/docs/parsers/ping.md @@ -3,7 +3,7 @@ # jc.parsers.ping -jc - JSON CLI output utility `ping` command output parser +jc - JSON Convert `ping` command output parser Supports `ping` and `ping6` output. diff --git a/docs/parsers/ping_s.md b/docs/parsers/ping_s.md index b904e2b7..f678bbca 100644 --- a/docs/parsers/ping_s.md +++ b/docs/parsers/ping_s.md @@ -3,7 +3,7 @@ # jc.parsers.ping\_s -jc - JSON CLI output utility `ping` command output streaming parser +jc - JSON Convert `ping` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/docs/parsers/pip_list.md b/docs/parsers/pip_list.md index de814615..33906cdf 100644 --- a/docs/parsers/pip_list.md +++ b/docs/parsers/pip_list.md @@ -3,7 +3,7 @@ # jc.parsers.pip\_list -jc - JSON CLI output utility `pip-list` command output parser +jc - JSON Convert `pip-list` command output parser Usage (cli): diff --git a/docs/parsers/pip_show.md b/docs/parsers/pip_show.md index 9de9de46..661bc526 100644 --- a/docs/parsers/pip_show.md +++ b/docs/parsers/pip_show.md @@ -3,7 +3,7 @@ # jc.parsers.pip\_show -jc - JSON CLI output utility `pip-show` command output parser +jc - JSON Convert `pip-show` command output parser Usage (cli): diff --git a/docs/parsers/ps.md b/docs/parsers/ps.md index b2e21c5c..ef02011a 100644 --- a/docs/parsers/ps.md +++ b/docs/parsers/ps.md @@ -3,7 +3,7 @@ # jc.parsers.ps -jc - JSON CLI output utility `ps` command output parser +jc - JSON Convert `ps` command output parser `ps` options supported: - `ef` diff --git a/docs/parsers/route.md b/docs/parsers/route.md index c44d9a2a..022676a7 100644 --- a/docs/parsers/route.md +++ b/docs/parsers/route.md @@ -3,7 +3,7 @@ # jc.parsers.route -jc - JSON CLI output utility `route` command output parser +jc - JSON Convert `route` command output parser Usage (cli): diff --git a/docs/parsers/rpm_qi.md b/docs/parsers/rpm_qi.md index 3d316d03..b0238a17 100644 --- a/docs/parsers/rpm_qi.md +++ b/docs/parsers/rpm_qi.md @@ -3,7 +3,7 @@ # jc.parsers.rpm\_qi -jc - JSON CLI output utility `rpm -qi` command output parser +jc - JSON Convert `rpm -qi` command output parser Works with `rpm -qi [package]` or `rpm -qia`. diff --git a/docs/parsers/rsync.md b/docs/parsers/rsync.md index 04f8c664..dd799fdf 100644 --- a/docs/parsers/rsync.md +++ b/docs/parsers/rsync.md @@ -3,7 +3,7 @@ # jc.parsers.rsync -jc - JSON CLI output utility `rsync` command output parser +jc - JSON Convert `rsync` command output parser Supports the `-i` or `--itemize-changes` options with all levels of verbosity. This parser will process the STDOUT output or a log file diff --git a/docs/parsers/rsync_s.md b/docs/parsers/rsync_s.md index 27b2c9a7..b3e41c30 100644 --- a/docs/parsers/rsync_s.md +++ b/docs/parsers/rsync_s.md @@ -3,7 +3,7 @@ # jc.parsers.rsync\_s -jc - JSON CLI output utility `rsync` command output streaming parser +jc - JSON Convert `rsync` command output streaming parser > This streaming parser outputs JSON Lines @@ -99,7 +99,10 @@ Examples: ```python @add_jc_meta -def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple] +def parse(data: Iterable[str], + raw: bool = False, + quiet: bool = False, + ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple] ``` Main text parsing generator function. Returns an iterator object. diff --git a/docs/parsers/sfdisk.md b/docs/parsers/sfdisk.md index eb0d8cde..4358b074 100644 --- a/docs/parsers/sfdisk.md +++ b/docs/parsers/sfdisk.md @@ -3,7 +3,7 @@ # jc.parsers.sfdisk -jc - JSON CLI output utility `sfdisk` command output parser +jc - JSON Convert `sfdisk` command output parser Supports the following `sfdisk` options: - `-l` diff --git a/docs/parsers/shadow.md b/docs/parsers/shadow.md index b184b650..ef615c26 100644 --- a/docs/parsers/shadow.md +++ b/docs/parsers/shadow.md @@ -3,7 +3,7 @@ # jc.parsers.shadow -jc - JSON CLI output utility `/etc/shadow` file parser +jc - JSON Convert `/etc/shadow` file parser Usage (cli): diff --git a/docs/parsers/ss.md b/docs/parsers/ss.md index 17031b5e..bd0ed975 100644 --- a/docs/parsers/ss.md +++ b/docs/parsers/ss.md @@ -3,7 +3,7 @@ # jc.parsers.ss -jc - JSON CLI output utility `ss` command output parser +jc - JSON Convert `ss` command output parser Extended information options like -e and -p are not supported and may cause parsing irregularities. diff --git a/docs/parsers/stat.md b/docs/parsers/stat.md index b5db81dd..9240b290 100644 --- a/docs/parsers/stat.md +++ b/docs/parsers/stat.md @@ -3,7 +3,7 @@ # jc.parsers.stat -jc - JSON CLI output utility `stat` command output parser +jc - JSON Convert `stat` command output parser The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the local time of the system the parser is run on) diff --git a/docs/parsers/stat_s.md b/docs/parsers/stat_s.md index 4a59f84d..0813541f 100644 --- a/docs/parsers/stat_s.md +++ b/docs/parsers/stat_s.md @@ -3,7 +3,7 @@ # jc.parsers.stat\_s -jc - JSON CLI output utility `stat` command output streaming parser +jc - JSON Convert `stat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/docs/parsers/sysctl.md b/docs/parsers/sysctl.md index 1b77027a..e0ac3892 100644 --- a/docs/parsers/sysctl.md +++ b/docs/parsers/sysctl.md @@ -3,7 +3,7 @@ # jc.parsers.sysctl -jc - JSON CLI output utility `sysctl -a` command output parser +jc - JSON Convert `sysctl -a` command output parser Note: Since `sysctl` output is not easily parsable only a very simple key/value object will be output. An attempt is made to convert obvious diff --git a/docs/parsers/systemctl.md b/docs/parsers/systemctl.md index 2359a0f4..e6d03231 100644 --- a/docs/parsers/systemctl.md +++ b/docs/parsers/systemctl.md @@ -3,7 +3,7 @@ # jc.parsers.systemctl -jc - JSON CLI output utility `systemctl` command output parser +jc - JSON Convert `systemctl` command output parser Usage (cli): diff --git a/docs/parsers/systemctl_lj.md b/docs/parsers/systemctl_lj.md index 324375d0..68bfed5d 100644 --- a/docs/parsers/systemctl_lj.md +++ b/docs/parsers/systemctl_lj.md @@ -3,7 +3,7 @@ # jc.parsers.systemctl\_lj -jc - JSON CLI output utility `systemctl list-jobs` command output parser +jc - JSON Convert `systemctl list-jobs` command output parser Usage (cli): diff --git a/docs/parsers/systemctl_ls.md b/docs/parsers/systemctl_ls.md index caca4b71..cd13a9c0 100644 --- a/docs/parsers/systemctl_ls.md +++ b/docs/parsers/systemctl_ls.md @@ -3,7 +3,7 @@ # jc.parsers.systemctl\_ls -jc - JSON CLI output utility `systemctl list-sockets` command output +jc - JSON Convert `systemctl list-sockets` command output parser Usage (cli): diff --git a/docs/parsers/systemctl_luf.md b/docs/parsers/systemctl_luf.md index 9624439e..ab3d2983 100644 --- a/docs/parsers/systemctl_luf.md +++ b/docs/parsers/systemctl_luf.md @@ -3,7 +3,7 @@ # jc.parsers.systemctl\_luf -jc - JSON CLI output utility `systemctl list-unit-files` command output +jc - JSON Convert `systemctl list-unit-files` command output parser Usage (cli): diff --git a/docs/parsers/systeminfo.md b/docs/parsers/systeminfo.md index bd85b45f..0b442e5f 100644 --- a/docs/parsers/systeminfo.md +++ b/docs/parsers/systeminfo.md @@ -3,7 +3,7 @@ # jc.parsers.systeminfo -jc - JSON CLI output utility `systeminfo` command output parser +jc - JSON Convert `systeminfo` command output parser Blank or missing elements are set to `null`. diff --git a/docs/parsers/time.md b/docs/parsers/time.md index 6ade177f..bdf3f1a4 100644 --- a/docs/parsers/time.md +++ b/docs/parsers/time.md @@ -3,7 +3,7 @@ # jc.parsers.time -jc - JSON CLI output utility `/usr/bin/time` command output parser +jc - JSON Convert `/usr/bin/time` command output parser Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be used to redirect the output to a file that can be read by `jc`. diff --git a/docs/parsers/timedatectl.md b/docs/parsers/timedatectl.md index 0e40adbe..ddcd4c73 100644 --- a/docs/parsers/timedatectl.md +++ b/docs/parsers/timedatectl.md @@ -3,7 +3,7 @@ # jc.parsers.timedatectl -jc - JSON CLI output utility `timedatectl` command output parser +jc - JSON Convert `timedatectl` command output parser The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the `universal_time` field is available. diff --git a/docs/parsers/tracepath.md b/docs/parsers/tracepath.md index 19636189..9a8256c5 100644 --- a/docs/parsers/tracepath.md +++ b/docs/parsers/tracepath.md @@ -3,7 +3,7 @@ # jc.parsers.tracepath -jc - JSON CLI output utility `tracepath` command output parser +jc - JSON Convert `tracepath` command output parser Supports `tracepath` and `tracepath6` output. diff --git a/docs/parsers/traceroute.md b/docs/parsers/traceroute.md index 1ab094fb..f98e5ba3 100644 --- a/docs/parsers/traceroute.md +++ b/docs/parsers/traceroute.md @@ -3,7 +3,7 @@ # jc.parsers.traceroute -jc - JSON CLI output utility `traceroute` command output parser +jc - JSON Convert `traceroute` command output parser Supports `traceroute` and `traceroute6` output. diff --git a/docs/parsers/ufw.md b/docs/parsers/ufw.md index ddc29105..86e625ee 100644 --- a/docs/parsers/ufw.md +++ b/docs/parsers/ufw.md @@ -3,7 +3,7 @@ # jc.parsers.ufw -jc - JSON CLI output utility `ufw status` command output parser +jc - JSON Convert `ufw status` command output parser Usage (cli): diff --git a/docs/parsers/ufw_appinfo.md b/docs/parsers/ufw_appinfo.md index 0ad1eecc..cb15ac4d 100644 --- a/docs/parsers/ufw_appinfo.md +++ b/docs/parsers/ufw_appinfo.md @@ -3,7 +3,7 @@ # jc.parsers.ufw\_appinfo -jc - JSON CLI output utility `ufw app info [application]` command +jc - JSON Convert `ufw app info [application]` command output parser Supports individual apps via `ufw app info [application]` and all apps list diff --git a/docs/parsers/uname.md b/docs/parsers/uname.md index 71e67ddc..d583146c 100644 --- a/docs/parsers/uname.md +++ b/docs/parsers/uname.md @@ -3,7 +3,7 @@ # jc.parsers.uname -jc - JSON CLI output utility `uname -a` command output parser +jc - JSON Convert `uname -a` command output parser Note: Must use `uname -a` diff --git a/docs/parsers/universal.md b/docs/parsers/universal.md index 00dca1d3..5327ed83 100644 --- a/docs/parsers/universal.md +++ b/docs/parsers/universal.md @@ -8,7 +8,7 @@ # jc.parsers.universal -jc - JSON CLI output utility universal Parsers +jc - JSON Convert universal parsers diff --git a/docs/parsers/upower.md b/docs/parsers/upower.md index be0384ad..f8d513a4 100644 --- a/docs/parsers/upower.md +++ b/docs/parsers/upower.md @@ -3,7 +3,7 @@ # jc.parsers.upower -jc - JSON CLI output utility `upower` command output parser +jc - JSON Convert `upower` command output parser The `updated_epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) diff --git a/docs/parsers/uptime.md b/docs/parsers/uptime.md index 9d5375bd..d2c5ccea 100644 --- a/docs/parsers/uptime.md +++ b/docs/parsers/uptime.md @@ -3,7 +3,7 @@ # jc.parsers.uptime -jc - JSON CLI output utility `uptime` command output parser +jc - JSON Convert `uptime` command output parser Usage (cli): diff --git a/docs/parsers/vmstat.md b/docs/parsers/vmstat.md index c6e76a38..fea78a6a 100644 --- a/docs/parsers/vmstat.md +++ b/docs/parsers/vmstat.md @@ -3,7 +3,7 @@ # jc.parsers.vmstat -jc - JSON CLI output utility `vmstat` command output parser +jc - JSON Convert `vmstat` command output parser Options supported: `-a`, `-w`, `-d`, `-t` diff --git a/docs/parsers/vmstat_s.md b/docs/parsers/vmstat_s.md index 2445f1b6..c2d35e39 100644 --- a/docs/parsers/vmstat_s.md +++ b/docs/parsers/vmstat_s.md @@ -3,7 +3,7 @@ # jc.parsers.vmstat\_s -jc - JSON CLI output utility `vmstat` command output streaming parser +jc - JSON Convert `vmstat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/docs/parsers/w.md b/docs/parsers/w.md index 378fa467..6ff07141 100644 --- a/docs/parsers/w.md +++ b/docs/parsers/w.md @@ -3,7 +3,7 @@ # jc.parsers.w -jc - JSON CLI output utility `w` command output parser +jc - JSON Convert `w` command output parser Usage (cli): diff --git a/docs/parsers/wc.md b/docs/parsers/wc.md index 49f2f82b..2969bf12 100644 --- a/docs/parsers/wc.md +++ b/docs/parsers/wc.md @@ -3,7 +3,7 @@ # jc.parsers.wc -jc - JSON CLI output utility `wc` command output parser +jc - JSON Convert `wc` command output parser Usage (cli): diff --git a/docs/parsers/who.md b/docs/parsers/who.md index 94953475..7d7eed62 100644 --- a/docs/parsers/who.md +++ b/docs/parsers/who.md @@ -3,7 +3,7 @@ # jc.parsers.who -jc - JSON CLI output utility `who` command output parser +jc - JSON Convert `who` command output parser Accepts any of the following who options (or no options): `-aTH` diff --git a/docs/parsers/xml.md b/docs/parsers/xml.md index 1dab4203..6e822260 100644 --- a/docs/parsers/xml.md +++ b/docs/parsers/xml.md @@ -3,7 +3,7 @@ # jc.parsers.xml -jc - JSON CLI output utility `XML` file parser +jc - JSON Convert `XML` file parser Usage (cli): diff --git a/docs/parsers/xrandr.md b/docs/parsers/xrandr.md index eb095eec..76d926b7 100644 --- a/docs/parsers/xrandr.md +++ b/docs/parsers/xrandr.md @@ -3,7 +3,7 @@ # jc.parsers.xrandr -jc - JSON CLI output utility `xrandr` command output parser +jc - JSON Convert `xrandr` command output parser Usage (cli): diff --git a/docs/parsers/yaml.md b/docs/parsers/yaml.md index 6e4d8cd2..6e774c7c 100644 --- a/docs/parsers/yaml.md +++ b/docs/parsers/yaml.md @@ -3,7 +3,7 @@ # jc.parsers.yaml -jc - JSON CLI output utility `YAML` file parser +jc - JSON Convert `YAML` file parser Usage (cli): diff --git a/docs/parsers/zipinfo.md b/docs/parsers/zipinfo.md index 665a1a31..e2ca96f7 100644 --- a/docs/parsers/zipinfo.md +++ b/docs/parsers/zipinfo.md @@ -3,7 +3,7 @@ # jc.parsers.zipinfo -jc - JSON CLI output utility `zipinfo` command output parser +jc - JSON Convert `zipinfo` command output parser Options supported: - none @@ -107,4 +107,4 @@ Returns: ### Parser Information Compatibility: linux, darwin -Version 0.01 by Matt J (https://github.com/listuser) +Version 1.0 by Matt J (https://github.com/listuser) diff --git a/docs/readme.md b/docs/readme.md index 7410dd4f..d224b4d7 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -2,7 +2,7 @@ # jc -JC - JSON CLI output utility +JC - JSON Convert * kellyjonbrazil@gmail.com @@ -26,9 +26,9 @@ https://github.com/kellyjonbrazil/jc/tree/master/docs ### Specific Version -Replace `{{full_version_number}}` - e.g. `1.17.7`: +Replace `` - e.g. `1.17.7`: -`https://github.com/kellyjonbrazil/jc/tree/v{{full_version_number}}/docs` +`https://github.com/kellyjonbrazil/jc/tree/v/docs` Specific versions can also be selected by tag in the branch dropdown menu. @@ -57,29 +57,65 @@ modules directly: ## Available Functions -Use `help(jc.lib)` for details: +Use `help(jc.lib)` for details. - parse(parser_module_name: str, data: str | Iterable) - -> dict | list[dict] | Iterable[dict] - High-level API to easily access the parser. This API will find both - built-in parsers and local plugin parsers. +### parse + + parse( + parser_module_name: str, + data: str | Iterable + ) -> dict | list[dict] | Iterable[dict] + +High-level API to easily access the parser. This API will find both +built-in parsers and local plugin parsers. + +### parser_info parser_info(parser_module_name: str) -> dict - Get the metadata for a particular parser. + +Get the metadata for a particular parser. + +### all_parser_info all_parser_info() -> list[dict] - Get the metadata for all parsers. + +Get the metadata for all parsers. + +### get_help get_help(parser_module_name: str) -> None - Convenience function to display the help screen for a parser using - its module name. + +Convenience function to display the help screen for a parser using +its module name. + +### parser_mod_list parser_mod_list() -> list - Get a list of all available parser module names to be used in - parse(), parser_info(), and get_help(). + +Get a list of all available parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. + +### plugin_parser_mod_list plugin_parser_mod_list() -> list - Get a list of plugin parser module names to be used in - parse(), parser_info(), and get_help(). This list is a subset of - parser_mod_list(). + +Get a list of plugin parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()`. + +### standard_parser_mod_list + + standard_parser_mod_list() -> list + +Get a list of standard parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()` and does not contain any streaming parsers. + +### streaming_parser_mod_list + + streaming_parser_mod_list() -> list + +Get a list of streaming parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()`. diff --git a/docs/streaming.md b/docs/streaming.md index b8971010..71e61b8a 100644 --- a/docs/streaming.md +++ b/docs/streaming.md @@ -12,7 +12,7 @@ # jc.streaming -jc - JSON CLI output utility streaming utils +jc - JSON Convert streaming utils @@ -105,7 +105,8 @@ In all cases above: ### raise\_or\_yield ```python -def raise_or_yield(ignore_exceptions: bool, e: BaseException, line: str) -> tuple +def raise_or_yield(ignore_exceptions: bool, e: BaseException, + line: str) -> tuple ``` Return the exception object and line string if ignore_exceptions is diff --git a/docs/utils.md b/docs/utils.md index c8c24180..f35a53a4 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -16,7 +16,7 @@ # jc.utils -jc - JSON CLI output utility utils +jc - JSON Convert utils @@ -63,7 +63,9 @@ Returns: ### compatibility ```python -def compatibility(mod_name: str, compatible: List, quiet: bool = False) -> None +def compatibility(mod_name: str, + compatible: List, + quiet: bool = False) -> None ``` Checks for the parser's compatibility with the running OS @@ -184,7 +186,8 @@ class timestamp() ### \_\_init\_\_ ```python -def __init__(datetime_string: str, format_hint: Union[List, Tuple, None] = None) -> None +def __init__(datetime_string: str, + format_hint: Union[List, Tuple, None] = None) -> None ``` Input a datetime text string of several formats and convert to a diff --git a/jc/__init__.py b/jc/__init__.py index a59ba5b2..71053c42 100644 --- a/jc/__init__.py +++ b/jc/__init__.py @@ -1,4 +1,4 @@ -"""JC - JSON CLI output utility +"""JC - JSON Convert * kellyjonbrazil@gmail.com @@ -22,9 +22,9 @@ https://github.com/kellyjonbrazil/jc/tree/master/docs ### Specific Version -Replace `{{full_version_number}}` - e.g. `1.17.7`: +Replace `` - e.g. `1.17.7`: -`https://github.com/kellyjonbrazil/jc/tree/v{{full_version_number}}/docs` +`https://github.com/kellyjonbrazil/jc/tree/v/docs` Specific versions can also be selected by tag in the branch dropdown menu. @@ -53,31 +53,68 @@ modules directly: ## Available Functions -Use `help(jc.lib)` for details: +Use `help(jc.lib)` for details. - parse(parser_module_name: str, data: str | Iterable) - -> dict | list[dict] | Iterable[dict] - High-level API to easily access the parser. This API will find both - built-in parsers and local plugin parsers. +### parse + + parse( + parser_module_name: str, + data: str | Iterable + ) -> dict | list[dict] | Iterable[dict] + +High-level API to easily access the parser. This API will find both +built-in parsers and local plugin parsers. + +### parser_info parser_info(parser_module_name: str) -> dict - Get the metadata for a particular parser. + +Get the metadata for a particular parser. + +### all_parser_info all_parser_info() -> list[dict] - Get the metadata for all parsers. + +Get the metadata for all parsers. + +### get_help get_help(parser_module_name: str) -> None - Convenience function to display the help screen for a parser using - its module name. + +Convenience function to display the help screen for a parser using +its module name. + +### parser_mod_list parser_mod_list() -> list - Get a list of all available parser module names to be used in - parse(), parser_info(), and get_help(). + +Get a list of all available parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. + +### plugin_parser_mod_list plugin_parser_mod_list() -> list - Get a list of plugin parser module names to be used in - parse(), parser_info(), and get_help(). This list is a subset of - parser_mod_list(). + +Get a list of plugin parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()`. + +### standard_parser_mod_list + + standard_parser_mod_list() -> list + +Get a list of standard parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()` and does not contain any streaming parsers. + +### streaming_parser_mod_list + + streaming_parser_mod_list() -> list + +Get a list of streaming parser module names to be used in +`parse()`, `parser_info()`, and `get_help()`. This list is a subset of +`parser_mod_list()`. """ from .lib import (__version__, parse, parser_mod_list, plugin_parser_mod_list, + standard_parser_mod_list, streaming_parser_mod_list, parser_info, all_parser_info, get_help) diff --git a/jc/cli.py b/jc/cli.py index f1fd5660..149f5c6b 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility +"""jc - JSON Convert JC cli module """ @@ -11,7 +11,7 @@ import shlex import subprocess import json from .lib import (__version__, all_parser_info, parsers, - _parser_argument, _get_parser) + _parser_argument, _get_parser, _parser_is_streaming) from . import utils from . import tracebackplus from .exceptions import LibraryNotInstalled, ParseError @@ -34,7 +34,7 @@ JC_ERROR_EXIT = 100 class info(): version = __version__ - description = 'JSON CLI output utility' + description = 'JSON Convert' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' website = 'https://github.com/kellyjonbrazil/jc' @@ -502,7 +502,7 @@ def main(): # differentiate between regular and streaming parsers # streaming - if getattr(parser.info, 'streaming', None): + if _parser_is_streaming(parser): result = parser.parse(sys.stdin, raw=raw, quiet=quiet, @@ -539,7 +539,7 @@ def main(): utils.error_message([ f'Parser issue with {parser_name}:', f'{e.__class__.__name__}: {e}', 'If this is the correct parser, try setting the locale to C (LANG=C).', - 'For details use the -d or -dd option. Use "jc -h" for help.' + f'For details use the -d or -dd option. Use "jc -h --{parser_name}" for help.' ]) sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT)) @@ -563,7 +563,7 @@ def main(): f'{parser_name} parser could not parse the input data.', f'{streaming_msg}', 'If this is the correct parser, try setting the locale to C (LANG=C).', - 'For details use the -d or -dd option. Use "jc -h" for help.' + f'For details use the -d or -dd option. Use "jc -h --{parser_name}" for help.' ]) sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT)) diff --git a/jc/exceptions.py b/jc/exceptions.py index 32218db6..932e728e 100644 --- a/jc/exceptions.py +++ b/jc/exceptions.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility exceptions""" +"""jc - JSON Convert exceptions""" class ParseError(Exception): diff --git a/jc/lib.py b/jc/lib.py index bbf3a43b..23fdaf31 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility +"""jc - JSON Convert JC lib module """ @@ -9,7 +9,7 @@ import importlib from typing import Dict, List, Iterable, Union, Iterator from jc import appdirs -__version__ = '1.18.3' +__version__ = '1.18.4' parsers = [ 'acpi', @@ -60,6 +60,7 @@ parsers = [ 'lsusb', 'mount', 'netstat', + 'nmcli', 'ntpq', 'passwd', 'ping', @@ -143,6 +144,17 @@ def _get_parser(parser_mod_name): modpath = 'jcparsers.' if parser_cli_name in local_parsers else 'jc.parsers.' return importlib.import_module(f'{modpath}{parser_mod_name}') +def _parser_is_streaming(parser): + """ + Returns True if this is a streaming parser, else False + + parser is a parser module object. + """ + if getattr(parser.info, 'streaming', None): + return True + + return False + def parse( parser_mod_name: str, data: Union[str, Iterable[str]], @@ -163,9 +175,7 @@ def parse( >>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022') {'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...} - To get a list of available parser module names, use `parser_mod_list()` - or `plugin_parser_mod_list()`. `plugin_parser_mod_list()` is a subset - of `parser_mod_list()`. + To get a list of available parser module names, use `parser_mod_list()`. You can also use the lower-level parser modules directly: @@ -227,6 +237,31 @@ def plugin_parser_mod_list() -> List[str]: """ return [_cliname_to_modname(p) for p in local_parsers] +def standard_parser_mod_list() -> List[str]: + """ + Returns a list of standard parser module names. This function is a + subset of `parser_mod_list()` and does not contain any streaming + parsers. + """ + plist = [] + for p in parsers: + parser = _get_parser(p) + if not _parser_is_streaming(parser): + plist.append(_cliname_to_modname(p)) + return plist + +def streaming_parser_mod_list() -> List[str]: + """ + Returns a list of streaming parser module names. This function is a + subset of `parser_mod_list()`. + """ + plist = [] + for p in parsers: + parser = _get_parser(p) + if _parser_is_streaming(parser): + plist.append(_cliname_to_modname(p)) + return plist + def parser_info(parser_mod_name: str) -> Dict: """ Returns a dictionary that includes the module metadata. diff --git a/jc/parsers/acpi.py b/jc/parsers/acpi.py index 4e9e41fe..46182eed 100644 --- a/jc/parsers/acpi.py +++ b/jc/parsers/acpi.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `acpi` command output parser +"""jc - JSON Convert `acpi` command output parser Usage (cli): diff --git a/jc/parsers/airport.py b/jc/parsers/airport.py index 715510f2..ae1d4291 100644 --- a/jc/parsers/airport.py +++ b/jc/parsers/airport.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `airport -I` command output parser +"""jc - JSON Convert `airport -I` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. diff --git a/jc/parsers/airport_s.py b/jc/parsers/airport_s.py index 5648195c..bf478efa 100644 --- a/jc/parsers/airport_s.py +++ b/jc/parsers/airport_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `airport -s` command output parser +"""jc - JSON Convert `airport -s` command output parser The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`. diff --git a/jc/parsers/arp.py b/jc/parsers/arp.py index 2f4e8a58..53f0c981 100644 --- a/jc/parsers/arp.py +++ b/jc/parsers/arp.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `arp` command output parser +"""jc - JSON Convert `arp` command output parser Supports `arp` and `arp -a` output. diff --git a/jc/parsers/blkid.py b/jc/parsers/blkid.py index ce5df6be..2e94b63f 100644 --- a/jc/parsers/blkid.py +++ b/jc/parsers/blkid.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `blkid` command output parser +"""jc - JSON Convert `blkid` command output parser Usage (cli): diff --git a/jc/parsers/cksum.py b/jc/parsers/cksum.py index 02b812f6..ea50103c 100644 --- a/jc/parsers/cksum.py +++ b/jc/parsers/cksum.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `cksum` command output parser +"""jc - JSON Convert `cksum` command output parser This parser works with the following checksum calculation utilities: - `sum` diff --git a/jc/parsers/crontab.py b/jc/parsers/crontab.py index 1736671e..59c0fe81 100644 --- a/jc/parsers/crontab.py +++ b/jc/parsers/crontab.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `crontab -l` command output and crontab +"""jc - JSON Convert `crontab -l` command output and crontab file parser Supports `crontab -l` command output and crontab files. diff --git a/jc/parsers/crontab_u.py b/jc/parsers/crontab_u.py index 0cd10f88..8ec1f13f 100644 --- a/jc/parsers/crontab_u.py +++ b/jc/parsers/crontab_u.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `crontab -l` command output and crontab +"""jc - JSON Convert `crontab -l` command output and crontab file parser This version of the `crontab -l` parser supports output that contains user diff --git a/jc/parsers/csv.py b/jc/parsers/csv.py index 2910c832..0df902ec 100644 --- a/jc/parsers/csv.py +++ b/jc/parsers/csv.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `csv` file parser +"""jc - JSON Convert `csv` file parser The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. diff --git a/jc/parsers/csv_s.py b/jc/parsers/csv_s.py index e4c573c4..86108659 100644 --- a/jc/parsers/csv_s.py +++ b/jc/parsers/csv_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `csv` file streaming parser +"""jc - JSON Convert `csv` file streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/date.py b/jc/parsers/date.py index df710f69..313ec444 100644 --- a/jc/parsers/date.py +++ b/jc/parsers/date.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `date` command output parser +"""jc - JSON Convert `date` command output parser The `epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/df.py b/jc/parsers/df.py index 9b2e857b..cb1edb3e 100644 --- a/jc/parsers/df.py +++ b/jc/parsers/df.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `df` command output parser +"""jc - JSON Convert `df` command output parser Usage (cli): diff --git a/jc/parsers/dig.py b/jc/parsers/dig.py index 0af225b1..d5757b09 100644 --- a/jc/parsers/dig.py +++ b/jc/parsers/dig.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `dig` command output parser +"""jc - JSON Convert `dig` command output parser Options supported: - `+noall +answer` options are supported in cases where only the answer diff --git a/jc/parsers/dir.py b/jc/parsers/dir.py index f9f168b1..a7665628 100644 --- a/jc/parsers/dir.py +++ b/jc/parsers/dir.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `dir` command output parser +"""jc - JSON Convert `dir` command output parser Options supported: - `/T timefield` diff --git a/jc/parsers/dmidecode.py b/jc/parsers/dmidecode.py index f87e06bf..0ec59c03 100644 --- a/jc/parsers/dmidecode.py +++ b/jc/parsers/dmidecode.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `dmidecode` command output parser +"""jc - JSON Convert `dmidecode` command output parser Usage (cli): diff --git a/jc/parsers/dpkg_l.py b/jc/parsers/dpkg_l.py index 260f1433..46f192d0 100644 --- a/jc/parsers/dpkg_l.py +++ b/jc/parsers/dpkg_l.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `dpkg -l` command output parser +"""jc - JSON Convert `dpkg -l` command output parser Set the `COLUMNS` environment variable to a large value to avoid field truncation. For example: diff --git a/jc/parsers/du.py b/jc/parsers/du.py index e91aaee0..c2fa2f0d 100644 --- a/jc/parsers/du.py +++ b/jc/parsers/du.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `du` command output parser +"""jc - JSON Convert `du` command output parser Usage (cli): diff --git a/jc/parsers/env.py b/jc/parsers/env.py index d6155df3..50cfaed4 100644 --- a/jc/parsers/env.py +++ b/jc/parsers/env.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `env` and `printenv` command output parser +"""jc - JSON Convert `env` and `printenv` command output parser This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the diff --git a/jc/parsers/file.py b/jc/parsers/file.py index d0cefe9f..1fbb3c67 100644 --- a/jc/parsers/file.py +++ b/jc/parsers/file.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `file` command output parser +"""jc - JSON Convert `file` command output parser Usage (cli): diff --git a/jc/parsers/finger.py b/jc/parsers/finger.py index d2b45eca..5da95946 100644 --- a/jc/parsers/finger.py +++ b/jc/parsers/finger.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `finger` command output parser +"""jc - JSON Convert `finger` command output parser Supports `-s` output option. Does not support the `-l` detail option. diff --git a/jc/parsers/foo.py b/jc/parsers/foo.py index afd56deb..c3a19357 100644 --- a/jc/parsers/foo.py +++ b/jc/parsers/foo.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `foo` command output parser +"""jc - JSON Convert `foo` command output parser <> diff --git a/jc/parsers/foo_s.py b/jc/parsers/foo_s.py index eadfc202..1113202d 100644 --- a/jc/parsers/foo_s.py +++ b/jc/parsers/foo_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `foo` command output streaming parser +"""jc - JSON Convert `foo` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/free.py b/jc/parsers/free.py index a7af04d5..21a4dc45 100644 --- a/jc/parsers/free.py +++ b/jc/parsers/free.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `free` command output parser +"""jc - JSON Convert `free` command output parser Usage (cli): diff --git a/jc/parsers/fstab.py b/jc/parsers/fstab.py index 6d2689da..3608253b 100644 --- a/jc/parsers/fstab.py +++ b/jc/parsers/fstab.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `fstab` file parser +"""jc - JSON Convert `fstab` file parser Usage (cli): diff --git a/jc/parsers/group.py b/jc/parsers/group.py index bf9bef87..7818ada2 100644 --- a/jc/parsers/group.py +++ b/jc/parsers/group.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/group` file parser +"""jc - JSON Convert `/etc/group` file parser Usage (cli): diff --git a/jc/parsers/gshadow.py b/jc/parsers/gshadow.py index d5df2b3b..581c1e26 100644 --- a/jc/parsers/gshadow.py +++ b/jc/parsers/gshadow.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/gshadow` file parser +"""jc - JSON Convert `/etc/gshadow` file parser Usage (cli): diff --git a/jc/parsers/hash.py b/jc/parsers/hash.py index 1efa91c6..b5f87c4c 100644 --- a/jc/parsers/hash.py +++ b/jc/parsers/hash.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `hash` command output parser +"""jc - JSON Convert `hash` command output parser Usage (cli): diff --git a/jc/parsers/hashsum.py b/jc/parsers/hashsum.py index 3f3356eb..0d963ca7 100644 --- a/jc/parsers/hashsum.py +++ b/jc/parsers/hashsum.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `hash sum` command output parser +"""jc - JSON Convert `hash sum` command output parser This parser works with the following hash calculation utilities: - `md5` diff --git a/jc/parsers/hciconfig.py b/jc/parsers/hciconfig.py index 9aff32f9..5e9551bb 100644 --- a/jc/parsers/hciconfig.py +++ b/jc/parsers/hciconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `hciconfig` command output parser +"""jc - JSON Convert `hciconfig` command output parser Usage (cli): diff --git a/jc/parsers/history.py b/jc/parsers/history.py index 2ed864a6..9ee422ff 100644 --- a/jc/parsers/history.py +++ b/jc/parsers/history.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `history` command output parser +"""jc - JSON Convert `history` command output parser This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the diff --git a/jc/parsers/hosts.py b/jc/parsers/hosts.py index 6f9a5071..e6f8d679 100644 --- a/jc/parsers/hosts.py +++ b/jc/parsers/hosts.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/hosts` file parser +"""jc - JSON Convert `/etc/hosts` file parser Usage (cli): diff --git a/jc/parsers/id.py b/jc/parsers/id.py index 3e14d467..046a28f9 100644 --- a/jc/parsers/id.py +++ b/jc/parsers/id.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `id` command output parser +"""jc - JSON Convert `id` command output parser Usage (cli): diff --git a/jc/parsers/ifconfig.py b/jc/parsers/ifconfig.py index 8367671f..3c6abc88 100644 --- a/jc/parsers/ifconfig.py +++ b/jc/parsers/ifconfig.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ifconfig` command output parser +"""jc - JSON Convert `ifconfig` command output parser Note: No `ifconfig` options are supported. diff --git a/jc/parsers/ini.py b/jc/parsers/ini.py index 23a9d15a..192e3292 100644 --- a/jc/parsers/ini.py +++ b/jc/parsers/ini.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `INI` file parser +"""jc - JSON Convert `INI` file parser Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix diff --git a/jc/parsers/iostat.py b/jc/parsers/iostat.py index 6eaf3ca6..59a43a6d 100644 --- a/jc/parsers/iostat.py +++ b/jc/parsers/iostat.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `iostat` command output parser +"""jc - JSON Convert `iostat` command output parser Note: `iostat` version 11 and higher include a JSON output option diff --git a/jc/parsers/iostat_s.py b/jc/parsers/iostat_s.py index d98f58bc..980e7908 100644 --- a/jc/parsers/iostat_s.py +++ b/jc/parsers/iostat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `iostat` command output streaming parser +"""jc - JSON Convert `iostat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/iptables.py b/jc/parsers/iptables.py index a0e755b9..b7de3886 100644 --- a/jc/parsers/iptables.py +++ b/jc/parsers/iptables.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `iptables` command output parser +"""jc - JSON Convert `iptables` command output parser Supports `-vLn` and `--line-numbers` for all tables. diff --git a/jc/parsers/iw_scan.py b/jc/parsers/iw_scan.py index 3c984719..883c3c76 100644 --- a/jc/parsers/iw_scan.py +++ b/jc/parsers/iw_scan.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `iw dev scan` command output parser +"""jc - JSON Convert `iw dev scan` command output parser This parser is considered beta quality. Not all fields are parsed and there are not enough samples to test. diff --git a/jc/parsers/jar_manifest.py b/jc/parsers/jar_manifest.py index e9afa424..3a68b9cc 100644 --- a/jc/parsers/jar_manifest.py +++ b/jc/parsers/jar_manifest.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `MANIFEST.MF` file parser +"""jc - JSON Convert `MANIFEST.MF` file parser Usage (cli): diff --git a/jc/parsers/jobs.py b/jc/parsers/jobs.py index cd7fd10b..b10ae7ae 100644 --- a/jc/parsers/jobs.py +++ b/jc/parsers/jobs.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `jobs` command output parser +"""jc - JSON Convert `jobs` command output parser Also supports the `-l` option. diff --git a/jc/parsers/kv.py b/jc/parsers/kv.py index a179bff4..db2d1544 100644 --- a/jc/parsers/kv.py +++ b/jc/parsers/kv.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `Key/Value` file parser +"""jc - JSON Convert `Key/Value` file parser Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. diff --git a/jc/parsers/last.py b/jc/parsers/last.py index ba6c7d16..2598e37c 100644 --- a/jc/parsers/last.py +++ b/jc/parsers/last.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `last` and `lastb` command output parser +"""jc - JSON Convert `last` and `lastb` command output parser Supports `-w` and `-F` options. diff --git a/jc/parsers/ls.py b/jc/parsers/ls.py index fba2c2a4..226060de 100644 --- a/jc/parsers/ls.py +++ b/jc/parsers/ls.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ls` and `vdir` command output parser +"""jc - JSON Convert `ls` and `vdir` command output parser Options supported: - `lbaR1` diff --git a/jc/parsers/ls_s.py b/jc/parsers/ls_s.py index 0ca3261c..f59c1bd6 100644 --- a/jc/parsers/ls_s.py +++ b/jc/parsers/ls_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ls` and `vdir` command output streaming +"""jc - JSON Convert `ls` and `vdir` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/lsblk.py b/jc/parsers/lsblk.py index 45ddd844..4ee44d69 100644 --- a/jc/parsers/lsblk.py +++ b/jc/parsers/lsblk.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `lsblk` command output parser +"""jc - JSON Convert `lsblk` command output parser Usage (cli): diff --git a/jc/parsers/lsmod.py b/jc/parsers/lsmod.py index 26720e17..1342d5cd 100644 --- a/jc/parsers/lsmod.py +++ b/jc/parsers/lsmod.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `lsmod` command output parser +"""jc - JSON Convert `lsmod` command output parser Usage (cli): diff --git a/jc/parsers/lsof.py b/jc/parsers/lsof.py index 89c962d5..08804dd0 100644 --- a/jc/parsers/lsof.py +++ b/jc/parsers/lsof.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `lsof` command output parser +"""jc - JSON Convert `lsof` command output parser Usage (cli): diff --git a/jc/parsers/lsusb.py b/jc/parsers/lsusb.py index 87d2cc55..4650d60d 100644 --- a/jc/parsers/lsusb.py +++ b/jc/parsers/lsusb.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `lsusb` command output parser +"""jc - JSON Convert `lsusb` command output parser Supports the `-v` option or no options. diff --git a/jc/parsers/mount.py b/jc/parsers/mount.py index 25c7c48f..6b7fc095 100644 --- a/jc/parsers/mount.py +++ b/jc/parsers/mount.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `mount` command output parser +"""jc - JSON Convert `mount` command output parser Usage (cli): diff --git a/jc/parsers/netstat.py b/jc/parsers/netstat.py index e3e9d3b5..f417c241 100644 --- a/jc/parsers/netstat.py +++ b/jc/parsers/netstat.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `netstat` command output parser +"""jc - JSON Convert `netstat` command output parser Caveats: - Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`) diff --git a/jc/parsers/netstat_freebsd_osx.py b/jc/parsers/netstat_freebsd_osx.py index e593ad36..eb610ea8 100644 --- a/jc/parsers/netstat_freebsd_osx.py +++ b/jc/parsers/netstat_freebsd_osx.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility FreeBSD and OSX netstat Parser""" +"""jc - JSON Convert FreeBSD and OSX netstat Parser""" def normalize_headers(header): diff --git a/jc/parsers/netstat_linux.py b/jc/parsers/netstat_linux.py index ccafef9d..c43a61af 100644 --- a/jc/parsers/netstat_linux.py +++ b/jc/parsers/netstat_linux.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility Linux netstat Parser""" +"""jc - JSON Convert Linux netstat Parser""" import string diff --git a/jc/parsers/nmcli.py b/jc/parsers/nmcli.py new file mode 100644 index 00000000..e89516cd --- /dev/null +++ b/jc/parsers/nmcli.py @@ -0,0 +1,419 @@ +"""jc - JSON Convert `nmcli` command output parser + +Supports the following `nmcli` subcommands: +- `nmcli general` +- `nmcli general permissions` +- `nmcli connection` +- `nmcli connection show ` +- `nmcli device` +- `nmcli device show` +- `nmcli device show ` + +Usage (cli): + + $ nmcli device show lo | jc --nmcli + + or + + $ jc nmcli device show lo + +Usage (module): + + import jc + result = jc.parse('nmcli', nmcli_command_output) + + or + + import jc.parsers.nmcli + result = jc.parsers.nmcli.parse(nmcli_command_output) + +Schema: + + Because there are so many options, the schema is not strictly defined. + Integer and Float value conversions are attempted and the original + values are kept if they fail. If you don't want automatic conversion, + then use the -r or raw=True option to disable it. + + The structure is flat, for the most part, but there are a couple of + "well-known" keys that are further parsed into objects for convenience. + These are documented below. + + [ + { + "": string/integer/float, [0] + "dhcp4_option_x": { + "name": string, + "value": string/integer/float, + }, + "dhcp6_option_x": { + "name": string, + "value": string/integer/float, + }, + "ip4_route_x": { + "dst": string, + "nh": string, + "mt": integer + }, + "ip6_route_x": { + "dst": string, + "nh": string, + "mt": integer, + "table": integer + } + } + ] + + [0] all values of `---` are converted to null + +Examples: + + $ nmcli connection show ens33 | jc --nmcli -p + [ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + ... + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": 100 + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": 100 + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + ... + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": 100 + } + } + ] + + $ nmcli connection show ens33 | jc --nmcli -p -r + [ + { + "connection_id": "ens33", + "connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744", + "connection_stable_id": null, + "connection_type": "802-3-ethernet", + "connection_interface_name": "ens33", + "connection_autoconnect": "yes", + ... + "ip4_address_1": "192.168.71.180/24", + "ip4_gateway": "192.168.71.2", + "ip4_route_1": { + "dst": "0.0.0.0/0", + "nh": "192.168.71.2", + "mt": "100" + }, + "ip4_route_2": { + "dst": "192.168.71.0/24", + "nh": "0.0.0.0", + "mt": "100" + }, + "ip4_dns_1": "192.168.71.2", + "ip4_domain_1": "localdomain", + "dhcp4_option_1": { + "name": "broadcast_address", + "value": "192.168.71.255" + }, + ... + "ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64", + "ip6_gateway": null, + "ip6_route_1": { + "dst": "fe80::/64", + "nh": "::", + "mt": "100" + } + } + ] +""" +import re +from typing import List, Dict, Optional +import jc.utils +from jc.parsers.universal import sparse_table_parse +from jc.exceptions import ParseError + + +class info(): + """Provides parser metadata (version, author, etc.)""" + version = '1.0' + description = '`nmcli` command parser' + author = 'Kelly Brazil' + author_email = 'kellyjonbrazil@gmail.com' + compatible = ['linux'] + magic_commands = ['nmcli'] + + +__version__ = info.version + + +def _process(proc_data: List[Dict]) -> List[Dict]: + """ + Final processing to conform to the schema. + + Parameters: + + proc_data: (List of Dictionaries) raw structured data to process + + Returns: + + List of Dictionaries. Structured to conform to the schema. + """ + + for entry in proc_data: + for key in entry: + # use normal int/float conversions since jc.utils.convert_to_int is too greedy + try: + if '.' in entry[key]: + entry[key] = float(entry[key]) + else: + entry[key] = int(entry[key]) + except Exception: + pass + + if ('_option_' in key or '_route_' in key) and key[-1].isdigit(): + for k in entry[key]: + try: + if '.' in entry[key][k]: + entry[key][k] = float(entry[key][k]) + else: + entry[key][k] = int(entry[key][k]) + except Exception: + pass + + return proc_data + +def _normalize_key(keyname: str) -> str: + return keyname.replace(' ', '_')\ + .replace('.', '_')\ + .replace('[', '_')\ + .replace(']', '')\ + .replace('-', '_')\ + .replace('GENERAL_', '')\ + .lower() + +def _normalize_value(value: str) -> Optional[str]: + value = value.strip() + + if value == '--': + return None + + if value.startswith('"') and value.endswith('"'): + value = value.strip('"') + + return value + + +def _normalize_header(keyname: str) -> str: + return keyname.replace('.', '_')\ + .replace('[', '_')\ + .replace(']', ' ')\ + .replace('-', '_')\ + .lower() + + +def _add_text_kv(key: str, value: Optional[str]) -> Optional[Dict]: + """ + Add keys with _text suffix if there is a text description inside + paranthesis at the end of a value. The value of the _text field will + only be the text inside the parenthesis. This allows cleanup of the + original field (convert to int/float/etc) without losing information. + """ + if value and '(' in value and value.endswith(')'): + new_val = re.search(r'\((\w+)\)$', value) + if new_val: + return ({key + '_text': new_val.group(1)}) + + return None + + +def _remove_text_from_value(value: Optional[str]) -> Optional[str]: + """ + Remove the text summary part of a value. Used when an extra text + summary k/v pair are added. + """ + if value: + return re.sub(r"\s+\((\w+)\)$", '', value) + + return None + + +def _split_routes(value: str) -> Dict: + # dst = 192.168.71.0/24, nh = 0.0.0.0, mt = 100 + # dst = ff00::/8, nh = ::, mt = 256, table=255 + output_dict = {} + val_list = value.split(',') + for val in val_list: + k, v = val.split('=') + output_dict[k.strip()] = v.strip() + + return output_dict + + +def _split_options(value: str) -> Dict: + # ip_address = 192.168.71.180 + # requested_broadcast_address = 1 + output_dict = {} + k, v = value.split('=') + output_dict['name'] = k.strip() + output_dict['value'] = v.strip() + + return output_dict + + +def _device_show_parse(data: str) -> List[Dict]: + raw_output: List = [] + item: Dict = {} + current_item = '' + + for line in filter(None, data.splitlines()): + key, value = line.split(':', maxsplit=1) + key_n = _normalize_key(key) + value_n = _normalize_value(value) + + if item and 'device' in key_n and value_n != current_item: + raw_output.append(item) + item = {} + current_item = value + + item.update({key_n: value_n}) + + text_kv = _add_text_kv(key_n, value_n) + if text_kv: + item[key_n] = _remove_text_from_value(value_n) + item.update(text_kv) + + if '_option_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_options(item[key_n]) + + if '_route_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_routes(item[key_n]) + + # get final item + if item: + raw_output.append(item) + + return raw_output + + +def _connection_show_x_parse(data: str) -> List[Dict]: + raw_output: List = [] + item: Dict = {} + + for line in filter(None, data.splitlines()): + key, value = line.split(':', maxsplit=1) + + key_n = _normalize_key(key) + value_n = _normalize_value(value) + item.update({key_n: value_n}) + + text_kv = _add_text_kv(key_n, value_n) + if text_kv: + item[key_n] = _remove_text_from_value(value_n) + item.update(text_kv) + + if '_option_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_options(item[key_n]) + + if '_route_' in key_n and key_n[-1].isdigit(): + item[key_n] = _split_routes(item[key_n]) + + if item: + raw_output.append(item) + + return raw_output + + +def _general_permissions_parse(data: str) -> List[Dict]: + raw_output = [] + output_dict = {} + for line in filter(None, data.splitlines()): + key, value = line.split() + key_n = _normalize_key(key) + output_dict[key_n] = value + + output_dict.pop('permission') + raw_output.append(output_dict) + + return raw_output + + +def _table_parse(data: str) -> List[Dict]: + data_list = list(filter(None, data.splitlines())) + data_list[0] = _normalize_header(data_list[0]) + raw_output = sparse_table_parse(data_list) + + for item in raw_output: + for key in item: + item[key] = _normalize_value(item[key]) + + return raw_output + + +def parse( + data: str, + raw: bool = False, + quiet: bool = False +) -> List[Dict]: + """ + Main text parsing function + + Parameters: + + data: (string) text data to parse + raw: (boolean) unprocessed output if True + quiet: (boolean) suppress warning messages if True + + Returns: + + List of Dictionaries. Raw or processed structured data. + """ + jc.utils.compatibility(__name__, info.compatible, quiet) + jc.utils.input_type_check(data) + + raw_output: List = [] + + if jc.utils.has_data(data): + + # nmcli (second line startswith \t) + if data.splitlines()[1].startswith('\t'): + raise ParseError('Use the device, connection, or general subcommand in nmcli.') + + # nmcli device show + # nmcli device show lo + elif data.startswith('GENERAL.DEVICE'): + raw_output = _device_show_parse(data) + + # nmcli connection show lo + elif data.startswith('connection.id:'): + raw_output = _connection_show_x_parse(data) + + # nmcli general permissions (k/v pairs) + elif data.startswith('PERMISSION '): + raw_output = _general_permissions_parse(data) + + # nmcli general + # nmcli connection + # nmcli device + else: + raw_output = _table_parse(data) + + return raw_output if raw else _process(raw_output) diff --git a/jc/parsers/ntpq.py b/jc/parsers/ntpq.py index f4eb7468..e8e474a6 100644 --- a/jc/parsers/ntpq.py +++ b/jc/parsers/ntpq.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ntpq -p` command output parser +"""jc - JSON Convert `ntpq -p` command output parser Usage (cli): diff --git a/jc/parsers/passwd.py b/jc/parsers/passwd.py index 9be3b867..6281fc5d 100644 --- a/jc/parsers/passwd.py +++ b/jc/parsers/passwd.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/passwd` file Parser +"""jc - JSON Convert `/etc/passwd` file Parser Usage (cli): diff --git a/jc/parsers/ping.py b/jc/parsers/ping.py index 70e05465..0758045b 100644 --- a/jc/parsers/ping.py +++ b/jc/parsers/ping.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ping` command output parser +"""jc - JSON Convert `ping` command output parser Supports `ping` and `ping6` output. diff --git a/jc/parsers/ping_s.py b/jc/parsers/ping_s.py index ab80d11b..34ce7369 100644 --- a/jc/parsers/ping_s.py +++ b/jc/parsers/ping_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ping` command output streaming parser +"""jc - JSON Convert `ping` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/pip_list.py b/jc/parsers/pip_list.py index a429d468..00f5d310 100644 --- a/jc/parsers/pip_list.py +++ b/jc/parsers/pip_list.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `pip-list` command output parser +"""jc - JSON Convert `pip-list` command output parser Usage (cli): diff --git a/jc/parsers/pip_show.py b/jc/parsers/pip_show.py index 38142d6c..f465c26a 100644 --- a/jc/parsers/pip_show.py +++ b/jc/parsers/pip_show.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `pip-show` command output parser +"""jc - JSON Convert `pip-show` command output parser Usage (cli): diff --git a/jc/parsers/ps.py b/jc/parsers/ps.py index 99a68c6d..06e7c7fa 100644 --- a/jc/parsers/ps.py +++ b/jc/parsers/ps.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ps` command output parser +"""jc - JSON Convert `ps` command output parser `ps` options supported: - `ef` diff --git a/jc/parsers/route.py b/jc/parsers/route.py index 3a5178bc..7eb07872 100644 --- a/jc/parsers/route.py +++ b/jc/parsers/route.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `route` command output parser +"""jc - JSON Convert `route` command output parser Usage (cli): diff --git a/jc/parsers/rpm_qi.py b/jc/parsers/rpm_qi.py index 2a6a81dd..52e42d74 100644 --- a/jc/parsers/rpm_qi.py +++ b/jc/parsers/rpm_qi.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `rpm -qi` command output parser +"""jc - JSON Convert `rpm -qi` command output parser Works with `rpm -qi [package]` or `rpm -qia`. diff --git a/jc/parsers/rsync.py b/jc/parsers/rsync.py index 8b56761a..eadfa495 100644 --- a/jc/parsers/rsync.py +++ b/jc/parsers/rsync.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `rsync` command output parser +"""jc - JSON Convert `rsync` command output parser Supports the `-i` or `--itemize-changes` options with all levels of verbosity. This parser will process the STDOUT output or a log file diff --git a/jc/parsers/rsync_s.py b/jc/parsers/rsync_s.py index 6a73c2ba..94b874e3 100644 --- a/jc/parsers/rsync_s.py +++ b/jc/parsers/rsync_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `rsync` command output streaming parser +"""jc - JSON Convert `rsync` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/sfdisk.py b/jc/parsers/sfdisk.py index d5f4ac88..9900b60b 100644 --- a/jc/parsers/sfdisk.py +++ b/jc/parsers/sfdisk.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `sfdisk` command output parser +"""jc - JSON Convert `sfdisk` command output parser Supports the following `sfdisk` options: - `-l` diff --git a/jc/parsers/shadow.py b/jc/parsers/shadow.py index 00427a37..ad1ae570 100644 --- a/jc/parsers/shadow.py +++ b/jc/parsers/shadow.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/etc/shadow` file parser +"""jc - JSON Convert `/etc/shadow` file parser Usage (cli): diff --git a/jc/parsers/ss.py b/jc/parsers/ss.py index 0416f097..10bd69dc 100644 --- a/jc/parsers/ss.py +++ b/jc/parsers/ss.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ss` command output parser +"""jc - JSON Convert `ss` command output parser Extended information options like -e and -p are not supported and may cause parsing irregularities. diff --git a/jc/parsers/stat.py b/jc/parsers/stat.py index af6bbd33..ca58789d 100644 --- a/jc/parsers/stat.py +++ b/jc/parsers/stat.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `stat` command output parser +"""jc - JSON Convert `stat` command output parser The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/stat_s.py b/jc/parsers/stat_s.py index e58759b8..3b302e38 100644 --- a/jc/parsers/stat_s.py +++ b/jc/parsers/stat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `stat` command output streaming parser +"""jc - JSON Convert `stat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/sysctl.py b/jc/parsers/sysctl.py index 388c0fb9..022546b1 100644 --- a/jc/parsers/sysctl.py +++ b/jc/parsers/sysctl.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `sysctl -a` command output parser +"""jc - JSON Convert `sysctl -a` command output parser Note: Since `sysctl` output is not easily parsable only a very simple key/value object will be output. An attempt is made to convert obvious diff --git a/jc/parsers/systemctl.py b/jc/parsers/systemctl.py index 58cbe8d0..47136e15 100644 --- a/jc/parsers/systemctl.py +++ b/jc/parsers/systemctl.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systemctl` command output parser +"""jc - JSON Convert `systemctl` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_lj.py b/jc/parsers/systemctl_lj.py index f078b20b..a6ccd5fd 100644 --- a/jc/parsers/systemctl_lj.py +++ b/jc/parsers/systemctl_lj.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systemctl list-jobs` command output parser +"""jc - JSON Convert `systemctl list-jobs` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_ls.py b/jc/parsers/systemctl_ls.py index 0b7302c9..670986d5 100644 --- a/jc/parsers/systemctl_ls.py +++ b/jc/parsers/systemctl_ls.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systemctl list-sockets` command output +"""jc - JSON Convert `systemctl list-sockets` command output parser Usage (cli): diff --git a/jc/parsers/systemctl_luf.py b/jc/parsers/systemctl_luf.py index 9eb91035..8fd540e8 100644 --- a/jc/parsers/systemctl_luf.py +++ b/jc/parsers/systemctl_luf.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systemctl list-unit-files` command output +"""jc - JSON Convert `systemctl list-unit-files` command output parser Usage (cli): diff --git a/jc/parsers/systeminfo.py b/jc/parsers/systeminfo.py index dfcd1ba8..85222662 100644 --- a/jc/parsers/systeminfo.py +++ b/jc/parsers/systeminfo.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `systeminfo` command output parser +"""jc - JSON Convert `systeminfo` command output parser Blank or missing elements are set to `null`. diff --git a/jc/parsers/time.py b/jc/parsers/time.py index c09b5c45..74b9ce56 100644 --- a/jc/parsers/time.py +++ b/jc/parsers/time.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `/usr/bin/time` command output parser +"""jc - JSON Convert `/usr/bin/time` command output parser Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be used to redirect the output to a file that can be read by `jc`. diff --git a/jc/parsers/timedatectl.py b/jc/parsers/timedatectl.py index 5a5d670a..e4957c69 100644 --- a/jc/parsers/timedatectl.py +++ b/jc/parsers/timedatectl.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `timedatectl` command output parser +"""jc - JSON Convert `timedatectl` command output parser The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the `universal_time` field is available. diff --git a/jc/parsers/tracepath.py b/jc/parsers/tracepath.py index 5a4458ed..2e0396a0 100644 --- a/jc/parsers/tracepath.py +++ b/jc/parsers/tracepath.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `tracepath` command output parser +"""jc - JSON Convert `tracepath` command output parser Supports `tracepath` and `tracepath6` output. diff --git a/jc/parsers/traceroute.py b/jc/parsers/traceroute.py index 5df5e70a..aa11b5a1 100644 --- a/jc/parsers/traceroute.py +++ b/jc/parsers/traceroute.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `traceroute` command output parser +"""jc - JSON Convert `traceroute` command output parser Supports `traceroute` and `traceroute6` output. diff --git a/jc/parsers/ufw.py b/jc/parsers/ufw.py index 58bedd57..cb0a8f39 100644 --- a/jc/parsers/ufw.py +++ b/jc/parsers/ufw.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ufw status` command output parser +"""jc - JSON Convert `ufw status` command output parser Usage (cli): diff --git a/jc/parsers/ufw_appinfo.py b/jc/parsers/ufw_appinfo.py index ec3e78ef..04524653 100644 --- a/jc/parsers/ufw_appinfo.py +++ b/jc/parsers/ufw_appinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `ufw app info [application]` command +"""jc - JSON Convert `ufw app info [application]` command output parser Supports individual apps via `ufw app info [application]` and all apps list diff --git a/jc/parsers/uname.py b/jc/parsers/uname.py index 3f8538a6..7260803f 100644 --- a/jc/parsers/uname.py +++ b/jc/parsers/uname.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `uname -a` command output parser +"""jc - JSON Convert `uname -a` command output parser Note: Must use `uname -a` diff --git a/jc/parsers/universal.py b/jc/parsers/universal.py index b1de1ca4..5fe253a4 100644 --- a/jc/parsers/universal.py +++ b/jc/parsers/universal.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility universal Parsers""" +"""jc - JSON Convert universal parsers""" import string diff --git a/jc/parsers/upower.py b/jc/parsers/upower.py index b6508231..7dd511a3 100644 --- a/jc/parsers/upower.py +++ b/jc/parsers/upower.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `upower` command output parser +"""jc - JSON Convert `upower` command output parser The `updated_epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on) diff --git a/jc/parsers/uptime.py b/jc/parsers/uptime.py index 9b433dcc..486f8799 100644 --- a/jc/parsers/uptime.py +++ b/jc/parsers/uptime.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `uptime` command output parser +"""jc - JSON Convert `uptime` command output parser Usage (cli): diff --git a/jc/parsers/vmstat.py b/jc/parsers/vmstat.py index f39a5b71..8b31acdd 100644 --- a/jc/parsers/vmstat.py +++ b/jc/parsers/vmstat.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `vmstat` command output parser +"""jc - JSON Convert `vmstat` command output parser Options supported: `-a`, `-w`, `-d`, `-t` diff --git a/jc/parsers/vmstat_s.py b/jc/parsers/vmstat_s.py index 3a0d0921..5e2899ea 100644 --- a/jc/parsers/vmstat_s.py +++ b/jc/parsers/vmstat_s.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `vmstat` command output streaming parser +"""jc - JSON Convert `vmstat` command output streaming parser > This streaming parser outputs JSON Lines diff --git a/jc/parsers/w.py b/jc/parsers/w.py index 386bd066..7ce640c8 100644 --- a/jc/parsers/w.py +++ b/jc/parsers/w.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `w` command output parser +"""jc - JSON Convert `w` command output parser Usage (cli): diff --git a/jc/parsers/wc.py b/jc/parsers/wc.py index ce10b46e..eb1def49 100644 --- a/jc/parsers/wc.py +++ b/jc/parsers/wc.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `wc` command output parser +"""jc - JSON Convert `wc` command output parser Usage (cli): diff --git a/jc/parsers/who.py b/jc/parsers/who.py index c66d4003..c3655bfc 100644 --- a/jc/parsers/who.py +++ b/jc/parsers/who.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `who` command output parser +"""jc - JSON Convert `who` command output parser Accepts any of the following who options (or no options): `-aTH` diff --git a/jc/parsers/xml.py b/jc/parsers/xml.py index 3100f586..9eda8d53 100644 --- a/jc/parsers/xml.py +++ b/jc/parsers/xml.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `XML` file parser +"""jc - JSON Convert `XML` file parser Usage (cli): diff --git a/jc/parsers/xrandr.py b/jc/parsers/xrandr.py index a2c94271..c2f5ed66 100644 --- a/jc/parsers/xrandr.py +++ b/jc/parsers/xrandr.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `xrandr` command output parser +"""jc - JSON Convert `xrandr` command output parser Usage (cli): @@ -288,7 +288,7 @@ def _parse_device(next_lines: List[str], quiet: bool = False) -> Optional[Device device[k] = int(v) except ValueError and not quiet: jc.utils.warning_message( - [f"Error: {next_line} : {k} - {v} is not int-able"] + [f"{next_line} : {k} - {v} is not int-able"] ) while next_lines: diff --git a/jc/parsers/yaml.py b/jc/parsers/yaml.py index f8c085cd..a8e815fd 100644 --- a/jc/parsers/yaml.py +++ b/jc/parsers/yaml.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `YAML` file parser +"""jc - JSON Convert `YAML` file parser Usage (cli): diff --git a/jc/parsers/zipinfo.py b/jc/parsers/zipinfo.py index 9ab7912b..d06ae365 100644 --- a/jc/parsers/zipinfo.py +++ b/jc/parsers/zipinfo.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility `zipinfo` command output parser +"""jc - JSON Convert `zipinfo` command output parser Options supported: - none @@ -85,7 +85,7 @@ import jc.parsers.universal class info(): """Provides parser metadata (version, author, etc.)""" - version = '0.01' + version = '1.0' description = '`zipinfo` command parser' author = 'Matt J' author_email = 'https://github.com/listuser' diff --git a/jc/streaming.py b/jc/streaming.py index 0e6dbc80..208e0687 100644 --- a/jc/streaming.py +++ b/jc/streaming.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility streaming utils""" +"""jc - JSON Convert streaming utils""" from functools import wraps from typing import Dict, Iterable diff --git a/jc/utils.py b/jc/utils.py index e30fe519..678f824a 100644 --- a/jc/utils.py +++ b/jc/utils.py @@ -1,4 +1,4 @@ -"""jc - JSON CLI output utility utils""" +"""jc - JSON Convert utils""" import sys import re import locale diff --git a/man/jc.1 b/man/jc.1 index 1151b676..cabf84e9 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2022-02-14 1.18.3 "JSON CLI output utility" +.TH jc 1 2022-03-05 1.18.4 "JSON Convert" .SH NAME jc \- JSONifies the output of many CLI tools and file-types .SH SYNOPSIS @@ -257,6 +257,11 @@ Key/Value file parser \fB--netstat\fP `netstat` command parser +.TP +.B +\fB--nmcli\fP +`nmcli` command parser + .TP .B \fB--ntpq\fP @@ -558,34 +563,28 @@ You may want to ignore parsing errors when using streaming parsers since these m .RS Successfully parsed line with \fB-qq\fP option: .RS +.na +.nf { - "command_data": "data", - "_jc_meta": { - "success": true - } - } .RE Unsuccessfully parsed line with \fB-qq\fP option: .RS +.na +.nf { - "_jc_meta": { - "success": false, - "error": "error message", - "line": "original line data" - } - } +.fi .RE .RE @@ -594,21 +593,23 @@ Unsuccessfully parsed line with \fB-qq\fP option: Most operating systems will buffer output that is being piped from process to process. The buffer is usually around 4KB. When viewing the output in the terminal the OS buffer is not engaged so output is immediately displayed on the screen. When piping multiple processes together, though, it may seem as if the output is hanging when the input data is very slow (e.g. \fBping\fP): .RS +.na +.nf $ ping 1.1.1.1 | jc --ping-s | jq - +.fi .RE This is because the OS engages the 4KB buffer between \fBjc\fP and \fBjq\fP in this example. To display the data on the terminal in realtime, you can disable the buffer with the \fB-u\fP (unbuffer) cli option: .RS +.na +.nf $ ping 1.1.1.1 | jc --ping-s -u | jq - -{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"1","ttl":"128","time_ms":"24.6","duplicate":false} - -{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"2","ttl":"128","time_ms":"26.8","duplicate":false} - +{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} +{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} etc... +.fi Note: Unbuffered output can be slower for large data streams. .RE diff --git a/setup.py b/setup.py index d0c112fa..72ba44ed 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='1.18.3', + version='1.18.4', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='Converts the output of popular command-line tools and file-types to JSON.', diff --git a/templates/manpage_template b/templates/manpage_template index cb9cfef2..fe1bc4fc 100644 --- a/templates/manpage_template +++ b/templates/manpage_template @@ -1,4 +1,4 @@ -.TH jc 1 {{ today }} {{ jc.version}} "JSON CLI output utility" +.TH jc 1 {{ today }} {{ jc.version}} "JSON Convert" .SH NAME jc \- JSONifies the output of many CLI tools and file-types .SH SYNOPSIS @@ -123,34 +123,28 @@ You may want to ignore parsing errors when using streaming parsers since these m .RS Successfully parsed line with \fB-qq\fP option: .RS +.na +.nf { - "command_data": "data", - "_jc_meta": { - "success": true - } - } .RE Unsuccessfully parsed line with \fB-qq\fP option: .RS +.na +.nf { - "_jc_meta": { - "success": false, - "error": "error message", - "line": "original line data" - } - } +.fi .RE .RE @@ -159,21 +153,23 @@ Unsuccessfully parsed line with \fB-qq\fP option: Most operating systems will buffer output that is being piped from process to process. The buffer is usually around 4KB. When viewing the output in the terminal the OS buffer is not engaged so output is immediately displayed on the screen. When piping multiple processes together, though, it may seem as if the output is hanging when the input data is very slow (e.g. \fBping\fP): .RS +.na +.nf $ ping 1.1.1.1 | jc --ping-s | jq - +.fi .RE This is because the OS engages the 4KB buffer between \fBjc\fP and \fBjq\fP in this example. To display the data on the terminal in realtime, you can disable the buffer with the \fB-u\fP (unbuffer) cli option: .RS +.na +.nf $ ping 1.1.1.1 | jc --ping-s -u | jq - -{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"1","ttl":"128","time_ms":"24.6","duplicate":false} - -{"type":"reply","pattern":null,"timestamp":null,"bytes":"64","response_ip":"1.1.1.1","icmp_seq":"2","ttl":"128","time_ms":"26.8","duplicate":false} - +{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} +{"type":"reply","pattern":null,"timestamp":null,"bytes":"64",...} etc... +.fi Note: Unbuffered output can be slower for large data streams. .RE diff --git a/templates/readme_template b/templates/readme_template index d7873222..286ca343 100644 --- a/templates/readme_template +++ b/templates/readme_template @@ -1,8 +1,6 @@ ![Tests](https://github.com/kellyjonbrazil/jc/workflows/Tests/badge.svg?branch=master) ![Pypi](https://img.shields.io/pypi/v/jc.svg) -> `jc` was recently featured in the [Console Open Source Newsletter](https://console.substack.com/p/console-89) - > Check out the `jc` Python [package documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs) for developers > Try the `jc` [web demo](https://jc-web-demo.herokuapp.com/) @@ -13,7 +11,7 @@ Ansible filter plugin in the `community.general` collection. See this for an example. # JC -JSON CLI output utility +JSON Convert `jc` JSONifies the output of many CLI tools and file-types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and @@ -55,16 +53,9 @@ will be a python dictionary, or list of dictionaries, instead of JSON: >>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) >>> data = jc.parse('dig', cmd_output) >>> ->>> data -[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', -'ra'], 'query_num': 1, 'answer_num': 1, 'authority_num': 0, 'additional_num': -1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp': 4096}}, -'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': +>>> data[0]['answer'] [{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': -'93.184.216.34'}], 'query_time': 52, 'server': -'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': -'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56, 'when_epoch': 1618614780, -'when_epoch_utc': None}] +'93.184.216.34'}] ``` > For `jc` Python package documentation, use `help('jc')`, `help('jc.lib')`, or diff --git a/tests/fixtures/centos-7.7/nmcli-connection-all.json b/tests/fixtures/centos-7.7/nmcli-connection-all.json new file mode 100644 index 00000000..df986a93 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection-all.json @@ -0,0 +1 @@ +[{"name":"ens33","uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","type":"ethernet","timestamp":1645643581,"timestamp_real":"Wed 23 Feb 2022 11:13:01 AM PST","autoconnect":"yes","autoconnect_priority":0,"readonly":"no","dbus_path":"/org/freedesktop/NetworkManager/Settings/1","active":"yes","device":"ens33","state":"activated","active_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","slave":null,"filename":"/etc/sysconfig/network-scripts/ifcfg-ens33"}] diff --git a/tests/fixtures/centos-7.7/nmcli-connection-all.out b/tests/fixtures/centos-7.7/nmcli-connection-all.out new file mode 100644 index 00000000..e2b771e0 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection-all.out @@ -0,0 +1,3 @@ +NAME UUID TYPE TIMESTAMP TIMESTAMP-REAL AUTOCONNECT AUTOCONNECT-PRIORITY READONLY DBUS-PATH ACTIVE DEVICE STATE ACTIVE-PATH SLAVE FILENAME +ens33 d92ece08-9e02-47d5-b2d2-92c80e155744 ethernet 1645643581 Wed 23 Feb 2022 11:13:01 AM PST yes 0 no /org/freedesktop/NetworkManager/Settings/1 yes ens33 activated /org/freedesktop/NetworkManager/ActiveConnection/1 -- /etc/sysconfig/network-scripts/ifcfg-ens33 + diff --git a/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json b/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json new file mode 100644 index 00000000..cb2058f7 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json @@ -0,0 +1 @@ +[{"connection_id":"ens33","connection_uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","connection_stable_id":null,"connection_type":"802-3-ethernet","connection_interface_name":"ens33","connection_autoconnect":"yes","connection_autoconnect_priority":0,"connection_autoconnect_retries":-1,"connection_autoconnect_retries_text":"default","connection_multi_connect":0,"connection_multi_connect_text":"default","connection_auth_retries":-1,"connection_timestamp":1645570618,"connection_read_only":"no","connection_permissions":null,"connection_zone":null,"connection_master":null,"connection_slave_type":null,"connection_autoconnect_slaves":-1,"connection_autoconnect_slaves_text":"default","connection_secondaries":null,"connection_gateway_ping_timeout":0,"connection_metered":"unknown","connection_lldp":"default","connection_mdns":-1,"connection_mdns_text":"default","connection_llmnr":-1,"connection_llmnr_text":"default","802_3_ethernet_port":null,"802_3_ethernet_speed":0,"802_3_ethernet_duplex":null,"802_3_ethernet_auto_negotiate":"no","802_3_ethernet_mac_address":null,"802_3_ethernet_cloned_mac_address":null,"802_3_ethernet_generate_mac_address_mask":null,"802_3_ethernet_mac_address_blacklist":null,"802_3_ethernet_mtu":"auto","802_3_ethernet_s390_subchannels":null,"802_3_ethernet_s390_nettype":null,"802_3_ethernet_s390_options":null,"802_3_ethernet_wake_on_lan":"default","802_3_ethernet_wake_on_lan_password":null,"ipv4_method":"auto","ipv4_dns":null,"ipv4_dns_search":null,"ipv4_dns_options":"","ipv4_dns_priority":0,"ipv4_addresses":null,"ipv4_gateway":null,"ipv4_routes":null,"ipv4_route_metric":-1,"ipv4_route_table":0,"ipv4_route_table_text":"unspec","ipv4_routing_rules":null,"ipv4_ignore_auto_routes":"no","ipv4_ignore_auto_dns":"no","ipv4_dhcp_client_id":null,"ipv4_dhcp_timeout":0,"ipv4_dhcp_timeout_text":"default","ipv4_dhcp_send_hostname":"yes","ipv4_dhcp_hostname":null,"ipv4_dhcp_fqdn":null,"ipv4_never_default":"no","ipv4_may_fail":"yes","ipv4_dad_timeout":-1,"ipv4_dad_timeout_text":"default","ipv6_method":"auto","ipv6_dns":null,"ipv6_dns_search":null,"ipv6_dns_options":"","ipv6_dns_priority":0,"ipv6_addresses":null,"ipv6_gateway":null,"ipv6_routes":null,"ipv6_route_metric":-1,"ipv6_route_table":0,"ipv6_route_table_text":"unspec","ipv6_routing_rules":null,"ipv6_ignore_auto_routes":"no","ipv6_ignore_auto_dns":"no","ipv6_never_default":"no","ipv6_may_fail":"yes","ipv6_ip6_privacy":-1,"ipv6_ip6_privacy_text":"unknown","ipv6_addr_gen_mode":"stable-privacy","ipv6_dhcp_duid":null,"ipv6_dhcp_send_hostname":"yes","ipv6_dhcp_hostname":null,"ipv6_token":null,"proxy_method":"none","proxy_browser_only":"no","proxy_pac_url":null,"proxy_pac_script":null,"name":"ens33","uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","devices":"ens33","state":"activated","default":"yes","default6":"no","spec_object":null,"vpn":"no","dbus_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","con_path":"/org/freedesktop/NetworkManager/Settings/1","zone":null,"master_path":null,"ip4_address_1":"192.168.71.180/24","ip4_gateway":"192.168.71.2","ip4_route_1":{"dst":"0.0.0.0/0","nh":"192.168.71.2","mt":100},"ip4_route_2":{"dst":"192.168.71.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"192.168.71.2","ip4_domain_1":"localdomain","dhcp4_option_1":{"name":"broadcast_address","value":"192.168.71.255"},"dhcp4_option_2":{"name":"dhcp_lease_time","value":1800},"dhcp4_option_3":{"name":"dhcp_message_type","value":5},"dhcp4_option_4":{"name":"dhcp_server_identifier","value":"192.168.71.254"},"dhcp4_option_5":{"name":"domain_name","value":"localdomain"},"dhcp4_option_6":{"name":"domain_name_servers","value":"192.168.71.2"},"dhcp4_option_7":{"name":"expiry","value":1645572241},"dhcp4_option_8":{"name":"ip_address","value":"192.168.71.180"},"dhcp4_option_9":{"name":"network_number","value":"192.168.71.0"},"dhcp4_option_10":{"name":"next_server","value":"192.168.71.254"},"dhcp4_option_11":{"name":"requested_broadcast_address","value":1},"dhcp4_option_12":{"name":"requested_classless_static_routes","value":1},"dhcp4_option_13":{"name":"requested_domain_name","value":1},"dhcp4_option_14":{"name":"requested_domain_name_servers","value":1},"dhcp4_option_15":{"name":"requested_domain_search","value":1},"dhcp4_option_16":{"name":"requested_host_name","value":1},"dhcp4_option_17":{"name":"requested_interface_mtu","value":1},"dhcp4_option_18":{"name":"requested_ms_classless_static_routes","value":1},"dhcp4_option_19":{"name":"requested_nis_domain","value":1},"dhcp4_option_20":{"name":"requested_nis_servers","value":1},"dhcp4_option_21":{"name":"requested_ntp_servers","value":1},"dhcp4_option_22":{"name":"requested_rfc3442_classless_static_routes","value":1},"dhcp4_option_23":{"name":"requested_root_path","value":1},"dhcp4_option_24":{"name":"requested_routers","value":1},"dhcp4_option_25":{"name":"requested_static_routes","value":1},"dhcp4_option_26":{"name":"requested_subnet_mask","value":1},"dhcp4_option_27":{"name":"requested_time_offset","value":1},"dhcp4_option_28":{"name":"requested_wpad","value":1},"dhcp4_option_29":{"name":"routers","value":"192.168.71.2"},"dhcp4_option_30":{"name":"subnet_mask","value":"255.255.255.0"},"ip6_address_1":"fe80::c1cb:715d:bc3e:b8a0/64","ip6_gateway":null,"ip6_route_1":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_2":{"dst":"ff00::/8","nh":"::","mt":256,"table":255}}] diff --git a/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out b/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out new file mode 100644 index 00000000..868e8c0f --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out @@ -0,0 +1,136 @@ +connection.id: ens33 +connection.uuid: d92ece08-9e02-47d5-b2d2-92c80e155744 +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: ens33 +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.multi-connect: 0 (default) +connection.auth-retries: -1 +connection.timestamp: 1645570618 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +connection.llmnr: -1 (default) +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: "" +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.routing-rules: -- +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: "" +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.routing-rules: -- +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.dhcp-duid: -- +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ens33 +GENERAL.UUID: d92ece08-9e02-47d5-b2d2-92c80e155744 +GENERAL.DEVICES: ens33 +GENERAL.STATE: activated +GENERAL.DEFAULT: yes +GENERAL.DEFAULT6: no +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/1 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- +IP4.ADDRESS[1]: 192.168.71.180/24 +IP4.GATEWAY: 192.168.71.2 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.71.2, mt = 100 +IP4.ROUTE[2]: dst = 192.168.71.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 192.168.71.2 +IP4.DOMAIN[1]: localdomain +DHCP4.OPTION[1]: broadcast_address = 192.168.71.255 +DHCP4.OPTION[2]: dhcp_lease_time = 1800 +DHCP4.OPTION[3]: dhcp_message_type = 5 +DHCP4.OPTION[4]: dhcp_server_identifier = 192.168.71.254 +DHCP4.OPTION[5]: domain_name = localdomain +DHCP4.OPTION[6]: domain_name_servers = 192.168.71.2 +DHCP4.OPTION[7]: expiry = 1645572241 +DHCP4.OPTION[8]: ip_address = 192.168.71.180 +DHCP4.OPTION[9]: network_number = 192.168.71.0 +DHCP4.OPTION[10]: next_server = 192.168.71.254 +DHCP4.OPTION[11]: requested_broadcast_address = 1 +DHCP4.OPTION[12]: requested_classless_static_routes = 1 +DHCP4.OPTION[13]: requested_domain_name = 1 +DHCP4.OPTION[14]: requested_domain_name_servers = 1 +DHCP4.OPTION[15]: requested_domain_search = 1 +DHCP4.OPTION[16]: requested_host_name = 1 +DHCP4.OPTION[17]: requested_interface_mtu = 1 +DHCP4.OPTION[18]: requested_ms_classless_static_routes = 1 +DHCP4.OPTION[19]: requested_nis_domain = 1 +DHCP4.OPTION[20]: requested_nis_servers = 1 +DHCP4.OPTION[21]: requested_ntp_servers = 1 +DHCP4.OPTION[22]: requested_rfc3442_classless_static_routes = 1 +DHCP4.OPTION[23]: requested_root_path = 1 +DHCP4.OPTION[24]: requested_routers = 1 +DHCP4.OPTION[25]: requested_static_routes = 1 +DHCP4.OPTION[26]: requested_subnet_mask = 1 +DHCP4.OPTION[27]: requested_time_offset = 1 +DHCP4.OPTION[28]: requested_wpad = 1 +DHCP4.OPTION[29]: routers = 192.168.71.2 +DHCP4.OPTION[30]: subnet_mask = 255.255.255.0 +IP6.ADDRESS[1]: fe80::c1cb:715d:bc3e:b8a0/64 +IP6.GATEWAY: -- +IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255 + diff --git a/tests/fixtures/centos-7.7/nmcli-connection.json b/tests/fixtures/centos-7.7/nmcli-connection.json new file mode 100644 index 00000000..823ebaa3 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection.json @@ -0,0 +1 @@ +[{"name":"ens33","uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","type":"ethernet","device":"ens33"}] diff --git a/tests/fixtures/centos-7.7/nmcli-connection.out b/tests/fixtures/centos-7.7/nmcli-connection.out new file mode 100644 index 00000000..c1b5bf7c --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-connection.out @@ -0,0 +1,3 @@ +NAME UUID TYPE DEVICE +ens33 d92ece08-9e02-47d5-b2d2-92c80e155744 ethernet ens33 + diff --git a/tests/fixtures/centos-7.7/nmcli-device-all.json b/tests/fixtures/centos-7.7/nmcli-device-all.json new file mode 100644 index 00000000..482d2116 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-all.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","state":"connected","ip4_connectivity":"full","ip6_connectivity":"full","dbus_path":"/org/freedesktop/NetworkManager/Devices/2","connection":"ens33","con_uuid":"d92ece08-9e02-47d5-b2d2-92c80e155744","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1"},{"device":"docker0","type":"bridge","state":"unmanaged","ip4_connectivity":"unknown","ip6_connectivity":"unknown","dbus_path":"/org/freedesktop/NetworkManager/Devices/3","connection":null,"con_uuid":null,"con_path":null},{"device":"lo","type":"loopback","state":"unmanaged","ip4_connectivity":"unknown","ip6_connectivity":"unknown","dbus_path":"/org/freedesktop/NetworkManager/Devices/1","connection":null,"con_uuid":null,"con_path":null}] diff --git a/tests/fixtures/centos-7.7/nmcli-device-all.out b/tests/fixtures/centos-7.7/nmcli-device-all.out new file mode 100644 index 00000000..2884f28f --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-all.out @@ -0,0 +1,5 @@ +DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH +ens33 ethernet connected full full /org/freedesktop/NetworkManager/Devices/2 ens33 d92ece08-9e02-47d5-b2d2-92c80e155744 /org/freedesktop/NetworkManager/ActiveConnection/1 +docker0 bridge unmanaged unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- -- +lo loopback unmanaged unknown unknown /org/freedesktop/NetworkManager/Devices/1 -- -- -- + diff --git a/tests/fixtures/centos-7.7/nmcli-device-show-ens33.json b/tests/fixtures/centos-7.7/nmcli-device-show-ens33.json new file mode 100644 index 00000000..9d3e6629 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show-ens33.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:3B:58:0E","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","wired_properties_carrier":"on","ip4_address_1":"192.168.71.180/24","ip4_gateway":"192.168.71.2","ip4_route_1":{"dst":"0.0.0.0/0","nh":"192.168.71.2","mt":100},"ip4_route_2":{"dst":"192.168.71.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"192.168.71.2","ip4_domain_1":"localdomain","ip6_address_1":"fe80::c1cb:715d:bc3e:b8a0/64","ip6_gateway":null,"ip6_route_1":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_2":{"dst":"ff00::/8","nh":"::","mt":256,"table":255}}] diff --git a/tests/fixtures/centos-7.7/nmcli-device-show-ens33.out b/tests/fixtures/centos-7.7/nmcli-device-show-ens33.out new file mode 100644 index 00000000..9ded86e8 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show-ens33.out @@ -0,0 +1,18 @@ +GENERAL.DEVICE: ens33 +GENERAL.TYPE: ethernet +GENERAL.HWADDR: 00:0C:29:3B:58:0E +GENERAL.MTU: 1500 +GENERAL.STATE: 100 (connected) +GENERAL.CONNECTION: ens33 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +WIRED-PROPERTIES.CARRIER: on +IP4.ADDRESS[1]: 192.168.71.180/24 +IP4.GATEWAY: 192.168.71.2 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.71.2, mt = 100 +IP4.ROUTE[2]: dst = 192.168.71.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 192.168.71.2 +IP4.DOMAIN[1]: localdomain +IP6.ADDRESS[1]: fe80::c1cb:715d:bc3e:b8a0/64 +IP6.GATEWAY: -- +IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255 diff --git a/tests/fixtures/centos-7.7/nmcli-device-show-lo.json b/tests/fixtures/centos-7.7/nmcli-device-show-lo.json new file mode 100644 index 00000000..b18607db --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show-lo.json @@ -0,0 +1 @@ +[{"device":"lo","type":"loopback","hwaddr":"00:00:00:00:00:00","mtu":65536,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"127.0.0.1/8","ip4_gateway":null,"ip6_address_1":"::1/128","ip6_gateway":null}] diff --git a/tests/fixtures/centos-7.7/nmcli-device-show-lo.out b/tests/fixtures/centos-7.7/nmcli-device-show-lo.out new file mode 100644 index 00000000..4214f760 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show-lo.out @@ -0,0 +1,12 @@ +GENERAL.DEVICE: lo +GENERAL.TYPE: loopback +GENERAL.HWADDR: 00:00:00:00:00:00 +GENERAL.MTU: 65536 +GENERAL.STATE: 10 (unmanaged) +GENERAL.CONNECTION: -- +GENERAL.CON-PATH: -- +IP4.ADDRESS[1]: 127.0.0.1/8 +IP4.GATEWAY: -- +IP6.ADDRESS[1]: ::1/128 +IP6.GATEWAY: -- + diff --git a/tests/fixtures/centos-7.7/nmcli-device-show.json b/tests/fixtures/centos-7.7/nmcli-device-show.json new file mode 100644 index 00000000..78b87947 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:3B:58:0E","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/1","wired_properties_carrier":"on","ip4_address_1":"192.168.71.180/24","ip4_gateway":"192.168.71.2","ip4_route_1":{"dst":"0.0.0.0/0","nh":"192.168.71.2","mt":100},"ip4_route_2":{"dst":"192.168.71.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"192.168.71.2","ip4_domain_1":"localdomain","ip6_address_1":"fe80::c1cb:715d:bc3e:b8a0/64","ip6_gateway":null,"ip6_route_1":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_2":{"dst":"ff00::/8","nh":"::","mt":256,"table":255}},{"device":"docker0","type":"bridge","hwaddr":"02:42:99:67:E8:21","mtu":1500,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"172.17.0.1/16","ip4_gateway":null,"ip4_route_1":{"dst":"172.17.0.0/16","nh":"0.0.0.0","mt":0},"ip6_gateway":null},{"device":"lo","type":"loopback","hwaddr":"00:00:00:00:00:00","mtu":65536,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"127.0.0.1/8","ip4_gateway":null,"ip6_address_1":"::1/128","ip6_gateway":null}] diff --git a/tests/fixtures/centos-7.7/nmcli-device-show.out b/tests/fixtures/centos-7.7/nmcli-device-show.out new file mode 100644 index 00000000..8aec04bd --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device-show.out @@ -0,0 +1,42 @@ +GENERAL.DEVICE: ens33 +GENERAL.TYPE: ethernet +GENERAL.HWADDR: 00:0C:29:3B:58:0E +GENERAL.MTU: 1500 +GENERAL.STATE: 100 (connected) +GENERAL.CONNECTION: ens33 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 +WIRED-PROPERTIES.CARRIER: on +IP4.ADDRESS[1]: 192.168.71.180/24 +IP4.GATEWAY: 192.168.71.2 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.71.2, mt = 100 +IP4.ROUTE[2]: dst = 192.168.71.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 192.168.71.2 +IP4.DOMAIN[1]: localdomain +IP6.ADDRESS[1]: fe80::c1cb:715d:bc3e:b8a0/64 +IP6.GATEWAY: -- +IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255 + +GENERAL.DEVICE: docker0 +GENERAL.TYPE: bridge +GENERAL.HWADDR: 02:42:99:67:E8:21 +GENERAL.MTU: 1500 +GENERAL.STATE: 10 (unmanaged) +GENERAL.CONNECTION: -- +GENERAL.CON-PATH: -- +IP4.ADDRESS[1]: 172.17.0.1/16 +IP4.GATEWAY: -- +IP4.ROUTE[1]: dst = 172.17.0.0/16, nh = 0.0.0.0, mt = 0 +IP6.GATEWAY: -- + +GENERAL.DEVICE: lo +GENERAL.TYPE: loopback +GENERAL.HWADDR: 00:00:00:00:00:00 +GENERAL.MTU: 65536 +GENERAL.STATE: 10 (unmanaged) +GENERAL.CONNECTION: -- +GENERAL.CON-PATH: -- +IP4.ADDRESS[1]: 127.0.0.1/8 +IP4.GATEWAY: -- +IP6.ADDRESS[1]: ::1/128 +IP6.GATEWAY: -- diff --git a/tests/fixtures/centos-7.7/nmcli-device.json b/tests/fixtures/centos-7.7/nmcli-device.json new file mode 100644 index 00000000..24eb3c58 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","state":"connected","connection":"ens33"},{"device":"docker0","type":"bridge","state":"unmanaged","connection":null},{"device":"lo","type":"loopback","state":"unmanaged","connection":null}] diff --git a/tests/fixtures/centos-7.7/nmcli-device.out b/tests/fixtures/centos-7.7/nmcli-device.out new file mode 100644 index 00000000..b5e73778 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-device.out @@ -0,0 +1,4 @@ +DEVICE TYPE STATE CONNECTION +ens33 ethernet connected ens33 +docker0 bridge unmanaged -- +lo loopback unmanaged -- diff --git a/tests/fixtures/centos-7.7/nmcli-general-all.json b/tests/fixtures/centos-7.7/nmcli-general-all.json new file mode 100644 index 00000000..fd1a97dd --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-general-all.json @@ -0,0 +1 @@ +[{"running":"running","version":"1.18.0","state":"connected","startup":"started","connectivity":"full","networking":"enabled","wifi_hw":"enabled","wifi":"enabled","wwan_hw":"enabled","wwan":"enabled"}] diff --git a/tests/fixtures/centos-7.7/nmcli-general-all.out b/tests/fixtures/centos-7.7/nmcli-general-all.out new file mode 100644 index 00000000..18cac50b --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-general-all.out @@ -0,0 +1,3 @@ +RUNNING VERSION STATE STARTUP CONNECTIVITY NETWORKING WIFI-HW WIFI WWAN-HW WWAN +running 1.18.0 connected started full enabled enabled enabled enabled enabled + diff --git a/tests/fixtures/centos-7.7/nmcli-general-permissions.json b/tests/fixtures/centos-7.7/nmcli-general-permissions.json new file mode 100644 index 00000000..1e63dbf0 --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-general-permissions.json @@ -0,0 +1 @@ +[{"org_freedesktop_networkmanager_enable_disable_network":"yes","org_freedesktop_networkmanager_enable_disable_wifi":"yes","org_freedesktop_networkmanager_enable_disable_wwan":"yes","org_freedesktop_networkmanager_enable_disable_wimax":"yes","org_freedesktop_networkmanager_sleep_wake":"yes","org_freedesktop_networkmanager_network_control":"yes","org_freedesktop_networkmanager_wifi_share_protected":"yes","org_freedesktop_networkmanager_wifi_share_open":"yes","org_freedesktop_networkmanager_settings_modify_system":"yes","org_freedesktop_networkmanager_settings_modify_own":"yes","org_freedesktop_networkmanager_settings_modify_hostname":"yes","org_freedesktop_networkmanager_settings_modify_global_dns":"yes","org_freedesktop_networkmanager_reload":"yes","org_freedesktop_networkmanager_checkpoint_rollback":"yes","org_freedesktop_networkmanager_enable_disable_statistics":"yes","org_freedesktop_networkmanager_enable_disable_connectivity_check":"yes","org_freedesktop_networkmanager_wifi_scan":"unknown"}] diff --git a/tests/fixtures/centos-7.7/nmcli-general-permissions.out b/tests/fixtures/centos-7.7/nmcli-general-permissions.out new file mode 100644 index 00000000..c1e94e0b --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli-general-permissions.out @@ -0,0 +1,18 @@ +PERMISSION VALUE +org.freedesktop.NetworkManager.enable-disable-network yes +org.freedesktop.NetworkManager.enable-disable-wifi yes +org.freedesktop.NetworkManager.enable-disable-wwan yes +org.freedesktop.NetworkManager.enable-disable-wimax yes +org.freedesktop.NetworkManager.sleep-wake yes +org.freedesktop.NetworkManager.network-control yes +org.freedesktop.NetworkManager.wifi.share.protected yes +org.freedesktop.NetworkManager.wifi.share.open yes +org.freedesktop.NetworkManager.settings.modify.system yes +org.freedesktop.NetworkManager.settings.modify.own yes +org.freedesktop.NetworkManager.settings.modify.hostname yes +org.freedesktop.NetworkManager.settings.modify.global-dns yes +org.freedesktop.NetworkManager.reload yes +org.freedesktop.NetworkManager.checkpoint-rollback yes +org.freedesktop.NetworkManager.enable-disable-statistics yes +org.freedesktop.NetworkManager.enable-disable-connectivity-check yes +org.freedesktop.NetworkManager.wifi.scan unknown diff --git a/tests/fixtures/centos-7.7/nmcli.out b/tests/fixtures/centos-7.7/nmcli.out new file mode 100644 index 00000000..1ac1c16b --- /dev/null +++ b/tests/fixtures/centos-7.7/nmcli.out @@ -0,0 +1,29 @@ +ens33: connected to ens33 + "Intel 82545EM" + ethernet (e1000), 00:0C:29:3B:58:0E, hw, mtu 1500 + ip4 default + inet4 192.168.71.181/24 + route4 0.0.0.0/0 + route4 192.168.71.0/24 + inet6 fe80::c1cb:715d:bc3e:b8a0/64 + route6 fe80::/64 + route6 ff00::/8 + +docker0: unmanaged + "docker0" + bridge, 02:42:76:3F:0D:C3, sw, mtu 1500 + +lo: unmanaged + "lo" + loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536 + +DNS configuration: + servers: 192.168.71.2 + domains: localdomain + interface: ens33 + +Use "nmcli device show" to get complete information about known devices and +"nmcli connection show" to get an overview on active connection profiles. + +Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details. + diff --git a/tests/fixtures/fedora32/nmcli-connection-show-ens33.json b/tests/fixtures/fedora32/nmcli-connection-show-ens33.json new file mode 100644 index 00000000..97355923 --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-connection-show-ens33.json @@ -0,0 +1 @@ +[{"connection_id":"ens33","connection_uuid":"fbea23dd-6738-403f-b3a5-5d4a3444216a","connection_stable_id":null,"connection_type":"802-3-ethernet","connection_interface_name":"ens33","connection_autoconnect":"yes","connection_autoconnect_priority":0,"connection_autoconnect_retries":-1,"connection_autoconnect_retries_text":"default","connection_multi_connect":0,"connection_multi_connect_text":"default","connection_auth_retries":-1,"connection_timestamp":1646019157,"connection_read_only":"no","connection_permissions":null,"connection_zone":null,"connection_master":null,"connection_slave_type":null,"connection_autoconnect_slaves":-1,"connection_autoconnect_slaves_text":"default","connection_secondaries":null,"connection_gateway_ping_timeout":0,"connection_metered":"unknown","connection_lldp":"default","connection_mdns":-1,"connection_mdns_text":"default","connection_llmnr":-1,"connection_llmnr_text":"default","connection_wait_device_timeout":-1,"802_3_ethernet_port":null,"802_3_ethernet_speed":0,"802_3_ethernet_duplex":null,"802_3_ethernet_auto_negotiate":"no","802_3_ethernet_mac_address":null,"802_3_ethernet_cloned_mac_address":null,"802_3_ethernet_generate_mac_address_mask":null,"802_3_ethernet_mac_address_blacklist":null,"802_3_ethernet_mtu":"auto","802_3_ethernet_s390_subchannels":null,"802_3_ethernet_s390_nettype":null,"802_3_ethernet_s390_options":null,"802_3_ethernet_wake_on_lan":"default","802_3_ethernet_wake_on_lan_password":null,"ipv4_method":"auto","ipv4_dns":null,"ipv4_dns_search":null,"ipv4_dns_options":null,"ipv4_dns_priority":0,"ipv4_addresses":null,"ipv4_gateway":null,"ipv4_routes":null,"ipv4_route_metric":-1,"ipv4_route_table":0,"ipv4_route_table_text":"unspec","ipv4_routing_rules":null,"ipv4_ignore_auto_routes":"no","ipv4_ignore_auto_dns":"no","ipv4_dhcp_client_id":null,"ipv4_dhcp_iaid":null,"ipv4_dhcp_timeout":0,"ipv4_dhcp_timeout_text":"default","ipv4_dhcp_send_hostname":"yes","ipv4_dhcp_hostname":null,"ipv4_dhcp_fqdn":null,"ipv4_dhcp_hostname_flags":"0x0","ipv4_dhcp_hostname_flags_text":"none","ipv4_never_default":"no","ipv4_may_fail":"yes","ipv4_dad_timeout":-1,"ipv4_dad_timeout_text":"default","ipv6_method":"auto","ipv6_dns":null,"ipv6_dns_search":null,"ipv6_dns_options":null,"ipv6_dns_priority":0,"ipv6_addresses":null,"ipv6_gateway":null,"ipv6_routes":null,"ipv6_route_metric":-1,"ipv6_route_table":0,"ipv6_route_table_text":"unspec","ipv6_routing_rules":null,"ipv6_ignore_auto_routes":"no","ipv6_ignore_auto_dns":"no","ipv6_never_default":"no","ipv6_may_fail":"yes","ipv6_ip6_privacy":-1,"ipv6_ip6_privacy_text":"unknown","ipv6_addr_gen_mode":"stable-privacy","ipv6_ra_timeout":0,"ipv6_ra_timeout_text":"default","ipv6_dhcp_duid":null,"ipv6_dhcp_iaid":null,"ipv6_dhcp_timeout":0,"ipv6_dhcp_timeout_text":"default","ipv6_dhcp_send_hostname":"yes","ipv6_dhcp_hostname":null,"ipv6_dhcp_hostname_flags":"0x0","ipv6_dhcp_hostname_flags_text":"none","ipv6_token":null,"proxy_method":"none","proxy_browser_only":"no","proxy_pac_url":null,"proxy_pac_script":null,"name":"ens33","uuid":"fbea23dd-6738-403f-b3a5-5d4a3444216a","devices":"ens33","ip_iface":"ens33","state":"activated","default":"yes","default6":"yes","spec_object":null,"vpn":"no","dbus_path":"/org/freedesktop/NetworkManager/ActiveConnection/2","con_path":"/org/freedesktop/NetworkManager/Settings/1","zone":null,"master_path":null,"ip4_address_1":"10.0.0.178/24","ip4_gateway":"10.0.0.1","ip4_route_1":{"dst":"0.0.0.0/0","nh":"10.0.0.1","mt":100},"ip4_route_2":{"dst":"10.0.0.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"75.75.75.75","ip4_dns_2":"75.75.76.76","ip4_domain_1":"hsd1.ca.comcast.net","dhcp4_option_1":{"name":"dhcp_lease_time","value":172800},"dhcp4_option_2":{"name":"domain_name","value":"hsd1.ca.comcast.net"},"dhcp4_option_3":{"name":"domain_name_servers","value":"75.75.75.75 75.75.76.76"},"dhcp4_option_4":{"name":"expiry","value":1646191487},"dhcp4_option_5":{"name":"ip_address","value":"10.0.0.178"},"dhcp4_option_6":{"name":"next_server","value":"10.0.0.1"},"dhcp4_option_7":{"name":"requested_broadcast_address","value":1},"dhcp4_option_8":{"name":"requested_domain_name","value":1},"dhcp4_option_9":{"name":"requested_domain_name_servers","value":1},"dhcp4_option_10":{"name":"requested_domain_search","value":1},"dhcp4_option_11":{"name":"requested_host_name","value":1},"dhcp4_option_12":{"name":"requested_interface_mtu","value":1},"dhcp4_option_13":{"name":"requested_ms_classless_static_routes","value":1},"dhcp4_option_14":{"name":"requested_nis_domain","value":1},"dhcp4_option_15":{"name":"requested_nis_servers","value":1},"dhcp4_option_16":{"name":"requested_ntp_servers","value":1},"dhcp4_option_17":{"name":"requested_rfc3442_classless_static_routes","value":1},"dhcp4_option_18":{"name":"requested_root_path","value":1},"dhcp4_option_19":{"name":"requested_routers","value":1},"dhcp4_option_20":{"name":"requested_static_routes","value":1},"dhcp4_option_21":{"name":"requested_subnet_mask","value":1},"dhcp4_option_22":{"name":"requested_time_offset","value":1},"dhcp4_option_23":{"name":"requested_wpad","value":1},"dhcp4_option_24":{"name":"routers","value":"10.0.0.1"},"dhcp4_option_25":{"name":"subnet_mask","value":"255.255.255.0"},"ip6_address_1":"2601:641:482:9cc0::2d6d/128","ip6_address_2":"fe80::9263:6fcc:6db6:8b56/64","ip6_gateway":"fe80::f88c:f4ff:fef1:d8f9","ip6_route_1":{"dst":"fd29:95c1:bb51::/64","nh":"fe80::1453:e8bf:c07a:2ca8","mt":100},"ip6_route_2":{"dst":"2601:641:482:9cc0::/60","nh":"::","mt":100},"ip6_route_3":{"dst":"::/0","nh":"fe80::f88c:f4ff:fef1:d8f9","mt":100},"ip6_route_4":{"dst":"ff00::/8","nh":"::","mt":256,"table":255},"ip6_route_5":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_6":{"dst":"2601:641:482:9cc0::2d6d/128","nh":"::","mt":100},"ip6_dns_1":"2001:558:feed::1","ip6_dns_2":"2001:558:feed::2","dhcp6_option_1":{"name":"dhcp6_name_servers","value":"2001:558:feed::1 2001:558:feed::2"},"dhcp6_option_2":{"name":"ip6_address","value":"2601:641:482:9cc0::2d6d"}}] diff --git a/tests/fixtures/fedora32/nmcli-connection-show-ens33.out b/tests/fixtures/fedora32/nmcli-connection-show-ens33.out new file mode 100644 index 00000000..876b57e9 --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-connection-show-ens33.out @@ -0,0 +1,148 @@ +connection.id: ens33 +connection.uuid: fbea23dd-6738-403f-b3a5-5d4a3444216a +connection.stable-id: -- +connection.type: 802-3-ethernet +connection.interface-name: ens33 +connection.autoconnect: yes +connection.autoconnect-priority: 0 +connection.autoconnect-retries: -1 (default) +connection.multi-connect: 0 (default) +connection.auth-retries: -1 +connection.timestamp: 1646019157 +connection.read-only: no +connection.permissions: -- +connection.zone: -- +connection.master: -- +connection.slave-type: -- +connection.autoconnect-slaves: -1 (default) +connection.secondaries: -- +connection.gateway-ping-timeout: 0 +connection.metered: unknown +connection.lldp: default +connection.mdns: -1 (default) +connection.llmnr: -1 (default) +connection.wait-device-timeout: -1 +802-3-ethernet.port: -- +802-3-ethernet.speed: 0 +802-3-ethernet.duplex: -- +802-3-ethernet.auto-negotiate: no +802-3-ethernet.mac-address: -- +802-3-ethernet.cloned-mac-address: -- +802-3-ethernet.generate-mac-address-mask:-- +802-3-ethernet.mac-address-blacklist: -- +802-3-ethernet.mtu: auto +802-3-ethernet.s390-subchannels: -- +802-3-ethernet.s390-nettype: -- +802-3-ethernet.s390-options: -- +802-3-ethernet.wake-on-lan: default +802-3-ethernet.wake-on-lan-password: -- +ipv4.method: auto +ipv4.dns: -- +ipv4.dns-search: -- +ipv4.dns-options: -- +ipv4.dns-priority: 0 +ipv4.addresses: -- +ipv4.gateway: -- +ipv4.routes: -- +ipv4.route-metric: -1 +ipv4.route-table: 0 (unspec) +ipv4.routing-rules: -- +ipv4.ignore-auto-routes: no +ipv4.ignore-auto-dns: no +ipv4.dhcp-client-id: -- +ipv4.dhcp-iaid: -- +ipv4.dhcp-timeout: 0 (default) +ipv4.dhcp-send-hostname: yes +ipv4.dhcp-hostname: -- +ipv4.dhcp-fqdn: -- +ipv4.dhcp-hostname-flags: 0x0 (none) +ipv4.never-default: no +ipv4.may-fail: yes +ipv4.dad-timeout: -1 (default) +ipv6.method: auto +ipv6.dns: -- +ipv6.dns-search: -- +ipv6.dns-options: -- +ipv6.dns-priority: 0 +ipv6.addresses: -- +ipv6.gateway: -- +ipv6.routes: -- +ipv6.route-metric: -1 +ipv6.route-table: 0 (unspec) +ipv6.routing-rules: -- +ipv6.ignore-auto-routes: no +ipv6.ignore-auto-dns: no +ipv6.never-default: no +ipv6.may-fail: yes +ipv6.ip6-privacy: -1 (unknown) +ipv6.addr-gen-mode: stable-privacy +ipv6.ra-timeout: 0 (default) +ipv6.dhcp-duid: -- +ipv6.dhcp-iaid: -- +ipv6.dhcp-timeout: 0 (default) +ipv6.dhcp-send-hostname: yes +ipv6.dhcp-hostname: -- +ipv6.dhcp-hostname-flags: 0x0 (none) +ipv6.token: -- +proxy.method: none +proxy.browser-only: no +proxy.pac-url: -- +proxy.pac-script: -- +GENERAL.NAME: ens33 +GENERAL.UUID: fbea23dd-6738-403f-b3a5-5d4a3444216a +GENERAL.DEVICES: ens33 +GENERAL.IP-IFACE: ens33 +GENERAL.STATE: activated +GENERAL.DEFAULT: yes +GENERAL.DEFAULT6: yes +GENERAL.SPEC-OBJECT: -- +GENERAL.VPN: no +GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/1 +GENERAL.ZONE: -- +GENERAL.MASTER-PATH: -- +IP4.ADDRESS[1]: 10.0.0.178/24 +IP4.GATEWAY: 10.0.0.1 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 10.0.0.1, mt = 100 +IP4.ROUTE[2]: dst = 10.0.0.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 75.75.75.75 +IP4.DNS[2]: 75.75.76.76 +IP4.DOMAIN[1]: hsd1.ca.comcast.net +DHCP4.OPTION[1]: dhcp_lease_time = 172800 +DHCP4.OPTION[2]: domain_name = hsd1.ca.comcast.net +DHCP4.OPTION[3]: domain_name_servers = 75.75.75.75 75.75.76.76 +DHCP4.OPTION[4]: expiry = 1646191487 +DHCP4.OPTION[5]: ip_address = 10.0.0.178 +DHCP4.OPTION[6]: next_server = 10.0.0.1 +DHCP4.OPTION[7]: requested_broadcast_address = 1 +DHCP4.OPTION[8]: requested_domain_name = 1 +DHCP4.OPTION[9]: requested_domain_name_servers = 1 +DHCP4.OPTION[10]: requested_domain_search = 1 +DHCP4.OPTION[11]: requested_host_name = 1 +DHCP4.OPTION[12]: requested_interface_mtu = 1 +DHCP4.OPTION[13]: requested_ms_classless_static_routes = 1 +DHCP4.OPTION[14]: requested_nis_domain = 1 +DHCP4.OPTION[15]: requested_nis_servers = 1 +DHCP4.OPTION[16]: requested_ntp_servers = 1 +DHCP4.OPTION[17]: requested_rfc3442_classless_static_routes = 1 +DHCP4.OPTION[18]: requested_root_path = 1 +DHCP4.OPTION[19]: requested_routers = 1 +DHCP4.OPTION[20]: requested_static_routes = 1 +DHCP4.OPTION[21]: requested_subnet_mask = 1 +DHCP4.OPTION[22]: requested_time_offset = 1 +DHCP4.OPTION[23]: requested_wpad = 1 +DHCP4.OPTION[24]: routers = 10.0.0.1 +DHCP4.OPTION[25]: subnet_mask = 255.255.255.0 +IP6.ADDRESS[1]: 2601:641:482:9cc0::2d6d/128 +IP6.ADDRESS[2]: fe80::9263:6fcc:6db6:8b56/64 +IP6.GATEWAY: fe80::f88c:f4ff:fef1:d8f9 +IP6.ROUTE[1]: dst = fd29:95c1:bb51::/64, nh = fe80::1453:e8bf:c07a:2ca8, mt = 100 +IP6.ROUTE[2]: dst = 2601:641:482:9cc0::/60, nh = ::, mt = 100 +IP6.ROUTE[3]: dst = ::/0, nh = fe80::f88c:f4ff:fef1:d8f9, mt = 100 +IP6.ROUTE[4]: dst = ff00::/8, nh = ::, mt = 256, table=255 +IP6.ROUTE[5]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[6]: dst = 2601:641:482:9cc0::2d6d/128, nh = ::, mt = 100 +IP6.DNS[1]: 2001:558:feed::1 +IP6.DNS[2]: 2001:558:feed::2 +DHCP6.OPTION[1]: dhcp6_name_servers = 2001:558:feed::1 2001:558:feed::2 +DHCP6.OPTION[2]: ip6_address = 2601:641:482:9cc0::2d6d diff --git a/tests/fixtures/fedora32/nmcli-device-show-ens33.json b/tests/fixtures/fedora32/nmcli-device-show-ens33.json new file mode 100644 index 00000000..0f722b60 --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-device-show-ens33.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:66:16:68","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/2","wired_properties_carrier":"on","ip4_address_1":"10.0.0.178/24","ip4_gateway":"10.0.0.1","ip4_route_1":{"dst":"0.0.0.0/0","nh":"10.0.0.1","mt":100},"ip4_route_2":{"dst":"10.0.0.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"75.75.75.75","ip4_dns_2":"75.75.76.76","ip4_domain_1":"hsd1.ca.comcast.net","ip6_address_1":"2601:641:482:9cc0::2d6d/128","ip6_address_2":"fe80::9263:6fcc:6db6:8b56/64","ip6_gateway":"fe80::f88c:f4ff:fef1:d8f9","ip6_route_1":{"dst":"fd29:95c1:bb51::/64","nh":"fe80::1453:e8bf:c07a:2ca8","mt":100},"ip6_route_2":{"dst":"2601:641:482:9cc0::/60","nh":"::","mt":100},"ip6_route_3":{"dst":"::/0","nh":"fe80::f88c:f4ff:fef1:d8f9","mt":100},"ip6_route_4":{"dst":"ff00::/8","nh":"::","mt":256,"table":255},"ip6_route_5":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_6":{"dst":"2601:641:482:9cc0::2d6d/128","nh":"::","mt":100},"ip6_dns_1":"2001:558:feed::1","ip6_dns_2":"2001:558:feed::2"}] diff --git a/tests/fixtures/fedora32/nmcli-device-show-ens33.out b/tests/fixtures/fedora32/nmcli-device-show-ens33.out new file mode 100644 index 00000000..987d1b4f --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-device-show-ens33.out @@ -0,0 +1,26 @@ +GENERAL.DEVICE: ens33 +GENERAL.TYPE: ethernet +GENERAL.HWADDR: 00:0C:29:66:16:68 +GENERAL.MTU: 1500 +GENERAL.STATE: 100 (connected) +GENERAL.CONNECTION: ens33 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +WIRED-PROPERTIES.CARRIER: on +IP4.ADDRESS[1]: 10.0.0.178/24 +IP4.GATEWAY: 10.0.0.1 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 10.0.0.1, mt = 100 +IP4.ROUTE[2]: dst = 10.0.0.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 75.75.75.75 +IP4.DNS[2]: 75.75.76.76 +IP4.DOMAIN[1]: hsd1.ca.comcast.net +IP6.ADDRESS[1]: 2601:641:482:9cc0::2d6d/128 +IP6.ADDRESS[2]: fe80::9263:6fcc:6db6:8b56/64 +IP6.GATEWAY: fe80::f88c:f4ff:fef1:d8f9 +IP6.ROUTE[1]: dst = fd29:95c1:bb51::/64, nh = fe80::1453:e8bf:c07a:2ca8, mt = 100 +IP6.ROUTE[2]: dst = 2601:641:482:9cc0::/60, nh = ::, mt = 100 +IP6.ROUTE[3]: dst = ::/0, nh = fe80::f88c:f4ff:fef1:d8f9, mt = 100 +IP6.ROUTE[4]: dst = ff00::/8, nh = ::, mt = 256, table=255 +IP6.ROUTE[5]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[6]: dst = 2601:641:482:9cc0::2d6d/128, nh = ::, mt = 100 +IP6.DNS[1]: 2001:558:feed::1 +IP6.DNS[2]: 2001:558:feed::2 diff --git a/tests/fixtures/fedora32/nmcli-device-show.json b/tests/fixtures/fedora32/nmcli-device-show.json new file mode 100644 index 00000000..9146c8fa --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-device-show.json @@ -0,0 +1 @@ +[{"device":"ens33","type":"ethernet","hwaddr":"00:0C:29:66:16:68","mtu":1500,"state":100,"state_text":"connected","connection":"ens33","con_path":"/org/freedesktop/NetworkManager/ActiveConnection/2","wired_properties_carrier":"on","ip4_address_1":"10.0.0.178/24","ip4_gateway":"10.0.0.1","ip4_route_1":{"dst":"0.0.0.0/0","nh":"10.0.0.1","mt":100},"ip4_route_2":{"dst":"10.0.0.0/24","nh":"0.0.0.0","mt":100},"ip4_dns_1":"75.75.75.75","ip4_dns_2":"75.75.76.76","ip4_domain_1":"hsd1.ca.comcast.net","ip6_address_1":"2601:641:482:9cc0::2d6d/128","ip6_address_2":"fe80::9263:6fcc:6db6:8b56/64","ip6_gateway":"fe80::f88c:f4ff:fef1:d8f9","ip6_route_1":{"dst":"fd29:95c1:bb51::/64","nh":"fe80::1453:e8bf:c07a:2ca8","mt":100},"ip6_route_2":{"dst":"2601:641:482:9cc0::/60","nh":"::","mt":100},"ip6_route_3":{"dst":"::/0","nh":"fe80::f88c:f4ff:fef1:d8f9","mt":100},"ip6_route_4":{"dst":"ff00::/8","nh":"::","mt":256,"table":255},"ip6_route_5":{"dst":"fe80::/64","nh":"::","mt":100},"ip6_route_6":{"dst":"2601:641:482:9cc0::2d6d/128","nh":"::","mt":100},"ip6_dns_1":"2001:558:feed::1","ip6_dns_2":"2001:558:feed::2"},{"device":"lo","type":"loopback","hwaddr":"00:00:00:00:00:00","mtu":65536,"state":10,"state_text":"unmanaged","connection":null,"con_path":null,"ip4_address_1":"127.0.0.1/8","ip4_gateway":null,"ip6_address_1":"::1/128","ip6_gateway":null,"ip6_route_1":{"dst":"::1/128","nh":"::","mt":256}}] diff --git a/tests/fixtures/fedora32/nmcli-device-show.out b/tests/fixtures/fedora32/nmcli-device-show.out new file mode 100644 index 00000000..907d2786 --- /dev/null +++ b/tests/fixtures/fedora32/nmcli-device-show.out @@ -0,0 +1,39 @@ +GENERAL.DEVICE: ens33 +GENERAL.TYPE: ethernet +GENERAL.HWADDR: 00:0C:29:66:16:68 +GENERAL.MTU: 1500 +GENERAL.STATE: 100 (connected) +GENERAL.CONNECTION: ens33 +GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/2 +WIRED-PROPERTIES.CARRIER: on +IP4.ADDRESS[1]: 10.0.0.178/24 +IP4.GATEWAY: 10.0.0.1 +IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 10.0.0.1, mt = 100 +IP4.ROUTE[2]: dst = 10.0.0.0/24, nh = 0.0.0.0, mt = 100 +IP4.DNS[1]: 75.75.75.75 +IP4.DNS[2]: 75.75.76.76 +IP4.DOMAIN[1]: hsd1.ca.comcast.net +IP6.ADDRESS[1]: 2601:641:482:9cc0::2d6d/128 +IP6.ADDRESS[2]: fe80::9263:6fcc:6db6:8b56/64 +IP6.GATEWAY: fe80::f88c:f4ff:fef1:d8f9 +IP6.ROUTE[1]: dst = fd29:95c1:bb51::/64, nh = fe80::1453:e8bf:c07a:2ca8, mt = 100 +IP6.ROUTE[2]: dst = 2601:641:482:9cc0::/60, nh = ::, mt = 100 +IP6.ROUTE[3]: dst = ::/0, nh = fe80::f88c:f4ff:fef1:d8f9, mt = 100 +IP6.ROUTE[4]: dst = ff00::/8, nh = ::, mt = 256, table=255 +IP6.ROUTE[5]: dst = fe80::/64, nh = ::, mt = 100 +IP6.ROUTE[6]: dst = 2601:641:482:9cc0::2d6d/128, nh = ::, mt = 100 +IP6.DNS[1]: 2001:558:feed::1 +IP6.DNS[2]: 2001:558:feed::2 + +GENERAL.DEVICE: lo +GENERAL.TYPE: loopback +GENERAL.HWADDR: 00:00:00:00:00:00 +GENERAL.MTU: 65536 +GENERAL.STATE: 10 (unmanaged) +GENERAL.CONNECTION: -- +GENERAL.CON-PATH: -- +IP4.ADDRESS[1]: 127.0.0.1/8 +IP4.GATEWAY: -- +IP6.ADDRESS[1]: ::1/128 +IP6.GATEWAY: -- +IP6.ROUTE[1]: dst = ::1/128, nh = ::, mt = 256 diff --git a/tests/test_nmcli.py b/tests/test_nmcli.py new file mode 100644 index 00000000..9091564f --- /dev/null +++ b/tests/test_nmcli.py @@ -0,0 +1,191 @@ +import os +import unittest +import json +import jc.parsers.nmcli +from jc.exceptions import ParseError + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-all.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_all = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-show-ens33.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_show_ens33 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-all.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_all = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-ens33.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_ens33 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-lo.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_lo = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-all.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_general_all = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-permissions.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_general_permissions = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-connection-show-ens33.out'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_connection_show_ens33 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-device-show-ens33.out'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_device_show_ens33 = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-device-show.out'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_device_show = f.read() + + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-all.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_all_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection-show-ens33.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_show_ens33_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-connection.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_connection_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-all.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_all_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-ens33.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_ens33_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show-lo.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_lo_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device-show.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_show_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-device.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_device_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-all.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_general_all_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/nmcli-general-permissions.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_nmcli_general_permissions_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-connection-show-ens33.json'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_connection_show_ens33_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-device-show-ens33.json'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_device_show_ens33_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/fedora32/nmcli-device-show.json'), 'r', encoding='utf-8') as f: + self.fedora32_nmcli_device_show_json = json.loads(f.read()) + + + + def test_nmcli_nodata(self): + """ + Test 'nmcli' with no data + """ + self.assertEqual(jc.parsers.nmcli.parse('', quiet=True), []) + + def test_nmcli_centos_7_7(self): + """ + Test 'nmcli' on Centos 7.7 - this should raise a ParseError exception + """ + self.assertRaises(ParseError, jc.parsers.nmcli.parse, self.centos_7_7_nmcli, quiet=True) + + def test_nmcli_connection_all_centos_7_7(self): + """ + Test 'nmcli -f all connection' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection_all, quiet=True), self.centos_7_7_nmcli_connection_all_json) + + def test_nmcli_connection_show_ens33_centos_7_7(self): + """ + Test 'nmcli connection show ens33' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection_show_ens33, quiet=True), self.centos_7_7_nmcli_connection_show_ens33_json) + + def test_nmcli_connection_centos_7_7(self): + """ + Test 'nmcli connection' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_connection, quiet=True), self.centos_7_7_nmcli_connection_json) + + def test_nmcli_device_all_centos_7_7(self): + """ + Test 'nmcli -f all device' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_all, quiet=True), self.centos_7_7_nmcli_device_all_json) + + def test_nmcli_device_show_ens33_centos_7_7(self): + """ + Test 'nmcli device show ens33' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show_ens33, quiet=True), self.centos_7_7_nmcli_device_show_ens33_json) + + def test_nmcli_device_show_lo_centos_7_7(self): + """ + Test 'nmcli device show lo' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show_lo, quiet=True), self.centos_7_7_nmcli_device_show_lo_json) + + def test_nmcli_device_show_centos_7_7(self): + """ + Test 'nmcli device show' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device_show, quiet=True), self.centos_7_7_nmcli_device_show_json) + + def test_nmcli_device_centos_7_7(self): + """ + Test 'nmcli device' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_device, quiet=True), self.centos_7_7_nmcli_device_json) + + def test_nmcli_general_all_centos_7_7(self): + """ + Test 'nmcli -f all general' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_general_all, quiet=True), self.centos_7_7_nmcli_general_all_json) + + def test_nmcli_general_permissions_centos_7_7(self): + """ + Test 'nmcli general permissions' on Centos 7.7 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.centos_7_7_nmcli_general_permissions, quiet=True), self.centos_7_7_nmcli_general_permissions_json) + + def test_nmcli_connection_show_ens33_fedora32(self): + """ + Test 'nmcli connection show ens33' on fedora32 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.fedora32_nmcli_connection_show_ens33, quiet=True), self.fedora32_nmcli_connection_show_ens33_json) + + def test_nmcli_device_show_ens33_fedora32(self): + """ + Test 'nmcli device show ens33' on fedora32 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.fedora32_nmcli_device_show_ens33, quiet=True), self.fedora32_nmcli_device_show_ens33_json) + + def test_nmcli_device_show_fedora32(self): + """ + Test 'nmcli device show' on fedora32 + """ + self.assertEqual(jc.parsers.nmcli.parse(self.fedora32_nmcli_device_show, quiet=True), self.fedora32_nmcli_device_show_json) + + +if __name__ == '__main__': + unittest.main()