diff --git a/README.md b/README.md index c17a36d7..5525fbee 100755 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ jc [OPTIONS] COMMAND The JSON output can be compact (default) or pretty formatted with the `-p` option. ### Parsers +- `--airport` enables the `airport` command parser (OSX) - `--arp` enables the `arp` command parser - `--blkid` enables the `blkid` command parser - `--crontab` enables the `crontab` command and file parser @@ -164,6 +165,27 @@ Tested on: - Excellent constructive feedback from Ilya Sher (https://github.com/ilyash-b) ## Examples +### airport +``` +$ airport | jc --airport -p +{ + "agrctlrssi": -66, + "agrextrssi": 0, + "agrctlnoise": -90, + "agrextnoise": 0, + "state": "running", + "op_mode": "station", + "lasttxrate": 195, + "maxrate": 867, + "lastassocstatus": 0, + "802_11_auth": "open", + "link_auth": "wpa2-psk", + "bssid": "3c:37:86:15:ad:f9", + "ssid": "SnazzleDazzle", + "mcs": 0, + "channel": "48,80" +} +``` ### arp ``` $ arp | jc --arp -p # or: jc -p arp diff --git a/docs/parsers/airport.md b/docs/parsers/airport.md index 08e848f7..81e27be0 100644 --- a/docs/parsers/airport.md +++ b/docs/parsers/airport.md @@ -13,12 +13,40 @@ Examples: $ airport | jc --airport -p { - + "agrctlrssi": -66, + "agrextrssi": 0, + "agrctlnoise": -90, + "agrextnoise": 0, + "state": "running", + "op_mode": "station", + "lasttxrate": 195, + "maxrate": 867, + "lastassocstatus": 0, + "802_11_auth": "open", + "link_auth": "wpa2-psk", + "bssid": "3c:37:86:15:ad:f9", + "ssid": "SnazzleDazzle", + "mcs": 0, + "channel": "48,80" } $ airport | jc --airport -p -r { - + "agrctlrssi": "-66", + "agrextrssi": "0", + "agrctlnoise": "-90", + "agrextnoise": "0", + "state": "running", + "op_mode": "station", + "lasttxrate": "195", + "maxrate": "867", + "lastassocstatus": "0", + "802_11_auth": "open", + "link_auth": "wpa2-psk", + "bssid": "3c:37:86:15:ad:f9", + "ssid": "SnazzleDazzle", + "mcs": "0", + "channel": "48,80" } ## info @@ -42,7 +70,21 @@ Returns: Dictionary. Structured data with the following schema: { - + "agrctlrssi": integer, + "agrextrssi": integer, + "agrctlnoise": integer, + "agrextnoise": integer, + "state": string, + "op_mode": string, + "lasttxrate": integer, + "maxrate": integer, + "lastassocstatus": integer, + "802_11_auth": string, + "link_auth": string, + "bssid": string, + "ssid": string, + "mcs": integer, + "channel": string } ## parse diff --git a/jc/parsers/airport.py b/jc/parsers/airport.py index c8968efe..bffa01ba 100644 --- a/jc/parsers/airport.py +++ b/jc/parsers/airport.py @@ -12,12 +12,40 @@ Examples: $ airport | jc --airport -p { - + "agrctlrssi": -66, + "agrextrssi": 0, + "agrctlnoise": -90, + "agrextnoise": 0, + "state": "running", + "op_mode": "station", + "lasttxrate": 195, + "maxrate": 867, + "lastassocstatus": 0, + "802_11_auth": "open", + "link_auth": "wpa2-psk", + "bssid": "3c:37:86:15:ad:f9", + "ssid": "SnazzleDazzle", + "mcs": 0, + "channel": "48,80" } $ airport | jc --airport -p -r { - + "agrctlrssi": "-66", + "agrextrssi": "0", + "agrctlnoise": "-90", + "agrextnoise": "0", + "state": "running", + "op_mode": "station", + "lasttxrate": "195", + "maxrate": "867", + "lastassocstatus": "0", + "802_11_auth": "open", + "link_auth": "wpa2-psk", + "bssid": "3c:37:86:15:ad:f9", + "ssid": "SnazzleDazzle", + "mcs": "0", + "channel": "48,80" } """ import jc.utils @@ -51,20 +79,32 @@ def process(proc_data): Dictionary. Structured data with the following schema: { - + "agrctlrssi": integer, + "agrextrssi": integer, + "agrctlnoise": integer, + "agrextnoise": integer, + "state": string, + "op_mode": string, + "lasttxrate": integer, + "maxrate": integer, + "lastassocstatus": integer, + "802_11_auth": string, + "link_auth": string, + "bssid": string, + "ssid": string, + "mcs": integer, + "channel": string } """ - # boolean changes - ''' - bool_list = ['ntp_enabled', 'ntp_synchronized', 'rtc_in_local_tz', 'dst_active', - 'system_clock_synchronized', 'systemd-timesyncd.service_active'] + # integer changes + int_list = ['agrctlrssi', 'agrextrssi', 'agrctlnoise', 'agrextnoise', + 'lasttxrate', 'maxrate', 'lastassocstatus', 'mcs'] for key in proc_data: - if key in bool_list: + if key in int_list: try: - proc_data[key] = True if proc_data[key] == 'yes' else False + proc_data[key] = int(proc_data[key]) except (ValueError): proc_data[key] = None - ''' return proc_data @@ -90,7 +130,7 @@ def parse(data, raw=False, quiet=False): for line in filter(None, data.splitlines()): linedata = line.split(':', maxsplit=1) - raw_output[linedata[0].strip().lower().replace(' ', '_')] = linedata[1].strip() + raw_output[linedata[0].strip().lower().replace(' ', '_').replace('.', '_')] = linedata[1].strip() if raw: return raw_output diff --git a/tests/fixtures/osx-10.14.6/airport-I.json b/tests/fixtures/osx-10.14.6/airport-I.json new file mode 100644 index 00000000..f0155ef1 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/airport-I.json @@ -0,0 +1 @@ +{"agrctlrssi": -66, "agrextrssi": 0, "agrctlnoise": -90, "agrextnoise": 0, "state": "running", "op_mode": "station", "lasttxrate": 195, "maxrate": 867, "lastassocstatus": 0, "802_11_auth": "open", "link_auth": "wpa2-psk", "bssid": "3c:37:86:15:ad:f9", "ssid": "SnazzleDazzle", "mcs": 0, "channel": "48,80"} diff --git a/tests/fixtures/osx-10.14.6/airport-I.out b/tests/fixtures/osx-10.14.6/airport-I.out index c2dad159..e6eeb569 100644 --- a/tests/fixtures/osx-10.14.6/airport-I.out +++ b/tests/fixtures/osx-10.14.6/airport-I.out @@ -10,6 +10,6 @@ lastAssocStatus: 0 802.11 auth: open link auth: wpa2-psk BSSID: 3c:37:86:15:ad:f9 - SSID: BrazzleDazzle + SSID: SnazzleDazzle MCS: 0 channel: 48,80