1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-24 20:56:11 +02:00

Dev v1.23.4 (#439)

* version bump

* fix regex for crlf line endings

* Completed Ip_route parser (#429)

* tests

* Merge pull request #398 from kellyjonbrazil/dev

Dev v1.23.2

* Merge pull request #398 from kellyjonbrazil/dev

Dev v1.23.2

---------

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
Co-authored-by: Jjack3032 <julian.jackson@parsons.us>

* formatting

* doc update

* use splitlines

* formatting

* formatting

* Parser for `find` linux command (#434)

* Added find parser and tests for Centos 7.7 and Ubuntu 18.04

* Added a test file, changed logic, and included a case for permission denied returned by find.

* Added a few more lines to the tests

* Changed logic for setting values to null and updated test cases.

* doc update

* doc update

* Added proc_net_tcp parser (#421)

Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>

* clean up net_tcp parser

* add resolve.conf test files

* doc update

* add resolve.conf parser

* doc update

* add sortlist functionality

* add resolve.conf parser tests

* doc update

---------

Co-authored-by: Julian5555 <58196809+Julian5555@users.noreply.github.com>
Co-authored-by: Jjack3032 <julian.jackson@parsons.us>
Co-authored-by: solomonleang <124934439+solomonleang@users.noreply.github.com>
Co-authored-by: AlvinSolomon <41175627+AlvinSolomon@users.noreply.github.com>
This commit is contained in:
Kelly Brazil
2023-07-30 10:08:39 -07:00
committed by GitHub
parent d58ca402a7
commit 4cd721be85
42 changed files with 1645 additions and 11 deletions
+1 -1
View File
@@ -158,4 +158,4 @@ Returns:
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
+82
View File
@@ -0,0 +1,82 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.find"></a>
# jc.parsers.find
jc - JSON Convert `find` command output parser
This parser returns a list of objects by default and a list of strings if
the `--raw` option is used.
Usage (cli):
$ find | jc --find
Usage (module):
import jc
result = jc.parse('find', find_command_output)
Schema:
[
{
"path": string,
"node": string,
"error": string
}
]
Examples:
$ find | jc --find -p
[
{
"path": "./directory"
"node": "filename"
},
{
"path": "./anotherdirectory"
"node": "anotherfile"
},
{
"path": null
"node": null
"error": "find: './inaccessible': Permission denied"
}
...
]
$ find | jc --find -p -r
[
"./templates/readme_template",
"./templates/manpage_template",
"./.github/workflows/pythonapp.yml",
...
]
<a id="jc.parsers.find.parse"></a>
### parse
```python
def parse(data, raw=False, quiet=False)
```
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 raw strings or
List of Dictionaries of processed structured data
### Parser Information
Compatibility: linux
Version 1.0 by Solomon Leang (solomonleang@gmail.com)
+74
View File
@@ -0,0 +1,74 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.ip_route"></a>
# jc.parsers.ip\_route
jc - JSON Convert `ip route` command output parser
Usage (cli):
$ ip route | jc --ip-route
or
$ jc ip-route
Usage (module):
import jc
result = jc.parse('ip_route', ip_route_command_output)
Schema:
[
{
"ip": string,
"via": string,
"dev": string,
"metric": integer,
"proto": string,
"scope": string,
"src": string,
"via": string,
"status": string
}
]
Examples:
$ ip route | jc --ip-route -p
[
{
"ip": "10.0.2.0/24",
"dev": "enp0s3",
"proto": "kernel",
"scope": "link",
"src": "10.0.2.15",
"metric": 100
}
]
<a id="jc.parsers.ip_route.parse"></a>
### parse
```python
def parse(data, raw=False, quiet=False)
```
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 Json objects if data is processed and Raw data if raw = true.
### Parser Information
Compatibility: linux
Version 1.0 by Julian Jackson (jackson.julian55@yahoo.com)
+186
View File
@@ -0,0 +1,186 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_tcp"></a>
# jc.parsers.proc\_net\_tcp
jc - JSON Convert `/proc/net/tcp` and `proc/net/tcp6` file parser
IPv4 and IPv6 addresses are converted to standard notation unless the raw
(--raw) option is used.
Usage (cli):
$ cat /proc/net/tcp | jc --proc
or
$ jc /proc/net/tcp
or
$ cat /proc/net/tcp | jc --proc-net-tcp
Usage (module):
import jc
result = jc.parse('proc', proc_net_tcp_file)
or
import jc
result = jc.parse('proc_net_tcp', proc_net_tcp_file)
Schema:
Field names and types gathered from the following:
https://www.kernel.org/doc/Documentation/networking/proc_net_tcp.txt
https://github.com/torvalds/linux/blob/master/net/ipv4/tcp_ipv4.c
https://github.com/torvalds/linux/blob/master/net/ipv6/tcp_ipv6.c
[
{
"entry": integer,
"local_address": string,
"local_port": integer,
"remote_address": string,
"remote_port": integer,
"state": string,
"tx_queue": string,
"rx_queue": string,
"timer_active": integer,
"jiffies_until_timer_expires": string,
"unrecovered_rto_timeouts": string,
"uid": integer,
"unanswered_0_window_probes": integer,
"inode": integer,
"sock_ref_count": integer,
"sock_mem_loc": string,
"retransmit_timeout": integer,
"soft_clock_tick": integer,
"ack_quick_pingpong": integer,
"sending_congestion_window": integer,
"slow_start_size_threshold": integer
}
]
Examples:
$ cat /proc/net/tcp | jc --proc -p
[
{
"entry": "0",
"local_address": "10.0.0.28",
"local_port": 42082,
"remote_address": "64.12.0.108",
"remote_port": 80,
"state": "04",
"tx_queue": "00000001",
"rx_queue": "00000000",
"timer_active": 1,
"jiffies_until_timer_expires": "00000015",
"unrecovered_rto_timeouts": "00000000",
"uid": 0,
"unanswered_0_window_probes": 0,
"inode": 0,
"sock_ref_count": 3,
"sock_mem_loc": "ffff8c7a0de930c0",
"retransmit_timeout": 21,
"soft_clock_tick": 4,
"ack_quick_pingpong": 30,
"sending_congestion_window": 10,
"slow_start_size_threshold": -1
},
{
"entry": "1",
"local_address": "10.0.0.28",
"local_port": 38864,
"remote_address": "104.244.42.65",
"remote_port": 80,
"state": "06",
"tx_queue": "00000000",
"rx_queue": "00000000",
"timer_active": 3,
"jiffies_until_timer_expires": "000007C5",
"unrecovered_rto_timeouts": "00000000",
"uid": 0,
"unanswered_0_window_probes": 0,
"inode": 0,
"sock_ref_count": 3,
"sock_mem_loc": "ffff8c7a12d31aa0"
},
...
]
$ cat /proc/net/tcp | jc --proc -p -r
[
{
"entry": "1",
"local_address": "1C00000A",
"local_port": "A462",
"remote_address": "6C000C40",
"remote_port": "0050",
"state": "04",
"tx_queue": "00000001",
"rx_queue": "00000000",
"timer_active": "01",
"jiffies_until_timer_expires": "00000015",
"unrecovered_rto_timeouts": "00000000",
"uid": "0",
"unanswered_0_window_probes": "0",
"inode": "0",
"sock_ref_count": "3",
"sock_mem_loc": "ffff8c7a0de930c0",
"retransmit_timeout": "21",
"soft_clock_tick": "4",
"ack_quick_pingpong": "30",
"sending_congestion_window": "10",
"slow_start_size_threshold": "-1"
},
{
"entry": "2",
"local_address": "1C00000A",
"local_port": "97D0",
"remote_address": "412AF468",
"remote_port": "0050",
"state": "06",
"tx_queue": "00000000",
"rx_queue": "00000000",
"timer_active": "03",
"jiffies_until_timer_expires": "000007C5",
"unrecovered_rto_timeouts": "00000000",
"uid": "0",
"unanswered_0_window_probes": "0",
"inode": "0",
"sock_ref_count": "3",
"sock_mem_loc": "ffff8c7a12d31aa0"
},
...
]
<a id="jc.parsers.proc_net_tcp.parse"></a>
### 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 Alvin Solomon (alvinms01@gmail.com)
+83
View File
@@ -0,0 +1,83 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.resolve_conf"></a>
# jc.parsers.resolve\_conf
jc - JSON Convert `/etc/resolve.conf` file parser
This parser may be more forgiving than the system parser. For example, if
multiple `search` lists are defined, this parser will append all entries to
the `search` field, while the system parser may only use the list from the
last defined instance.
Usage (cli):
$ cat /etc/resolve.conf | jc --resolve-conf
Usage (module):
import jc
result = jc.parse('resolve_conf', resolve_conf_output)
Schema:
{
"domain": string,
"search": [
string
],
"nameservers": [
string
],
"options": [
string
],
"sortlist": [
string
]
}
Examples:
$ cat /etc/resolve.conf | jc --resolve-conf -p
{
"search": [
"eng.myprime.com",
"dev.eng.myprime.com",
"labs.myprime.com",
"qa.myprime.com"
],
"nameservers": [
"10.136.17.15"
],
"options": [
"rotate",
"ndots:1"
]
}
<a id="jc.parsers.resolve_conf.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType
```
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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)