1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2026-04-03 17:44:07 +02:00

Compare commits

...

246 Commits

Author SHA1 Message Date
Kelly Brazil
81ea83064c Merge pull request #306 from kellyjonbrazil/dev
Dev v1.22.1
2022-10-24 16:30:36 +00:00
Kelly Brazil
45859b01e5 doc update 2022-10-24 09:17:09 -07:00
Kelly Brazil
5b8f166169 doc update 2022-10-24 09:15:58 -07:00
Kelly Brazil
7e045ba7b0 doc update 2022-10-24 09:14:01 -07:00
Kelly Brazil
6247975ee6 update jc-web link to render 2022-10-23 13:20:50 -07:00
Kelly Brazil
297451230c lspci docs and tests 2022-10-23 09:15:23 -07:00
Kelly Brazil
754d555768 doc update 2022-10-21 13:09:13 -07:00
Kelly Brazil
b61a91f82d add pci-ids and udevadm tests 2022-10-21 12:57:28 -07:00
Kelly Brazil
1ac7a724bd integer conversions 2022-10-21 12:45:19 -07:00
Kelly Brazil
2fcf46505c add schema, typing, and doc update 2022-10-21 12:44:57 -07:00
Kelly Brazil
fdec4f08c0 add schema docs for pci-ids 2022-10-21 11:50:06 -07:00
Kelly Brazil
076c197385 more explicit type annotations 2022-10-21 10:56:10 -07:00
Kelly Brazil
3432e830f2 doc update 2022-10-19 13:46:32 -07:00
Kelly Brazil
14a237749c type annotation cleanup 2022-10-19 13:32:16 -07:00
Kelly Brazil
1559c4751e type annotate decorator function 2022-10-19 12:02:12 -07:00
Kelly Brazil
af7c4ce8ec doc update 2022-10-19 08:33:09 -07:00
Kelly Brazil
5763ce6160 Don't get too fancy with dict type annotations 2022-10-19 08:30:09 -07:00
Kelly Brazil
d7ca6caae8 use jc_types 2022-10-18 15:46:29 -07:00
Kelly Brazil
2c4f232aaa use jc_types 2022-10-18 15:45:29 -07:00
Kelly Brazil
bddfa71fa6 use object for typing since these functions accept other types 2022-10-18 15:44:53 -07:00
Kelly Brazil
f537ab058b use Tuple for <3.9 compatibility 2022-10-18 11:27:12 -07:00
Kelly Brazil
1b44b5b05a use typing Tuple for <3.9 compatibility 2022-10-18 11:24:55 -07:00
Kelly Brazil
f6e971c652 fix metadata return type 2022-10-18 11:04:08 -07:00
Kelly Brazil
dfa7a71f53 move custom types to jc_types 2022-10-18 11:01:59 -07:00
Kelly Brazil
3639e02843 doc update 2022-10-18 09:37:10 -07:00
Kelly Brazil
27b6e79c8a ignore mocking typing errors 2022-10-18 09:36:17 -07:00
Kelly Brazil
f370151b54 make iso_datetime deprecated only. no need to make hidden. 2022-10-18 09:35:59 -07:00
Kelly Brazil
597a8f468e normalize show_hidden and show_deprecated to be False by default 2022-10-18 09:35:24 -07:00
Kelly Brazil
8bd7a00410 add py.typed to package 2022-10-18 09:14:43 -07:00
Kelly Brazil
4867052972 fix AboutJCType 2022-10-15 18:27:55 -07:00
Kelly Brazil
688c3a34f6 define CustomColorType 2022-10-15 18:21:53 -07:00
Kelly Brazil
e357b27433 more granular type annotations 2022-10-15 17:53:02 -07:00
Kelly Brazil
dd70bf92f3 doc update 2022-10-15 14:43:45 -07:00
Kelly Brazil
0a97523928 doc update 2022-10-15 14:36:35 -07:00
Kelly Brazil
f67bd02283 More granular type annotations 2022-10-15 14:34:09 -07:00
Kelly Brazil
ef1055a9b6 more granular type annotations 2022-10-15 14:06:38 -07:00
Kelly Brazil
cd970b5871 TypedDict fixup for older python versions 2022-10-15 13:53:56 -07:00
Kelly Brazil
11b0863a65 Use TypedDict for more granular typing 2022-10-15 13:44:44 -07:00
Kelly Brazil
5b8cb497de add more type annotations 2022-10-14 17:28:34 -07:00
Kelly Brazil
38e2addbb6 simplify type annotation for MetadataType 2022-10-14 17:23:38 -07:00
Kelly Brazil
58158ce8b1 add type annotations 2022-10-14 17:12:58 -07:00
Kelly Brazil
5ca281f02e add type annotations 2022-10-14 15:54:26 -07:00
Kelly Brazil
ac39ce6b98 formatting 2022-10-14 14:07:05 -07:00
Kelly Brazil
38fb0a6828 allow parser module as parse() argument 2022-10-14 14:05:16 -07:00
Kelly Brazil
38c41cfaf4 formatting 2022-10-14 13:49:10 -07:00
Kelly Brazil
95ba628ac3 add more type annotations 2022-10-14 13:38:05 -07:00
Kelly Brazil
a53f2ecbaf split slot info 2022-10-12 09:07:17 -07:00
Kelly Brazil
aa1ff55bbe lower-case key names 2022-10-12 08:48:42 -07:00
Kelly Brazil
097d013447 remove bail if a, h, or v in magic_options to keep from confusing behavior 2022-10-11 17:18:55 -07:00
Kelly Brazil
3916623c46 remove multiple ands in conditional 2022-10-11 16:22:10 -07:00
Kelly Brazil
42c50c5fa1 remove unneeded fields 2022-10-11 13:44:28 -07:00
Kelly Brazil
ea515bbecc add show_hidden and show_deprecated tests 2022-10-11 12:19:11 -07:00
Kelly Brazil
9f8006060b deprecated parser support in lib 2022-10-10 16:34:32 -07:00
Kelly Brazil
6cd51c4426 add ip_split field 2022-10-10 12:21:02 -07:00
Kelly Brazil
b1e96bb50c add ip_split field 2022-10-10 12:19:39 -07:00
Kelly Brazil
50d3bda3b7 prefix ids with underscores for easier querying with jq, etc. 2022-10-10 11:37:33 -07:00
Kelly Brazil
3dfa4a1bbc rename iso-datetime to datetime-iso 2022-10-09 11:05:32 -07:00
Kelly Brazil
d1922acfc8 add datetime_iso tests 2022-10-09 11:03:31 -07:00
Kelly Brazil
3947e424e7 rename iso-datetime parser to datetime-iso 2022-10-09 11:00:02 -07:00
Kelly Brazil
25e202a09e doc update 2022-10-08 09:04:21 -07:00
Kelly Brazil
8eab3c1590 fixes for cli refactor 2022-10-08 09:04:04 -07:00
Kelly Brazil
4f294aa0ef add pci_ids parser 2022-10-07 16:36:46 -07:00
Kelly Brazil
81aa09a2e2 initial lspci parser 2022-10-07 13:06:20 -07:00
Kelly Brazil
10fc8cb48d add udevadm parser 2022-10-07 11:28:56 -07:00
Kelly Brazil
186f0708cc doc update 2022-10-07 09:34:42 -07:00
Kelly Brazil
622b3ff9ed add __slots__ to timestamp class 2022-10-06 09:05:36 -07:00
Kelly Brazil
c06963c3d6 doc update 2022-10-04 15:16:35 -07:00
Kelly Brazil
9009313748 move error codes from attribute to global constant 2022-10-04 15:04:00 -07:00
Kelly Brazil
d55a8c3079 clean up exit methods 2022-10-04 14:52:51 -07:00
Kelly Brazil
fee6a61f19 Merge pull request #299 from kellyjonbrazil/cli-refactor
Cli refactor
2022-10-04 21:18:58 +00:00
Kelly Brazil
6f1ef09d2a formatting 2022-10-04 14:13:48 -07:00
Kelly Brazil
cf6c13e605 remove old cli module 2022-10-04 14:07:02 -07:00
Kelly Brazil
028f55910a fix for rare instances when the output is a list of lists (yaml | yaml -> json) 2022-10-04 12:14:32 -07:00
Kelly Brazil
d7684d39a8 set magic_run_command_str in magic_parser 2022-10-04 11:48:36 -07:00
Kelly Brazil
f652ccd4b1 fix tests for env_colors 2022-10-04 11:39:50 -07:00
Kelly Brazil
6be92498bc remove self.env_colors attribute 2022-10-04 11:32:18 -07:00
Kelly Brazil
677e04ab7d cleanup 2022-10-04 11:15:37 -07:00
Kelly Brazil
46fdc457fc fix exit codes 2022-10-04 10:10:59 -07:00
Kelly Brazil
0306b6b73b simplify file open method 2022-10-04 09:38:46 -07:00
Kelly Brazil
c881653d55 simplify the run() method 2022-10-04 09:26:40 -07:00
Kelly Brazil
7650d831e3 add slots 2022-10-03 18:03:06 -07:00
Kelly Brazil
e7a8cc3b8b fix unbuffer 2022-10-03 17:38:55 -07:00
Kelly Brazil
d173b2f237 fix magic parser for cases where standard parser is found 2022-10-03 15:04:18 -07:00
Kelly Brazil
49ba6ed0f2 formatting 2022-10-03 13:13:10 -07:00
Kelly Brazil
2792d05c7f fix magic parser and tests 2022-10-03 13:03:42 -07:00
Kelly Brazil
cacda0f3cc fix cli tests 2022-10-03 12:49:13 -07:00
Kelly Brazil
c420547ff8 simplify monochrome settings 2022-10-03 11:30:29 -07:00
Kelly Brazil
83d388613f cleanup 2022-10-03 08:58:09 -07:00
Kelly Brazil
094b059aea fix magic options 2022-10-02 19:30:50 -07:00
Kelly Brazil
e36a8c627b fix meta timestamp 2022-10-02 18:55:54 -07:00
Kelly Brazil
d341e91290 cleanup 2022-10-02 18:29:02 -07:00
Kelly Brazil
557afc95bd initial working 2022-10-02 18:20:14 -07:00
Kelly Brazil
cb9979ac94 refactor cli 2022-10-02 16:58:20 -07:00
Kelly Brazil
5486957141 version bump 2022-09-29 09:14:53 -07:00
Kelly Brazil
d49155df95 make regex patterns raw strings to reduce pytest warnings 2022-09-28 15:09:06 -07:00
Kelly Brazil
0dd4b5f620 parser version bump 2022-09-28 14:56:37 -07:00
Kelly Brazil
690603bfda fix proc-pid-stat parser for command names with spaces and newlines 2022-09-28 14:55:25 -07:00
Kelly Brazil
b877cc9509 Merge pull request #292 from kellyjonbrazil/dev
Dev v1.22.0
2022-09-27 19:40:54 +00:00
Kelly Brazil
32fddce8fb Add autocompletions 2022-09-27 11:49:41 -07:00
Kelly Brazil
03a2b35846 Add metadata object to empty results list 2022-09-27 11:11:16 -07:00
Kelly Brazil
086cdc559c version bump 2022-09-26 19:50:39 -07:00
Kelly Brazil
97eefe28f1 doc fixes 2022-09-26 19:41:35 -07:00
Kelly Brazil
32019c99f4 check git diff 5 commits back before generating parser doc 2022-09-26 19:21:25 -07:00
Kelly Brazil
f30e15159f finalize shell completions 2022-09-26 16:59:55 -07:00
Kelly Brazil
efd0bae0d6 add /proc shel completions 2022-09-26 15:46:59 -07:00
Kelly Brazil
253aa03e07 fix parser order 2022-09-26 13:32:33 -07:00
Kelly Brazil
32183118de update parser order 2022-09-26 13:30:52 -07:00
Kelly Brazil
6c8ad1139c add proc-net-unix parser and tests 2022-09-26 13:28:21 -07:00
Kelly Brazil
980c2907ad add proc-net-route parser and tests 2022-09-26 13:16:18 -07:00
Kelly Brazil
00129f4b40 doc update 2022-09-26 11:41:23 -07:00
Kelly Brazil
f178bea0d0 add signature detection tests for the proc parser 2022-09-26 11:33:48 -07:00
Kelly Brazil
c583598257 add proc-net-protocols parser and tests 2022-09-26 08:28:48 -07:00
Kelly Brazil
1e14425555 add proc-net-packet parser and tests 2022-09-25 20:14:53 -07:00
Kelly Brazil
4a103927cd add proc-net-netstat parser and tests 2022-09-25 20:00:44 -07:00
Kelly Brazil
ab3dc41358 add proc-net-netlink parser and tests 2022-09-25 19:36:12 -07:00
Kelly Brazil
c9fcd3d203 add proc-net-ipv6-route parser and tests 2022-09-25 18:28:23 -07:00
Kelly Brazil
5186347b48 add proc-net-igmp6 parser and tests 2022-09-25 18:16:54 -07:00
Kelly Brazil
e4a40704b5 add proc-net-igmp parser and tests 2022-09-25 15:19:43 -07:00
Kelly Brazil
fcfbbc6d84 add proc-net-if-inet6 parser and tests 2022-09-25 14:13:20 -07:00
Kelly Brazil
95a38c7712 add proc-net-dev-mcast parser docs and tests 2022-09-25 13:50:42 -07:00
Kelly Brazil
be0f4477bf add proc-net-dev_mcast parser 2022-09-25 13:44:29 -07:00
Kelly Brazil
3ebd897601 add ./docgen all functionality 2022-09-25 13:32:03 -07:00
Kelly Brazil
c60e1e8d7f doc update 2022-09-25 13:08:17 -07:00
Kelly Brazil
eb205562bf force docupdate 2022-09-25 13:07:31 -07:00
Kelly Brazil
83a50bb610 add proc-net-dev parser 2022-09-25 13:02:25 -07:00
Kelly Brazil
331171b826 optimize docgen 2022-09-25 12:38:17 -07:00
Kelly Brazil
1d9965dad6 force doc update 2022-09-25 12:35:23 -07:00
Kelly Brazil
647820c75e optimize docgen 2022-09-25 12:09:12 -07:00
Kelly Brazil
d9c7dde174 add proc_net_arp parser and tests 2022-09-25 12:09:01 -07:00
Kelly Brazil
ef8c688fa1 add proc_pid_status parser and tests 2022-09-25 09:57:48 -07:00
Kelly Brazil
b0f0d02e75 add proc-pid-statm parser and tests 2022-09-25 09:03:38 -07:00
Kelly Brazil
51bc2674bd add proc_pid_stat tests 2022-09-24 17:53:24 -07:00
Kelly Brazil
5fc2008517 add proc_pid_smaps and proc_pid_stat parsers 2022-09-24 17:49:43 -07:00
Kelly Brazil
611e5c7ea2 proc_pid tests 2022-09-24 15:48:22 -07:00
Kelly Brazil
74c8b0678a add proc tests 2022-09-23 17:46:52 -07:00
Kelly Brazil
00afd79858 add test fixtures and tests 2022-09-23 16:58:34 -07:00
Kelly Brazil
45fae976f0 test optimizations 2022-09-23 16:30:43 -07:00
Kelly Brazil
ae9c1746f1 proc-buddyinfo tests 2022-09-23 16:19:52 -07:00
Kelly Brazil
fa1699298b new test templates 2022-09-23 16:19:35 -07:00
Kelly Brazil
c8720b259c optimize tests 2022-09-23 14:02:27 -07:00
Kelly Brazil
113a90a5a0 optimize tests 2022-09-23 10:58:28 -07:00
Kelly Brazil
7c0e43b2e1 pidstat doc update 2022-09-22 14:41:40 -07:00
Kelly Brazil
d51df73f37 pid -H vs -h doc fix 2022-09-22 14:35:53 -07:00
Kelly Brazil
8da203648b update ini examples 2022-09-22 14:28:03 -07:00
Kelly Brazil
12cc670fa0 doc update 2022-09-22 08:50:06 -07:00
Kelly Brazil
88222edb7f ini and kv parser: don't convert keynames to lowercase 2022-09-22 08:39:01 -07:00
Kelly Brazil
7ca0a511d5 doc update 2022-09-22 08:15:55 -07:00
Kelly Brazil
02e08403e3 schema update 2022-09-22 08:15:51 -07:00
Kelly Brazil
e29262b95a version bump for free parser 2022-09-22 08:05:05 -07:00
Kelly Brazil
c449914936 Merge pull request #290 from papparapa/fix-free-w-parse
fix wrong test function name
2022-09-22 15:02:41 +00:00
papparapa
9c290b5e11 Merge branch 'dev' into fix-free-w-parse 2022-09-21 19:58:16 +09:00
papparapa
2d9dcde0e3 fix wrong test function name 2022-09-21 10:36:11 +00:00
Kelly Brazil
da681a463e Merge pull request #289 from papparapa/fix-free-w-parse
fix free -w parse
2022-09-21 00:59:16 +00:00
papparapa
aeb494703e Merge branch 'dev' into fix-free-w-parse 2022-09-21 07:43:07 +09:00
papparapa
da4e3670b1 fix free -w parse 2022-09-20 13:02:14 +00:00
Kelly Brazil
075e2301e4 doc update 2022-09-19 21:00:00 -07:00
Kelly Brazil
df3f94b017 doc update and unbindable fix 2022-09-19 20:54:46 -07:00
Kelly Brazil
3df006fb97 use stdlib int conversion 2022-09-19 20:35:18 -07:00
Kelly Brazil
52d98a1157 doc update and schema update 2022-09-19 20:32:26 -07:00
Kelly Brazil
7c772d3a5a split super_options 2022-09-19 19:58:40 -07:00
Kelly Brazil
a583ecba7b add proc-pid-mountinfo parser (initial) 2022-09-19 19:26:08 -07:00
Kelly Brazil
76e7347ecf add proc-pid-maps parser 2022-09-19 18:33:30 -07:00
Kelly Brazil
e49e6ad179 simplify parse code 2022-09-19 17:54:04 -07:00
Kelly Brazil
859bece921 add proc-pid-io parser 2022-09-19 17:49:18 -07:00
Kelly Brazil
8ffde41fa4 add proc-pid-fdinfo parser 2022-09-19 16:50:01 -07:00
Kelly Brazil
c88bf3e94b fix signature order 2022-09-17 17:50:43 -07:00
Kelly Brazil
e623ceacc8 remove unused _process code 2022-09-17 17:43:21 -07:00
Kelly Brazil
92a044ba9b add proc-zoneinfo parser 2022-09-17 17:39:16 -07:00
Kelly Brazil
906eeefa52 add proc-vmstat parser 2022-09-17 13:34:40 -07:00
Kelly Brazil
e5913cd10d add proc-vmstat parser 2022-09-17 13:33:31 -07:00
Kelly Brazil
52d252f199 formatting 2022-09-17 13:27:50 -07:00
Kelly Brazil
28425cc493 add proc-vmallocinfo parser 2022-09-17 13:26:10 -07:00
Kelly Brazil
a0ae19a8fd formatting 2022-09-17 12:36:22 -07:00
Kelly Brazil
0bebb312dd add proc-version parser 2022-09-17 12:32:15 -07:00
Kelly Brazil
0e35e85753 add proc-uptime parser 2022-09-16 16:14:28 -07:00
Kelly Brazil
bc816bb858 add proc-swaps parser 2022-09-16 16:04:25 -07:00
Kelly Brazil
e171861629 add proc-stat parser 2022-09-16 15:54:13 -07:00
Kelly Brazil
8f539af4ab add proc-softirqs parser 2022-09-16 14:50:14 -07:00
Kelly Brazil
122a4d8f32 add proc-slabinfo parser 2022-09-16 11:40:54 -07:00
Kelly Brazil
8bd935791e add proc-partitions parser 2022-09-16 11:17:02 -07:00
Kelly Brazil
edbae09a17 add proc-pagetypeinfo parser 2022-09-16 11:06:33 -07:00
Kelly Brazil
d115d43559 add proc-pid-numa-maps parser 2022-09-16 10:02:44 -07:00
Kelly Brazil
bdb218cb0f doc update 2022-09-15 16:59:15 -07:00
Kelly Brazil
e4e07b76ec doc update 2022-09-15 16:57:45 -07:00
Kelly Brazil
fd28fea3b6 Merge pull request #287 from kellyjonbrazil/procfile
Procfile
2022-09-15 16:15:30 +00:00
Kelly Brazil
d3c1a73ced doc update 2022-09-15 08:49:12 -07:00
Kelly Brazil
c4de1c53b9 Merge pull request #284 from pbrezina/id
id: support space in names
2022-09-15 15:46:32 +00:00
Kelly Brazil
860167b950 Merge pull request #286 from kellyjonbrazil/master
Sync to dev
2022-09-15 15:44:31 +00:00
Kelly Brazil
4ebde3af5f parser version bump 2022-09-15 08:40:58 -07:00
Pavel Březina
ab5e9a46b4 id: support space in names
id parser did not work correctly if space is present in user or group
name.
2022-09-14 13:36:56 +02:00
Kelly Brazil
c348fa89a9 proc-locks fixes 2022-09-13 20:40:48 -07:00
Kelly Brazil
140dc656a2 initial proc-locks parser 2022-09-13 16:45:33 -07:00
Kelly Brazil
2cad23a7f3 add proc-loadavg parser 2022-09-13 16:27:11 -07:00
Kelly Brazil
9e5c3ae6fb add proc-ioports parser 2022-09-13 14:12:24 -07:00
Kelly Brazil
ab33836637 add proc-iomem parser 2022-09-13 14:04:15 -07:00
Kelly Brazil
cb684fa6de update schema and docs 2022-09-13 13:42:06 -07:00
Kelly Brazil
de6307dc38 remove debug print 2022-09-12 22:59:14 -07:00
Kelly Brazil
da51b2b5a0 initial proc_interrupts parser 2022-09-12 22:43:37 -07:00
Kelly Brazil
03f0984e1d doc update 2022-09-09 17:13:43 -07:00
Kelly Brazil
e1f6007dea add proc-filesystems parser 2022-09-09 17:03:51 -07:00
Kelly Brazil
0508256d28 formatting 2022-09-09 16:32:33 -07:00
Kelly Brazil
993fcd989b add driver_rtc parser 2022-09-09 16:28:34 -07:00
Kelly Brazil
65d647bc0a tighten up diskstats signature 2022-09-09 15:20:38 -07:00
Kelly Brazil
23d5204634 simplify parser by using simple_table_parse 2022-09-09 15:07:44 -07:00
Kelly Brazil
8a239b8f9c add proc-diskstats parser 2022-09-09 14:33:12 -07:00
Kelly Brazil
0a89652ae5 doc update 2022-09-08 16:53:26 -07:00
Kelly Brazil
6d6054d1dc update compatibility 2022-09-08 16:52:26 -07:00
Kelly Brazil
bc9cdadfb0 updated schema 2022-09-07 15:23:48 -07:00
Kelly Brazil
cfe98506a5 fix help examples 2022-09-07 14:25:09 -07:00
Kelly Brazil
c4c159f056 clean up examples 2022-09-07 13:56:16 -07:00
Kelly Brazil
4d761d7e8a add exception handling for file open errors 2022-09-07 12:52:05 -07:00
Kelly Brazil
c1f36f7455 add magic syntax for /proc to docs 2022-09-07 12:31:17 -07:00
Kelly Brazil
c976c3226d add magic support for /proc files 2022-09-07 11:59:54 -07:00
Kelly Brazil
cc6287c124 try/except int conversions 2022-09-07 08:40:37 -07:00
Kelly Brazil
966fe97759 add proc-devices parser and doc update 2022-09-06 17:59:26 -07:00
Kelly Brazil
1f2fe65185 add proc-crypto parser and doc update 2022-09-06 17:29:56 -07:00
Kelly Brazil
b83cd24d57 add proc-cpuinfo parser and doc update 2022-09-06 17:05:14 -07:00
Kelly Brazil
5b4e4fd943 add proc-consoles parser and doc update 2022-09-06 15:52:26 -07:00
Kelly Brazil
61cd9acaa2 add buddyinfo parser and doc update 2022-09-06 15:19:59 -07:00
Kelly Brazil
d2895928bd add examples to doc 2022-09-06 11:46:35 -07:00
Kelly Brazil
5c354b02ea doc update 2022-09-06 11:42:24 -07:00
Kelly Brazil
a764642a85 fixup help, man, readme, about docs 2022-09-06 10:07:19 -07:00
Kelly Brazil
a9b0fe6728 add 'hidden' attribute to parsers and wire up to jc.lib.all_parser_info() 2022-09-06 09:21:40 -07:00
Kelly Brazil
79ade2c182 move to module architecture. first two proc parsers 2022-09-04 10:42:16 -07:00
Kelly Brazil
146dc070ea reorder patterns 2022-09-03 14:05:57 -07:00
Kelly Brazil
c1b2bae333 add more net files 2022-09-03 11:34:28 -07:00
Kelly Brazil
e771b36a18 add more signatures 2022-09-03 10:52:35 -07:00
Kelly Brazil
edcb2280cc add more filetypes 2022-09-02 19:20:36 -07:00
Kelly Brazil
a249ca1da3 add initial procfile parser 2022-09-02 18:29:16 -07:00
Kelly Brazil
f1383b5c66 Merge pull request #277 from kellyjonbrazil/dev
fix for ipv6 ip-address parser with older python and version bump
2022-08-29 15:02:04 +00:00
Kelly Brazil
00e497828e Merge branch 'master' into dev 2022-08-29 14:54:40 +00:00
Kelly Brazil
5968eb697e fix for ipv6 ip-address parser with older python and version bump 2022-08-29 07:51:27 -07:00
Kelly Brazil
ea78b389c9 Merge pull request #275 from kellyjonbrazil/dev
Dev v1.21.1
2022-08-28 23:54:24 +00:00
Kelly Brazil
0b726f7acc doc update 2022-08-28 16:41:06 -07:00
Kelly Brazil
4d4b95c995 fix for linx arp -a cases where an icomplete hw address is present 2022-08-28 12:40:46 -07:00
Kelly Brazil
fc06d195ec fix for arp -a cases where there are incomplete hw addresses 2022-08-28 12:31:57 -07:00
Kelly Brazil
c7fc2e3b92 fix for older python versions that don't provide the netmask attribute when a decimal ip is used 2022-08-28 11:58:51 -07:00
Kelly Brazil
980fc77812 version bump 2022-08-28 11:49:32 -07:00
Kelly Brazil
75dc1722da Merge branch 'dev' of https://github.com/kellyjonbrazil/jc into dev 2022-08-28 11:45:59 -07:00
Kelly Brazil
9326f1f0da Merge pull request #274 from kellyjonbrazil/master
Pull doc updates into Dev
2022-08-28 18:45:20 +00:00
Kelly Brazil
ac831444ce fix for older python versions that don't handle decimal ip's cleanly 2022-08-28 11:40:53 -07:00
Kelly Brazil
4746cb3814 add --meta-out info to exit code section 2022-08-24 09:24:03 -07:00
Kelly Brazil
6c38a3bbaa add echo $? to show exit code 2022-08-24 09:11:06 -07:00
Kelly Brazil
9699a184d1 add exit code with --meta-out to readme 2022-08-24 09:07:34 -07:00
Kelly Brazil
51eb2c9fa8 doc update 2022-08-21 16:23:56 -07:00
Kelly Brazil
abf6ea1fec doc update 2022-08-21 16:20:13 -07:00
475 changed files with 72657 additions and 4952 deletions

View File

@@ -1,5 +1,90 @@
jc changelog
20221024 v1.22.1
- add `udevadm` command parser
- add `lspci` command parser
- add `pci.ids` file parser
- fix `proc-pid-stat` parser for command names with spaces and newlines
- enhance `ip-address` parser to add `ip_split` field
- rename `iso-datetime` parser to `datetime-iso`. A deprecation warning will
display until `iso-datetime` is removed in a future version.
- refactor cli module
- optimize performance of calculated timestamps
- add more type annotations
- add support for deprecating parsers
- move jc-web demo site from heroku to render.com
20220926 v1.22.0
- Add /proc file parsers for linux. Support for the following files:
`/proc/buddyinfo`
`/proc/consoles`
`/proc/cpuinfo`
`/proc/crypto`
`/proc/devices`
`/proc/diskstats`
`/proc/filesystems`
`/proc/interrupts`
`/proc/iomem`
`/proc/ioports`
`/proc/loadavg`
`/proc/locks`
`/proc/meminfo`
`/proc/modules`
`/proc/mtrr`
`/proc/pagetypeinfo`
`/proc/partitions`
`/proc/slabinfo`
`/proc/softirqs`
`/proc/stat`
`/proc/swaps`
`/proc/uptime`
`/proc/version`
`/proc/vmallocinfo`
`/proc/vmstat`
`/proc/zoneinfo`
`/proc/driver/rtc`
`/proc/net/arp`
`/proc/net/dev`
`/proc/net/dev_mcast`
`/proc/net/if_inet6`
`/proc/net/igmp`
`/proc/net/igmp6`
`/proc/net/ipv6_route`
`/proc/net/netlink`
`/proc/net/netstat`
`/proc/net/packet`
`/proc/net/protocols`
`/proc/net/route`
`/proc/net/unix`
`/proc/<pid>/fdinfo/<fd>`
`/proc/<pid>/io`
`/proc/<pid>/maps`
`/proc/<pid>/mountinfo`
`/proc/<pid>/numa_maps`
`/proc/<pid>/smaps`
`/proc/<pid>/stat`
`/proc/<pid>/statm`
`/proc/<pid>/status`
- Magic syntax support for `/proc` files
- Enhance bash and zsh autocompletions for `/proc` files
- Enhance `free` parser to support `-w` option integer conversions
- Fix `ini` and `kv` parsers so they don't change keynames to lower case
NOTE: This can be a breaking change in your scripts
- Fix `id` command parser to allow usernames and groupnames with spaces
- Enhance metadata output to output metadata even when results are empty
- Optimize tests
- Optimize documentation build script
20220829 v1.21.2
- Fix IP Address string parser for older python versions that don't cleanly
accept decimal input format - IPv6 fix (e.g. python 3.6)
20220828 v1.21.1
- Fix IP Address string parser for older python versions that don't cleanly
accept decimal input format - IPv4 fix (e.g. python 3.6)
- Fix `arp -a` parser for cases where incomplete hardware addresses are found
in the arp table on linux
20220821 v1.21.0
- Add IP Address string parser
- Add Syslog standard and streaming string parsers (RFC 3164 and RFC 5424)

View File

@@ -1637,18 +1637,18 @@ cat example.ini | jc --ini -p
```json
{
"bitbucket.org": {
"serveraliveinterval": "45",
"compression": "yes",
"compressionlevel": "9",
"forwardx11": "yes",
"user": "hg"
"ServeraLiveInterval": "45",
"Compression": "yes",
"CompressionLevel": "9",
"ForwardX11": "yes",
"User": "hg"
},
"topsecret.server.com": {
"serveraliveinterval": "45",
"compression": "yes",
"compressionlevel": "9",
"forwardx11": "no",
"port": "50022"
"ServeraLiveInterval": "45",
"Compression": "yes",
"CompressionLevel": "9",
"ForwardX11": "no",
"Port": "50022"
}
}
```
@@ -1707,6 +1707,12 @@ echo 192.168.2.10/24 | jc --ip-address -p
"ip": "192.168.2.10",
"ip_compressed": "192.168.2.10",
"ip_exploded": "192.168.2.10",
"ip_split": [
"192",
"168",
"2",
"10"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
@@ -1819,7 +1825,7 @@ iptables --line-numbers -v -L -t nat | jc --iptables -p # or: jc -p ip
```
### ISO Datetime string
```bash
echo "2022-07-20T14:52:45Z" | jc --iso-datetime -p
echo "2022-07-20T14:52:45Z" | jc --datetime-iso -p
```
```json
{

View File

@@ -1,2 +1,3 @@
include jc/py.typed
include man/jc.1
include CHANGELOG

120
README.md
View File

@@ -3,7 +3,7 @@
> 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/)
> Try the `jc` [web demo](https://jc-web.onrender.com/)
> JC is [now available](https://galaxy.ansible.com/community/general) as an
Ansible filter plugin in the `community.general` collection. See this
@@ -70,7 +70,7 @@ values are converted, and, in some cases, additional semantic context fields are
added.
To access the raw, pre-processed JSON, use the `-r` cli option or the `raw=True`
function parameter in `parse()`.
function parameter in `parse()` when using `jc` as a python library.
Schemas for each parser can be found at the documentation link beside each
[**Parser**](#parsers) below.
@@ -133,14 +133,18 @@ on Github.
`jc` accepts piped input from `STDIN` and outputs a JSON representation of the
previous command's output to `STDOUT`.
```bash
COMMAND | jc PARSER [OPTIONS]
COMMAND | jc [OPTIONS] PARSER
cat FILE | jc [OPTIONS] PARSER
echo STRING | jc [OPTIONS] PARSER
```
Alternatively, the "magic" syntax can be used by prepending `jc` to the command
to be converted. Options can be passed to `jc` immediately before the command is
given. (Note: command aliases and shell builtins are not supported)
to be converted or in front of the absolute path for Proc files. Options can be
passed to `jc` immediately before the command or Proc file path is given.
(Note: command aliases and shell builtins are not supported)
```bash
jc [OPTIONS] COMMAND
jc [OPTIONS] /proc/<path-to-procfile>
```
The JSON output can be compact (default) or pretty formatted with the `-p`
@@ -166,6 +170,7 @@ option.
| ` --csv` | CSV file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/csv) |
| ` --csv-s` | CSV file streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/csv_s) |
| ` --date` | `date` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/date) |
| ` --datetime-iso` | ISO 8601 Datetime string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/datetime_iso) |
| ` --df` | `df` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/df) |
| ` --dig` | `dig` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dig) |
| ` --dir` | `dir` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/dir) |
@@ -195,7 +200,6 @@ option.
| ` --iostat-s` | `iostat` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iostat_s) |
| ` --ip-address` | IPv4 and IPv6 Address string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ip_address) |
| ` --iptables` | `iptables` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iptables) |
| ` --iso-datetime` | ISO 8601 Datetime string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iso_datetime) |
| ` --iw-scan` | `iw dev [device] scan` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/iw_scan) |
| ` --jar-manifest` | Java MANIFEST.MF file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/jar_manifest) |
| ` --jobs` | `jobs` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/jobs) |
@@ -207,6 +211,7 @@ option.
| ` --lsblk` | `lsblk` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsblk) |
| ` --lsmod` | `lsmod` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsmod) |
| ` --lsof` | `lsof` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsof) |
| ` --lspci` | `lspci -mmv` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lspci) |
| ` --lsusb` | `lsusb` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb) |
| ` --m3u` | M3U and M3U8 file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/m3u) |
| ` --mdadm` | `mdadm` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/mdadm) |
@@ -217,14 +222,16 @@ option.
| ` --nmcli` | `nmcli` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli) |
| ` --ntpq` | `ntpq -p` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq) |
| ` --passwd` | `/etc/passwd` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd) |
| ` --pidstat` | `pidstat -h` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat) |
| ` --pidstat-s` | `pidstat -h` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat_s) |
| ` --pci-ids` | `pci.ids` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pci_ids) |
| ` --pidstat` | `pidstat -H` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat) |
| ` --pidstat-s` | `pidstat -H` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pidstat_s) |
| ` --ping` | `ping` and `ping6` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ping) |
| ` --ping-s` | `ping` and `ping6` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ping_s) |
| ` --pip-list` | `pip list` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_list) |
| ` --pip-show` | `pip show` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_show) |
| ` --plist` | PLIST file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/plist) |
| ` --postconf` | `postconf -M` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/postconf) |
| ` --proc` | `/proc/` file parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/proc) |
| ` --ps` | `ps` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ps) |
| ` --route` | `route` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/route) |
| ` --rpm-qi` | `rpm -qi` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/rpm_qi) |
@@ -252,6 +259,7 @@ option.
| ` --top-s` | `top -b` command streaming parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/top_s) |
| ` --tracepath` | `tracepath` and `tracepath6` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/tracepath) |
| ` --traceroute` | `traceroute` and `traceroute6` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/traceroute) |
| ` --udevadm` | `udevadm info` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/udevadm) |
| ` --ufw` | `ufw status` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ufw) |
| ` --ufw-appinfo` | `ufw app info [application]` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ufw_appinfo) |
| ` --uname` | `uname -a` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/uname) |
@@ -278,7 +286,7 @@ option.
| `-a` | `--about` | About `jc`. Prints information about `jc` and the parsers (in JSON or YAML, of course!) |
| `-C` | `--force-color` | Force color output even when using pipes (overrides `-m` and the `NO_COLOR` env variable) |
| `-d` | `--debug` | Debug mode. Prints trace messages if parsing issues are encountered (use`-dd` for verbose debugging) |
| `-h` | `--help` | Help. Use `jc -h --parser_name` for parser documentation |
| `-h` | `--help` | Help. Use `jc -h --parser_name` for parser documentation. Use twice to show hidden parsers (e.g. `-hh`) |
| `-m` | `--monochrome` | Monochrome output |
| `-M` | `--meta-out` | Add metadata to output including timestamp, parser name, magic command, magic command exit code, etc. | |
| `-p` | `--pretty` | Pretty format the JSON output |
@@ -292,7 +300,9 @@ option.
### Exit Codes
Any fatal errors within `jc` will generate an exit code of `100`, otherwise the
exit code will be `0`. When using the "magic" syntax (e.g. `jc ifconfig eth0`),
exit code will be `0`.
When using the "magic" syntax (e.g. `jc ifconfig eth0`),
`jc` will store the exit code of the program being parsed and add it to the `jc`
exit code. This way it is easier to determine if an error was from the parsed
program or `jc`.
@@ -306,6 +316,44 @@ Consider the following examples using `ifconfig`:
| `0` | `100` | `100` | Error in `jc` |
| `1` | `100` | `101` | Error in both `ifconfig` and `jc` |
When using the "magic" syntax you can also retrieve the exit code of the called
program by using the `--meta-out` or `-M` option. This will append a `_jc_meta`
object to the output that will include the magic command information, including
the exit code.
Here is an example with `ping`:
```bash
$ jc --meta-out -p ping -c2 192.168.1.252
{
"destination_ip": "192.168.1.252",
"data_bytes": 56,
"pattern": null,
"destination": "192.168.1.252",
"packets_transmitted": 2,
"packets_received": 0,
"packet_loss_percent": 100.0,
"duplicates": 0,
"responses": [
{
"type": "timeout",
"icmp_seq": 0,
"duplicate": false
}
],
"_jc_meta": {
"parser": "ping",
"timestamp": 1661357115.27949,
"magic_command": [
"ping",
"-c2",
"192.168.1.252"
],
"magic_command_exit": 2
}
}
$ echo $?
2
```
### Setting Custom Colors via Environment Variable
You can specify custom colors via the `JC_COLORS` environment variable. The
@@ -497,12 +545,12 @@ that case you can suppress the warning message with the `-q` cli option or the
macOS:
```bash
cat lsof.out | jc --lsof -q
cat lsof.out | jc -q --lsof
```
or Windows:
```bash
type lsof.out | jc --lsof -q
type lsof.out | jc -q --lsof
```
Tested on:
@@ -546,7 +594,7 @@ documentation.
### arp
```bash
arp | jc --arp -p # or: jc -p arp
arp | jc -p --arp # or: jc -p arp
```
```json
[
@@ -585,7 +633,7 @@ cat homes.csv
...
```
```bash
cat homes.csv | jc --csv -p
cat homes.csv | jc -p --csv
```
```json
[
@@ -626,7 +674,7 @@ cat homes.csv | jc --csv -p
```
### /etc/hosts file
```bash
cat /etc/hosts | jc --hosts -p
cat /etc/hosts | jc -p --hosts
```
```json
[
@@ -653,7 +701,7 @@ cat /etc/hosts | jc --hosts -p
```
### ifconfig
```bash
ifconfig | jc --ifconfig -p # or: jc -p ifconfig
ifconfig | jc -p --ifconfig # or: jc -p ifconfig
```
```json
[
@@ -711,29 +759,29 @@ Port = 50022
ForwardX11 = no
```
```bash
cat example.ini | jc --ini -p
cat example.ini | jc -p --ini
```
```json
{
"bitbucket.org": {
"serveraliveinterval": "45",
"compression": "yes",
"compressionlevel": "9",
"forwardx11": "yes",
"user": "hg"
"ServeraLiveInterval": "45",
"Compression": "yes",
"CompressionLevel": "9",
"ForwardX11": "yes",
"User": "hg"
},
"topsecret.server.com": {
"serveraliveinterval": "45",
"compression": "yes",
"compressionlevel": "9",
"forwardx11": "no",
"port": "50022"
"ServeraLiveInterval": "45",
"Compression": "yes",
"CompressionLevel": "9",
"ForwardX11": "no",
"Port": "50022"
}
}
```
### ls
```bash
$ ls -l /usr/bin | jc --ls -p # or: jc -p ls -l /usr/bin
$ ls -l /usr/bin | jc -p --ls # or: jc -p ls -l /usr/bin
```
```json
[
@@ -769,7 +817,7 @@ $ ls -l /usr/bin | jc --ls -p # or: jc -p ls -l /usr/bin
```
### netstat
```bash
netstat -apee | jc --netstat -p # or: jc -p netstat -apee
netstat -apee | jc -p --netstat # or: jc -p netstat -apee
```
```json
[
@@ -857,7 +905,7 @@ netstat -apee | jc --netstat -p # or: jc -p netstat -apee
```
### /etc/passwd file
```bash
cat /etc/passwd | jc --passwd -p
cat /etc/passwd | jc -p --passwd
```
```json
[
@@ -883,7 +931,7 @@ cat /etc/passwd | jc --passwd -p
```
### ping
```bash
ping 8.8.8.8 -c 3 | jc --ping -p # or: jc -p ping 8.8.8.8 -c 3
ping 8.8.8.8 -c 3 | jc -p --ping # or: jc -p ping 8.8.8.8 -c 3
```
```json
{
@@ -936,7 +984,7 @@ ping 8.8.8.8 -c 3 | jc --ping -p # or: jc -p ping 8.8.8.8 -c 3
```
### ps
```bash
ps axu | jc --ps -p # or: jc -p ps axu
ps axu | jc -p --ps # or: jc -p ps axu
```
```json
[
@@ -983,7 +1031,7 @@ ps axu | jc --ps -p # or: jc -p ps axu
```
### traceroute
```bash
traceroute -m 2 8.8.8.8 | jc --traceroute -p
traceroute -m 2 8.8.8.8 | jc -p --traceroute
# or: jc -p traceroute -m 2 8.8.8.8
```
```json
@@ -1048,7 +1096,7 @@ traceroute -m 2 8.8.8.8 | jc --traceroute -p
```
### uptime
```bash
uptime | jc --uptime -p # or: jc -p uptime
uptime | jc -p --uptime # or: jc -p uptime
```
```json
{
@@ -1093,7 +1141,7 @@ cat cd_catalog.xml
...
```
```bash
cat cd_catalog.xml | jc --xml -p
cat cd_catalog.xml | jc -p --xml
```
```json
{
@@ -1145,7 +1193,7 @@ spec:
mode: ISTIO_MUTUAL
```
```bash
cat istio.yaml | jc --yaml -p
cat istio.yaml | jc -p --yaml
```
```json
[

View File

@@ -3,8 +3,8 @@ _jc()
local cur prev words cword jc_commands jc_parsers jc_options \
jc_about_options jc_about_mod_options jc_help_options jc_special_options
jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lsusb md5 md5sum mdadm mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo)
jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --cef --cef-s --chage --cksum --crontab --crontab-u --csv --csv-s --date --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iso-datetime --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --stat --stat-s --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo)
jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 udevadm ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo)
jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --cef --cef-s --chage --cksum --crontab --crontab-u --csv --csv-s --date --datetime-iso --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pci-ids --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --stat --stat-s --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo)
jc_options=(--force-color -C --debug -d --monochrome -m --meta-out -M --pretty -p --quiet -q --raw -r --unbuffer -u --yaml-out -y)
jc_about_options=(--about -a)
jc_about_mod_options=(--pretty -p --yaml-out -y --monochrome -m --force-color -C)
@@ -67,6 +67,12 @@ _jc()
fi
done
# if "/pr[oc]" (magic for Procfile parsers) is in the current word, complete with files/directories in the path
if [[ "${cur}" =~ "/pr" ]]; then
_filedir
return 0
fi
# if a parser arg is found anywhere in the line, only show options and help options
for i in "${words[@]::${#words[@]}-1}"; do
if [[ " ${jc_parsers[*]} " =~ " ${i} " ]]; then

View File

@@ -9,7 +9,7 @@ _jc() {
jc_help_options jc_help_options_describe \
jc_special_options jc_special_options_describe
jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lsusb md5 md5sum mdadm mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo)
jc_commands=(acpi airport arp blkid chage cksum crontab date df dig dmidecode dpkg du env file finger free git gpg hciconfig id ifconfig iostat iptables iw jobs last lastb ls lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat netstat nmcli ntpq pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss stat sum sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 udevadm ufw uname update-alternatives upower uptime vdir vmstat w wc who xrandr zipinfo)
jc_commands_describe=(
'acpi:run "acpi" command with magic syntax.'
'airport:run "airport" command with magic syntax.'
@@ -43,6 +43,7 @@ _jc() {
'lsblk:run "lsblk" command with magic syntax.'
'lsmod:run "lsmod" command with magic syntax.'
'lsof:run "lsof" command with magic syntax.'
'lspci:run "lspci" command with magic syntax.'
'lsusb:run "lsusb" command with magic syntax.'
'md5:run "md5" command with magic syntax.'
'md5sum:run "md5sum" command with magic syntax.'
@@ -82,6 +83,7 @@ _jc() {
'tracepath6:run "tracepath6" command with magic syntax.'
'traceroute:run "traceroute" command with magic syntax.'
'traceroute6:run "traceroute6" command with magic syntax.'
'udevadm:run "udevadm" command with magic syntax.'
'ufw:run "ufw" command with magic syntax.'
'uname:run "uname" command with magic syntax.'
'update-alternatives:run "update-alternatives" command with magic syntax.'
@@ -95,7 +97,7 @@ _jc() {
'xrandr:run "xrandr" command with magic syntax.'
'zipinfo:run "zipinfo" command with magic syntax.'
)
jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --cef --cef-s --chage --cksum --crontab --crontab-u --csv --csv-s --date --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iso-datetime --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --stat --stat-s --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo)
jc_parsers=(--acpi --airport --airport-s --arp --asciitable --asciitable-m --blkid --cef --cef-s --chage --cksum --crontab --crontab-u --csv --csv-s --date --datetime-iso --df --dig --dir --dmidecode --dpkg-l --du --email-address --env --file --finger --free --fstab --git-log --git-log-s --gpg --group --gshadow --hash --hashsum --hciconfig --history --hosts --id --ifconfig --ini --iostat --iostat-s --ip-address --iptables --iw-scan --jar-manifest --jobs --jwt --kv --last --ls --ls-s --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --netstat --nmcli --ntpq --passwd --pci-ids --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --plist --postconf --proc --proc-buddyinfo --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --route --rpm-qi --rsync --rsync-s --sfdisk --shadow --ss --stat --stat-s --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --top --top-s --tracepath --traceroute --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --vmstat --vmstat-s --w --wc --who --x509-cert --xml --xrandr --yaml --zipinfo)
jc_parsers_describe=(
'--acpi:`acpi` command parser'
'--airport:`airport -I` command parser'
@@ -113,6 +115,7 @@ _jc() {
'--csv:CSV file parser'
'--csv-s:CSV file streaming parser'
'--date:`date` command parser'
'--datetime-iso:ISO 8601 Datetime string parser'
'--df:`df` command parser'
'--dig:`dig` command parser'
'--dir:`dir` command parser'
@@ -142,7 +145,6 @@ _jc() {
'--iostat-s:`iostat` command streaming parser'
'--ip-address:IPv4 and IPv6 Address string parser'
'--iptables:`iptables` command parser'
'--iso-datetime:ISO 8601 Datetime string parser'
'--iw-scan:`iw dev [device] scan` command parser'
'--jar-manifest:Java MANIFEST.MF file parser'
'--jobs:`jobs` command parser'
@@ -154,6 +156,7 @@ _jc() {
'--lsblk:`lsblk` command parser'
'--lsmod:`lsmod` command parser'
'--lsof:`lsof` command parser'
'--lspci:`lspci -mmv` command parser'
'--lsusb:`lsusb` command parser'
'--m3u:M3U and M3U8 file parser'
'--mdadm:`mdadm` command parser'
@@ -164,14 +167,65 @@ _jc() {
'--nmcli:`nmcli` command parser'
'--ntpq:`ntpq -p` command parser'
'--passwd:`/etc/passwd` file parser'
'--pidstat:`pidstat -h` command parser'
'--pidstat-s:`pidstat -h` command streaming parser'
'--pci-ids:`pci.ids` file parser'
'--pidstat:`pidstat -H` command parser'
'--pidstat-s:`pidstat -H` command streaming parser'
'--ping:`ping` and `ping6` command parser'
'--ping-s:`ping` and `ping6` command streaming parser'
'--pip-list:`pip list` command parser'
'--pip-show:`pip show` command parser'
'--plist:PLIST file parser'
'--postconf:`postconf -M` command parser'
'--proc:`/proc/` file parser'
'--proc-buddyinfo:`/proc/buddyinfo` file parser'
'--proc-consoles:`/proc/consoles` file parser'
'--proc-cpuinfo:`/proc/cpuinfo` file parser'
'--proc-crypto:`/proc/crypto` file parser'
'--proc-devices:`/proc/devices` file parser'
'--proc-diskstats:`/proc/diskstats` file parser'
'--proc-filesystems:`/proc/filesystems` file parser'
'--proc-interrupts:`/proc/interrupts` file parser'
'--proc-iomem:`/proc/iomem` file parser'
'--proc-ioports:`/proc/ioports` file parser'
'--proc-loadavg:`/proc/loadavg` file parser'
'--proc-locks:`/proc/locks` file parser'
'--proc-meminfo:`/proc/meminfo` file parser'
'--proc-modules:`/proc/modules` file parser'
'--proc-mtrr:`/proc/mtrr` file parser'
'--proc-pagetypeinfo:`/proc/pagetypeinfo` file parser'
'--proc-partitions:`/proc/partitions` file parser'
'--proc-slabinfo:`/proc/slabinfo` file parser'
'--proc-softirqs:`/proc/softirqs` file parser'
'--proc-stat:`/proc/stat` file parser'
'--proc-swaps:`/proc/swaps` file parser'
'--proc-uptime:`/proc/uptime` file parser'
'--proc-version:`/proc/version` file parser'
'--proc-vmallocinfo:`/proc/vmallocinfo` file parser'
'--proc-vmstat:`/proc/vmstat` file parser'
'--proc-zoneinfo:`/proc/zoneinfo` file parser'
'--proc-driver-rtc:`/proc/driver/rtc` file parser'
'--proc-net-arp:`/proc/net/arp` file parser'
'--proc-net-dev:`/proc/net/dev` file parser'
'--proc-net-dev-mcast:`/proc/net/dev_mcast` file parser'
'--proc-net-if-inet6:`/proc/net/if_inet6` file parser'
'--proc-net-igmp:`/proc/net/igmp` file parser'
'--proc-net-igmp6:`/proc/net/igmp6` file parser'
'--proc-net-ipv6-route:`/proc/net/ipv6_route` file parser'
'--proc-net-netlink:`/proc/net/netlink` file parser'
'--proc-net-netstat:`/proc/net/netstat` file parser'
'--proc-net-packet:`/proc/net/packet` file parser'
'--proc-net-protocols:`/proc/net/protocols` file parser'
'--proc-net-route:`/proc/net/route` file parser'
'--proc-net-unix:`/proc/net/unix` file parser'
'--proc-pid-fdinfo:`/proc/<pid>/fdinfo/<fd>` file parser'
'--proc-pid-io:`/proc/<pid>/io` file parser'
'--proc-pid-maps:`/proc/<pid>/maps` file parser'
'--proc-pid-mountinfo:`/proc/<pid>/mountinfo` file parser'
'--proc-pid-numa-maps:`/proc/<pid>/numa_maps` file parser'
'--proc-pid-smaps:`/proc/<pid>/smaps` file parser'
'--proc-pid-stat:`/proc/<pid>/stat` file parser'
'--proc-pid-statm:`/proc/<pid>/statm` file parser'
'--proc-pid-status:`/proc/<pid>/status` file parser'
'--ps:`ps` command parser'
'--route:`route` command parser'
'--rpm-qi:`rpm -qi` command parser'
@@ -199,6 +253,7 @@ _jc() {
'--top-s:`top -b` command streaming parser'
'--tracepath:`tracepath` and `tracepath6` command parser'
'--traceroute:`traceroute` and `traceroute6` command parser'
'--udevadm:`udevadm info` command parser'
'--ufw:`ufw status` command parser'
'--ufw-appinfo:`ufw app info [application]` command parser'
'--uname:`uname -a` command parser'
@@ -327,6 +382,13 @@ _jc() {
fi
done
# if "/pr[oc]" (magic for Procfile parsers) is in the current word, complete with files/directories in the path
if [[ "${words[-1]}" =~ "/pr" ]]; then
# run files completion
_files
return 0
fi
# if a parser arg is found anywhere in the line, only show options and help options
for i in ${words:0:-1}; do
if (( $jc_parsers[(Ie)${i}] )); then

View File

@@ -1,6 +1,9 @@
#!/bin/bash
# Generate docs.md
# requires pydoc-markdown 4.6.1
# use ./docgen all to generate all docs
readme_config=$(cat <<'EOF'
{
"processors": [
@@ -112,23 +115,25 @@ do
parsers+=("$value")
done < <(jc -a | jq -c '.parsers[] | select(.plugin != true)')
for parser in "${parsers[@]}"
do (
for parser in "${parsers[@]}"; do
parser_name=$(jq -r '.name' <<< "$parser")
compatible=$(jq -r '.compatible | join(", ")' <<< "$parser")
version=$(jq -r '.version' <<< "$parser")
author=$(jq -r '.author' <<< "$parser")
author_email=$(jq -r '.author_email' <<< "$parser")
{
if [[ $1 == "all" ]] || ! git diff --quiet --exit-code HEAD~5 -- "parsers/${parser_name}.py"; then
compatible=$(jq -r '.compatible | join(", ")' <<< "$parser")
version=$(jq -r '.version' <<< "$parser")
author=$(jq -r '.author' <<< "$parser")
author_email=$(jq -r '.author_email' <<< "$parser")
echo "Building docs for: ${parser_name}"
echo "[Home](https://kellyjonbrazil.github.io/jc/)" > ../docs/parsers/"${parser_name}".md
pydoc-markdown -m jc.parsers."${parser_name}" "${parser_config}" >> ../docs/parsers/"${parser_name}".md
echo "### Parser Information" >> ../docs/parsers/"${parser_name}".md
echo "Compatibility: ${compatible}" >> ../docs/parsers/"${parser_name}".md
echo >> ../docs/parsers/"${parser_name}".md
echo "Version ${version} by ${author} (${author_email})" >> ../docs/parsers/"${parser_name}".md
echo "+++ ${parser_name} docs complete"
) &
echo "Building docs for: ${parser_name}"
echo "[Home](https://kellyjonbrazil.github.io/jc/)" > ../docs/parsers/"${parser_name}".md
pydoc-markdown -m jc.parsers."${parser_name}" "${parser_config}" >> ../docs/parsers/"${parser_name}".md
echo "### Parser Information" >> ../docs/parsers/"${parser_name}".md
echo "Compatibility: ${compatible}" >> ../docs/parsers/"${parser_name}".md
echo >> ../docs/parsers/"${parser_name}".md
echo "Version ${version} by ${author} (${author_email})" >> ../docs/parsers/"${parser_name}".md
echo "+++ ${parser_name} docs complete"
fi
} &
done
wait
echo "Document Generation Complete"

View File

@@ -21,27 +21,49 @@ jc - JSON Convert lib module
### parse
```python
def parse(parser_mod_name: str,
data: Union[str, bytes, Iterable[str]],
quiet: bool = False,
raw: bool = False,
ignore_exceptions: bool = None,
**kwargs) -> Union[Dict, List[Dict], Iterator[Dict]]
def parse(
parser_mod_name: Union[str, ModuleType],
data: Union[str, bytes, Iterable[str]],
quiet: bool = False,
raw: bool = False,
ignore_exceptions: bool = None,
**kwargs
) -> Union[JSONDictType, List[JSONDictType], Iterator[JSONDictType]]
```
Parse the string data using the supplied parser module.
Parse the data (string or bytes) using the supplied parser (string or
module object).
This function provides a high-level API to simplify parser use. This
function will call built-in parsers and custom plugin parsers.
Example:
Example (standard parsers):
>>> import jc
>>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
{'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...}
>>> date_obj = jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
>>> print(f'The year is: {date_obj["year"]}')
The year is: 2022
Example (streaming parsers):
>>> import jc
>>> ping_gen = jc.parse('ping_s', ping_output.splitlines())
>>> for item in ping_gen:
>>> print(f'Response time: {item["time_ms"]} ms')
Response time: 102 ms
Response time: 109 ms
...
To get a list of available parser module names, use `parser_mod_list()`.
Alternatively, a parser module object can be supplied:
>>> import jc
>>> import jc.parsers.date as jc_date
>>> date_obj = jc.parse(jc_date, 'Tue Jan 18 10:23:07 PST 2022')
>>> print(f'The year is: {date_obj["year"]}')
The year is: 2022
You can also use the lower-level parser modules directly:
>>> import jc.parsers.date
@@ -62,11 +84,14 @@ parsers without this API:
Parameters:
parser_mod_name: (string) name of the parser module. This
function will accept module_name,
parser_mod_name: (string or name of the parser module. This
Module) function will accept module_name,
cli-name, and --argument-name
variants of the module name.
A Module object can also be passed
directly or via _get_parser()
data: (string or data to parse (string or bytes for
bytes or standard parsers, iterable of
iterable) strings for streaming parsers)
@@ -88,7 +113,8 @@ Returns:
### parser\_mod\_list
```python
def parser_mod_list() -> List[str]
def parser_mod_list(show_hidden: bool = False,
show_deprecated: bool = False) -> List[str]
```
Returns a list of all available parser module names.
@@ -98,7 +124,8 @@ Returns a list of all available parser module names.
### plugin\_parser\_mod\_list
```python
def plugin_parser_mod_list() -> List[str]
def plugin_parser_mod_list(show_hidden: bool = False,
show_deprecated: bool = False) -> List[str]
```
Returns a list of plugin parser module names. This function is a
@@ -109,7 +136,8 @@ subset of `parser_mod_list()`.
### standard\_parser\_mod\_list
```python
def standard_parser_mod_list() -> List[str]
def standard_parser_mod_list(show_hidden: bool = False,
show_deprecated: bool = False) -> List[str]
```
Returns a list of standard parser module names. This function is a
@@ -121,7 +149,8 @@ parsers.
### streaming\_parser\_mod\_list
```python
def streaming_parser_mod_list() -> List[str]
def streaming_parser_mod_list(show_hidden: bool = False,
show_deprecated: bool = False) -> List[str]
```
Returns a list of streaming parser module names. This function is a
@@ -132,7 +161,8 @@ subset of `parser_mod_list()`.
### parser\_info
```python
def parser_info(parser_mod_name: str, documentation: bool = False) -> Dict
def parser_info(parser_mod_name: str,
documentation: bool = False) -> ParserInfoType
```
Returns a dictionary that includes the parser module metadata.
@@ -151,15 +181,22 @@ Parameters:
### all\_parser\_info
```python
def all_parser_info(documentation: bool = False) -> List[Dict]
def all_parser_info(documentation: bool = False,
show_hidden: bool = False,
show_deprecated: bool = False) -> List[ParserInfoType]
```
Returns a list of dictionaries that includes metadata for all parser
modules.
modules. By default only non-hidden, non-deprecated parsers are
returned.
Parameters:
documentation: (boolean) include parser docstrings if True
show_hidden: (boolean) also show parsers marked as hidden
in their info metadata.
show_deprecated: (boolean) also show parsers marked as
deprecated in their info metadata.
<a id="jc.lib.get_help"></a>

View File

@@ -140,4 +140,4 @@ Returns:
### Parser Information
Compatibility: linux, aix, freebsd, darwin
Version 1.10 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.11 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,91 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.datetime_iso"></a>
# jc.parsers.datetime\_iso
jc - JSON Convert ISO 8601 Datetime string parser
This parser supports standard ISO 8601 strings that include both date and
time. If no timezone or offset information is available in the sring, then
UTC timezone is used.
Usage (cli):
$ echo "2022-07-20T14:52:45Z" | jc --iso-datetime
Usage (module):
import jc
result = jc.parse('iso_datetime', iso_8601_string)
Schema:
{
"year": integer,
"month": string,
"month_num": integer,
"day": integer,
"weekday": string,
"weekday_num": integer,
"hour": integer,
"hour_24": integer,
"minute": integer,
"second": integer,
"microsecond": integer,
"period": string,
"utc_offset": string,
"day_of_year": integer,
"week_of_year": integer,
"iso": string,
"timestamp": integer # [0]
}
[0] timezone aware UNIX timestamp expressed in UTC
Examples:
$ echo "2022-07-20T14:52:45Z" | jc --iso-datetime -p
{
"year": 2022,
"month": "Jul",
"month_num": 7,
"day": 20,
"weekday": "Wed",
"weekday_num": 3,
"hour": 2,
"hour_24": 14,
"minute": 52,
"second": 45,
"microsecond": 0,
"period": "PM",
"utc_offset": "+0000",
"day_of_year": 201,
"week_of_year": 29,
"iso": "2022-07-20T14:52:45+00:00",
"timestamp": 1658328765
}
<a id="jc.parsers.datetime_iso.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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux, aix, freebsd, darwin, win32, cygwin
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -95,4 +95,4 @@ Returns:
### Parser Information
Compatibility: linux
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -128,4 +128,4 @@ Returns:
### Parser Information
Compatibility: linux, darwin, aix, freebsd
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -54,18 +54,18 @@ Examples:
$ cat example.ini | jc --ini -p
{
"bitbucket.org": {
"serveraliveinterval": "45",
"compression": "yes",
"compressionlevel": "9",
"forwardx11": "yes",
"user": "hg"
"ServerAliveInterval": "45",
"Compression": "yes",
"CompressionLevel": "9",
"ForwardX11": "yes",
"User": "hg"
},
"topsecret.server.com": {
"serveraliveinterval": "45",
"compression": "yes",
"compressionlevel": "9",
"forwardx11": "no",
"port": "50022"
"ServerAliveInterval": "45",
"Compression": "yes",
"CompressionLevel": "9",
"ForwardX11": "no",
"Port": "50022"
}
}
@@ -92,4 +92,4 @@ Returns:
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -26,6 +26,9 @@ Schema:
"ip": string,
"ip_compressed": string,
"ip_exploded": string,
"ip_split": [
string
],
"scope_id": string/null,
"ipv4_mapped": string/null,
"six_to_four": string/null,
@@ -83,6 +86,12 @@ Examples:
"ip": "192.168.2.10",
"ip_compressed": "192.168.2.10",
"ip_exploded": "192.168.2.10",
"ip_split": [
"192",
"168",
"2",
"10"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
@@ -138,6 +147,12 @@ Examples:
"ip": "192.168.2.10",
"ip_compressed": "192.168.2.10",
"ip_exploded": "192.168.2.10",
"ip_split": [
"192",
"168",
"2",
"10"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
@@ -191,14 +206,24 @@ Examples:
"version": 6,
"max_prefix_length": 128,
"ip": "127:0:de::1",
"ip_compressed": "127:0:de::1%128",
"ip_compressed": "127:0:de::1",
"ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001",
"ip_split": [
"0127",
"0000",
"00de",
"0000",
"0000",
"0000",
"0000",
"0001"
],
"scope_id": "128",
"ipv4_mapped": null,
"six_to_four": null,
"teredo_client": null,
"teredo_server": null,
"dns_ptr": "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.....0.7.2.1.0.ip6.arpa",
"dns_ptr": "1.0.0.0.0.0...0.0.0.e.d.0.0.0.0.0.0.7.2.1.0.ip6.arpa",
"network": "127:0:de::",
"broadcast": "127:0:de::ffff:ffff",
"hostmask": "::ffff:ffff",
@@ -231,13 +256,13 @@ Examples:
"last_host": "01:27:00:00:00:de:00:00:00:00:00:00:ff:ff:ff:fe"
},
"bin": {
"ip": "000000010010011100000000000000000000000011011110000000...",
"network": "0000000100100111000000000000000000000000110111100...",
"broadcast": "00000001001001110000000000000000000000001101111...",
"hostmask": "000000000000000000000000000000000000000000000000...",
"netmask": "1111111111111111111111111111111111111111111111111...",
"first_host": "0000000100100111000000000000000000000000110111...",
"last_host": "00000001001001110000000000000000000000001101111..."
"ip": "0000000100100111000000000000000000000000110...000000000001",
"network": "00000001001001110000000000000000000000...000000000000",
"broadcast": "000000010010011100000000000000000000...111111111111",
"hostmask": "0000000000000000000000000000000000000...111111111111",
"netmask": "11111111111111111111111111111111111111...000000000000",
"first_host": "00000001001001110000000000000000000...000000000001",
"last_host": "000000010010011100000000000000000000...1111111111110"
}
}
@@ -248,12 +273,22 @@ Examples:
"ip": "127:0:de::1",
"ip_compressed": "127:0:de::1",
"ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001",
"ip_split": [
"0127",
"0000",
"00de",
"0000",
"0000",
"0000",
"0000",
"0001"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
"teredo_client": null,
"teredo_server": null,
"dns_ptr": "1.0.0.0.0.0.0....0.0.0.e.d.0.0.0.0.0.0.7.2.1.0.ip6.arpa",
"dns_ptr": "1.0.0.0.0.0....0.0.0.0.e.d.0.0.0.0.0.0.7.2.1.0.ip6.arpa",
"network": "127:0:de::1",
"broadcast": "127:0:de::1",
"hostmask": "::",
@@ -286,13 +321,13 @@ Examples:
"last_host": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01"
},
"bin": {
"ip": "0000000100100111000000000000000000000000110111100000000...",
"network": "00000001001001110000000000000000000000001101111000...",
"broadcast": "000000010010011100000000000000000000000011011110...",
"hostmask": "0000000000000000000000000000000000000000000000000...",
"netmask": "11111111111111111111111111111111111111111111111111...",
"first_host": "00000001001001110000000000000000000000001101111...",
"last_host": "000000010010011100000000000000000000000011011110..."
"ip": "0000000100100111000000000000000000000000110111100...000001",
"network": "00000001001001110000000000000000000000001101...000001",
"broadcast": "000000010010011100000000000000000000000011...000001",
"hostmask": "0000000000000000000000000000000000000000000...000000",
"netmask": "11111111111111111111111111111111111111111111...111111",
"first_host": "00000001001001110000000000000000000000001...000001",
"last_host": "000000010010011100000000000000000000000011...0000001"
}
}
@@ -304,12 +339,22 @@ Examples:
"ip": "::ffff:c0a8:123",
"ip_compressed": "::ffff:c0a8:123",
"ip_exploded": "0000:0000:0000:0000:0000:ffff:c0a8:0123",
"ip_split": [
"0000",
"0000",
"0000",
"0000",
"0000",
"ffff",
"c0a8",
"0123"
],
"scope_id": null,
"ipv4_mapped": "192.168.1.35",
"six_to_four": null,
"teredo_client": null,
"teredo_server": null,
"dns_ptr": "3.2.1.0.8.a.0.c.f.f.f.f.0.0.0....0.0.0.0.0.0.0.ip6.arpa",
"dns_ptr": "3.2.1.0.8.a.0.c.f.f.f.f.0.0....0.0.0.0.0.0.ip6.arpa",
"network": "::ffff:c0a8:123",
"broadcast": "::ffff:c0a8:123",
"hostmask": "::",
@@ -342,13 +387,13 @@ Examples:
"last_host": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23"
},
"bin": {
"ip": "0000000000000000000000000000000000000000000000000000000...",
"network": "00000000000000000000000000000000000000000000000000...",
"broadcast": "000000000000000000000000000000000000000000000000...",
"hostmask": "0000000000000000000000000000000000000000000000000...",
"netmask": "11111111111111111111111111111111111111111111111111...",
"first_host": "00000000000000000000000000000000000000000000000...",
"last_host": "000000000000000000000000000000000000000000000000..."
"ip": "000000000000000000000000000000000000000000000...100100011",
"network": "0000000000000000000000000000000000000000...000100011",
"broadcast": "00000000000000000000000000000000000000...000100011",
"hostmask": "000000000000000000000000000000000000000...000000000",
"netmask": "1111111111111111111111111111111111111111...111111111",
"first_host": "0000000000000000000000000000000000000...100100011",
"last_host": "00000000000000000000000000000000000000...0100100011"
}
}
@@ -360,12 +405,22 @@ Examples:
"ip": "2002:c000:204::",
"ip_compressed": "2002:c000:204::",
"ip_exploded": "2002:c000:0204:0000:0000:0000:0000:0000",
"ip_split": [
"2002",
"c000",
"0204",
"0000",
"0000",
"0000",
"0000",
"0000"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": "192.0.2.4",
"teredo_client": null,
"teredo_server": null,
"dns_ptr": "0.0.0.0.0.0.0.0......0.4.0.2.0.0.0.0.c.2.0.0.2.ip6.arpa",
"dns_ptr": "0.0.0.0.0.0.0...0.0.0.4.0.2.0.0.0.0.c.2.0.0.2.ip6.arpa",
"network": "2002:c000:204::",
"broadcast": "2002:c000:204:ffff:ffff:ffff:ffff:ffff",
"hostmask": "::ffff:ffff:ffff:ffff:ffff",
@@ -398,13 +453,13 @@ Examples:
"last_host": "20:02:c0:00:02:04:ff:ff:ff:ff:ff:ff:ff:ff:ff:fe"
},
"bin": {
"ip": "0010000000000010110000000000000000000010000001000000000...",
"network": "00100000000000101100000000000000000000100000010000...",
"broadcast": "001000000000001011000000000000000000001000000100...",
"hostmask": "0000000000000000000000000000000000000000000000001...",
"netmask": "11111111111111111111111111111111111111111111111100...",
"first_host": "00100000000000101100000000000000000000100000010...",
"last_host": "001000000000001011000000000000000000001000000100..."
"ip": "00100000000000101100000000000000000000100000010...00000000",
"network": "001000000000001011000000000000000000001000...00000000",
"broadcast": "0010000000000010110000000000000000000010...11111111",
"hostmask": "00000000000000000000000000000000000000000...11111111",
"netmask": "111111111111111111111111111111111111111111...00000000",
"first_host": "001000000000001011000000000000000000001...00000001",
"last_host": "0010000000000010110000000000000000000010...111111110"
}
}
@@ -416,12 +471,22 @@ Examples:
"ip": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
"ip_compressed": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
"ip_exploded": "2001:0000:4136:e378:8000:63bf:3fff:fdd2",
"ip_split": [
"2001",
"0000",
"4136",
"e378",
"8000",
"63bf",
"3fff",
"fdd2"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
"teredo_client": "192.0.2.45",
"teredo_server": "65.54.227.120",
"dns_ptr": "2.d.d.f.f.f.f.3.f.b.3.6.0.0.0....0.0.0.1.0.0.2.ip6.arpa",
"dns_ptr": "2.d.d.f.f.f.f.3.f.b.3.6.0.0.0.8.8....0.1.0.0.2.ip6.arpa",
"network": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
"broadcast": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
"hostmask": "::",
@@ -454,13 +519,13 @@ Examples:
"last_host": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2"
},
"bin": {
"ip": "001000000000000100000000000000000100000100110110111000...",
"network": "0010000000000001000000000000000001000001001101101...",
"broadcast": "00100000000000010000000000000000010000010011011...",
"hostmask": "000000000000000000000000000000000000000000000000...",
"netmask": "1111111111111111111111111111111111111111111111111...",
"first_host": "0010000000000001000000000000000001000001001101...",
"last_host": "00100000000000010000000000000000010000010011011..."
"ip": "0010000000000001000000000000000001000001001...110111010010",
"network": "00100000000000010000000000000000010000...110111010010",
"broadcast": "001000000000000100000000000000000100...110111010010",
"hostmask": "0000000000000000000000000000000000000...000000000000",
"netmask": "11111111111111111111111111111111111111...111111111111",
"first_host": "00100000000000010000000000000000010...110111010010",
"last_host": "001000000000000100000000000000000100...110111010010"
}
}
@@ -487,4 +552,4 @@ Returns:
### Parser Information
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -5,65 +5,10 @@
jc - JSON Convert ISO 8601 Datetime string parser
This parser supports standard ISO 8601 strings that include both date and
time. If no timezone or offset information is available in the sring, then
UTC timezone is used.
This parser has been renamed to datetime-iso (cli) or datetime_iso (module).
Usage (cli):
$ echo "2022-07-20T14:52:45Z" | jc --iso-datetime
Usage (module):
import jc
result = jc.parse('iso_datetime', iso_8601_string)
Schema:
{
"year": integer,
"month": string,
"month_num": integer,
"day": integer,
"weekday": string,
"weekday_num": integer,
"hour": integer,
"hour_24": integer,
"minute": integer,
"second": integer,
"microsecond": integer,
"period": string,
"utc_offset": string,
"day_of_year": integer,
"week_of_year": integer,
"iso": string,
"timestamp": integer # [0]
}
[0] timezone aware UNIX timestamp expressed in UTC
Examples:
$ echo "2022-07-20T14:52:45Z" | jc --iso-datetime -p
{
"year": 2022,
"month": "Jul",
"month_num": 7,
"day": 20,
"weekday": "Wed",
"weekday_num": 3,
"hour": 2,
"hour_24": 14,
"minute": 52,
"second": 45,
"microsecond": 0,
"period": "PM",
"utc_offset": "+0000",
"day_of_year": 201,
"week_of_year": 29,
"iso": "2022-07-20T14:52:45+00:00",
"timestamp": 1658328765
}
This parser will be removed in a future version, so please start using
the new parser name.
<a id="jc.parsers.iso_datetime.parse"></a>
@@ -73,7 +18,8 @@ Examples:
def parse(data, raw=False, quiet=False)
```
Main text parsing function
This parser is deprecated and calls datetime_iso. Please use datetime_iso
directly. This parser will be removed in the future.
Parameters:
@@ -88,4 +34,4 @@ Returns:
### Parser Information
Compatibility: linux, aix, freebsd, darwin, win32, cygwin
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -140,6 +140,6 @@ Returns:
List of Dictionaries. Raw or processed structured data.
### Parser Information
Compatibility: linux
Compatibility: linux, darwin, aix, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)

148
docs/parsers/lspci.md Normal file
View File

@@ -0,0 +1,148 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.lspci"></a>
# jc.parsers.lspci
jc - JSON Convert `lspci -mmv` command output parser
This parser supports the following `lspci` options:
- `-mmv`
- `-nmmv`
- `-nnmmv`
Usage (cli):
$ lspci -nnmmv | jc --lspci
or
$ jc lspci -nnmmv
Usage (module):
import jc
result = jc.parse('lspci', lspci_command_output)
Schema:
[
{
"slot": string,
"domain": string,
"domain_int": integer,
"bus": string,
"bus_int": integer,
"dev": string,
"dev_int": integer,
"function": string,
"function_int": integer,
"class": string,
"class_id": string,
"class_id_int": integer,
"vendor": string,
"vendor_id": string,
"vendor_id_int": integer,
"device": string,
"device_id": string,
"device_id_int": integer,
"svendor": string,
"svendor_id": string,
"svendor_id_int": integer,
"sdevice": string,
"sdevice_id": string,
"sdevice_id_int": integer,
"rev": string,
"physlot": string,
"physlot_int": integer,
"progif": string,
"progif_int": integer
}
]
Examples:
$ lspci -nnmmv | jc --lspci -p
[
{
"slot": "ff:02:05.0",
"domain": "ff",
"domain_int": 255,
"bus": "02",
"bus_int": 2,
"dev": "05",
"dev_int": 5,
"function": "0",
"function_int": 0,
"class": "SATA controller",
"class_id": "0106",
"class_id_int": 262,
"vendor": "VMware",
"vendor_id": "15ad",
"vendor_id_int": 5549,
"device": "SATA AHCI controller",
"device_id": "07e0",
"device_id_int": 2016,
"svendor": "VMware",
"svendor_id": "15ad",
"svendor_id_int": 5549,
"sdevice": "SATA AHCI controller",
"sdevice_id": "07e0",
"sdevice_id_int": 2016,
"physlot": "37",
"physlot_int": 55,
"progif": "01",
"progif_int": 1
},
...
]
$ lspci -nnmmv | jc --lspci -p -r
[
{
"slot": "ff:02:05.0",
"domain": "ff",
"bus": "02",
"dev": "05",
"function": "0",
"class": "SATA controller",
"class_id": "0106",
"vendor": "VMware",
"vendor_id": "15ad",
"device": "SATA AHCI controller",
"device_id": "07e0",
"svendor": "VMware",
"svendor_id": "15ad",
"sdevice": "SATA AHCI controller",
"sdevice_id": "07e0",
"physlot": "37",
"progif": "01"
},
...
]
<a id="jc.parsers.lspci.parse"></a>
### parse
```python
def parse(data: str,
raw: bool = False,
quiet: bool = False) -> List[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:
List of Dictionaries. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

99
docs/parsers/pci_ids.md Normal file
View File

@@ -0,0 +1,99 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.pci_ids"></a>
# jc.parsers.pci\_ids
jc - JSON Convert `pci.ids` file parser
This parser converts the pci.ids database file.
https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids
A nested schema allows straightforward queries with tools like `jq`. Hex id
numbers are prefixed with an underscore (`_`) so bracket notation is not
necessary when referencing. For example:
$ cat pci.ids | jc --pci-ids | jq '.vendors._9005._0053._9005._ffff.subsystem_name'
"AIC-7896 SCSI Controller mainboard implementation"
Here are the vendor and class mappings:
jq '.vendors._001c._0001._001c._0005.subsystem_name'
| | | |
| | | subdevice
| | subvendor
| device
vendor
jq '.classes._0c._03._40'
| | |
| | prog_if
| subclass
class
Usage (cli):
$ cat pci.ids | jc --pci-ids
Usage (module):
import jc
result = jc.parse('pci_ids', pci_ids_file_output)
Schema:
{
"vendors": {
"_<vendor_id>": {
"vendor_name": string,
"_<device_id>": {
"device_name": string,
"_<subvendor_id>": {
"_<subdevice_id": string
}
}
}
},
"classes": {
"_<class_id>": {
"class_name": string,
"_<subclass_id>": {
"subclass_name": string,
"_<prog_if>": string
}
}
}
}
Examples:
$ cat pci.ids | jc --pci-ids | jq '.vendors._001c._0001._001c._0005.subsystem_name'
"2 Channel CAN Bus SJC1000 (Optically Isolated)"
$ cat pci.ids | jc --pci-ids | jq '.classes._0c._03._40'
"USB4 Host Interface"
<a id="jc.parsers.pci_ids.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)

View File

@@ -3,18 +3,18 @@
# jc.parsers.pidstat
jc - JSON Convert `pidstat -h` command output parser
jc - JSON Convert `pidstat -H` command output parser
Must use the `-h` option in `pidstat`. All other `pidstat` options are
supported in combination with `-h`.
Must use the `-H` (or `-h`, if `-H` is not available) option in `pidstat`.
All other `pidstat` options are supported in combination with this option.
Usage (cli):
$ pidstat -h | jc --pidstat
$ pidstat -H | jc --pidstat
or
$ jc pidstat -h
$ jc pidstat -H
Usage (module):
@@ -51,7 +51,7 @@ Schema:
Examples:
$ pidstat -hl | jc --pidstat -p
$ pidstat -Hl | jc --pidstat -p
[
{
"time": 1646859134,
@@ -88,7 +88,7 @@ Examples:
}
]
$ pidstat -hl | jc --pidstat -p -r
$ pidstat -Hl | jc --pidstat -p -r
[
{
"time": "1646859134",

View File

@@ -3,17 +3,17 @@
# jc.parsers.pidstat\_s
jc - JSON Convert `pidstat -h` command output streaming parser
jc - JSON Convert `pidstat -H` command output streaming parser
> This streaming parser outputs JSON Lines (cli) or returns an Iterable of
> Dictionaries (module)
Must use the `-h` option in `pidstat`. All other `pidstat` options are
supported in combination with `-h`.
Must use the `-H` (or `-h`, if `-H` is not available) option in `pidstat`.
All other `pidstat` options are supported in combination with this option.
Usage (cli):
$ pidstat | jc --pidstat-s
$ pidstat -H | jc --pidstat-s
> Note: When piping `jc` converted `pidstat` output to other processes it
> may appear the output is hanging due to the OS pipe buffers. This is
@@ -65,13 +65,13 @@ Schema:
Examples:
$ pidstat -hl | jc --pidstat-s
$ pidstat -Hl | jc --pidstat-s
{"time":1646859134,"uid":0,"pid":1,"percent_usr":0.0,"percent_syste...}
{"time":1646859134,"uid":0,"pid":6,"percent_usr":0.0,"percent_syste...}
{"time":1646859134,"uid":0,"pid":9,"percent_usr":0.0,"percent_syste...}
...
$ pidstat -hl | jc --pidstat-s -r
$ pidstat -Hl | jc --pidstat-s -r
{"time":"1646859134","uid":"0","pid":"1","percent_usr":"0.00","perc...}
{"time":"1646859134","uid":"0","pid":"6","percent_usr":"0.00","perc...}
{"time":"1646859134","uid":"0","pid":"9","percent_usr":"0.00","perc...}

142
docs/parsers/proc.md Normal file
View File

@@ -0,0 +1,142 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc"></a>
# jc.parsers.proc
jc - JSON Convert Proc file output parser
This parser automatically identifies the Proc file and calls the
corresponding parser to peform the parsing.
Magic syntax for converting `/proc` files is also supported by running
`jc /proc/<path to file>`. Any `jc` options must be specified before the
`/proc` path.
specific Proc file parsers can also be called directly, if desired and have
a naming convention of `proc-<name>` (cli) or `proc_<name>` (module).
Usage (cli):
$ cat /proc/meminfo | jc --proc
or
$ jc /proc/meminfo
or
$ cat /proc/meminfo | jc --proc-memifno
Usage (module):
import jc
result = jc.parse('proc', proc_file)
Schema:
See the specific Proc parser for the schema:
$ jc --help --proc-<name>
For example:
$ jc --help --proc-meminfo
Specific Proc file parser names can be found with `jc -hh` or `jc -a`.
Schemas can also be found online at:
https://kellyjonbrazil.github.io/jc/docs/parsers/proc_<name>
For example:
https://kellyjonbrazil.github.io/jc/docs/parsers/proc_meminfo
Examples:
$ cat /proc/modules | jc --proc -p
[
{
"module": "binfmt_misc",
"size": 24576,
"used": 1,
"used_by": [],
"status": "Live",
"location": "0xffffffffc0ab4000"
},
{
"module": "vsock_loopback",
"size": 16384,
"used": 0,
"used_by": [],
"status": "Live",
"location": "0xffffffffc0a14000"
},
{
"module": "vmw_vsock_virtio_transport_common",
"size": 36864,
"used": 1,
"used_by": [
"vsock_loopback"
],
"status": "Live",
"location": "0xffffffffc0a03000"
},
...
]
$ proc_modules | jc --proc_modules -p -r
[
{
"module": "binfmt_misc",
"size": "24576",
"used": "1",
"used_by": [],
"status": "Live",
"location": "0xffffffffc0ab4000"
},
{
"module": "vsock_loopback",
"size": "16384",
"used": "0",
"used_by": [],
"status": "Live",
"location": "0xffffffffc0a14000"
},
{
"module": "vmw_vsock_virtio_transport_common",
"size": "36864",
"used": "1",
"used_by": [
"vsock_loopback"
],
"status": "Live",
"location": "0xffffffffc0a03000"
},
...
]
<a id="jc.parsers.proc.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,128 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_buddyinfo"></a>
# jc.parsers.proc\_buddyinfo
jc - JSON Convert `/proc/buddyinfo` file parser
Usage (cli):
$ cat /proc/buddyinfo | jc --proc
or
$ jc /proc/buddyinfo
or
$ cat /proc/buddyinfo | jc --proc-buddyinfo
Usage (module):
import jc
result = jc.parse('proc', proc_buddyinfo_file)
or
import jc
result = jc.parse('proc_buddyinfo', proc_buddyinfo_file)
Schema:
All values are integers.
[
{
"node": integer,
"zone": string,
"free_chunks": [
integer # [0]
]
}
]
[0] array index correlates to the Order number.
E.g. free_chunks[0] is the value for Order 0
Examples:
$ cat /proc/buddyinfo | jc --proc -p
[
{
"node": 0,
"zone": "DMA",
"free_chunks": [
0,
0,
0,
1,
1,
1,
1,
1,
0,
1,
3
]
},
{
"node": 0,
"zone": "DMA32",
"free_chunks": [
78,
114,
82,
52,
38,
25,
13,
9,
3,
4,
629
]
},
{
"node": 0,
"zone": "Normal",
"free_chunks": [
0,
22,
8,
10,
1,
1,
2,
11,
13,
0,
0
]
}
]
<a id="jc.parsers.proc_buddyinfo.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,111 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_consoles"></a>
# jc.parsers.proc\_consoles
jc - JSON Convert `/proc/consoles` file parser
Usage (cli):
$ cat /proc/consoles | jc --proc
or
$ jc /proc/consoles
or
$ cat /proc/consoles | jc --proc-consoles
Usage (module):
import jc
result = jc.parse('proc', proc_consoles_file)
or
import jc
result = jc.parse('proc_consoles', proc_consoles_file)
Schema:
[
{
"device": string,
"operations": string,
"operations_list": [
string # [0]
],
"flags": string,
"flags_list": [
string # [1]
],
"major": integer,
"minor": integer
}
]
[0] Values: read, write, unblank
[1] Values: enabled, preferred, primary boot, prink buffer,
braille device, safe when CPU offline
Examples:
$ cat /proc/consoles | jc --proc -p
[
{
"device": "tty0",
"operations": "-WU",
"operations_list": [
"write",
"unblank"
],
"flags": "ECp",
"flags_list": [
"enabled",
"preferred",
"printk buffer"
],
"major": 4,
"minor": 7
},
{
"device": "ttyS0",
"operations": "-W-",
"operations_list": [
"write"
],
"flags": "Ep",
"flags_list": [
"enabled",
"printk buffer"
],
"major": 4,
"minor": 64
}
]
<a id="jc.parsers.proc_consoles.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,247 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_cpuinfo"></a>
# jc.parsers.proc\_cpuinfo
jc - JSON Convert `/proc/cpuinfo` file parser
Usage (cli):
$ cat /proc/cpuinfo | jc --proc
or
$ jc /proc/cpuinfo
or
$ cat /proc/cpuinfo | jc --proc-cpuinfo
Usage (module):
import jc
result = jc.parse('proc', proc_cpuinfo_file)
or
import jc
result = jc.parse('proc_cpuinfo', proc_cpuinfo_file)
Schema:
Integer, float, and boolean ("yes"/"no") conversions are attempted. Blank
strings are converted to `null`.
"Well-known" keys like `cache size`, `address types`, `bugs`, and `flags`
are processed into sensible data types. (see below)
If this is not desired, then use the `--raw` (CLI) or `raw=True` (Module)
option.
[
{
"processor": integer,
"address sizes": string,
"address_size_physical": integer, # in bits
"address_size_virtual": integer, # in bits
"cache size": string,
"cache_size_num": integer,
"cache_size_unit": string,
"flags": [
string
],
"bugs": [
string
],
"bogomips": float,
<key>: string/int/float/boolean/null
}
]
Examples:
$ cat /proc/cpuinfo | jc --proc -p
[
{
"processor": 0,
"vendor_id": "GenuineIntel",
"cpu family": 6,
"model": 142,
"model name": "Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz",
"stepping": 10,
"cpu MHz": 2400.0,
"cache size": "6144 KB",
"physical id": 0,
"siblings": 1,
"core id": 0,
"cpu cores": 1,
"apicid": 0,
"initial apicid": 0,
"fpu": true,
"fpu_exception": true,
"cpuid level": 22,
"wp": true,
"bogomips": 4800.0,
"clflush size": 64,
"cache_alignment": 64,
"address sizes": "45 bits physical, 48 bits virtual",
"power management": null,
"address_size_physical": 45,
"address_size_virtual": 48,
"cache_size_num": 6144,
"cache_size_unit": "KB",
"flags": [
"fpu",
"vme",
"de",
"pse",
"tsc",
"msr",
"pae",
"mce",
"cx8",
"apic",
"sep",
"mtrr",
"pge",
"mca",
"cmov",
"pat",
"pse36",
"clflush",
"mmx",
"fxsr",
"sse",
"sse2",
"ss",
"syscall",
"nx",
"pdpe1gb",
"rdtscp",
"lm",
"constant_tsc",
"arch_perfmon",
"nopl",
"xtopology",
"tsc_reliable",
"nonstop_tsc",
"cpuid",
"pni",
"pclmulqdq",
"ssse3",
"fma",
"cx16",
"pcid",
"sse4_1",
"sse4_2",
"x2apic",
"movbe",
"popcnt",
"tsc_deadline_timer",
"aes",
"xsave",
"avx",
"f16c",
"rdrand",
"hypervisor",
"lahf_lm",
"abm",
"3dnowprefetch",
"cpuid_fault",
"invpcid_single",
"pti",
"ssbd",
"ibrs",
"ibpb",
"stibp",
"fsgsbase",
"tsc_adjust",
"bmi1",
"avx2",
"smep",
"bmi2",
"invpcid",
"rdseed",
"adx",
"smap",
"clflushopt",
"xsaveopt",
"xsavec",
"xgetbv1",
"xsaves",
"arat",
"md_clear",
"flush_l1d",
"arch_capabilities"
],
"bugs": [
"cpu_meltdown",
"spectre_v1",
"spectre_v2",
"spec_store_bypass",
"l1tf",
"mds",
"swapgs",
"itlb_multihit",
"srbds"
]
},
...
]
$ cat /proc/cpuinfo | jc --proc_cpuinfo -p -r
[
{
"processor": "0",
"vendor_id": "GenuineIntel",
"cpu family": "6",
"model": "142",
"model name": "Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz",
"stepping": "10",
"cpu MHz": "2400.000",
"cache size": "6144 KB",
"physical id": "0",
"siblings": "1",
"core id": "0",
"cpu cores": "1",
"apicid": "0",
"initial apicid": "0",
"fpu": "yes",
"fpu_exception": "yes",
"cpuid level": "22",
"wp": "yes",
"flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge ...",
"bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass ...",
"bogomips": "4800.00",
"clflush size": "64",
"cache_alignment": "64",
"address sizes": "45 bits physical, 48 bits virtual",
"power management": ""
},
...
]
<a id="jc.parsers.proc_cpuinfo.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 Kelly Brazil (kellyjonbrazil@gmail.com)

143
docs/parsers/proc_crypto.md Normal file
View File

@@ -0,0 +1,143 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_crypto"></a>
# jc.parsers.proc\_crypto
jc - JSON Convert `/proc/crypto` file parser
Usage (cli):
$ cat /proc/crypto | jc --proc
or
$ jc /proc/crypto
or
$ cat /proc/crypto | jc --proc-crypto
Usage (module):
import jc
result = jc.parse('proc', proc_crypto_file)
or
import jc
result = jc.parse('proc_crypto', proc_crypto_file)
Schema:
"Well-known" keys like `priority` and `refcnt` are converted to integers.
Also, keynames ending in "size" are converted to integers.
If this is not desired, then use the `--raw` (CLI) or `raw=True` (Module)
option.
[
{
"name": string,
"driver": string,
"module": string,
"priority": integer,
"refcnt": integer,
"selftest": string,
"internal": string,
"type": string,
"*size": integer
}
]
Examples:
$ cat /proc/crypto | jc --proc -p
[
{
"name": "ecdh",
"driver": "ecdh-generic",
"module": "ecdh_generic",
"priority": 100,
"refcnt": 1,
"selftest": "passed",
"internal": "no",
"type": "kpp"
},
{
"name": "blake2b-512",
"driver": "blake2b-512-generic",
"module": "blake2b_generic",
"priority": 100,
"refcnt": 1,
"selftest": "passed",
"internal": "no",
"type": "shash",
"blocksize": 128,
"digestsize": 64
},
...
]
$ cat /proc/crypto | jc --proc_crypto -p -r
[
{
"name": "ecdh",
"driver": "ecdh-generic",
"module": "ecdh_generic",
"priority": "100",
"refcnt": "1",
"selftest": "passed",
"internal": "no",
"type": "kpp"
},
{
"name": "blake2b-512",
"driver": "blake2b-512-generic",
"module": "blake2b_generic",
"priority": "100",
"refcnt": "1",
"selftest": "passed",
"internal": "no",
"type": "shash",
"blocksize": "128",
"digestsize": "64"
},
{
"name": "blake2b-384",
"driver": "blake2b-384-generic",
"module": "blake2b_generic",
"priority": "100",
"refcnt": "1",
"selftest": "passed",
"internal": "no",
"type": "shash",
"blocksize": "128",
"digestsize": "48"
},
...
]
<a id="jc.parsers.proc_crypto.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,103 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_devices"></a>
# jc.parsers.proc\_devices
jc - JSON Convert `/proc/devices` file parser
Usage (cli):
$ cat /proc/devices | jc --proc
or
$ jc /proc/devices
or
$ cat /proc/devices | jc --proc-devices
Usage (module):
import jc
result = jc.parse('proc', proc_devices_file)
or
import jc
result = jc.parse('proc_devices', proc_devices_file)
Schema:
Since devices can be members of multiple groups, the value for each device
is a list.
{
"character": {
"<device number>": [
string
]
},
"block": {
"<device number>": [
string
]
}
}
Examples:
$ cat /proc/devices | jc --proc -p
{
"character": {
"1": [
"mem"
],
"4": [
"/dev/vc/0",
"tty",
"ttyS"
],
"5": [
"/dev/tty",
"/dev/console",
"/dev/ptmx",
"ttyprintk"
],
"block": {
"7": [
"loop"
],
"8": [
"sd"
],
"9": [
"md"
]
}
}
<a id="jc.parsers.proc_devices.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,202 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_diskstats"></a>
# jc.parsers.proc\_diskstats
jc - JSON Convert `/proc/diskstats` file parser
Usage (cli):
$ cat /proc/diskstats | jc --proc
or
$ jc /proc/diskstats
or
$ cat /proc/diskstats | jc --proc-diskstats
Usage (module):
import jc
result = jc.parse('proc', proc_diskstats_file)
or
import jc
result = jc.parse('proc_diskstats', proc_diskstats_file)
Schema:
[
{
"maj": integer,
"min": integer,
"device": string,
"reads_completed": integer,
"reads_merged": integer,
"sectors_read": integer,
"read_time_ms": integer,
"writes_completed": integer,
"writes_merged": integer,
"sectors_written": integer,
"write_time_ms": integer,
"io_in_progress": integer,
"io_time_ms": integer,
"weighted_io_time_ms": integer,
"discards_completed_successfully": integer,
"discards_merged": integer,
"sectors_discarded": integer,
"discarding_time_ms": integer,
"flush_requests_completed_successfully": integer,
"flushing_time_ms": integer
}
]
Examples:
$ cat /proc/diskstats | jc --proc -p
[
{
"maj": 7,
"min": 0,
"device": "loop0",
"reads_completed": 48,
"reads_merged": 0,
"sectors_read": 718,
"read_time_ms": 19,
"writes_completed": 0,
"writes_merged": 0,
"sectors_written": 0,
"write_time_ms": 0,
"io_in_progress": 0,
"io_time_ms": 36,
"weighted_io_time_ms": 19,
"discards_completed_successfully": 0,
"discards_merged": 0,
"sectors_discarded": 0,
"discarding_time_ms": 0,
"flush_requests_completed_successfully": 0,
"flushing_time_ms": 0
},
{
"maj": 7,
"min": 1,
"device": "loop1",
"reads_completed": 41,
"reads_merged": 0,
"sectors_read": 688,
"read_time_ms": 17,
"writes_completed": 0,
"writes_merged": 0,
"sectors_written": 0,
"write_time_ms": 0,
"io_in_progress": 0,
"io_time_ms": 28,
"weighted_io_time_ms": 17,
"discards_completed_successfully": 0,
"discards_merged": 0,
"sectors_discarded": 0,
"discarding_time_ms": 0,
"flush_requests_completed_successfully": 0,
"flushing_time_ms": 0
},
...
]
$ cat /proc/diskstats | jc --proc_diskstats -p -r
[
{
"maj": "7",
"min": "0",
"device": "loop0",
"reads_completed": "48",
"reads_merged": "0",
"sectors_read": "718",
"read_time_ms": "19",
"writes_completed": "0",
"writes_merged": "0",
"sectors_written": "0",
"write_time_ms": "0",
"io_in_progress": "0",
"io_time_ms": "36",
"weighted_io_time_ms": "19",
"discards_completed_successfully": "0",
"discards_merged": "0",
"sectors_discarded": "0",
"discarding_time_ms": "0",
"flush_requests_completed_successfully": "0",
"flushing_time_ms": "0"
},
{
"maj": "7",
"min": "1",
"device": "loop1",
"reads_completed": "41",
"reads_merged": "0",
"sectors_read": "688",
"read_time_ms": "17",
"writes_completed": "0",
"writes_merged": "0",
"sectors_written": "0",
"write_time_ms": "0",
"io_in_progress": "0",
"io_time_ms": "28",
"weighted_io_time_ms": "17",
"discards_completed_successfully": "0",
"discards_merged": "0",
"sectors_discarded": "0",
"discarding_time_ms": "0",
"flush_requests_completed_successfully": "0",
"flushing_time_ms": "0"
},
{
"maj": "7",
"min": "2",
"device": "loop2",
"reads_completed": "119",
"reads_merged": "0",
"sectors_read": "2956",
"read_time_ms": "18",
"writes_completed": "0",
"writes_merged": "0",
"sectors_written": "0",
"write_time_ms": "0",
"io_in_progress": "0",
"io_time_ms": "56",
"weighted_io_time_ms": "18",
"discards_completed_successfully": "0",
"discards_merged": "0",
"sectors_discarded": "0",
"discarding_time_ms": "0",
"flush_requests_completed_successfully": "0",
"flushing_time_ms": "0"
},
...
]
<a id="jc.parsers.proc_diskstats.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,126 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_driver_rtc"></a>
# jc.parsers.proc\_driver\_rtc
jc - JSON Convert `/proc/driver/rtc` file parser
Usage (cli):
$ cat /proc/driver/rtc | jc --proc
or
$ jc /proc/driver/rtc
or
$ cat /proc/driver/rtc | jc --proc-driver-rtc
Usage (module):
import jc
result = jc.parse('proc', proc_driver_rtc_file)
or
import jc
result = jc.parse('proc_driver_rtc', proc_driver_rtc_file)
Schema:
"yes" and "no" values are converted to `true`/`false`. Integer conversions
are attempted. If you do not want this behavior, then use `--raw` (cli) or
`raw=True` (module).
{
"rtc_time": string,
"rtc_date": string,
"alrm_time": string,
"alrm_date": string,
"alarm_IRQ": boolean,
"alrm_pending": boolean,
"update IRQ enabled": boolean,
"periodic IRQ enabled": boolean,
"periodic IRQ frequency": integer,
"max user IRQ frequency": integer,
"24hr": boolean,
"periodic_IRQ": boolean,
"update_IRQ": boolean,
"HPET_emulated": boolean,
"BCD": boolean,
"DST_enable": boolean,
"periodic_freq": integer,
"batt_status": string
}
Examples:
$ cat /proc/driver/rtc | jc --proc -p
{
"rtc_time": "16:09:21",
"rtc_date": "2022-09-03",
"alrm_time": "00:00:00",
"alrm_date": "2022-09-03",
"alarm_IRQ": false,
"alrm_pending": false,
"update IRQ enabled": false,
"periodic IRQ enabled": false,
"periodic IRQ frequency": 1024,
"max user IRQ frequency": 64,
"24hr": true,
"periodic_IRQ": false,
"update_IRQ": false,
"HPET_emulated": true,
"BCD": true,
"DST_enable": false,
"periodic_freq": 1024,
"batt_status": "okay"
}
$ cat /proc/driver/rtc | jc --proc -p -r
{
"rtc_time": "16:09:21",
"rtc_date": "2022-09-03",
"alrm_time": "00:00:00",
"alrm_date": "2022-09-03",
"alarm_IRQ": "no",
"alrm_pending": "no",
"update IRQ enabled": "no",
"periodic IRQ enabled": "no",
"periodic IRQ frequency": "1024",
"max user IRQ frequency": "64",
"24hr": "yes",
"periodic_IRQ": "no",
"update_IRQ": "no",
"HPET_emulated": "yes",
"BCD": "yes",
"DST_enable": "no",
"periodic_freq": "1024",
"batt_status": "okay"
}
<a id="jc.parsers.proc_driver_rtc.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,81 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_filesystems"></a>
# jc.parsers.proc\_filesystems
jc - JSON Convert `/proc/filesystems` file parser
Usage (cli):
$ cat /proc/filesystems | jc --proc
or
$ jc /proc/filesystems
or
$ cat /proc/filesystems | jc --proc-filesystems
Usage (module):
import jc
result = jc.parse('proc', proc_filesystems_file)
or
import jc
result = jc.parse('proc_filesystems', proc_filesystems_file)
Schema:
[
{
"filesystem": string,
"nodev": boolean
}
]
Examples:
$ cat /proc/filesystems | jc --proc -p
[
{
"filesystem": "sysfs",
"nodev": true
},
{
"filesystem": "tmpfs",
"nodev": true
},
{
"filesystem": "bdev",
"nodev": true
},
...
]
<a id="jc.parsers.proc_filesystems.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,133 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_interrupts"></a>
# jc.parsers.proc\_interrupts
jc - JSON Convert `/proc/interrupts` file parser
Usage (cli):
$ cat /proc/interrupts | jc --proc
or
$ jc /proc/interrupts
or
$ cat /proc/interrupts | jc --proc-interrupts
Usage (module):
import jc
result = jc.parse('proc', proc_interrupts_file)
or
import jc
result = jc.parse('proc_interrupts', proc_interrupts_file)
Schema:
[
{
"irq": string,
"cpu_num": integer,
"interrupts": [
integer
],
"type": string,
"device": [
string
]
}
]
Examples:
$ cat /proc/interrupts | jc --proc -p
[
{
"irq": "0",
"cpu_num": 2,
"interrupts": [
18,
0
],
"type": "IO-APIC",
"device": [
"2-edge",
"timer"
]
},
{
"irq": "1",
"cpu_num": 2,
"interrupts": [
0,
73
],
"type": "IO-APIC",
"device": [
"1-edge",
"i8042"
]
},
...
]
$ cat /proc/interrupts | jc --proc-interrupts -p -r
[
{
"irq": "0",
"cpu_num": 2,
"interrupts": [
"18",
"0"
],
"type": "IO-APIC",
"device": [
"2-edge",
"timer"
]
},
{
"irq": "1",
"cpu_num": 2,
"interrupts": [
"0",
"73"
],
"type": "IO-APIC",
"device": [
"1-edge",
"i8042"
]
},
...
]
<a id="jc.parsers.proc_interrupts.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,85 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_iomem"></a>
# jc.parsers.proc\_iomem
jc - JSON Convert `/proc/iomem` file parser
Usage (cli):
$ cat /proc/iomem | jc --proc
or
$ jc /proc/iomem
or
$ cat /proc/iomem | jc --proc-iomem
Usage (module):
import jc
result = jc.parse('proc', proc_iomem_file)
or
import jc
result = jc.parse('proc_iomem', proc_iomem_file)
Schema:
[
{
"start": string,
"end": string,
"device": string
}
]
Examples:
$ cat /proc/iomem | jc --proc -p
[
{
"start": "00000000",
"end": "00000fff",
"device": "Reserved"
},
{
"start": "00001000",
"end": "0009e7ff",
"device": "System RAM"
},
{
"start": "0009e800",
"end": "0009ffff",
"device": "Reserved"
},
...
]
<a id="jc.parsers.proc_iomem.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,85 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_ioports"></a>
# jc.parsers.proc\_ioports
jc - JSON Convert `/proc/ioports` file parser
Usage (cli):
$ cat /proc/ioports | jc --proc
or
$ jc /proc/ioports
or
$ cat /proc/ioports | jc --proc-ioports
Usage (module):
import jc
result = jc.parse('proc', proc_ioports_file)
or
import jc
result = jc.parse('proc_ioports', proc_ioports_file)
Schema:
[
{
"start": string,
"end": string,
"device": string
}
]
Examples:
$ cat /proc/ioports | jc --proc -p
[
{
"start": "0000",
"end": "0cf7",
"device": "PCI Bus 0000:00"
},
{
"start": "0000",
"end": "001f",
"device": "dma1"
},
{
"start": "0020",
"end": "0021",
"device": "PNP0001:00"
},
...
]
<a id="jc.parsers.proc_ioports.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,88 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_loadavg"></a>
# jc.parsers.proc\_loadavg
jc - JSON Convert `/proc/loadavg` file parser
Usage (cli):
$ cat /proc/loadavg | jc --proc
or
$ jc /proc/loadavg
or
$ cat /proc/loadavg | jc --proc-loadavg
Usage (module):
import jc
result = jc.parse('proc', proc_loadavg_file)
or
import jc
result = jc.parse('proc_loadavg', proc_loadavg_file)
Schema:
All values are integers.
{
"load_1m": float,
"load_5m": float,
"load_15m": float,
"running": integer,
"available": integer,
"last_pid": integer
}
Examples:
$ cat /proc/loadavg | jc --proc -p
{
"load_1m": 0.0,
"load_5m": 0.01,
"load_15m": 0.03,
"running": 2,
"available": 111,
"last_pid": 2039
}
$ cat /proc/loadavg | jc --proc -p -r
{
"load_1m": "0.00",
"load_5m": "0.01",
"load_15m": "0.03",
"running": "2",
"available": "111",
"last_pid": "2039"
}
<a id="jc.parsers.proc_loadavg.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

130
docs/parsers/proc_locks.md Normal file
View File

@@ -0,0 +1,130 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_locks"></a>
# jc.parsers.proc\_locks
jc - JSON Convert `/proc/locks` file parser
Usage (cli):
$ cat /proc/locks | jc --proc
or
$ jc /proc/locks
or
$ cat /proc/locks | jc --proc-locks
Usage (module):
import jc
result = jc.parse('proc', proc_locks_file)
or
import jc
result = jc.parse('proc_locks', proc_locks_file)
Schema:
[
{
"id": integer,
"class": string,
"type": string,
"access": string,
"pid": integer,
"maj": string,
"min": string,
"inode": integer,
"start": string,
"end": string
}
]
Examples:
$ cat /proc/locks | jc --proc -p
[
{
"id": 1,
"class": "POSIX",
"type": "ADVISORY",
"access": "WRITE",
"pid": 877,
"maj": "00",
"min": "19",
"inode": 812,
"start": "0",
"end": "EOF"
},
{
"id": 2,
"class": "FLOCK",
"type": "ADVISORY",
"access": "WRITE",
"pid": 854,
"maj": "00",
"min": "19",
"inode": 805,
"start": "0",
"end": "EOF"
},
...
]
$ cat /proc/locks | jc --proc-locks -p -r
[
{
"id": "1",
"class": "POSIX",
"type": "ADVISORY",
"access": "WRITE",
"pid": "877",
"maj": "00",
"min": "19",
"inode": "812",
"start": "0",
"end": "EOF"
},
{
"id": "2",
"class": "FLOCK",
"type": "ADVISORY",
"access": "WRITE",
"pid": "854",
"maj": "00",
"min": "19",
"inode": "805",
"start": "0",
"end": "EOF"
},
...
]
<a id="jc.parsers.proc_locks.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,118 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_meminfo"></a>
# jc.parsers.proc\_meminfo
jc - JSON Convert `/proc/meminfo` file parser
Usage (cli):
$ cat /proc/meminfo | jc --proc
or
$ jc /proc/meminfo
or
$ cat /proc/meminfo | jc --proc-meminfo
Usage (module):
import jc
result = jc.parse('proc', proc_meminfo_file)
or
import jc
result = jc.parse('proc_meminfo', proc_meminfo_file)
Schema:
All values are integers.
{
<keyName> integer
}
Examples:
$ cat /proc/meminfo | jc --proc -p
{
"MemTotal": 3997272,
"MemFree": 2760316,
"MemAvailable": 3386876,
"Buffers": 40452,
"Cached": 684856,
"SwapCached": 0,
"Active": 475816,
"Inactive": 322064,
"Active(anon)": 70216,
"Inactive(anon)": 148,
"Active(file)": 405600,
"Inactive(file)": 321916,
"Unevictable": 19476,
"Mlocked": 19476,
"SwapTotal": 3996668,
"SwapFree": 3996668,
"Dirty": 152,
"Writeback": 0,
"AnonPages": 92064,
"Mapped": 79464,
"Shmem": 1568,
"KReclaimable": 188216,
"Slab": 288096,
"SReclaimable": 188216,
"SUnreclaim": 99880,
"KernelStack": 5872,
"PageTables": 1812,
"NFS_Unstable": 0,
"Bounce": 0,
"WritebackTmp": 0,
"CommitLimit": 5995304,
"Committed_AS": 445240,
"VmallocTotal": 34359738367,
"VmallocUsed": 21932,
"VmallocChunk": 0,
"Percpu": 107520,
"HardwareCorrupted": 0,
"AnonHugePages": 0,
"ShmemHugePages": 0,
"ShmemPmdMapped": 0,
"FileHugePages": 0,
"FilePmdMapped": 0,
"HugePages_Total": 0,
"HugePages_Free": 0,
"HugePages_Rsvd": 0,
"HugePages_Surp": 0,
"Hugepagesize": 2048,
"Hugetlb": 0,
"DirectMap4k": 192320,
"DirectMap2M": 4001792,
"DirectMap1G": 2097152
}
<a id="jc.parsers.proc_meminfo.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,132 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_modules"></a>
# jc.parsers.proc\_modules
jc - JSON Convert `/proc/modules` file parser
Usage (cli):
$ cat /proc/modules | jc --proc
or
$ jc /proc/modules
or
$ cat /proc/modules | jc --proc-modules
Usage (module):
import jc
result = jc.parse('proc', proc_modules_file)
or
import jc
result = jc.parse('proc_modules', proc_modules_file)
Schema:
[
{
"module": string,
"size": integer,
"used": integer,
"used_by": [
string
],
"status": string,
"location": string
}
]
Examples:
$ cat /proc/modules | jc --proc -p
[
{
"module": "binfmt_misc",
"size": 24576,
"used": 1,
"used_by": [],
"status": "Live",
"location": "0xffffffffc0ab4000"
},
{
"module": "vsock_loopback",
"size": 16384,
"used": 0,
"used_by": [],
"status": "Live",
"location": "0xffffffffc0a14000"
},
{
"module": "vmw_vsock_virtio_transport_common",
"size": 36864,
"used": 1,
"used_by": [
"vsock_loopback"
],
"status": "Live",
"location": "0xffffffffc0a03000"
},
...
]
$ cat /proc/modules | jc --proc-modules -p -r
[
{
"module": "binfmt_misc",
"size": "24576",
"used": "1",
"used_by": [],
"status": "Live",
"location": "0xffffffffc0ab4000"
},
{
"module": "vsock_loopback",
"size": "16384",
"used": "0",
"used_by": [],
"status": "Live",
"location": "0xffffffffc0a14000"
},
{
"module": "vmw_vsock_virtio_transport_common",
"size": "36864",
"used": "1",
"used_by": [
"vsock_loopback"
],
"status": "Live",
"location": "0xffffffffc0a03000"
},
...
]
<a id="jc.parsers.proc_modules.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 Kelly Brazil (kellyjonbrazil@gmail.com)

111
docs/parsers/proc_mtrr.md Normal file
View File

@@ -0,0 +1,111 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_mtrr"></a>
# jc.parsers.proc\_mtrr
jc - JSON Convert `/proc/mtrr` file parser
Usage (cli):
$ cat /proc/mtrr | jc --proc
or
$ jc /proc/mtrr
or
$ cat /proc/mtrr | jc --proc-mtrr
Usage (module):
import jc
result = jc.parse('proc', proc_mtrr_file)
or
import jc
result = jc.parse('proc_mtrr', proc_mtrr_file)
Schema:
[
{
"register": string,
"type": string,
"base": string,
"base_mb": integer,
"size": integer,
"count": integer,
"<key>": string # additional key/values are strings
}
]
Examples:
$ cat /proc/mtrr | jc --proc -p
[
{
"register": "reg00",
"type": "write-back",
"base": "0x000000000",
"base_mb": 0,
"size": 2048,
"count": 1
},
{
"register": "reg01",
"type": "write-back",
"base": "0x080000000",
"base_mb": 2048,
"size": 1024,
"count": 1
},
...
]
$ cat /proc/mtrr | jc --proc-mtrr -p -r
[
{
"register": "reg00",
"type": "write-back",
"base": "0x000000000",
"base_mb": "0",
"size": "2048MB",
"count": "1"
},
{
"register": "reg01",
"type": "write-back",
"base": "0x080000000",
"base_mb": "2048",
"size": "1024MB",
"count": "1"
},
...
]
<a id="jc.parsers.proc_mtrr.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,81 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_arp"></a>
# jc.parsers.proc\_net\_arp
jc - JSON Convert `/proc/net/arp` file parser
Usage (cli):
$ cat /proc/net/arp | jc --proc
or
$ jc /proc/net/arp
or
$ cat /proc/net/arp | jc --proc-net-arp
Usage (module):
import jc
result = jc.parse('proc', proc_net_arp_file)
or
import jc
result = jc.parse('proc_net_arp', proc_net_arp_file)
Schema:
[
{
"IP_address": string,
"HW_type": string,
"Flags": string,
"HW_address": string,
"Mask": string,
"Device": string
}
]
Examples:
$ cat /proc/net/arp | jc --proc -p
[
{
"IP_address": "192.168.71.254",
"HW_type": "0x1",
"Flags": "0x2",
"HW_address": "00:50:56:f3:2f:ae",
"Mask": "*",
"Device": "ens33"
},
...
]
<a id="jc.parsers.proc_net_arp.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,127 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_dev"></a>
# jc.parsers.proc\_net\_dev
jc - JSON Convert `/proc/net/dev` file parser
Usage (cli):
$ cat /proc/net/dev | jc --proc
or
$ jc /proc/net/dev
or
$ cat /proc/net/dev | jc --proc-net-dev
Usage (module):
import jc
result = jc.parse('proc', proc_net_dev_file)
or
import jc
result = jc.parse('proc_net_dev', proc_net_dev_file)
Schema:
[
{
"interface": string,
"r_bytes": integer,
"r_packets": integer,
"r_errs": integer,
"r_drop": integer,
"r_fifo": integer,
"r_frame": integer,
"r_compressed": integer,
"r_multicast": integer,
"t_bytes": integer,
"t_packets": integer,
"t_errs": integer,
"t_drop": integer,
"t_fifo": integer,
"t_colls": integer,
"t_carrier": integer,
"t_compressed": integer
}
]
Examples:
$ cat /proc/net/dev | jc --proc -p
[
{
"interface": "lo",
"r_bytes": 13222,
"r_packets": 152,
"r_errs": 0,
"r_drop": 0,
"r_fifo": 0,
"r_frame": 0,
"r_compressed": 0,
"r_multicast": 0,
"t_bytes": 13222,
"t_packets": 152,
"t_errs": 0,
"t_drop": 0,
"t_fifo": 0,
"t_colls": 0,
"t_carrier": 0,
"t_compressed": 0
},
...
]
$ cat /proc/net/dev | jc --proc-net-dev -p -r
[
{
"interface": "lo:",
"r_bytes": "13222",
"r_packets": "152",
"r_errs": "0",
"r_drop": "0",
"r_fifo": "0",
"r_frame": "0",
"r_compressed": "0",
"r_multicast": "0",
"t_bytes": "13222",
"t_packets": "152",
"t_errs": "0",
"t_drop": "0",
"t_fifo": "0",
"t_colls": "0",
"t_carrier": "0",
"t_compressed": "0"
},
...
]
<a id="jc.parsers.proc_net_dev.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,105 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_dev_mcast"></a>
# jc.parsers.proc\_net\_dev\_mcast
jc - JSON Convert `/proc/net/dev_mcast` file parser
Usage (cli):
$ cat /proc/net/dev_mcast | jc --proc
or
$ jc /proc/net/dev_mcast
or
$ cat /proc/net/dev_mcast | jc --proc-net-dev-mcast
Usage (module):
import jc
result = jc.parse('proc', proc_net_dev_mcast_file)
or
import jc
result = jc.parse('proc_net_dev_mcast', proc_net_dev_mcast_file)
Schema:
[
{
"index": integer,
"interface": string,
"dmi_u": integer,
"dmi_g": integer,
"dmi_address": string
}
]
Examples:
$ cat /proc/net/dev_mcast | jc --proc -p
[
{
"index": 2,
"interface": "ens33",
"dmi_u": 1,
"dmi_g": 0,
"dmi_address": "333300000001"
},
{
"index": 2,
"interface": "ens33",
"dmi_u": 1,
"dmi_g": 0,
"dmi_address": "01005e000001"
},
...
]
$ cat /proc/net/dev_mcast | jc --proc-net-dev-mcast -p -r
[
{
"index": "2",
"interface": "ens33",
"dmi_u": "1",
"dmi_g": "0",
"dmi_address": "333300000001"
},
{
"index": "2",
"interface": "ens33",
"dmi_u": "1",
"dmi_g": "0",
"dmi_address": "01005e000001"
},
...
]
<a id="jc.parsers.proc_net_dev_mcast.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,88 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_if_inet6"></a>
# jc.parsers.proc\_net\_if\_inet6
jc - JSON Convert `/proc/net/if_inet6` file parser
Usage (cli):
$ cat /proc/net/if_inet6 | jc --proc
or
$ jc /proc/net/if_inet6
or
$ cat /proc/net/if_inet6 | jc --proc-net-if-inet6
Usage (module):
import jc
result = jc.parse('proc', proc_net_if_inet6_file)
or
import jc
result = jc.parse('proc_net_if_inet6', proc_net_if_inet6_file)
Schema:
[
{
"address": string,
"index": string,
"prefix": string,
"scope": string,
"flags": string,
"name": string
}
]
Examples:
$ cat /proc/net/if_inet6 | jc --proc -p
[
{
"address": "fe80000000000000020c29fffea4e315",
"index": "02",
"prefix": "40",
"scope": "20",
"flags": "80",
"name": "ens33"
},
{
"address": "00000000000000000000000000000001",
"index": "01",
"prefix": "80",
"scope": "10",
"flags": "80",
"name": "lo"
}
]
<a id="jc.parsers.proc_net_if_inet6.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,152 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_igmp"></a>
# jc.parsers.proc\_net\_igmp
jc - JSON Convert `/proc/net/igmp` file parser
Usage (cli):
$ cat /proc/net/igmp | jc --proc
or
$ jc /proc/net/igmp
or
$ cat /proc/net/igmp | jc --proc-net-igmp
Usage (module):
import jc
result = jc.parse('proc', proc_net_igmp_file)
or
import jc
result = jc.parse('proc_net_igmp', proc_net_igmp_file)
Schema:
[
{
"index": integer,
"device": string,
"count": integer,
"querier": string,
"groups": [
{
"address": string,
"users": integer,
"timer": string,
"reporter": integer
}
]
}
]
Examples:
$ cat /proc/net/igmp | jc --proc -p
[
{
"index": 0,
"device": "lo",
"count": 0,
"querier": "V3",
"groups": [
{
"address": "010000E0",
"users": 1,
"timer": "0:00000000",
"reporter": 0
}
]
},
{
"index": 2,
"device": "eth0",
"count": 26,
"querier": "V2",
"groups": [
{
"address": "260301E0",
"users": 1,
"timer": "0:00000000",
"reporter": 1
},
{
"address": "9B0101E0",
"users": 1,
"timer": "0:00000000",
"reporter": 1
},
]
}
...
]
$ cat /proc/net/igmp | jc --proc-net-igmp -p -r
[
{
"index": "0",
"device": "lo",
"count": "0",
"querier": "V3",
"groups": [
{
"address": "010000E0",
"users": "1",
"timer": "0:00000000",
"reporter": "0"
}
]
},
{
"index": "2",
"device": "eth0",
"count": "26",
"querier": "V2",
"groups": [
{
"address": "260301E0",
"users": "1",
"timer": "0:00000000",
"reporter": "1"
},
{
"address": "9B0101E0",
"users": "1",
"timer": "0:00000000",
"reporter": "1"
},
]
}
...
}
<a id="jc.parsers.proc_net_igmp.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,125 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_igmp6"></a>
# jc.parsers.proc\_net\_igmp6
jc - JSON Convert `/proc/net/igmp6` file parser
Usage (cli):
$ cat /proc/net/igmp6 | jc --proc
or
$ jc /proc/net/igmp6
or
$ cat /proc/net/igmp6 | jc --proc-net-igmp6
Usage (module):
import jc
result = jc.parse('proc', proc_net_igmp6_file)
or
import jc
result = jc.parse('proc_net_igmp6', proc_net_igmp6_file)
Schema:
[
{
"index": integer,
"name": string,
"address": string,
"users": integer,
"group": string,
"reporters": integer
}
]
Examples:
$ cat /proc/net/igmp6 | jc --proc -p
[
{
"index": 1,
"name": "lo",
"address": "ff020000000000000000000000000001",
"users": 1,
"group": "0000000C",
"reporters": 0
},
{
"index": 1,
"name": "lo",
"address": "ff010000000000000000000000000001",
"users": 1,
"group": "00000008",
"reporters": 0
},
{
"index": 2,
"name": "ens33",
"address": "ff0200000000000000000001ffa4e315",
"users": 1,
"group": "00000004",
"reporters": 0
},
...
]
$ cat /proc/net/igmp6 | jc --proc-net-igmp6 -p -r
[
{
"index": "1",
"name": "lo",
"address": "ff020000000000000000000000000001",
"users": "1",
"group": "0000000C",
"reporters": "0"
},
{
"index": "1",
"name": "lo",
"address": "ff010000000000000000000000000001",
"users": "1",
"group": "00000008",
"reporters": "0"
},
{
"index": "2",
"name": "ens33",
"address": "ff0200000000000000000001ffa4e315",
"users": "1",
"group": "00000004",
"reporters": "0"
}
]
<a id="jc.parsers.proc_net_igmp6.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,89 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_ipv6_route"></a>
# jc.parsers.proc\_net\_ipv6\_route
jc - JSON Convert `/proc/net/ipv6_route` file parser
Usage (cli):
$ cat /proc/net/ipv6_route | jc --proc
or
$ jc /proc/net/ipv6_route
or
$ cat /proc/net/ipv6_route | jc --proc-net-ipv6-route
Usage (module):
import jc
result = jc.parse('proc', proc_net_ipv6_route_file)
or
import jc
result = jc.parse('proc_net_ipv6_route', proc_net_ipv6_route_file)
Schema:
[
{
"dest_net": string,
"dest_prefix": string,
"source_net": string,
"source_prefix": string,
"next_hop": string,
"metric": string,
"ref_count": string,
"use_count": string,
"flags": string,
"device": string
}
]
Examples:
$ cat /proc/net/ipv6_route | jc --proc -p
[
{
"dest_net": "00000000000000000000000000000001",
"dest_prefix": "80",
"source_net": "00000000000000000000000000000000",
"source_prefix": "00",
"next_hop": "00000000000000000000000000000000",
"metric": "00000100",
"ref_count": "00000001",
"use_count": "00000000",
"flags": "00000001",
"device": "lo"
},
...
]
<a id="jc.parsers.proc_net_ipv6_route.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,130 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_netlink"></a>
# jc.parsers.proc\_net\_netlink
jc - JSON Convert `/proc/net/netlink` file parser
Usage (cli):
$ cat /proc/net/netlink | jc --proc
or
$ jc /proc/net/netlink
or
$ cat /proc/net/netlink | jc --proc-net-netlink
Usage (module):
import jc
result = jc.parse('proc', proc_net_netlink_file)
or
import jc
result = jc.parse('proc_net_netlink', proc_net_netlink_file)
Schema:
[
{
"sk": string,
"Eth": integer,
"Pid": integer,
"Groups": string,
"Rmem": integer,
"Wmem": integer,
"Dump": integer,
"Locks": integer,
"Drops": integer,
"Inode": integer
}
]
Examples:
$ cat /proc/net/netlink | jc --proc -p
[
{
"sk": "ffff9b61adaff000",
"Eth": 0,
"Pid": 1,
"Groups": "800405d5",
"Rmem": 0,
"Wmem": 0,
"Dump": 0,
"Locks": 2,
"Drops": 0,
"Inode": 29791
},
{
"sk": "ffff9b61a792a000",
"Eth": 0,
"Pid": 837,
"Groups": "00000111",
"Rmem": 0,
"Wmem": 0,
"Dump": 0,
"Locks": 2,
"Drops": 0,
"Inode": 35337
},
...
]
$ cat /proc/net/netlink | jc --proc-net-netlink -p -r
[
{
"sk": "ffff9b61adaff000",
"Eth": "0",
"Pid": "1",
"Groups": "800405d5",
"Rmem": "0",
"Wmem": "0",
"Dump": "0",
"Locks": "2",
"Drops": "0",
"Inode": "29791"
},
{
"sk": "ffff9b61a792a000",
"Eth": "0",
"Pid": "837",
"Groups": "00000111",
"Rmem": "0",
"Wmem": "0",
"Dump": "0",
"Locks": "2",
"Drops": "0",
"Inode": "35337"
},
...
]
<a id="jc.parsers.proc_net_netlink.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,324 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_netstat"></a>
# jc.parsers.proc\_net\_netstat
jc - JSON Convert `/proc/net/netstat` file parser
Usage (cli):
$ cat /proc/net/netstat | jc --proc
or
$ jc /proc/net/netstat
or
$ cat /proc/net/netstat | jc --proc-net-netstat
Usage (module):
import jc
result = jc.parse('proc', proc_net_netstat_file)
or
import jc
result = jc.parse('proc_net_netstat', proc_net_netstat_file)
Schema:
All values except "type" are integers
[
{
"type": string,
"<key>": integer
}
]
Examples:
$ cat /proc/net/netstat | jc --proc -p
[
{
"SyncookiesSent": 0,
"SyncookiesRecv": 0,
"SyncookiesFailed": 0,
"EmbryonicRsts": 0,
"PruneCalled": 0,
"RcvPruned": 0,
"OfoPruned": 0,
"OutOfWindowIcmps": 0,
"LockDroppedIcmps": 0,
"ArpFilter": 0,
"TW": 3,
"TWRecycled": 0,
"TWKilled": 0,
"PAWSActive": 0,
"PAWSEstab": 0,
"DelayedACKs": 10,
"DelayedACKLocked": 53,
"DelayedACKLost": 0,
"ListenOverflows": 0,
"ListenDrops": 0,
"TCPHPHits": 2387,
"TCPPureAcks": 12711,
"TCPHPAcks": 53535,
"TCPRenoRecovery": 0,
"TCPSackRecovery": 0,
"TCPSACKReneging": 0,
"TCPSACKReorder": 0,
"TCPRenoReorder": 0,
"TCPTSReorder": 0,
"TCPFullUndo": 0,
"TCPPartialUndo": 0,
"TCPDSACKUndo": 0,
"TCPLossUndo": 0,
"TCPLostRetransmit": 0,
"TCPRenoFailures": 0,
"TCPSackFailures": 0,
"TCPLossFailures": 0,
"TCPFastRetrans": 0,
"TCPSlowStartRetrans": 0,
"TCPTimeouts": 0,
"TCPLossProbes": 0,
"TCPLossProbeRecovery": 0,
"TCPRenoRecoveryFail": 0,
"TCPSackRecoveryFail": 0,
"TCPRcvCollapsed": 0,
"TCPBacklogCoalesce": 2883,
"TCPDSACKOldSent": 0,
"TCPDSACKOfoSent": 0,
"TCPDSACKRecv": 0,
"TCPDSACKOfoRecv": 0,
"TCPAbortOnData": 0,
"TCPAbortOnClose": 1,
"TCPAbortOnMemory": 0,
"TCPAbortOnTimeout": 0,
"TCPAbortOnLinger": 0,
"TCPAbortFailed": 0,
"TCPMemoryPressures": 0,
"TCPMemoryPressuresChrono": 0,
"TCPSACKDiscard": 0,
"TCPDSACKIgnoredOld": 0,
"TCPDSACKIgnoredNoUndo": 0,
"TCPSpuriousRTOs": 0,
"TCPMD5NotFound": 0,
"TCPMD5Unexpected": 0,
"TCPMD5Failure": 0,
"TCPSackShifted": 0,
"TCPSackMerged": 0,
"TCPSackShiftFallback": 0,
"TCPBacklogDrop": 0,
"PFMemallocDrop": 0,
"TCPMinTTLDrop": 0,
"TCPDeferAcceptDrop": 0,
"IPReversePathFilter": 0,
"TCPTimeWaitOverflow": 0,
"TCPReqQFullDoCookies": 0,
"TCPReqQFullDrop": 0,
"TCPRetransFail": 0,
"TCPRcvCoalesce": 151,
"TCPOFOQueue": 0,
"TCPOFODrop": 0,
"TCPOFOMerge": 0,
"TCPChallengeACK": 0,
"TCPSYNChallenge": 0,
"TCPFastOpenActive": 0,
"TCPFastOpenActiveFail": 0,
"TCPFastOpenPassive": 0,
"TCPFastOpenPassiveFail": 0,
"TCPFastOpenListenOverflow": 0,
"TCPFastOpenCookieReqd": 0,
"TCPFastOpenBlackhole": 0,
"TCPSpuriousRtxHostQueues": 0,
"BusyPollRxPackets": 0,
"TCPAutoCorking": 28376,
"TCPFromZeroWindowAdv": 0,
"TCPToZeroWindowAdv": 0,
"TCPWantZeroWindowAdv": 0,
"TCPSynRetrans": 0,
"TCPOrigDataSent": 119438,
"TCPHystartTrainDetect": 3,
"TCPHystartTrainCwnd": 60,
"TCPHystartDelayDetect": 0,
"TCPHystartDelayCwnd": 0,
"TCPACKSkippedSynRecv": 0,
"TCPACKSkippedPAWS": 0,
"TCPACKSkippedSeq": 0,
"TCPACKSkippedFinWait2": 0,
"TCPACKSkippedTimeWait": 0,
"TCPACKSkippedChallenge": 0,
"TCPWinProbe": 0,
"TCPKeepAlive": 6,
"TCPMTUPFail": 0,
"TCPMTUPSuccess": 0,
"TCPDelivered": 119453,
"TCPDeliveredCE": 0,
"TCPAckCompressed": 0,
"TCPZeroWindowDrop": 0,
"TCPRcvQDrop": 0,
"TCPWqueueTooBig": 0,
"TCPFastOpenPassiveAltKey": 0,
"TcpTimeoutRehash": 0,
"TcpDuplicateDataRehash": 0,
"type": "TcpExt"
},
...
]
$ cat /proc/net/netstat | jc --proc-net-netstat -p -r
[
{
"SyncookiesSent": "0",
"SyncookiesRecv": "0",
"SyncookiesFailed": "0",
"EmbryonicRsts": "0",
"PruneCalled": "0",
"RcvPruned": "0",
"OfoPruned": "0",
"OutOfWindowIcmps": "0",
"LockDroppedIcmps": "0",
"ArpFilter": "0",
"TW": "3",
"TWRecycled": "0",
"TWKilled": "0",
"PAWSActive": "0",
"PAWSEstab": "0",
"DelayedACKs": "10",
"DelayedACKLocked": "53",
"DelayedACKLost": "0",
"ListenOverflows": "0",
"ListenDrops": "0",
"TCPHPHits": "2387",
"TCPPureAcks": "12711",
"TCPHPAcks": "53535",
"TCPRenoRecovery": "0",
"TCPSackRecovery": "0",
"TCPSACKReneging": "0",
"TCPSACKReorder": "0",
"TCPRenoReorder": "0",
"TCPTSReorder": "0",
"TCPFullUndo": "0",
"TCPPartialUndo": "0",
"TCPDSACKUndo": "0",
"TCPLossUndo": "0",
"TCPLostRetransmit": "0",
"TCPRenoFailures": "0",
"TCPSackFailures": "0",
"TCPLossFailures": "0",
"TCPFastRetrans": "0",
"TCPSlowStartRetrans": "0",
"TCPTimeouts": "0",
"TCPLossProbes": "0",
"TCPLossProbeRecovery": "0",
"TCPRenoRecoveryFail": "0",
"TCPSackRecoveryFail": "0",
"TCPRcvCollapsed": "0",
"TCPBacklogCoalesce": "2883",
"TCPDSACKOldSent": "0",
"TCPDSACKOfoSent": "0",
"TCPDSACKRecv": "0",
"TCPDSACKOfoRecv": "0",
"TCPAbortOnData": "0",
"TCPAbortOnClose": "1",
"TCPAbortOnMemory": "0",
"TCPAbortOnTimeout": "0",
"TCPAbortOnLinger": "0",
"TCPAbortFailed": "0",
"TCPMemoryPressures": "0",
"TCPMemoryPressuresChrono": "0",
"TCPSACKDiscard": "0",
"TCPDSACKIgnoredOld": "0",
"TCPDSACKIgnoredNoUndo": "0",
"TCPSpuriousRTOs": "0",
"TCPMD5NotFound": "0",
"TCPMD5Unexpected": "0",
"TCPMD5Failure": "0",
"TCPSackShifted": "0",
"TCPSackMerged": "0",
"TCPSackShiftFallback": "0",
"TCPBacklogDrop": "0",
"PFMemallocDrop": "0",
"TCPMinTTLDrop": "0",
"TCPDeferAcceptDrop": "0",
"IPReversePathFilter": "0",
"TCPTimeWaitOverflow": "0",
"TCPReqQFullDoCookies": "0",
"TCPReqQFullDrop": "0",
"TCPRetransFail": "0",
"TCPRcvCoalesce": "151",
"TCPOFOQueue": "0",
"TCPOFODrop": "0",
"TCPOFOMerge": "0",
"TCPChallengeACK": "0",
"TCPSYNChallenge": "0",
"TCPFastOpenActive": "0",
"TCPFastOpenActiveFail": "0",
"TCPFastOpenPassive": "0",
"TCPFastOpenPassiveFail": "0",
"TCPFastOpenListenOverflow": "0",
"TCPFastOpenCookieReqd": "0",
"TCPFastOpenBlackhole": "0",
"TCPSpuriousRtxHostQueues": "0",
"BusyPollRxPackets": "0",
"TCPAutoCorking": "28376",
"TCPFromZeroWindowAdv": "0",
"TCPToZeroWindowAdv": "0",
"TCPWantZeroWindowAdv": "0",
"TCPSynRetrans": "0",
"TCPOrigDataSent": "119438",
"TCPHystartTrainDetect": "3",
"TCPHystartTrainCwnd": "60",
"TCPHystartDelayDetect": "0",
"TCPHystartDelayCwnd": "0",
"TCPACKSkippedSynRecv": "0",
"TCPACKSkippedPAWS": "0",
"TCPACKSkippedSeq": "0",
"TCPACKSkippedFinWait2": "0",
"TCPACKSkippedTimeWait": "0",
"TCPACKSkippedChallenge": "0",
"TCPWinProbe": "0",
"TCPKeepAlive": "6",
"TCPMTUPFail": "0",
"TCPMTUPSuccess": "0",
"TCPDelivered": "119453",
"TCPDeliveredCE": "0",
"TCPAckCompressed": "0",
"TCPZeroWindowDrop": "0",
"TCPRcvQDrop": "0",
"TCPWqueueTooBig": "0",
"TCPFastOpenPassiveAltKey": "0",
"TcpTimeoutRehash": "0",
"TcpDuplicateDataRehash": "0",
"type": "TcpExt"
},
...
]
<a id="jc.parsers.proc_net_netstat.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,95 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_packet"></a>
# jc.parsers.proc\_net\_packet
jc - JSON Convert `/proc/net/packet` file parser
Usage (cli):
$ cat /proc/net/packet | jc --proc
or
$ jc /proc/net/packet
or
$ cat /proc/net/packet | jc --proc-net-packet
Usage (module):
import jc
result = jc.parse('proc', proc_net_packet_file)
or
import jc
result = jc.parse('proc_net_packet', proc_net_packet_file)
Schema:
{
"sk": string,
"RefCnt": integer,
"Type": integer,
"Proto": string,
"Iface": integer,
"R": integer,
"Rmem": integer,
"User": integer,
"Inode": integer
}
Examples:
$ cat /proc/net/packet | jc --proc -p
{
"sk": "ffff9b61b56c1800",
"RefCnt": 3,
"Type": 3,
"Proto": "88cc",
"Iface": 2,
"R": 1,
"Rmem": 0,
"User": 101,
"Inode": 34754
}
$ cat /proc/net/packet | jc --proc-net-packet -p -r
{
"sk": "ffff9b61b56c1800",
"RefCnt": "3",
"Type": "3",
"Proto": "88cc",
"Iface": "2",
"R": "1",
"Rmem": "0",
"User": "101",
"Inode": "34754"
}
<a id="jc.parsers.proc_net_packet.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,157 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_protocols"></a>
# jc.parsers.proc\_net\_protocols
jc - JSON Convert `/proc/net/protocols` file parser
Usage (cli):
$ cat /proc/net/protocols | jc --proc
or
$ jc /proc/net/protocols
or
$ cat /proc/net/protocols | jc --proc-net-protocols
Usage (module):
import jc
result = jc.parse('proc', proc_net_protocols_file)
or
import jc
result = jc.parse('proc_net_protocols', proc_net_protocols_file)
Schema:
[
{
"protocol": string,
"size": integer,
"sockets": integer,
"memory": integer,
"press": string,
"maxhdr": integer,
"slab": boolean,
"module": string,
"cl": boolean,
"co": boolean,
"di": boolean,
"ac": boolean,
"io": boolean,
"in": boolean,
"de": boolean,
"sh": boolean,
"ss": boolean,
"gs": boolean,
"se": boolean,
"re": boolean,
"sp": boolean,
"bi": boolean,
"br": boolean,
"ha": boolean,
"uh": boolean,
"gp": boolean,
"em": boolean,
}
]
Examples:
$ cat /proc/net/protocols | jc --proc -p
[
{
"protocol": "AF_VSOCK",
"size": 1216,
"sockets": 0,
"memory": -1,
"press": "NI",
"maxhdr": 0,
"slab": true,
"module": "vsock",
"cl": false,
"co": false,
"di": false,
"ac": false,
"io": false,
"in": false,
"de": false,
"sh": false,
"ss": false,
"gs": false,
"se": false,
"re": false,
"sp": false,
"bi": false,
"br": false,
"ha": false,
"uh": false,
"gp": false,
"em": false
},
...
]
$ cat /proc/net/protocols | jc --proc-net-protocols -p -r
[
{
"protocol": "AF_VSOCK",
"size": "1216",
"sockets": "0",
"memory": "-1",
"press": "NI",
"maxhdr": "0",
"slab": "yes",
"module": "vsock",
"cl": "n",
"co": "n",
"di": "n",
"ac": "n",
"io": "n",
"in": "n",
"de": "n",
"sh": "n",
"ss": "n",
"gs": "n",
"se": "n",
"re": "n",
"sp": "n",
"bi": "n",
"br": "n",
"ha": "n",
"uh": "n",
"gp": "n",
"em": "n"
},
...
]
<a id="jc.parsers.proc_net_protocols.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,109 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_route"></a>
# jc.parsers.proc\_net\_route
jc - JSON Convert `/proc/net/route` file parser
Usage (cli):
$ cat /proc/net/route | jc --proc
or
$ jc /proc/net/route
or
$ cat /proc/net/route | jc --proc-net-route
Usage (module):
import jc
result = jc.parse('proc', proc_net_route_file)
or
import jc
result = jc.parse('proc_net_route', proc_net_route_file)
Schema:
[
{
"Iface": string,
"Destination": string,
"Gateway": string,
"Flags": string,
"RefCnt": integer,
"Use": integer,
"Metric": integer,
"Mask": string,
"MTU": integer,
"Window": integer,
"IRTT": integer
}
]
Examples:
$ cat /proc/net/route | jc --proc -p
[
{
"Iface": "ens33",
"Destination": "00000000",
"Gateway": "0247A8C0",
"Flags": "0003",
"RefCnt": 0,
"Use": 0,
"Metric": 100,
"Mask": "00000000",
"MTU": 0,
"Window": 0,
"IRTT": 0
},
...
]
$ cat /proc/net/route | jc --proc-net-route -p -r
[
{
"Iface": "ens33",
"Destination": "00000000",
"Gateway": "0247A8C0",
"Flags": "0003",
"RefCnt": "0",
"Use": "0",
"Metric": "100",
"Mask": "00000000",
"MTU": "0",
"Window": "0",
"IRTT": "0"
},
...
]
<a id="jc.parsers.proc_net_route.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,100 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_net_unix"></a>
# jc.parsers.proc\_net\_unix
jc - JSON Convert `/proc/net/unix` file parser
Usage (cli):
$ cat /proc/net/unix | jc --proc
or
$ jc /proc/net/unix
or
$ cat /proc/net/unix | jc --proc-net-unix
Usage (module):
import jc
result = jc.parse('proc', proc_net_unix_file)
or
import jc
result = jc.parse('proc_net_unix', proc_net_unix_file)
Schema:
[
{
"Num": string,
"RefCount": string,
"Protocol": string,
"Flags": string,
"Type": string,
"St": string,
"Inode": integer,
"Path": string
}
]
Examples:
$ cat /proc/net/unix | jc --proc -p
[
{
"Num": "ffff9b61ac49c400:",
"RefCount": "00000002",
"Protocol": "00000000",
"Flags": "00010000",
"Type": "0001",
"St": "01",
"Inode": 42776,
"Path": "/var/snap/lxd/common/lxd/unix.socket"
},
...
]
$ cat /proc/net/unix | jc --proc-net-unix -p -r
[
{
"Num": "ffff9b61ac49c400:",
"RefCount": "00000002",
"Protocol": "00000000",
"Flags": "00010000",
"Type": "0001",
"St": "01",
"Inode": "42776",
"Path": "/var/snap/lxd/common/lxd/unix.socket"
},
...
]
<a id="jc.parsers.proc_net_unix.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,141 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pagetypeinfo"></a>
# jc.parsers.proc\_pagetypeinfo
jc - JSON Convert `/proc/pagetypeinfo` file parser
Usage (cli):
$ cat /proc/pagetypeinfo | jc --proc
or
$ jc /proc/pagetypeinfo
or
$ cat /proc/pagetypeinfo | jc --proc-pagetypeinfo
Usage (module):
import jc
result = jc.parse('proc', proc_pagetypeinfo_file)
or
import jc
result = jc.parse('proc_pagetypeinfo', proc_pagetypeinfo_file)
Schema:
{
"page_block_order": integer,
"pages_per_block": integer,
"free_pages": [
{
"node": integer,
"zone": string,
"type": string,
"free": [
integer # [0]
]
],
"num_blocks_type": [
{
"node": integer,
"zone": string,
"unmovable": integer,
"movable": integer,
"reclaimable": integer,
"high_atomic": integer,
"isolate": integer
}
]
}
[0] array index correlates to the Order number.
E.g. free[0] is the value for Order 0
Examples:
$ cat /proc/pagetypeinfo | jc --proc -p
{
"page_block_order": 9,
"pages_per_block": 512,
"free_pages": [
{
"node": 0,
"zone": "DMA",
"type": "Unmovable",
"free": [
0,
0,
0,
1,
1,
1,
1,
1,
0,
0,
0
]
},
...
],
"num_blocks_type": [
{
"node": 0,
"zone": "DMA",
"unmovable": 1,
"movable": 7,
"reclaimable": 0,
"high_atomic": 0,
"isolate": 0
},
{
"node": 0,
"zone": "DMA32",
"unmovable": 8,
"movable": 1472,
"reclaimable": 48,
"high_atomic": 0,
"isolate": 0
},
{
"node": 0,
"zone": "Normal",
"unmovable": 120,
"movable": 345,
"reclaimable": 47,
"high_atomic": 0,
"isolate": 0
}
]
}
<a id="jc.parsers.proc_pagetypeinfo.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,100 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_partitions"></a>
# jc.parsers.proc\_partitions
jc - JSON Convert `/proc/partitions` file parser
Usage (cli):
$ cat /proc/partitions | jc --proc
or
$ jc /proc/partitions
or
$ cat /proc/partitions | jc --proc-partitions
Usage (module):
import jc
result = jc.parse('proc', proc_partitions_file)
or
import jc
result = jc.parse('proc_partitions', proc_partitions_file)
Schema:
[
{
"major": integer,
"minor": integer,
"num_blocks": integer,
"name": string
}
]
Examples:
$ cat /proc/partitions | jc --proc -p
[
{
"major": 7,
"minor": 0,
"num_blocks": 56896,
"name": "loop0"
},
{
"major": 7,
"minor": 1,
"num_blocks": 56868,
"name": "loop1"
},
...
]
$ cat /proc/partitions | jc --proc-partitions -p -r
[
{
"major": "7",
"minor": "0",
"num_blocks": "56896",
"name": "loop0"
},
{
"major": "7",
"minor": "1",
"num_blocks": "56868",
"name": "loop1"
},
...
]
<a id="jc.parsers.proc_partitions.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,127 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_fdinfo"></a>
# jc.parsers.proc\_pid\_fdinfo
jc - JSON Convert `/proc/<pid>/fdinfo/<fd>` file parser
Usage (cli):
$ cat /proc/1/fdinfo/5 | jc --proc
or
$ jc /proc/1/fdinfo/5
or
$ cat /proc/1/fdinfo/5 | jc --proc-pid-fdinfo
Usage (module):
import jc
result = jc.parse('proc', proc_pid_fdinfo_file)
or
import jc
result = jc.parse('proc_pid_fdinfo', proc_pid_fdinfo_file)
Schema:
Any unspecified fields are strings.
{
"pos": integer,
"flags": integer,
"mnt_id": integer,
"scm_fds": string,
"ino": integer,
"lock": string,
"epoll": {
"tfd": integer,
"events": string,
"data": string,
"pos": integer,
"ino": string,
"sdev": string
},
"inotify": {
"wd": integer,
"ino": string,
"sdev": string,
"mask": string,
"ignored_mask": string,
"fhandle-bytes": string,
"fhandle-type": string,
"f_handle": string
},
"fanotify": {
"flags": string,
"event-flags": string,
"mnt_id": string,
"mflags": string,
"mask": string,
"ignored_mask": string,
"ino": string,
"sdev": string,
"fhandle-bytes": string,
"fhandle-type": string,
"f_handle": string
},
"clockid": integer,
"ticks": integer,
"settime flags": integer,
"it_value": [
integer
],
"it_interval": [
integer
]
}
Examples:
$ cat /proc/1/fdinfo/5 | jc --proc -p
{
"pos": 0,
"flags": 2,
"mnt_id": 9,
"ino": 63107,
"clockid": 0,
"ticks": 0,
"settime flags": 1,
"it_value": [
0,
49406829
],
"it_interval": [
1,
0
]
}
<a id="jc.parsers.proc_pid_fdinfo.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,74 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_io"></a>
# jc.parsers.proc\_pid\_io
jc - JSON Convert `/proc/<pid>/io` file parser
Usage (cli):
$ cat /proc/1/io | jc --proc
or
$ jc /proc/1/io
or
$ cat /proc/1/io | jc --proc-pid-io
Usage (module):
import jc
result = jc.parse('proc', proc_pid_io_file)
or
import jc
result = jc.parse('proc_pid_io', proc_pid_io_file)
Schema:
All values are integers.
{
<keyName> integer
}
Examples:
$ cat /proc/1/io | jc --proc -p
{
"rchar": 4699288382,
"wchar": 2931802997,
"syscr": 661897,
"syscw": 890910,
"read_bytes": 168468480,
"write_bytes": 27357184,
"cancelled_write_bytes": 16883712
}
<a id="jc.parsers.proc_pid_io.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,125 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_maps"></a>
# jc.parsers.proc\_pid\_maps
jc - JSON Convert `/proc/<pid>/maps` file parser
Usage (cli):
$ cat /proc/1/maps | jc --proc
or
$ jc /proc/1/maps
or
$ cat /proc/1/maps | jc --proc-pid-maps
Usage (module):
import jc
result = jc.parse('proc', proc_pid_maps_file)
or
import jc
result = jc.parse('proc_pid_maps', proc_pid_maps_file)
Schema:
[
{
"start": string,
"end": string,
"perms": [
string
],
"offset": string,
"inode": integer,
"pathname": string,
"maj": string,
"min": string
}
]
Examples:
$ cat /proc/1/maps | jc --proc -p
[
{
"perms": [
"read",
"private"
],
"offset": "00000000",
"inode": 798126,
"pathname": "/usr/lib/systemd/systemd",
"start": "55a9e753c000",
"end": "55a9e7570000",
"maj": "fd",
"min": "00"
},
{
"perms": [
"read",
"execute",
"private"
],
"offset": "00034000",
"inode": 798126,
"pathname": "/usr/lib/systemd/systemd",
"start": "55a9e7570000",
"end": "55a9e763a000",
"maj": "fd",
"min": "00"
},
...
]
$ cat /proc/1/maps | jc --proc-pid-maps -p -r
[
{
"address": "55a9e753c000-55a9e7570000",
"perms": "r--p",
"offset": "00000000",
"dev": "fd:00",
"inode": "798126",
"pathname": "/usr/lib/systemd/systemd"
},
{
"address": "55a9e7570000-55a9e763a000",
"perms": "r-xp",
"offset": "00034000",
"dev": "fd:00",
"inode": "798126",
"pathname": "/usr/lib/systemd/systemd"
},
...
]
<a id="jc.parsers.proc_pid_maps.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,170 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_mountinfo"></a>
# jc.parsers.proc\_pid\_mountinfo
jc - JSON Convert `/proc/<pid>/mountinfo` file parser
Usage (cli):
$ cat /proc/1/mountinfo | jc --proc
or
$ jc /proc/1/mountinfo
or
$ cat /proc/1/mountinfo | jc --proc-pid-mountinfo
Usage (module):
import jc
result = jc.parse('proc', proc_pid_mountinfo_file)
or
import jc
result = jc.parse('proc_pid_mountinfo', proc_pid_mountinfo_file)
Schema:
[
{
"mount_id": integer,
"parent_id": integer,
"maj": integer,
"min": integer,
"root": string,
"mount_point": string,
"mount_options": [
string
],
"optional_fields": { # [0]
"<key>": integer # [1]
},
"fs_type": string,
"mount_source": string,
"super_options": [
integer # [2]
],
"super_options_fields": {
"<key>": string
}
}
]
[0] if empty, then private mount
[1] unbindable will always have a value of 0
[2] integer conversions are attempted. Use --raw or raw=True for
original string values.
Examples:
$ cat /proc/1/mountinfo | jc --proc -p
[
{
"mount_id": 24,
"parent_id": 30,
"maj": 0,
"min": 22,
"root": "/",
"mount_point": "/sys",
"mount_options": [
"rw",
"nosuid",
"nodev",
"noexec",
"relatime"
],
"optional_fields": {
"master": 1,
"shared": 7
},
"fs_type": "sysfs",
"mount_source": "sysfs",
"super_options": [
"rw"
]
},
{
"mount_id": 25,
"parent_id": 30,
"maj": 0,
"min": 23,
"root": "/",
"mount_point": "/proc",
"mount_options": [
"rw",
"nosuid",
"nodev",
"noexec",
"relatime"
],
"optional_fields": {
"shared": 14
},
"fs_type": "proc",
"mount_source": "proc",
"super_options": [
"rw"
]
},
...
]
$ cat /proc/1/mountinfo | jc --proc-pid-mountinfo -p -r
[
{
"mount_id": "24",
"parent_id": "30",
"maj": "0",
"min": "22",
"root": "/",
"mount_point": "/sys",
"mount_options": "rw,nosuid,nodev,noexec,relatime",
"optional_fields": "master:1 shared:7 ",
"fs_type": "sysfs",
"mount_source": "sysfs",
"super_options": "rw"
},
{
"mount_id": "25",
"parent_id": "30",
"maj": "0",
"min": "23",
"root": "/",
"mount_point": "/proc",
"mount_options": "rw,nosuid,nodev,noexec,relatime",
"optional_fields": "shared:14 ",
"fs_type": "proc",
"mount_source": "proc",
"super_options": "rw"
},
...
]
<a id="jc.parsers.proc_pid_mountinfo.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,126 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_numa_maps"></a>
# jc.parsers.proc\_pid\_numa\_maps
jc - JSON Convert `/proc/<pid>/numa_maps` file parser
This parser will attempt to convert number values to integers. If that is
not desired, please use the `--raw` option (cli) or `raw=True` argument
(module).
Usage (cli):
$ cat /proc/1/numa_maps | jc --proc
or
$ jc /proc/1/numa_maps
or
$ cat /proc/1/numa_maps | jc --proc-pid-numa-maps
Usage (module):
import jc
result = jc.parse('proc', proc_pid_numa_maps_file)
or
import jc
result = jc.parse('proc_pid_numa_maps', proc_pid_numa_maps_file)
Schema:
Integer conversion for Key/value pairs will be attempted.
[
{
"address": string,
"policy": string,
"<key>": string/integer,
"options": [
string # [0]
]
}
]
[0] remaining individual words that are not part of a key/value pair
Examples:
$ cat /proc/1/numa_maps | jc --proc -p
[
{
"address": "7f53b5083000",
"policy": "default",
"file": "/usr/lib/x86_64-linux-gnu/ld-2.32.so",
"anon": 2,
"dirty": 2,
"N0": 2,
"kernelpagesize_kB": 4
},
{
"address": "7ffd1b23e000",
"policy": "default",
"anon": 258,
"dirty": 258,
"N0": 258,
"kernelpagesize_kB": 4,
"options": [
"stack"
]
},
...
]
$ cat /proc/1/numa_maps | jc --proc-pid-numa-maps -p -r
[
{
"address": "7f53b5083000",
"policy": "default",
"file": "/usr/lib/x86_64-linux-gnu/ld-2.32.so",
"anon": "2",
"dirty": "2",
"N0": "2",
"kernelpagesize_kB": "4"
},
{
"address": "7ffd1b23e000",
"policy": "default",
"anon": "258",
"dirty": "258",
"N0": "258",
"kernelpagesize_kB": "4",
"options": [
"stack"
]
},
...
]
<a id="jc.parsers.proc_pid_numa_maps.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,191 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_smaps"></a>
# jc.parsers.proc\_pid\_smaps
jc - JSON Convert `/proc/<pid>/smaps` file parser
Usage (cli):
$ cat /proc/1/smaps | jc --proc
or
$ jc /proc/1/smaps
or
$ cat /proc/1/smaps | jc --proc-pid-smaps
Usage (module):
import jc
result = jc.parse('proc', proc_pid_smaps_file)
or
import jc
result = jc.parse('proc_pid_smaps', proc_pid_smaps_file)
Schema:
[
{
"start": string,
"end": string,
"perms": [
string
],
"offset": string,
"maj": string,
"min": string,
"inode": integer,
"pathname": string,
"Size": integer,
"KernelPageSize": integer,
"MMUPageSize": integer,
"Rss": integer,
"Pss": integer,
"Shared_Clean": integer,
"Shared_Dirty": integer,
"Private_Clean": integer,
"Private_Dirty": integer,
"Referenced": integer,
"Anonymous": integer,
"LazyFree": integer,
"AnonHugePages": integer,
"ShmemPmdMapped": integer,
"FilePmdMapped": integer,
"Shared_Hugetlb": integer,
"Private_Hugetlb": integer,
"Swap": integer,
"SwapPss": integer,
"Locked": integer,
"THPeligible": integer,
"VmFlags": [
string
],
"VmFlags_pretty": [
string
]
}
]
Examples:
$ cat /proc/1/smaps | jc --proc -p
[
{
"start": "55a9e753c000",
"end": "55a9e7570000",
"perms": [
"read",
"private"
],
"offset": "00000000",
"maj": "fd",
"min": "00",
"inode": 798126,
"pathname": "/usr/lib/systemd/systemd",
"Size": 208,
"KernelPageSize": 4,
"MMUPageSize": 4,
"Rss": 208,
"Pss": 104,
"Shared_Clean": 208,
"Shared_Dirty": 0,
"Private_Clean": 0,
"Private_Dirty": 0,
"Referenced": 208,
"Anonymous": 0,
"LazyFree": 0,
"AnonHugePages": 0,
"ShmemPmdMapped": 0,
"FilePmdMapped": 0,
"Shared_Hugetlb": 0,
"Private_Hugetlb": 0,
"Swap": 0,
"SwapPss": 0,
"Locked": 0,
"THPeligible": 0,
"VmFlags": [
"rd",
"mr",
"mw",
"me",
"dw",
"sd"
],
"VmFlags_pretty": [
"readable",
"may read",
"may write",
"may execute",
"disabled write to the mapped file",
"soft-dirty flag"
]
},
...
]
$ cat /proc/1/smaps | jc --proc-pid-smaps -p -r
[
{
"start": "55a9e753c000",
"end": "55a9e7570000",
"perms": "r--p",
"offset": "00000000",
"maj": "fd",
"min": "00",
"inode": "798126",
"pathname": "/usr/lib/systemd/systemd",
"Size": "208 kB",
"KernelPageSize": "4 kB",
"MMUPageSize": "4 kB",
"Rss": "208 kB",
"Pss": "104 kB",
"Shared_Clean": "208 kB",
"Shared_Dirty": "0 kB",
"Private_Clean": "0 kB",
"Private_Dirty": "0 kB",
"Referenced": "208 kB",
"Anonymous": "0 kB",
"LazyFree": "0 kB",
"AnonHugePages": "0 kB",
"ShmemPmdMapped": "0 kB",
"FilePmdMapped": "0 kB",
"Shared_Hugetlb": "0 kB",
"Private_Hugetlb": "0 kB",
"Swap": "0 kB",
"SwapPss": "0 kB",
"Locked": "0 kB",
"THPeligible": "0",
"VmFlags": "rd mr mw me dw sd"
},
...
]
<a id="jc.parsers.proc_pid_smaps.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,226 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_stat"></a>
# jc.parsers.proc\_pid\_stat
jc - JSON Convert `/proc/<pid>/stat` file parser
Usage (cli):
$ cat /proc/1/stat | jc --proc
or
$ jc /proc/1/stat
or
$ cat /proc/1/stat | jc --proc-pid-stat
Usage (module):
import jc
result = jc.parse('proc', proc_pid_stat_file)
or
import jc
result = jc.parse('proc_pid_stat', proc_pid_stat_file)
Schema:
{
"pid": integer,
"comm": string,
"state": string,
"state_pretty": string,
"ppid": integer,
"pgrp": integer,
"session": integer,
"tty_nr": integer,
"tpg_id": integer,
"flags": integer,
"minflt": integer,
"cminflt": integer,
"majflt": integer,
"cmajflt": integer,
"utime": integer,
"stime": integer,
"cutime": integer,
"cstime": integer,
"priority": integer,
"nice": integer,
"num_threads": integer,
"itrealvalue": integer,
"starttime": integer,
"vsize": integer,
"rss": integer,
"rsslim": integer,
"startcode": integer,
"endcode": integer,
"startstack": integer,
"kstkeep": integer,
"kstkeip": integer,
"signal": integer,
"blocked": integer,
"sigignore": integer,
"sigcatch": integer,
"wchan": integer,
"nswap": integer,
"cnswap": integer,
"exit_signal": integer,
"processor": integer,
"rt_priority": integer,
"policy": integer,
"delayacct_blkio_ticks": integer,
"guest_time": integer,
"cguest_time": integer,
"start_data": integer,
"end_data": integer,
"start_brk": integer,
"arg_start": integer,
"arg_end": integer,
"env_start": integer,
"env_end": integer,
"exit_code": integer,
}
Examples:
$ cat /proc/1/stat | jc --proc -p
{
"pid": 1,
"comm": "systemd",
"state": "S",
"ppid": 0,
"pgrp": 1,
"session": 1,
"tty_nr": 0,
"tpg_id": -1,
"flags": 4194560,
"minflt": 23478,
"cminflt": 350218,
"majflt": 99,
"cmajflt": 472,
"utime": 107,
"stime": 461,
"cutime": 2672,
"cstime": 4402,
"priority": 20,
"nice": 0,
"num_threads": 1,
"itrealvalue": 0,
"starttime": 128,
"vsize": 174063616,
"rss": 3313,
"rsslim": 18446744073709551615,
"startcode": 94188219072512,
"endcode": 94188219899461,
"startstack": 140725059845296,
"kstkeep": 0,
"kstkeip": 0,
"signal": 0,
"blocked": 671173123,
"sigignore": 4096,
"sigcatch": 1260,
"wchan": 1,
"nswap": 0,
"cnswap": 0,
"exit_signal": 17,
"processor": 0,
"rt_priority": 0,
"policy": 0,
"delayacct_blkio_ticks": 18,
"guest_time": 0,
"cguest_time": 0,
"start_data": 94188220274448,
"end_data": 94188220555504,
"start_brk": 94188243599360,
"arg_start": 140725059845923,
"arg_end": 140725059845934,
"env_start": 140725059845934,
"env_end": 140725059846125,
"exit_code": 0,
"state_pretty": "Sleeping in an interruptible wait"
}
$ cat /proc/1/stat | jc --proc-pid-stat -p -r
{
"pid": 1,
"comm": "systemd",
"state": "S",
"ppid": 0,
"pgrp": 1,
"session": 1,
"tty_nr": 0,
"tpg_id": -1,
"flags": 4194560,
"minflt": 23478,
"cminflt": 350218,
"majflt": 99,
"cmajflt": 472,
"utime": 107,
"stime": 461,
"cutime": 2672,
"cstime": 4402,
"priority": 20,
"nice": 0,
"num_threads": 1,
"itrealvalue": 0,
"starttime": 128,
"vsize": 174063616,
"rss": 3313,
"rsslim": 18446744073709551615,
"startcode": 94188219072512,
"endcode": 94188219899461,
"startstack": 140725059845296,
"kstkeep": 0,
"kstkeip": 0,
"signal": 0,
"blocked": 671173123,
"sigignore": 4096,
"sigcatch": 1260,
"wchan": 1,
"nswap": 0,
"cnswap": 0,
"exit_signal": 17,
"processor": 0,
"rt_priority": 0,
"policy": 0,
"delayacct_blkio_ticks": 18,
"guest_time": 0,
"cguest_time": 0,
"start_data": 94188220274448,
"end_data": 94188220555504,
"start_brk": 94188243599360,
"arg_start": 140725059845923,
"arg_end": 140725059845934,
"env_start": 140725059845934,
"env_end": 140725059846125,
"exit_code": 0
}
<a id="jc.parsers.proc_pid_stat.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,78 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_statm"></a>
# jc.parsers.proc\_pid\_statm
jc - JSON Convert `/proc/<pid>/statm` file parser
Usage (cli):
$ cat /proc/1/statm | jc --proc
or
$ jc /proc/1/statm
or
$ cat /proc/1/statm | jc --proc-pid-statm
Usage (module):
import jc
result = jc.parse('proc', proc_pid_statm_file)
or
import jc
result = jc.parse('proc_pid_statm', proc_pid_statm_file)
Schema:
{
"size": integer,
"resident": integer,
"shared": integer,
"text": integer,
"lib": integer,
"data": integer,
"dt": integer
}
Examples:
$ cat /proc/1/statm | jc --proc -p
{
"size": 42496,
"resident": 3313,
"shared": 2169,
"text": 202,
"lib": 0,
"data": 5180,
"dt": 0
}
<a id="jc.parsers.proc_pid_statm.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,295 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_pid_status"></a>
# jc.parsers.proc\_pid\_status
jc - JSON Convert `/proc/<pid>/status` file parser
Usage (cli):
$ cat /proc/1/status | jc --proc
or
$ jc /proc/1/status
or
$ cat /proc/1/status | jc --proc-pid-status
Usage (module):
import jc
result = jc.parse('proc', proc_pid_status_file)
or
import jc
result = jc.parse('proc_pid_status', proc_pid_status_file)
Schema:
{
"Name": string,
"Umask": string,
"State": string,
"State_pretty": string,
"Tgid": integer,
"Ngid": integer,
"Pid": integer,
"PPid": integer,
"TracerPid": integer,
"Uid": [
integer
],
"Gid": [
integer
],
"FDSize": integer,
"Groups": string,
"NStgid": integer,
"NSpid": integer,
"NSpgid": integer,
"NSsid": integer,
"VmPeak": integer,
"VmSize": integer,
"VmLck": integer,
"VmPin": integer,
"VmHWM": integer,
"VmRSS": integer,
"RssAnon": integer,
"RssFile": integer,
"RssShmem": integer,
"VmData": integer,
"VmStk": integer,
"VmExe": integer,
"VmLib": integer,
"VmPTE": integer,
"VmSwap": integer,
"HugetlbPages": integer,
"CoreDumping": integer,
"THP_enabled": integer,
"Threads": integer,
"SigQ": string,
"SigQ_current": integer,
"SigQ_limit": integer,
"SigPnd": string,
"ShdPnd": string,
"SigBlk": string,
"SigIgn": string,
"SigCgt": string,
"CapInh": string,
"CapPrm": string,
"CapEff": string,
"CapBnd": string,
"CapAmb": string,
"NoNewPrivs": integer,
"Seccomp": integer,
"Speculation_Store_Bypass": string,
"Cpus_allowed": [
string
],
"Cpus_allowed_list": string,
"Mems_allowed": [
string
],
"Mems_allowed_list": string,
"voluntary_ctxt_switches": integer,
"nonvoluntary_ctxt_switches": integer
}
Examples:
$ cat /proc/1/status | jc --proc -p
{
"Name": "systemd",
"Umask": "0000",
"State": "S",
"Tgid": 1,
"Ngid": 0,
"Pid": 1,
"PPid": 0,
"TracerPid": 0,
"Uid": [
0,
0,
0,
0
],
"Gid": [
0,
0,
0,
0
],
"FDSize": 128,
"Groups": "",
"NStgid": 1,
"NSpid": 1,
"NSpgid": 1,
"NSsid": 1,
"VmPeak": 235380,
"VmSize": 169984,
"VmLck": 0,
"VmPin": 0,
"VmHWM": 13252,
"VmRSS": 13252,
"RssAnon": 4576,
"RssFile": 8676,
"RssShmem": 0,
"VmData": 19688,
"VmStk": 1032,
"VmExe": 808,
"VmLib": 9772,
"VmPTE": 96,
"VmSwap": 0,
"HugetlbPages": 0,
"CoreDumping": 0,
"THP_enabled": 1,
"Threads": 1,
"SigQ": "0/15245",
"SigPnd": "0000000000000000",
"ShdPnd": "0000000000000000",
"SigBlk": "7be3c0fe28014a03",
"SigIgn": "0000000000001000",
"SigCgt": "00000001800004ec",
"CapInh": "0000000000000000",
"CapPrm": "000000ffffffffff",
"CapEff": "000000ffffffffff",
"CapBnd": "000000ffffffffff",
"CapAmb": "0000000000000000",
"NoNewPrivs": 0,
"Seccomp": 0,
"Speculation_Store_Bypass": "thread vulnerable",
"Cpus_allowed": [
"ffffffff",
"ffffffff",
"ffffffff",
"ffffffff"
],
"Cpus_allowed_list": "0-127",
"Mems_allowed": [
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000000",
"00000001"
],
"Mems_allowed_list": "0",
"voluntary_ctxt_switches": 1856,
"nonvoluntary_ctxt_switches": 6620,
"State_pretty": "sleeping",
"SigQ_current": 0,
"SigQ_limit": 15245
}
$ cat /proc/1/status | jc --proc-pid-status -p -r
{
"Name": "systemd",
"Umask": "0000",
"State": "S (sleeping)",
"Tgid": "1",
"Ngid": "0",
"Pid": "1",
"PPid": "0",
"TracerPid": "0",
"Uid": "0\t0\t0\t0",
"Gid": "0\t0\t0\t0",
"FDSize": "128",
"Groups": "",
"NStgid": "1",
"NSpid": "1",
"NSpgid": "1",
"NSsid": "1",
"VmPeak": "235380 kB",
"VmSize": "169984 kB",
"VmLck": "0 kB",
"VmPin": "0 kB",
"VmHWM": "13252 kB",
"VmRSS": "13252 kB",
"RssAnon": "4576 kB",
"RssFile": "8676 kB",
"RssShmem": "0 kB",
"VmData": "19688 kB",
"VmStk": "1032 kB",
"VmExe": "808 kB",
"VmLib": "9772 kB",
"VmPTE": "96 kB",
"VmSwap": "0 kB",
"HugetlbPages": "0 kB",
"CoreDumping": "0",
"THP_enabled": "1",
"Threads": "1",
"SigQ": "0/15245",
"SigPnd": "0000000000000000",
"ShdPnd": "0000000000000000",
"SigBlk": "7be3c0fe28014a03",
"SigIgn": "0000000000001000",
"SigCgt": "00000001800004ec",
"CapInh": "0000000000000000",
"CapPrm": "000000ffffffffff",
"CapEff": "000000ffffffffff",
"CapBnd": "000000ffffffffff",
"CapAmb": "0000000000000000",
"NoNewPrivs": "0",
"Seccomp": "0",
"Speculation_Store_Bypass": "thread vulnerable",
"Cpus_allowed": "ffffffff,ffffffff,ffffffff,ffffffff",
"Cpus_allowed_list": "0-127",
"Mems_allowed": "00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001",
"Mems_allowed_list": "0",
"voluntary_ctxt_switches": "1856",
"nonvoluntary_ctxt_switches": "6620"
}
<a id="jc.parsers.proc_pid_status.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,100 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_slabinfo"></a>
# jc.parsers.proc\_slabinfo
jc - JSON Convert `/proc/slabinfo` file parser
Usage (cli):
$ cat /proc/slabinfo | jc --proc
or
$ jc /proc/slabinfo
or
$ cat /proc/slabinfo | jc --proc-slabinfo
Usage (module):
import jc
result = jc.parse('proc', proc_slabinfo_file)
or
import jc
result = jc.parse('proc_slabinfo', proc_slabinfo_file)
Schema:
[
{
"name": string,
"active_objs": integer,
"num_objs": integer,
"obj_size": integer,
"obj_per_slab": integer,
"pages_per_slab": integer,
"tunables": {
"limit": integer,
"batch_count": integer,
"shared_factor": integer
},
"slabdata": {
"active_slabs": integer,
"num_slabs": integer,
"shared_avail": integer
}
]
Examples:
$ cat /proc/slabinfo | jc --proc -p
[
{
"name": "ext4_groupinfo_4k",
"active_objs": 224,
"num_objs": 224,
"obj_size": 144,
"obj_per_slab": 56,
"pages_per_slab": 2,
"tunables": {
"limit": 0,
"batch_count": 0,
"shared_factor": 0
},
"slabdata": {
"active_slabs": 4,
"num_slabs": 4,
"shared_avail": 0
}
},
...
]
<a id="jc.parsers.proc_slabinfo.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,85 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_softirqs"></a>
# jc.parsers.proc\_softirqs
jc - JSON Convert `/proc/softirqs` file parser
Usage (cli):
$ cat /proc/softirqs | jc --proc
or
$ jc /proc/softirqs
or
$ cat /proc/softirqs | jc --proc-softirqs
Usage (module):
import jc
result = jc.parse('proc', proc_softirqs_file)
or
import jc
result = jc.parse('proc_softirqs', proc_softirqs_file)
Schema:
[
{
"counter": string,
"CPU<number>": integer,
}
]
Examples:
$ cat /proc/softirqs | jc --proc -p
[
{
"counter": "HI",
"CPU0": 1,
"CPU1": 34056,
"CPU2": 0,
"CPU3": 0,
"CPU4": 0
},
{
"counter": "TIMER",
"CPU0": 322970,
"CPU1": 888166,
"CPU2": 0,
"CPU3": 0,
"CPU4": 0
},
...
]
<a id="jc.parsers.proc_softirqs.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 Kelly Brazil (kellyjonbrazil@gmail.com)

161
docs/parsers/proc_stat.md Normal file
View File

@@ -0,0 +1,161 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_stat"></a>
# jc.parsers.proc\_stat
jc - JSON Convert `/proc/stat` file parser
Usage (cli):
$ cat /proc/stat | jc --proc
or
$ jc /proc/stat
or
$ cat /proc/stat | jc --proc-stat
Usage (module):
import jc
result = jc.parse('proc', proc_stat_file)
or
import jc
result = jc.parse('proc_stat', proc_stat_file)
Schema:
{
"cpu": {
"user": integer,
"nice": integer,
"system": integer,
"idle": integer,
"iowait": integer,
"irq": integer,
"softirq": integer,
"steal": integer,
"guest": integer,
"guest_nice": integer
},
"cpu<number>": {
"user": integer,
"nice": integer,
"system": integer,
"idle": integer,
"iowait": integer,
"irq": integer,
"softirq": integer,
"steal": integer,
"guest": integer,
"guest_nice": integer
},
"interrupts": [
integer
],
"context_switches": integer,
"boot_time": integer,
"processes": integer,
"processes_running": integer,
"processes_blocked": integer,
"softirq": [
integer
]
}
Examples:
$ cat /proc/stat | jc --proc -p
{
"cpu": {
"user": 6002,
"nice": 152,
"system": 8398,
"idle": 3444436,
"iowait": 448,
"irq": 0,
"softirq": 1174,
"steal": 0,
"guest": 0,
"guest_nice": 0
},
"cpu0": {
"user": 2784,
"nice": 137,
"system": 4367,
"idle": 1732802,
"iowait": 225,
"irq": 0,
"softirq": 221,
"steal": 0,
"guest": 0,
"guest_nice": 0
},
"cpu1": {
"user": 3218,
"nice": 15,
"system": 4031,
"idle": 1711634,
"iowait": 223,
"irq": 0,
"softirq": 953,
"steal": 0,
"guest": 0,
"guest_nice": 0
},
"interrupts": [
2496709,
18,
73,
0,
0,
...
],
"context_switches": 4622716,
"boot_time": 1662154781,
"processes": 9831,
"processes_running": 1,
"processes_blocked": 0,
"softirq": [
3478985,
35230,
1252057,
3467,
128583,
51014,
0,
171199,
1241297,
0,
596138
]
}
<a id="jc.parsers.proc_stat.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,91 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_swaps"></a>
# jc.parsers.proc\_swaps
jc - JSON Convert `/proc/swaps` file parser
Usage (cli):
$ cat /proc/swaps | jc --proc
or
$ jc /proc/swaps
or
$ cat /proc/swaps | jc --proc-swaps
Usage (module):
import jc
result = jc.parse('proc', proc_swaps_file)
or
import jc
result = jc.parse('proc_swaps', proc_swaps_file)
Schema:
[
{
"filename": string,
"type": string,
"size": integer,
"used": integer,
"priority": integer
}
]
Examples:
$ cat /proc/swaps | jc --proc -p
[
{
"filename": "/swap.img",
"type": "file",
"size": 3996668,
"used": 0,
"priority": -2
},
...
]
$ cat /proc/swaps | jc --proc-swaps -p -r
[
{
"filename": "/swap.img",
"type": "file",
"size": "3996668",
"used": "0",
"priority": "-2"
},
...
]
<a id="jc.parsers.proc_swaps.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,68 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_uptime"></a>
# jc.parsers.proc\_uptime
jc - JSON Convert `/proc/uptime` file parser
Usage (cli):
$ cat /proc/uptime | jc --proc
or
$ jc /proc/uptime
or
$ cat /proc/uptime | jc --proc-uptime
Usage (module):
import jc
result = jc.parse('proc', proc_uptime_file)
or
import jc
result = jc.parse('proc_uptime', proc_uptime_file)
Schema:
{
"up_time": float,
"idle_time": float
}
Examples:
$ cat /proc/uptime | jc --proc -p
{
"up_time": 46901.13,
"idle_time": 46856.66
}
<a id="jc.parsers.proc_uptime.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,79 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_version"></a>
# jc.parsers.proc\_version
jc - JSON Convert `/proc/version` file parser
> Note: This parser will parse `/proc/version` files that follow the
> common format used by most popular linux distributions.
Usage (cli):
$ cat /proc/version | jc --proc
or
$ jc /proc/version
or
$ cat /proc/version | jc --proc-version
Usage (module):
import jc
result = jc.parse('proc', proc_version_file)
or
import jc
result = jc.parse('proc_version', proc_version_file)
Schema:
{
"version": string,
"email": string,
"gcc": string,
"build": string,
"flags": string/null,
"date": string
}
Examples:
$ cat /proc/version | jc --proc -p
{
"version": "5.8.0-63-generic",
"email": "buildd@lcy01-amd64-028",
"gcc": "gcc (Ubuntu 10.3.0-1ubuntu1~20.10) 10.3.0, GNU ld (GNU Binutils for Ubuntu) 2.35.1",
"build": "#71-Ubuntu",
"flags": "SMP",
"date": "Tue Jul 13 15:59:12 UTC 2021"
}
<a id="jc.parsers.proc_version.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,126 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_vmallocinfo"></a>
# jc.parsers.proc\_vmallocinfo
jc - JSON Convert `/proc/vmallocinfo` file parser
This parser will attempt to convert number values to integers. If that is
not desired, please use the `--raw` option (cli) or `raw=True` argument
(module).
Usage (cli):
$ cat /proc/vmallocinfo | jc --proc
or
$ jc /proc/vmallocinfo
or
$ cat /proc/vmallocinfo | jc --proc-vmallocinfo
Usage (module):
import jc
result = jc.parse('proc', proc_vmallocinfo_file)
or
import jc
result = jc.parse('proc_vmallocinfo', proc_vmallocinfo_file)
Schema:
[
{
"start": string,
"end": string,
"size": integer,
"caller": string,
"options": [
string
],
"phys": string
"pages": integer,
"N<id>": integer
}
]
Examples:
$ cat /proc/vmallocinfo | jc --proc -p
[
{
"start": "0xffffb3c1c0000000",
"end": "0xffffb3c1c0005000",
"size": 20480,
"caller": "map_irq_stack+0x93/0xe0",
"options": [
"vmap"
],
"phys": "0x00000000bfefe000"
},
{
"start": "0xffffb3c1c0005000",
"end": "0xffffb3c1c0007000",
"size": 8192,
"caller": "acpi_os_map_iomem+0x1ac/0x1c0",
"options": [
"ioremap"
],
"phys": "0x00000000bfeff000"
},
...
]
$ cat /proc/vmallocinfo | jc --proc-vmallocinfo -p -r
[
{
"start": "0xffffb3c1c0000000",
"end": "0xffffb3c1c0005000",
"size": "20480",
"caller": "map_irq_stack+0x93/0xe0",
"options": [
"vmap"
],
"phys": "0x00000000bfefe000"
},
{
"start": "0xffffb3c1c0005000",
"end": "0xffffb3c1c0007000",
"size": "8192",
"caller": "acpi_os_map_iomem+0x1ac/0x1c0",
"options": [
"ioremap"
],
"phys": "0x00000000bfeff000"
},
...
]
<a id="jc.parsers.proc_vmallocinfo.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,84 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_vmstat"></a>
# jc.parsers.proc\_vmstat
jc - JSON Convert `/proc/vmstat` file parser
Usage (cli):
$ cat /proc/vmstat | jc --proc
or
$ jc /proc/vmstat
or
$ cat /proc/vmstat | jc --proc-vmstat
Usage (module):
import jc
result = jc.parse('proc', proc_vmstat_file)
or
import jc
result = jc.parse('proc_vmstat', proc_vmstat_file)
Schema:
All values are integers.
{
<keyName> integer
}
Examples:
$ cat /proc/vmstat | jc --proc -p
{
"nr_free_pages": 615337,
"nr_zone_inactive_anon": 39,
"nr_zone_active_anon": 34838,
"nr_zone_inactive_file": 104036,
"nr_zone_active_file": 130601,
"nr_zone_unevictable": 4897,
"nr_zone_write_pending": 45,
"nr_mlock": 4897,
"nr_page_table_pages": 548,
"nr_kernel_stack": 5984,
"nr_bounce": 0,
"nr_zspages": 0,
"nr_free_cma": 0,
"numa_hit": 1910597,
"numa_miss": 0,
"numa_foreign": 0,
...
}
<a id="jc.parsers.proc_vmstat.parse"></a>
### parse
```python
def parse(data: str, raw: bool = False, quiet: bool = False) -> 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:
Dictionary. Raw or processed structured data.
### Parser Information
Compatibility: linux
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -0,0 +1,334 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.proc_zoneinfo"></a>
# jc.parsers.proc\_zoneinfo
jc - JSON Convert `/proc/zoneinfo` file parser
Usage (cli):
$ cat /proc/zoneinfo | jc --proc
or
$ jc /proc/zoneinfo
or
$ cat /proc/zoneinfo | jc --proc-zoneinfo
Usage (module):
import jc
result = jc.parse('proc', proc_zoneinfo_file)
or
import jc
result = jc.parse('proc_zoneinfo', proc_zoneinfo_file)
Schema:
All values are integers.
[
{
"node": integer,
"<zone>": {
"pages": {
"free": integer,
"min": integer,
"low": integer,
"high": integer,
"spanned": integer,
"present": integer,
"managed": integer,
"protection": [
integer
],
"<key>": integer
},
"pagesets": [
{
"cpu": integer,
"count": integer,
"high": integer,
"batch": integer,
"vm stats threshold": integer,
"<key>": integer
}
]
},
"<key>": integer, # [0]
}
]
[0] per-node stats
Examples:
$ cat /proc/zoneinfo | jc --proc -p
[
{
"node": 0,
"DMA": {
"pages": {
"free": 3832,
"min": 68,
"low": 85,
"high": 102,
"spanned": 4095,
"present": 3997,
"managed": 3976,
"protection": [
0,
2871,
3795,
3795,
3795
],
"nr_free_pages": 3832,
"nr_zone_inactive_anon": 0,
"nr_zone_active_anon": 0,
"nr_zone_inactive_file": 0,
"nr_zone_active_file": 0,
"nr_zone_unevictable": 0,
"nr_zone_write_pending": 0,
"nr_mlock": 0,
"nr_page_table_pages": 0,
"nr_kernel_stack": 0,
"nr_bounce": 0,
"nr_zspages": 0,
"nr_free_cma": 0,
"numa_hit": 3,
"numa_miss": 0,
"numa_foreign": 0,
"numa_interleave": 1,
"numa_local": 3,
"numa_other": 0
},
"pagesets": [
{
"cpu": 0,
"count": 0,
"high": 0,
"batch": 1,
"vm stats threshold": 4
},
{
"cpu": 1,
"count": 0,
"high": 0,
"batch": 1,
"vm stats threshold": 4,
"node_unreclaimable": 0,
"start_pfn": 1
}
]
},
"nr_inactive_anon": 39,
"nr_active_anon": 34839,
"nr_inactive_file": 104172,
"nr_active_file": 130748,
"nr_unevictable": 4897,
"nr_slab_reclaimable": 49017,
"nr_slab_unreclaimable": 26177,
"nr_isolated_anon": 0,
"nr_isolated_file": 0,
"workingset_nodes": 0,
"workingset_refault": 0,
"workingset_activate": 0,
"workingset_restore": 0,
"workingset_nodereclaim": 0,
"nr_anon_pages": 40299,
"nr_mapped": 25140,
"nr_file_pages": 234396,
"nr_dirty": 0,
"nr_writeback": 0,
"nr_writeback_temp": 0,
"nr_shmem": 395,
"nr_shmem_hugepages": 0,
"nr_shmem_pmdmapped": 0,
"nr_file_hugepages": 0,
"nr_file_pmdmapped": 0,
"nr_anon_transparent_hugepages": 0,
"nr_vmscan_write": 0,
"nr_vmscan_immediate_reclaim": 0,
"nr_dirtied": 168223,
"nr_written": 144616,
"nr_kernel_misc_reclaimable": 0,
"nr_foll_pin_acquired": 0,
"nr_foll_pin_released": 0,
"DMA32": {
"pages": {
"free": 606010,
"min": 12729,
"low": 15911,
"high": 19093,
"spanned": 1044480,
"present": 782288,
"managed": 758708,
"protection": [
0,
0,
924,
924,
924
],
"nr_free_pages": 606010,
"nr_zone_inactive_anon": 4,
"nr_zone_active_anon": 17380,
"nr_zone_inactive_file": 41785,
"nr_zone_active_file": 64545,
"nr_zone_unevictable": 5,
"nr_zone_write_pending": 0,
"nr_mlock": 5,
"nr_page_table_pages": 101,
"nr_kernel_stack": 224,
"nr_bounce": 0,
"nr_zspages": 0,
"nr_free_cma": 0,
"numa_hit": 576595,
"numa_miss": 0,
"numa_foreign": 0,
"numa_interleave": 2,
"numa_local": 576595,
"numa_other": 0
},
"pagesets": [
{
"cpu": 0,
"count": 253,
"high": 378,
"batch": 63,
"vm stats threshold": 24
},
{
"cpu": 1,
"count": 243,
"high": 378,
"batch": 63,
"vm stats threshold": 24,
"node_unreclaimable": 0,
"start_pfn": 4096
}
]
},
"Normal": {
"pages": {
"free": 5113,
"min": 4097,
"low": 5121,
"high": 6145,
"spanned": 262144,
"present": 262144,
"managed": 236634,
"protection": [
0,
0,
0,
0,
0
],
"nr_free_pages": 5113,
"nr_zone_inactive_anon": 35,
"nr_zone_active_anon": 17459,
"nr_zone_inactive_file": 62387,
"nr_zone_active_file": 66203,
"nr_zone_unevictable": 4892,
"nr_zone_write_pending": 0,
"nr_mlock": 4892,
"nr_page_table_pages": 447,
"nr_kernel_stack": 5760,
"nr_bounce": 0,
"nr_zspages": 0,
"nr_free_cma": 0,
"numa_hit": 1338441,
"numa_miss": 0,
"numa_foreign": 0,
"numa_interleave": 66037,
"numa_local": 1338441,
"numa_other": 0
},
"pagesets": [
{
"cpu": 0,
"count": 340,
"high": 378,
"batch": 63,
"vm stats threshold": 16
},
{
"cpu": 1,
"count": 174,
"high": 378,
"batch": 63,
"vm stats threshold": 16,
"node_unreclaimable": 0,
"start_pfn": 1048576
}
]
},
"Movable": {
"pages": {
"free": 0,
"min": 0,
"low": 0,
"high": 0,
"spanned": 0,
"present": 0,
"managed": 0,
"protection": [
0,
0,
0,
0,
0
]
}
},
"Device": {
"pages": {
"free": 0,
"min": 0,
"low": 0,
"high": 0,
"spanned": 0,
"present": 0,
"managed": 0,
"protection": [
0,
0,
0,
0,
0
]
}
}
}
]
<a id="jc.parsers.proc_zoneinfo.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 Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -83,7 +83,10 @@ Examples:
```python
@add_jc_meta
def parse(data, raw=False, quiet=False, ignore_exceptions=False)
def parse(data: Iterable[str],
raw: bool = False,
quiet: bool = False,
ignore_exceptions: bool = False) -> StreamingOutputType
```
Main text parsing generator function. Returns an iterable object.
@@ -104,4 +107,4 @@ Returns:
### Parser Information
Compatibility: linux, darwin, freebsd
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)

143
docs/parsers/udevadm.md Normal file
View File

@@ -0,0 +1,143 @@
[Home](https://kellyjonbrazil.github.io/jc/)
<a id="jc.parsers.udevadm"></a>
# jc.parsers.udevadm
jc - JSON Convert `udevadm info` command output parser
Usage (cli):
$ udevadm info --query=all /dev/sda | jc --udevadm
or
$ jc udevadm info --query=all /dev/sda
Usage (module):
import jc
result = jc.parse('udevadm', udevadm_command_output)
Schema:
{
"P": string,
"N": string,
"L": integer,
"S": [
string
],
"E": {
"<key>": string
}
}
Examples:
$ udevadm info --query=all /dev/sda | jc --udevadm -p
{
"P": "/devices/pci0000:00/0000:00:10.0/host32/target32:0:0/32:0:0:0/block/sda",
"N": "sda",
"L": 0,
"S": [
"disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0"
],
"E": {
"DEVPATH": "/devices/pci0000:00/0000:00:10.0/host32/target32:0:0/32:0:0:0/block/sda",
"DEVNAME": "/dev/sda",
"DEVTYPE": "disk",
"MAJOR": "8",
"MINOR": "0",
"SUBSYSTEM": "block",
"USEC_INITIALIZED": "6100111",
"SCSI_TPGS": "0",
"SCSI_TYPE": "disk",
"SCSI_VENDOR": "VMware,",
"SCSI_VENDOR_ENC": "VMware,\\x20",
"SCSI_MODEL": "VMware_Virtual_S",
"SCSI_MODEL_ENC": "VMware\\x20Virtual\\x20S",
"SCSI_REVISION": "1.0",
"ID_SCSI": "1",
"ID_VENDOR": "VMware_",
"ID_VENDOR_ENC": "VMware\\x2c\\x20",
"ID_MODEL": "VMware_Virtual_S",
"ID_MODEL_ENC": "VMware\\x20Virtual\\x20S",
"ID_REVISION": "1.0",
"ID_TYPE": "disk",
"MPATH_SBIN_PATH": "/sbin",
"ID_BUS": "scsi",
"ID_PATH": "pci-0000:00:10.0-scsi-0:0:0:0",
"ID_PATH_TAG": "pci-0000_00_10_0-scsi-0_0_0_0",
"ID_PART_TABLE_UUID": "a5bd0c01-4210-46f2-b558-5c11c209a8f7",
"ID_PART_TABLE_TYPE": "gpt",
"DEVLINKS": "/dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0",
"TAGS": ":systemd:"
}
}
$ udevadm info --query=all /dev/sda | jc --udevadm -p -r
{
"P": "/devices/pci0000:00/0000:00:10.0/host32/target32:0:0/32:0:0:0/block/sda",
"N": "sda",
"L": "0",
"S": [
"disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0"
],
"E": {
"DEVPATH": "/devices/pci0000:00/0000:00:10.0/host32/target32:0:0/32:0:0:0/block/sda",
"DEVNAME": "/dev/sda",
"DEVTYPE": "disk",
"MAJOR": "8",
"MINOR": "0",
"SUBSYSTEM": "block",
"USEC_INITIALIZED": "6100111",
"SCSI_TPGS": "0",
"SCSI_TYPE": "disk",
"SCSI_VENDOR": "VMware,",
"SCSI_VENDOR_ENC": "VMware,\\x20",
"SCSI_MODEL": "VMware_Virtual_S",
"SCSI_MODEL_ENC": "VMware\\x20Virtual\\x20S",
"SCSI_REVISION": "1.0",
"ID_SCSI": "1",
"ID_VENDOR": "VMware_",
"ID_VENDOR_ENC": "VMware\\x2c\\x20",
"ID_MODEL": "VMware_Virtual_S",
"ID_MODEL_ENC": "VMware\\x20Virtual\\x20S",
"ID_REVISION": "1.0",
"ID_TYPE": "disk",
"MPATH_SBIN_PATH": "/sbin",
"ID_BUS": "scsi",
"ID_PATH": "pci-0000:00:10.0-scsi-0:0:0:0",
"ID_PATH_TAG": "pci-0000_00_10_0-scsi-0_0_0_0",
"ID_PART_TABLE_UUID": "a5bd0c01-4210-46f2-b558-5c11c209a8f7",
"ID_PART_TABLE_TYPE": "gpt",
"DEVLINKS": "/dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0",
"TAGS": ":systemd:"
}
}
<a id="jc.parsers.udevadm.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
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@@ -11,12 +11,17 @@ and file-types to dictionaries and lists of dictionaries.
## Interactive Documentation
Using `jc` in your python programs:
>>> help('jc')
>>> help('jc.lib')
>>> jc.get_help('parser_module_name')
Developing `jc` parsers:
>>> help('jc.utils')
>>> help('jc.streaming')
>>> help('jc.parsers.universal')
>>> jc.get_help('parser_module_name')
## Online Documentation

View File

@@ -19,7 +19,7 @@ jc - JSON Convert streaming utils
### streaming\_input\_type\_check
```python
def streaming_input_type_check(data: Iterable) -> None
def streaming_input_type_check(data: Iterable[Union[str, bytes]]) -> None
```
Ensure input data is an iterable, but not a string or bytes. Raises
@@ -40,7 +40,8 @@ Ensure each line is a string. Raises `TypeError` if not.
### stream\_success
```python
def stream_success(output_line: Dict, ignore_exceptions: bool) -> Dict
def stream_success(output_line: JSONDictType,
ignore_exceptions: bool) -> JSONDictType
```
Add `_jc_meta` object to output line if `ignore_exceptions=True`
@@ -50,7 +51,7 @@ Add `_jc_meta` object to output line if `ignore_exceptions=True`
### stream\_error
```python
def stream_error(e: BaseException, line: str) -> Dict
def stream_error(e: BaseException, line: str) -> Dict[str, MetadataType]
```
Return an error `_jc_meta` field.
@@ -60,7 +61,7 @@ Return an error `_jc_meta` field.
### add\_jc\_meta
```python
def add_jc_meta(func)
def add_jc_meta(func: F) -> F
```
Decorator for streaming parsers to add stream_success and stream_error
@@ -106,7 +107,7 @@ In all cases above:
```python
def raise_or_yield(ignore_exceptions: bool, e: BaseException,
line: str) -> tuple
line: str) -> Tuple[BaseException, str]
```
Return the exception object and line string if ignore_exceptions is

View File

@@ -64,7 +64,7 @@ Returns:
### is\_compatible
```python
def is_compatible(compatible: List) -> bool
def is_compatible(compatible: List[str]) -> bool
```
Returns True if the parser is compatible with the running OS platform.
@@ -75,7 +75,7 @@ Returns True if the parser is compatible with the running OS platform.
```python
def compatibility(mod_name: str,
compatible: List,
compatible: List[str],
quiet: bool = False) -> None
```
@@ -125,7 +125,7 @@ Returns:
### convert\_to\_int
```python
def convert_to_int(value: Union[str, float]) -> Optional[int]
def convert_to_int(value: object) -> Optional[int]
```
Converts string and float input to int. Strips all non-numeric
@@ -144,7 +144,7 @@ Returns:
### convert\_to\_float
```python
def convert_to_float(value: Union[str, int]) -> Optional[float]
def convert_to_float(value: object) -> Optional[float]
```
Converts string and int input to float. Strips all non-numeric
@@ -163,7 +163,7 @@ Returns:
### convert\_to\_bool
```python
def convert_to_bool(value: Union[str, int, float]) -> bool
def convert_to_bool(value: object) -> bool
```
Converts string, integer, or float input to boolean by checking
@@ -201,8 +201,8 @@ class timestamp()
### \_\_init\_\_
```python
def __init__(datetime_string: str,
format_hint: Optional[Iterable] = None) -> None
def __init__(datetime_string: Optional[str],
format_hint: Optional[Iterable[int]] = None) -> None
```
Input a datetime text string of several formats and convert to a

View File

@@ -7,12 +7,17 @@ and file-types to dictionaries and lists of dictionaries.
## Interactive Documentation
Using `jc` in your python programs:
>>> help('jc')
>>> help('jc.lib')
>>> jc.get_help('parser_module_name')
Developing `jc` parsers:
>>> help('jc.utils')
>>> help('jc.streaming')
>>> help('jc.parsers.universal')
>>> jc.get_help('parser_module_name')
## Online Documentation

View File

@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# type: ignore
# Copyright (c) 2005-2010 ActiveState Software Inc.
# Copyright (c) 2013 Eddy Petrișor

1205
jc/cli.py

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,7 @@ long_options_map: Dict[str, List[str]] = {
'--zsh-comp': ['Z', 'gen Zsh completion: jc -Z > "${fpath[1]}/_jc"']
}
new_pygments_colors = {
new_pygments_colors: Dict[str, str] = {
'black': 'ansiblack',
'red': 'ansired',
'green': 'ansigreen',
@@ -37,7 +37,7 @@ new_pygments_colors = {
'white': 'ansiwhite',
}
old_pygments_colors = {
old_pygments_colors: Dict[str, str] = {
'black': '#ansiblack',
'red': '#ansidarkred',
'green': '#ansidarkgreen',
@@ -55,3 +55,42 @@ old_pygments_colors = {
'brightcyan': '#ansiturquoise',
'white': '#ansiwhite',
}
helptext_preamble_string: str = f'''\
jc converts the output of many commands, file-types, and strings to JSON or YAML
Usage:
Standard syntax:
COMMAND | jc [OPTIONS] PARSER
cat FILE | jc [OPTIONS] PARSER
echo STRING | jc [OPTIONS] PARSER
Magic syntax:
jc [OPTIONS] COMMAND
jc [OPTIONS] /proc/<path-to-procfile>
Parsers:
'''
helptext_end_string: str = '''\
Examples:
Standard Syntax:
$ dig www.google.com | jc --pretty --dig
$ cat /proc/meminfo | jc --pretty --proc
Magic Syntax:
$ jc --pretty dig www.google.com
$ jc --pretty /proc/meminfo
Parser Documentation:
$ jc --help --dig
Show Hidden Parsers:
$ jc -hh
'''

56
jc/jc_types.py Normal file
View File

@@ -0,0 +1,56 @@
"""jc - JSON Convert lib module"""
import sys
from datetime import datetime
from typing import Dict, List, Tuple, Iterator, Optional, Union
JSONDictType = Dict[str, Union[str, int, float, bool, List, Dict, None]]
MetadataType = Dict[str, Optional[Union[str, int, float, List[str], datetime]]]
StreamingOutputType = Iterator[Union[JSONDictType, Tuple[BaseException, str]]]
if sys.version_info >= (3, 8):
from typing import TypedDict
ParserInfoType = TypedDict(
'ParserInfoType',
{
"name": str,
"argument": str,
"version": str,
"description": str,
"author": str,
"author_email": str,
"compatible": List[str],
"magic_commands": List[str],
"documentation": str,
"streaming": bool,
"plugin": bool,
"hidden": bool,
"deprecated": bool
},
total=False
)
TimeStampFormatType = TypedDict(
'TimeStampFormatType',
{
'id': int,
'format': str,
'locale': Optional[str]
}
)
else:
ParserInfoType = Dict
TimeStampFormatType = Dict
AboutJCType = Dict[str, Union[str, int, List[ParserInfoType]]]
try:
from pygments.token import (Name, Number, String, Keyword)
CustomColorType = Dict[Union[Name.Tag, Number, String, Keyword], str]
except Exception:
CustomColorType = Dict # type: ignore

260
jc/lib.py
View File

@@ -3,12 +3,15 @@ import sys
import os
import re
import importlib
from typing import Dict, List, Iterable, Union, Iterator
from typing import List, Iterable, Union, Iterator
from types import ModuleType
from .jc_types import ParserInfoType, JSONDictType
from jc import appdirs
__version__ = '1.21.0'
parsers = [
__version__ = '1.22.1'
parsers: List[str] = [
'acpi',
'airport',
'airport-s',
@@ -25,6 +28,7 @@ parsers = [
'csv',
'csv-s',
'date',
'datetime-iso',
'df',
'dig',
'dir',
@@ -66,6 +70,7 @@ parsers = [
'lsblk',
'lsmod',
'lsof',
'lspci',
'lsusb',
'm3u',
'mdadm',
@@ -76,6 +81,7 @@ parsers = [
'nmcli',
'ntpq',
'passwd',
'pci-ids',
'pidstat',
'pidstat-s',
'ping',
@@ -84,6 +90,56 @@ parsers = [
'pip-show',
'plist',
'postconf',
'proc',
'proc-buddyinfo',
'proc-consoles',
'proc-cpuinfo',
'proc-crypto',
'proc-devices',
'proc-diskstats',
'proc-filesystems',
'proc-interrupts',
'proc-iomem',
'proc-ioports',
'proc-loadavg',
'proc-locks',
'proc-meminfo',
'proc-modules',
'proc-mtrr',
'proc-pagetypeinfo',
'proc-partitions',
'proc-slabinfo',
'proc-softirqs',
'proc-stat',
'proc-swaps',
'proc-uptime',
'proc-version',
'proc-vmallocinfo',
'proc-vmstat',
'proc-zoneinfo',
'proc-driver-rtc',
'proc-net-arp',
'proc-net-dev',
'proc-net-dev-mcast',
'proc-net-if-inet6',
'proc-net-igmp',
'proc-net-igmp6',
'proc-net-ipv6-route',
'proc-net-netlink',
'proc-net-netstat',
'proc-net-packet',
'proc-net-protocols',
'proc-net-route',
'proc-net-unix',
'proc-pid-fdinfo',
'proc-pid-io',
'proc-pid-maps',
'proc-pid-mountinfo',
'proc-pid-numa-maps',
'proc-pid-smaps',
'proc-pid-stat',
'proc-pid-statm',
'proc-pid-status',
'ps',
'route',
'rpm-qi',
@@ -111,6 +167,7 @@ parsers = [
'top-s',
'tracepath',
'traceroute',
'udevadm',
'ufw',
'ufw-appinfo',
'uname',
@@ -131,19 +188,19 @@ parsers = [
'zipinfo'
]
def _cliname_to_modname(parser_cli_name):
def _cliname_to_modname(parser_cli_name: str) -> str:
"""Return real module name (dashes converted to underscores)"""
return parser_cli_name.replace('--', '').replace('-', '_')
def _modname_to_cliname(parser_mod_name):
def _modname_to_cliname(parser_mod_name: str) -> str:
"""Return module's cli name (underscores converted to dashes)"""
return parser_mod_name.replace('_', '-')
# Create the local_parsers list. This is a list of custom or
# override parsers from <user_data_dir>/jc/jcparsers/*.py.
# Once this list is created, extend the parsers list with it.
local_parsers = []
data_dir = appdirs.user_data_dir('jc', 'jc')
local_parsers: List[str] = []
data_dir = appdirs.user_data_dir('jc', 'jc') # type: ignore
local_parsers_dir = os.path.join(data_dir, 'jcparsers')
if os.path.isdir(local_parsers_dir):
sys.path.append(data_dir)
@@ -158,21 +215,20 @@ if os.path.isdir(local_parsers_dir):
except Exception:
pass
def _parser_argument(parser_mod_name):
def _parser_argument(parser_mod_name: str) -> str:
"""Return short name of the parser with dashes and with -- prefix"""
parser = _modname_to_cliname(parser_mod_name)
return f'--{parser}'
def _get_parser(parser_mod_name):
def _get_parser(parser_mod_name: str) -> ModuleType:
"""Return the parser module object"""
# ensure parser_mod_name is a true module name and not a cli name
parser_mod_name = _cliname_to_modname(parser_mod_name)
parser_cli_name = _modname_to_cliname(parser_mod_name)
modpath = 'jcparsers.' if parser_cli_name in local_parsers else 'jc.parsers.'
modpath: str = '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):
def _parser_is_streaming(parser: ModuleType) -> bool:
"""
Returns True if this is a streaming parser, else False
@@ -183,28 +239,70 @@ def _parser_is_streaming(parser):
return False
def _parser_is_hidden(parser: ModuleType) -> bool:
"""
Returns True if this is a hidden parser, else False
parser is a parser module object.
"""
if getattr(parser.info, 'hidden', None):
return True
return False
def _parser_is_deprecated(parser: ModuleType) -> bool:
"""
Returns True if this is a deprecated parser, else False
parser is a parser module object.
"""
if getattr(parser.info, 'deprecated', None):
return True
return False
def parse(
parser_mod_name: str,
parser_mod_name: Union[str, ModuleType],
data: Union[str, bytes, Iterable[str]],
quiet: bool = False,
raw: bool = False,
ignore_exceptions: bool = None,
**kwargs
) -> Union[Dict, List[Dict], Iterator[Dict]]:
) -> Union[JSONDictType, List[JSONDictType], Iterator[JSONDictType]]:
"""
Parse the string data using the supplied parser module.
Parse the data (string or bytes) using the supplied parser (string or
module object).
This function provides a high-level API to simplify parser use. This
function will call built-in parsers and custom plugin parsers.
Example:
Example (standard parsers):
>>> import jc
>>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
{'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...}
>>> date_obj = jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
>>> print(f'The year is: {date_obj["year"]}')
The year is: 2022
Example (streaming parsers):
>>> import jc
>>> ping_gen = jc.parse('ping_s', ping_output.splitlines())
>>> for item in ping_gen:
>>> print(f'Response time: {item["time_ms"]} ms')
Response time: 102 ms
Response time: 109 ms
...
To get a list of available parser module names, use `parser_mod_list()`.
Alternatively, a parser module object can be supplied:
>>> import jc
>>> import jc.parsers.date as jc_date
>>> date_obj = jc.parse(jc_date, 'Tue Jan 18 10:23:07 PST 2022')
>>> print(f'The year is: {date_obj["year"]}')
The year is: 2022
You can also use the lower-level parser modules directly:
>>> import jc.parsers.date
@@ -225,11 +323,14 @@ def parse(
Parameters:
parser_mod_name: (string) name of the parser module. This
function will accept module_name,
parser_mod_name: (string or name of the parser module. This
Module) function will accept module_name,
cli-name, and --argument-name
variants of the module name.
A Module object can also be passed
directly or via _get_parser()
data: (string or data to parse (string or bytes for
bytes or standard parsers, iterable of
iterable) strings for streaming parsers)
@@ -246,51 +347,113 @@ def parse(
Standard Parsers: Dictionary or List of Dictionaries
Streaming Parsers: Generator Object containing Dictionaries
"""
jc_parser = _get_parser(parser_mod_name)
if isinstance(parser_mod_name, ModuleType):
jc_parser = parser_mod_name
else:
jc_parser = _get_parser(parser_mod_name)
if ignore_exceptions is not None:
return jc_parser.parse(data, quiet=quiet, raw=raw,
ignore_exceptions=ignore_exceptions, **kwargs)
return jc_parser.parse(
data,
quiet=quiet,
raw=raw,
ignore_exceptions=ignore_exceptions,
**kwargs
)
return jc_parser.parse(data, quiet=quiet, raw=raw, **kwargs)
def parser_mod_list() -> List[str]:
def parser_mod_list(
show_hidden: bool = False,
show_deprecated: bool = False
) -> List[str]:
"""Returns a list of all available parser module names."""
return [_cliname_to_modname(p) for p in parsers]
plist: List[str] = []
for p in parsers:
parser = _get_parser(p)
def plugin_parser_mod_list() -> List[str]:
if not show_hidden and _parser_is_hidden(parser):
continue
if not show_deprecated and _parser_is_deprecated(parser):
continue
plist.append(_cliname_to_modname(p))
return plist
def plugin_parser_mod_list(
show_hidden: bool = False,
show_deprecated: bool = False
) -> List[str]:
"""
Returns a list of plugin parser module names. This function is a
subset of `parser_mod_list()`.
"""
return [_cliname_to_modname(p) for p in local_parsers]
plist: List[str] = []
for p in local_parsers:
parser = _get_parser(p)
def standard_parser_mod_list() -> List[str]:
if not show_hidden and _parser_is_hidden(parser):
continue
if not show_deprecated and _parser_is_deprecated(parser):
continue
plist.append(_cliname_to_modname(p))
return plist
def standard_parser_mod_list(
show_hidden: bool = False,
show_deprecated: bool = False
) -> 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 = []
plist: List[str] = []
for p in parsers:
parser = _get_parser(p)
if not _parser_is_streaming(parser):
if not show_hidden and _parser_is_hidden(parser):
continue
if not show_deprecated and _parser_is_deprecated(parser):
continue
plist.append(_cliname_to_modname(p))
return plist
def streaming_parser_mod_list() -> List[str]:
def streaming_parser_mod_list(
show_hidden: bool = False,
show_deprecated: bool = False
) -> List[str]:
"""
Returns a list of streaming parser module names. This function is a
subset of `parser_mod_list()`.
"""
plist = []
plist: List[str] = []
for p in parsers:
parser = _get_parser(p)
if _parser_is_streaming(parser):
if not show_hidden and _parser_is_hidden(parser):
continue
if not show_deprecated and _parser_is_deprecated(parser):
continue
plist.append(_cliname_to_modname(p))
return plist
def parser_info(parser_mod_name: str, documentation: bool = False) -> Dict:
def parser_info(parser_mod_name: str, documentation: bool = False) -> ParserInfoType:
"""
Returns a dictionary that includes the parser module metadata.
@@ -306,7 +469,7 @@ def parser_info(parser_mod_name: str, documentation: bool = False) -> Dict:
# ensure parser_mod_name is a true module name and not a cli name
parser_mod_name = _cliname_to_modname(parser_mod_name)
parser_mod = _get_parser(parser_mod_name)
info_dict: Dict = {}
info_dict: ParserInfoType = {}
if hasattr(parser_mod, 'info'):
info_dict['name'] = parser_mod_name
@@ -315,7 +478,7 @@ def parser_info(parser_mod_name: str, documentation: bool = False) -> Dict:
for k, v in parser_entry.items():
if not k.startswith('__'):
info_dict[k] = v
info_dict[k] = v # type: ignore
if _modname_to_cliname(parser_mod_name) in local_parsers:
info_dict['plugin'] = True
@@ -328,16 +491,39 @@ def parser_info(parser_mod_name: str, documentation: bool = False) -> Dict:
return info_dict
def all_parser_info(documentation: bool = False) -> List[Dict]:
def all_parser_info(
documentation: bool = False,
show_hidden: bool = False,
show_deprecated: bool = False
) -> List[ParserInfoType]:
"""
Returns a list of dictionaries that includes metadata for all parser
modules.
modules. By default only non-hidden, non-deprecated parsers are
returned.
Parameters:
documentation: (boolean) include parser docstrings if True
show_hidden: (boolean) also show parsers marked as hidden
in their info metadata.
show_deprecated: (boolean) also show parsers marked as
deprecated in their info metadata.
"""
return [parser_info(p, documentation=documentation) for p in parsers]
plist: List[str] = []
for p in parsers:
parser = _get_parser(p)
if not show_hidden and _parser_is_hidden(parser):
continue
if not show_deprecated and _parser_is_deprecated(parser):
continue
plist.append(_cliname_to_modname(p))
p_info_list: List[ParserInfoType] = [parser_info(p, documentation=documentation) for p in plist]
return p_info_list
def get_help(parser_mod_name: str) -> None:
"""

View File

@@ -119,7 +119,7 @@ import jc.parsers.universal
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.10'
version = '1.11'
description = '`arp` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -221,13 +221,24 @@ def parse(
else:
for line in cleandata:
splitline = line.split()
output_line = {
'name': splitline[0],
'address': splitline[1].lstrip('(').rstrip(')'),
'hwtype': splitline[4].lstrip('[').rstrip(']'),
'hwaddress': splitline[3],
'iface': splitline[6],
}
if '<incomplete>' not in splitline:
output_line = {
'name': splitline[0],
'address': splitline[1].lstrip('(').rstrip(')'),
'hwtype': splitline[4].lstrip('[').rstrip(']'),
'hwaddress': splitline[3],
'iface': splitline[6],
}
else:
output_line = {
'name': splitline[0],
'address': splitline[1].lstrip('(').rstrip(')'),
'hwtype': None,
'hwaddress': None,
'iface': splitline[5],
}
raw_output.append(output_line)
return raw_output if raw else _process(raw_output)

313
jc/parsers/datetime_iso.py Normal file
View File

@@ -0,0 +1,313 @@
"""jc - JSON Convert ISO 8601 Datetime string parser
This parser supports standard ISO 8601 strings that include both date and
time. If no timezone or offset information is available in the sring, then
UTC timezone is used.
Usage (cli):
$ echo "2022-07-20T14:52:45Z" | jc --iso-datetime
Usage (module):
import jc
result = jc.parse('iso_datetime', iso_8601_string)
Schema:
{
"year": integer,
"month": string,
"month_num": integer,
"day": integer,
"weekday": string,
"weekday_num": integer,
"hour": integer,
"hour_24": integer,
"minute": integer,
"second": integer,
"microsecond": integer,
"period": string,
"utc_offset": string,
"day_of_year": integer,
"week_of_year": integer,
"iso": string,
"timestamp": integer # [0]
}
[0] timezone aware UNIX timestamp expressed in UTC
Examples:
$ echo "2022-07-20T14:52:45Z" | jc --iso-datetime -p
{
"year": 2022,
"month": "Jul",
"month_num": 7,
"day": 20,
"weekday": "Wed",
"weekday_num": 3,
"hour": 2,
"hour_24": 14,
"minute": 52,
"second": 45,
"microsecond": 0,
"period": "PM",
"utc_offset": "+0000",
"day_of_year": 201,
"week_of_year": 29,
"iso": "2022-07-20T14:52:45+00:00",
"timestamp": 1658328765
}
"""
import datetime
import re
import typing
from decimal import Decimal
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = 'ISO 8601 Datetime string parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
details = 'Using the pyiso8601 library from https://github.com/micktwomey/pyiso8601/releases/tag/1.0.2'
compatible = ['linux', 'aix', 'freebsd', 'darwin', 'win32', 'cygwin']
__version__ = info.version
####################################################
"""
pyiso8601 library from https://github.com/micktwomey/pyiso8601/releases/tag/1.0.2
"""
"""
Copyright (c) 2007 - 2022 Michael Twomey
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
"""ISO 8601 date time string parsing
Basic usage:
>>> import iso8601
>>> iso8601._parse_date("2007-01-25T12:00:00Z")
datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.Utc ...>)
>>>
"""
# __all__ = ["_parse_date", "_ParseError", "UTC", "_FixedOffset"]
# Adapted from http://delete.me.uk/2005/03/iso8601.html
ISO8601_REGEX = re.compile(
r"""
(?P<year>[0-9]{4})
(
(
(-(?P<monthdash>[0-9]{1,2}))
|
(?P<month>[0-9]{2})
(?!$) # Don't allow YYYYMM
)
(
(
(-(?P<daydash>[0-9]{1,2}))
|
(?P<day>[0-9]{2})
)
(
(
(?P<separator>[ T])
(?P<hour>[0-9]{2})
(:{0,1}(?P<minute>[0-9]{2})){0,1}
(
:{0,1}(?P<second>[0-9]{1,2})
([.,](?P<second_fraction>[0-9]+)){0,1}
){0,1}
(?P<timezone>
Z
|
(
(?P<tz_sign>[-+])
(?P<tz_hour>[0-9]{2})
:{0,1}
(?P<tz_minute>[0-9]{2}){0,1}
)
){0,1}
){0,1}
)
){0,1} # YYYY-MM
){0,1} # YYYY only
$
""",
re.VERBOSE,
)
class _ParseError(ValueError):
"""Raised when there is a problem parsing a date string"""
UTC = datetime.timezone.utc
def _FixedOffset(
offset_hours: float, offset_minutes: float, name: str
) -> datetime.timezone:
return datetime.timezone(
datetime.timedelta(hours=offset_hours, minutes=offset_minutes), name
)
def _parse_timezone(
matches: typing.Dict[str, str],
default_timezone: typing.Optional[datetime.timezone] = UTC,
) -> typing.Optional[datetime.timezone]:
"""Parses ISO 8601 time zone specs into tzinfo offsets"""
tz = matches.get("timezone", None)
if tz == "Z":
return UTC
# This isn't strictly correct, but it's common to encounter dates without
# timezones so I'll assume the default (which defaults to UTC).
# Addresses issue 4.
if tz is None:
return default_timezone
sign = matches.get("tz_sign", None)
hours = int(matches.get("tz_hour", 0))
minutes = int(matches.get("tz_minute", 0))
description = f"{sign}{hours:02d}:{minutes:02d}"
if sign == "-":
hours = -hours
minutes = -minutes
return _FixedOffset(hours, minutes, description)
def _parse_date(
datestring: str, default_timezone: typing.Optional[datetime.timezone] = UTC
) -> datetime.datetime:
"""Parses ISO 8601 dates into datetime objects
The timezone is parsed from the date string. However it is quite common to
have dates without a timezone (not strictly correct). In this case the
default timezone specified in default_timezone is used. This is UTC by
default.
:param datestring: The date to parse as a string
:param default_timezone: A datetime tzinfo instance to use when no timezone
is specified in the datestring. If this is set to
None then a naive datetime object is returned.
:returns: A datetime.datetime instance
:raises: _ParseError when there is a problem parsing the date or
constructing the datetime instance.
"""
try:
m = ISO8601_REGEX.match(datestring)
except Exception as e:
raise _ParseError(e)
if not m:
raise _ParseError(f"Unable to parse date string {datestring!r}")
# Drop any Nones from the regex matches
# TODO: check if there's a way to omit results in regexes
groups: typing.Dict[str, str] = {
k: v for k, v in m.groupdict().items() if v is not None
}
try:
return datetime.datetime(
year=int(groups.get("year", 0)),
month=int(groups.get("month", groups.get("monthdash", 1))),
day=int(groups.get("day", groups.get("daydash", 1))),
hour=int(groups.get("hour", 0)),
minute=int(groups.get("minute", 0)),
second=int(groups.get("second", 0)),
microsecond=int(
Decimal(f"0.{groups.get('second_fraction', 0)}") * Decimal("1000000.0")
),
tzinfo=_parse_timezone(groups, default_timezone=default_timezone),
)
except Exception as e:
raise _ParseError(e)
####################################################
def _process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary. Structured data to conform to the schema.
"""
# no further processing
return proc_data
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:
Dictionary. Raw or processed structured data.
"""
jc.utils.compatibility(__name__, info.compatible, quiet)
jc.utils.input_type_check(data)
raw_output = {}
if jc.utils.has_data(data):
dt = _parse_date(data)
raw_output = {
'year': dt.year,
'month': dt.strftime('%b'),
'month_num': dt.month,
'day': dt.day,
'weekday': dt.strftime('%a'),
'weekday_num': dt.isoweekday(),
'hour': int(dt.strftime('%I')),
'hour_24': dt.hour,
'minute': dt.minute,
'second': dt.second,
'microsecond': dt.microsecond,
'period': dt.strftime('%p').upper(),
'utc_offset': dt.strftime('%z') or None,
'day_of_year': int(dt.strftime('%j')),
'week_of_year': int(dt.strftime('%W')),
'iso': dt.isoformat(),
'timestamp': int(dt.timestamp())
}
return raw_output if raw else _process(raw_output)

View File

@@ -34,6 +34,7 @@ Examples:
[]
"""
from typing import List, Dict
from jc.jc_types import JSONDictType
import jc.utils
@@ -53,7 +54,7 @@ class info():
__version__ = info.version
def _process(proc_data: List[Dict]) -> List[Dict]:
def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]:
"""
Final processing to conform to the schema.
@@ -78,7 +79,7 @@ def parse(
data: str,
raw: bool = False,
quiet: bool = False
) -> List[Dict]:
) -> List[JSONDictType]:
"""
Main text parsing function
@@ -95,7 +96,7 @@ def parse(
jc.utils.compatibility(__name__, info.compatible, quiet)
jc.utils.input_type_check(data)
raw_output: List = []
raw_output: List[Dict] = []
if jc.utils.has_data(data):

View File

@@ -40,11 +40,12 @@ Examples:
{example output}
...
"""
from typing import Dict, Iterable, Union
from typing import Dict, Iterable
import jc.utils
from jc.streaming import (
add_jc_meta, streaming_input_type_check, streaming_line_input_type_check, raise_or_yield
)
from jc.jc_types import JSONDictType, StreamingOutputType
from jc.exceptions import ParseError
@@ -63,7 +64,7 @@ class info():
__version__ = info.version
def _process(proc_data: Dict) -> Dict:
def _process(proc_data: JSONDictType) -> JSONDictType:
"""
Final processing to conform to the schema.
@@ -90,7 +91,7 @@ def parse(
raw: bool = False,
quiet: bool = False,
ignore_exceptions: bool = False
) -> Union[Iterable[Dict], tuple]:
) -> StreamingOutputType:
"""
Main text parsing generator function. Returns an iterable object.

View File

@@ -73,7 +73,7 @@ import jc.parsers.universal
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.6'
version = '1.7'
description = '`free` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -96,7 +96,7 @@ def _process(proc_data):
List of Dictionaries. Structured data to conform to the schema.
"""
int_list = {'total', 'used', 'free', 'shared', 'buff_cache', 'available'}
int_list = {'total', 'used', 'free', 'shared', 'buff_cache', 'buffers', 'cache', 'available'}
for entry in proc_data:
for key in entry:

View File

@@ -100,12 +100,13 @@ Examples:
}
}
"""
import re
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.5'
version = '1.6'
description = '`id` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -170,28 +171,28 @@ def parse(data, raw=False, quiet=False):
raw_output = {}
# Clear any blank lines
cleandata = list(filter(None, data.split()))
# re.split produces first element empty
cleandata = re.split(r' ?(uid|gid|groups|context)=', data.strip())[1:]
if jc.utils.has_data(data):
for section in cleandata:
if section.startswith('uid'):
uid_parsed = section.replace('(', '=').replace(')', '=')
for key, value in zip(cleandata[0::2], cleandata[1::2]):
if key == 'uid':
uid_parsed = value.replace('(', '=').replace(')', '=')
uid_parsed = uid_parsed.split('=')
raw_output['uid'] = {}
raw_output['uid']['id'] = uid_parsed[1]
raw_output['uid']['name'] = _get_item(uid_parsed, 2)
raw_output['uid']['id'] = uid_parsed[0]
raw_output['uid']['name'] = _get_item(uid_parsed, 1)
if section.startswith('gid'):
gid_parsed = section.replace('(', '=').replace(')', '=')
if key == 'gid':
gid_parsed = value.replace('(', '=').replace(')', '=')
gid_parsed = gid_parsed.split('=')
raw_output['gid'] = {}
raw_output['gid']['id'] = gid_parsed[1]
raw_output['gid']['name'] = _get_item(gid_parsed, 2)
raw_output['gid']['id'] = gid_parsed[0]
raw_output['gid']['name'] = _get_item(gid_parsed, 1)
if section.startswith('groups'):
groups_parsed = section.replace('(', '=').replace(')', '=')
if key == 'groups':
groups_parsed = value.replace('(', '=').replace(')', '=')
groups_parsed = groups_parsed.replace('groups=', '')
groups_parsed = groups_parsed.split(',')
raw_output['groups'] = []
@@ -203,9 +204,8 @@ def parse(data, raw=False, quiet=False):
group_dict['name'] = _get_item(grp_parsed, 1)
raw_output['groups'].append(group_dict)
if section.startswith('context'):
context_parsed = section.replace('context=', '')
context_parsed = context_parsed.split(':', maxsplit=3)
if key == 'context':
context_parsed = value.split(':', maxsplit=3)
raw_output['context'] = {}
raw_output['context']['user'] = context_parsed[0]
raw_output['context']['role'] = context_parsed[1]

View File

@@ -49,18 +49,18 @@ Examples:
$ cat example.ini | jc --ini -p
{
"bitbucket.org": {
"serveraliveinterval": "45",
"compression": "yes",
"compressionlevel": "9",
"forwardx11": "yes",
"user": "hg"
"ServerAliveInterval": "45",
"Compression": "yes",
"CompressionLevel": "9",
"ForwardX11": "yes",
"User": "hg"
},
"topsecret.server.com": {
"serveraliveinterval": "45",
"compression": "yes",
"compressionlevel": "9",
"forwardx11": "no",
"port": "50022"
"ServerAliveInterval": "45",
"Compression": "yes",
"CompressionLevel": "9",
"ForwardX11": "no",
"Port": "50022"
}
}
"""
@@ -70,7 +70,7 @@ import configparser
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.7'
version = '1.8'
description = 'INI file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -145,6 +145,10 @@ def parse(data, raw=False, quiet=False):
ini = configparser.ConfigParser(allow_no_value=True,
interpolation=None,
strict=False)
# don't convert keys to lower-case:
ini.optionxform = lambda option: option
try:
ini.read_string(data)
raw_output = {s: dict(ini.items(s)) for s in ini.sections()}

View File

@@ -21,6 +21,9 @@ Schema:
"ip": string,
"ip_compressed": string,
"ip_exploded": string,
"ip_split": [
string
],
"scope_id": string/null,
"ipv4_mapped": string/null,
"six_to_four": string/null,
@@ -78,6 +81,12 @@ Examples:
"ip": "192.168.2.10",
"ip_compressed": "192.168.2.10",
"ip_exploded": "192.168.2.10",
"ip_split": [
"192",
"168",
"2",
"10"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
@@ -133,6 +142,12 @@ Examples:
"ip": "192.168.2.10",
"ip_compressed": "192.168.2.10",
"ip_exploded": "192.168.2.10",
"ip_split": [
"192",
"168",
"2",
"10"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
@@ -186,14 +201,24 @@ Examples:
"version": 6,
"max_prefix_length": 128,
"ip": "127:0:de::1",
"ip_compressed": "127:0:de::1%128",
"ip_compressed": "127:0:de::1",
"ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001",
"ip_split": [
"0127",
"0000",
"00de",
"0000",
"0000",
"0000",
"0000",
"0001"
],
"scope_id": "128",
"ipv4_mapped": null,
"six_to_four": null,
"teredo_client": null,
"teredo_server": null,
"dns_ptr": "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.....0.7.2.1.0.ip6.arpa",
"dns_ptr": "1.0.0.0.0.0...0.0.0.e.d.0.0.0.0.0.0.7.2.1.0.ip6.arpa",
"network": "127:0:de::",
"broadcast": "127:0:de::ffff:ffff",
"hostmask": "::ffff:ffff",
@@ -226,13 +251,13 @@ Examples:
"last_host": "01:27:00:00:00:de:00:00:00:00:00:00:ff:ff:ff:fe"
},
"bin": {
"ip": "000000010010011100000000000000000000000011011110000000...",
"network": "0000000100100111000000000000000000000000110111100...",
"broadcast": "00000001001001110000000000000000000000001101111...",
"hostmask": "000000000000000000000000000000000000000000000000...",
"netmask": "1111111111111111111111111111111111111111111111111...",
"first_host": "0000000100100111000000000000000000000000110111...",
"last_host": "00000001001001110000000000000000000000001101111..."
"ip": "0000000100100111000000000000000000000000110...000000000001",
"network": "00000001001001110000000000000000000000...000000000000",
"broadcast": "000000010010011100000000000000000000...111111111111",
"hostmask": "0000000000000000000000000000000000000...111111111111",
"netmask": "11111111111111111111111111111111111111...000000000000",
"first_host": "00000001001001110000000000000000000...000000000001",
"last_host": "000000010010011100000000000000000000...1111111111110"
}
}
@@ -243,12 +268,22 @@ Examples:
"ip": "127:0:de::1",
"ip_compressed": "127:0:de::1",
"ip_exploded": "0127:0000:00de:0000:0000:0000:0000:0001",
"ip_split": [
"0127",
"0000",
"00de",
"0000",
"0000",
"0000",
"0000",
"0001"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
"teredo_client": null,
"teredo_server": null,
"dns_ptr": "1.0.0.0.0.0.0....0.0.0.e.d.0.0.0.0.0.0.7.2.1.0.ip6.arpa",
"dns_ptr": "1.0.0.0.0.0....0.0.0.0.e.d.0.0.0.0.0.0.7.2.1.0.ip6.arpa",
"network": "127:0:de::1",
"broadcast": "127:0:de::1",
"hostmask": "::",
@@ -281,13 +316,13 @@ Examples:
"last_host": "01:27:00:00:00:de:00:00:00:00:00:00:00:00:00:01"
},
"bin": {
"ip": "0000000100100111000000000000000000000000110111100000000...",
"network": "00000001001001110000000000000000000000001101111000...",
"broadcast": "000000010010011100000000000000000000000011011110...",
"hostmask": "0000000000000000000000000000000000000000000000000...",
"netmask": "11111111111111111111111111111111111111111111111111...",
"first_host": "00000001001001110000000000000000000000001101111...",
"last_host": "000000010010011100000000000000000000000011011110..."
"ip": "0000000100100111000000000000000000000000110111100...000001",
"network": "00000001001001110000000000000000000000001101...000001",
"broadcast": "000000010010011100000000000000000000000011...000001",
"hostmask": "0000000000000000000000000000000000000000000...000000",
"netmask": "11111111111111111111111111111111111111111111...111111",
"first_host": "00000001001001110000000000000000000000001...000001",
"last_host": "000000010010011100000000000000000000000011...0000001"
}
}
@@ -299,12 +334,22 @@ Examples:
"ip": "::ffff:c0a8:123",
"ip_compressed": "::ffff:c0a8:123",
"ip_exploded": "0000:0000:0000:0000:0000:ffff:c0a8:0123",
"ip_split": [
"0000",
"0000",
"0000",
"0000",
"0000",
"ffff",
"c0a8",
"0123"
],
"scope_id": null,
"ipv4_mapped": "192.168.1.35",
"six_to_four": null,
"teredo_client": null,
"teredo_server": null,
"dns_ptr": "3.2.1.0.8.a.0.c.f.f.f.f.0.0.0....0.0.0.0.0.0.0.ip6.arpa",
"dns_ptr": "3.2.1.0.8.a.0.c.f.f.f.f.0.0....0.0.0.0.0.0.ip6.arpa",
"network": "::ffff:c0a8:123",
"broadcast": "::ffff:c0a8:123",
"hostmask": "::",
@@ -337,13 +382,13 @@ Examples:
"last_host": "00:00:00:00:00:00:00:00:00:00:ff:ff:c0:a8:01:23"
},
"bin": {
"ip": "0000000000000000000000000000000000000000000000000000000...",
"network": "00000000000000000000000000000000000000000000000000...",
"broadcast": "000000000000000000000000000000000000000000000000...",
"hostmask": "0000000000000000000000000000000000000000000000000...",
"netmask": "11111111111111111111111111111111111111111111111111...",
"first_host": "00000000000000000000000000000000000000000000000...",
"last_host": "000000000000000000000000000000000000000000000000..."
"ip": "000000000000000000000000000000000000000000000...100100011",
"network": "0000000000000000000000000000000000000000...000100011",
"broadcast": "00000000000000000000000000000000000000...000100011",
"hostmask": "000000000000000000000000000000000000000...000000000",
"netmask": "1111111111111111111111111111111111111111...111111111",
"first_host": "0000000000000000000000000000000000000...100100011",
"last_host": "00000000000000000000000000000000000000...0100100011"
}
}
@@ -355,12 +400,22 @@ Examples:
"ip": "2002:c000:204::",
"ip_compressed": "2002:c000:204::",
"ip_exploded": "2002:c000:0204:0000:0000:0000:0000:0000",
"ip_split": [
"2002",
"c000",
"0204",
"0000",
"0000",
"0000",
"0000",
"0000"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": "192.0.2.4",
"teredo_client": null,
"teredo_server": null,
"dns_ptr": "0.0.0.0.0.0.0.0......0.4.0.2.0.0.0.0.c.2.0.0.2.ip6.arpa",
"dns_ptr": "0.0.0.0.0.0.0...0.0.0.4.0.2.0.0.0.0.c.2.0.0.2.ip6.arpa",
"network": "2002:c000:204::",
"broadcast": "2002:c000:204:ffff:ffff:ffff:ffff:ffff",
"hostmask": "::ffff:ffff:ffff:ffff:ffff",
@@ -393,13 +448,13 @@ Examples:
"last_host": "20:02:c0:00:02:04:ff:ff:ff:ff:ff:ff:ff:ff:ff:fe"
},
"bin": {
"ip": "0010000000000010110000000000000000000010000001000000000...",
"network": "00100000000000101100000000000000000000100000010000...",
"broadcast": "001000000000001011000000000000000000001000000100...",
"hostmask": "0000000000000000000000000000000000000000000000001...",
"netmask": "11111111111111111111111111111111111111111111111100...",
"first_host": "00100000000000101100000000000000000000100000010...",
"last_host": "001000000000001011000000000000000000001000000100..."
"ip": "00100000000000101100000000000000000000100000010...00000000",
"network": "001000000000001011000000000000000000001000...00000000",
"broadcast": "0010000000000010110000000000000000000010...11111111",
"hostmask": "00000000000000000000000000000000000000000...11111111",
"netmask": "111111111111111111111111111111111111111111...00000000",
"first_host": "001000000000001011000000000000000000001...00000001",
"last_host": "0010000000000010110000000000000000000010...111111110"
}
}
@@ -411,12 +466,22 @@ Examples:
"ip": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
"ip_compressed": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
"ip_exploded": "2001:0000:4136:e378:8000:63bf:3fff:fdd2",
"ip_split": [
"2001",
"0000",
"4136",
"e378",
"8000",
"63bf",
"3fff",
"fdd2"
],
"scope_id": null,
"ipv4_mapped": null,
"six_to_four": null,
"teredo_client": "192.0.2.45",
"teredo_server": "65.54.227.120",
"dns_ptr": "2.d.d.f.f.f.f.3.f.b.3.6.0.0.0....0.0.0.1.0.0.2.ip6.arpa",
"dns_ptr": "2.d.d.f.f.f.f.3.f.b.3.6.0.0.0.8.8....0.1.0.0.2.ip6.arpa",
"network": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
"broadcast": "2001:0:4136:e378:8000:63bf:3fff:fdd2",
"hostmask": "::",
@@ -449,13 +514,13 @@ Examples:
"last_host": "20:01:00:00:41:36:e3:78:80:00:63:bf:3f:ff:fd:d2"
},
"bin": {
"ip": "001000000000000100000000000000000100000100110110111000...",
"network": "0010000000000001000000000000000001000001001101101...",
"broadcast": "00100000000000010000000000000000010000010011011...",
"hostmask": "000000000000000000000000000000000000000000000000...",
"netmask": "1111111111111111111111111111111111111111111111111...",
"first_host": "0010000000000001000000000000000001000001001101...",
"last_host": "00100000000000010000000000000000010000010011011..."
"ip": "0010000000000001000000000000000001000001001...110111010010",
"network": "00100000000000010000000000000000010000...110111010010",
"broadcast": "001000000000000100000000000000000100...110111010010",
"hostmask": "0000000000000000000000000000000000000...000000000000",
"netmask": "11111111111111111111111111111111111111...111111111111",
"first_host": "00100000000000010000000000000000010...110111010010",
"last_host": "001000000000000100000000000000000100...110111010010"
}
}
"""
@@ -468,7 +533,7 @@ import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
version = '1.3'
description = 'IPv4 and IPv6 Address string parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -565,15 +630,38 @@ def parse(
broadcast_string = str(network.broadcast_address)
broadcast_ipobj = ipaddress.ip_address(broadcast_string)
hostmask_string = str(interface.with_hostmask).split('/')[1]
# older versions of python (e.g. 3.6) don't provide hostmask when a decimal IP is entered
try:
hostmask_string = str(interface.hostmask)
except AttributeError:
if interface.version == 4:
hostmask_string = '0.0.0.0'
if interface.version == 6:
hostmask_string = '::'
hostmask_ipobj = ipaddress.ip_address(hostmask_string)
netmask_string = str(interface.with_netmask).split('/')[1]
# older versions of python (e.g. 3.6) don't provide netmask when a decimal IP is entered
try:
netmask_string = str(interface.netmask)
except AttributeError:
if interface.version == 4:
netmask_string = '255.255.255.255'
if interface.version == 6:
netmask_string = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
netmask_ipobj = ipaddress.ip_address(netmask_string)
bare_ip_string = str(interface.ip)
bare_ip = ipaddress.ip_address(bare_ip_string)
ip_ptr = bare_ip.reverse_pointer
ip_compressed = bare_ip.compressed
ip_exploded = bare_ip.exploded
if interface.version == 4:
ip_split = ip_exploded.split('.')
else:
ip_split = ip_exploded.split(':')
# fix for ipv6-only attributes
scope_id = None
@@ -622,8 +710,9 @@ def parse(
'version': interface.version,
'max_prefix_length': interface.max_prefixlen,
'ip': bare_ip_string,
'ip_compressed': bare_ip.compressed,
'ip_exploded': bare_ip.exploded,
'ip_compressed': ip_compressed,
'ip_exploded': ip_exploded,
'ip_split': ip_split,
'scope_id': scope_id,
'ipv4_mapped': ipv4_mapped,
'six_to_four': sixtofour,

View File

@@ -1,275 +1,32 @@
"""jc - JSON Convert ISO 8601 Datetime string parser
This parser supports standard ISO 8601 strings that include both date and
time. If no timezone or offset information is available in the sring, then
UTC timezone is used.
This parser has been renamed to datetime-iso (cli) or datetime_iso (module).
Usage (cli):
$ echo "2022-07-20T14:52:45Z" | jc --iso-datetime
Usage (module):
import jc
result = jc.parse('iso_datetime', iso_8601_string)
Schema:
{
"year": integer,
"month": string,
"month_num": integer,
"day": integer,
"weekday": string,
"weekday_num": integer,
"hour": integer,
"hour_24": integer,
"minute": integer,
"second": integer,
"microsecond": integer,
"period": string,
"utc_offset": string,
"day_of_year": integer,
"week_of_year": integer,
"iso": string,
"timestamp": integer # [0]
}
[0] timezone aware UNIX timestamp expressed in UTC
Examples:
$ echo "2022-07-20T14:52:45Z" | jc --iso-datetime -p
{
"year": 2022,
"month": "Jul",
"month_num": 7,
"day": 20,
"weekday": "Wed",
"weekday_num": 3,
"hour": 2,
"hour_24": 14,
"minute": 52,
"second": 45,
"microsecond": 0,
"period": "PM",
"utc_offset": "+0000",
"day_of_year": 201,
"week_of_year": 29,
"iso": "2022-07-20T14:52:45+00:00",
"timestamp": 1658328765
}
This parser will be removed in a future version, so please start using
the new parser name.
"""
import datetime
import re
import typing
from decimal import Decimal
from jc.parsers import datetime_iso
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = 'ISO 8601 Datetime string parser'
version = '1.1'
description = 'Deprecated - please use datetime-iso'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
details = 'Using the pyiso8601 library from https://github.com/micktwomey/pyiso8601/releases/tag/1.0.2'
details = 'Deprecated - please use datetime-iso'
compatible = ['linux', 'aix', 'freebsd', 'darwin', 'win32', 'cygwin']
deprecated = True
__version__ = info.version
####################################################
"""
pyiso8601 library from https://github.com/micktwomey/pyiso8601/releases/tag/1.0.2
"""
"""
Copyright (c) 2007 - 2022 Michael Twomey
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
"""ISO 8601 date time string parsing
Basic usage:
>>> import iso8601
>>> iso8601._parse_date("2007-01-25T12:00:00Z")
datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.Utc ...>)
>>>
"""
# __all__ = ["_parse_date", "_ParseError", "UTC", "_FixedOffset"]
# Adapted from http://delete.me.uk/2005/03/iso8601.html
ISO8601_REGEX = re.compile(
r"""
(?P<year>[0-9]{4})
(
(
(-(?P<monthdash>[0-9]{1,2}))
|
(?P<month>[0-9]{2})
(?!$) # Don't allow YYYYMM
)
(
(
(-(?P<daydash>[0-9]{1,2}))
|
(?P<day>[0-9]{2})
)
(
(
(?P<separator>[ T])
(?P<hour>[0-9]{2})
(:{0,1}(?P<minute>[0-9]{2})){0,1}
(
:{0,1}(?P<second>[0-9]{1,2})
([.,](?P<second_fraction>[0-9]+)){0,1}
){0,1}
(?P<timezone>
Z
|
(
(?P<tz_sign>[-+])
(?P<tz_hour>[0-9]{2})
:{0,1}
(?P<tz_minute>[0-9]{2}){0,1}
)
){0,1}
){0,1}
)
){0,1} # YYYY-MM
){0,1} # YYYY only
$
""",
re.VERBOSE,
)
class _ParseError(ValueError):
"""Raised when there is a problem parsing a date string"""
UTC = datetime.timezone.utc
def _FixedOffset(
offset_hours: float, offset_minutes: float, name: str
) -> datetime.timezone:
return datetime.timezone(
datetime.timedelta(hours=offset_hours, minutes=offset_minutes), name
)
def _parse_timezone(
matches: typing.Dict[str, str],
default_timezone: typing.Optional[datetime.timezone] = UTC,
) -> typing.Optional[datetime.timezone]:
"""Parses ISO 8601 time zone specs into tzinfo offsets"""
tz = matches.get("timezone", None)
if tz == "Z":
return UTC
# This isn't strictly correct, but it's common to encounter dates without
# timezones so I'll assume the default (which defaults to UTC).
# Addresses issue 4.
if tz is None:
return default_timezone
sign = matches.get("tz_sign", None)
hours = int(matches.get("tz_hour", 0))
minutes = int(matches.get("tz_minute", 0))
description = f"{sign}{hours:02d}:{minutes:02d}"
if sign == "-":
hours = -hours
minutes = -minutes
return _FixedOffset(hours, minutes, description)
def _parse_date(
datestring: str, default_timezone: typing.Optional[datetime.timezone] = UTC
) -> datetime.datetime:
"""Parses ISO 8601 dates into datetime objects
The timezone is parsed from the date string. However it is quite common to
have dates without a timezone (not strictly correct). In this case the
default timezone specified in default_timezone is used. This is UTC by
default.
:param datestring: The date to parse as a string
:param default_timezone: A datetime tzinfo instance to use when no timezone
is specified in the datestring. If this is set to
None then a naive datetime object is returned.
:returns: A datetime.datetime instance
:raises: _ParseError when there is a problem parsing the date or
constructing the datetime instance.
"""
try:
m = ISO8601_REGEX.match(datestring)
except Exception as e:
raise _ParseError(e)
if not m:
raise _ParseError(f"Unable to parse date string {datestring!r}")
# Drop any Nones from the regex matches
# TODO: check if there's a way to omit results in regexes
groups: typing.Dict[str, str] = {
k: v for k, v in m.groupdict().items() if v is not None
}
try:
return datetime.datetime(
year=int(groups.get("year", 0)),
month=int(groups.get("month", groups.get("monthdash", 1))),
day=int(groups.get("day", groups.get("daydash", 1))),
hour=int(groups.get("hour", 0)),
minute=int(groups.get("minute", 0)),
second=int(groups.get("second", 0)),
microsecond=int(
Decimal(f"0.{groups.get('second_fraction', 0)}") * Decimal("1000000.0")
),
tzinfo=_parse_timezone(groups, default_timezone=default_timezone),
)
except Exception as e:
raise _ParseError(e)
####################################################
def _process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary. Structured data to conform to the schema.
"""
# no further processing
return proc_data
def parse(data, raw=False, quiet=False):
"""
Main text parsing function
This parser is deprecated and calls datetime_iso. Please use datetime_iso
directly. This parser will be removed in the future.
Parameters:
@@ -281,33 +38,8 @@ def parse(data, raw=False, quiet=False):
Dictionary. Raw or processed structured data.
"""
jc.utils.compatibility(__name__, info.compatible, quiet)
jc.utils.input_type_check(data)
jc.utils.warning_message([
'iso-datetime parser is deprecated. Please use datetime-iso instead.'
])
raw_output = {}
if jc.utils.has_data(data):
dt = _parse_date(data)
raw_output = {
'year': dt.year,
'month': dt.strftime('%b'),
'month_num': dt.month,
'day': dt.day,
'weekday': dt.strftime('%a'),
'weekday_num': dt.isoweekday(),
'hour': int(dt.strftime('%I')),
'hour_24': dt.hour,
'minute': dt.minute,
'second': dt.second,
'microsecond': dt.microsecond,
'period': dt.strftime('%p').upper(),
'utc_offset': dt.strftime('%z') or None,
'day_of_year': int(dt.strftime('%j')),
'week_of_year': int(dt.strftime('%W')),
'iso': dt.isoformat(),
'timestamp': int(dt.timestamp())
}
return raw_output if raw else _process(raw_output)
return datetime_iso.parse(data, raw=raw, quiet=quiet)

View File

@@ -124,7 +124,7 @@ class info():
description = '`lsof` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
compatible = ['linux', 'darwin', 'aix', 'freebsd']
magic_commands = ['lsof']

241
jc/parsers/lspci.py Normal file
View File

@@ -0,0 +1,241 @@
"""jc - JSON Convert `lspci -mmv` command output parser
This parser supports the following `lspci` options:
- `-mmv`
- `-nmmv`
- `-nnmmv`
Usage (cli):
$ lspci -nnmmv | jc --lspci
or
$ jc lspci -nnmmv
Usage (module):
import jc
result = jc.parse('lspci', lspci_command_output)
Schema:
[
{
"slot": string,
"domain": string,
"domain_int": integer,
"bus": string,
"bus_int": integer,
"dev": string,
"dev_int": integer,
"function": string,
"function_int": integer,
"class": string,
"class_id": string,
"class_id_int": integer,
"vendor": string,
"vendor_id": string,
"vendor_id_int": integer,
"device": string,
"device_id": string,
"device_id_int": integer,
"svendor": string,
"svendor_id": string,
"svendor_id_int": integer,
"sdevice": string,
"sdevice_id": string,
"sdevice_id_int": integer,
"rev": string,
"physlot": string,
"physlot_int": integer,
"progif": string,
"progif_int": integer
}
]
Examples:
$ lspci -nnmmv | jc --lspci -p
[
{
"slot": "ff:02:05.0",
"domain": "ff",
"domain_int": 255,
"bus": "02",
"bus_int": 2,
"dev": "05",
"dev_int": 5,
"function": "0",
"function_int": 0,
"class": "SATA controller",
"class_id": "0106",
"class_id_int": 262,
"vendor": "VMware",
"vendor_id": "15ad",
"vendor_id_int": 5549,
"device": "SATA AHCI controller",
"device_id": "07e0",
"device_id_int": 2016,
"svendor": "VMware",
"svendor_id": "15ad",
"svendor_id_int": 5549,
"sdevice": "SATA AHCI controller",
"sdevice_id": "07e0",
"sdevice_id_int": 2016,
"physlot": "37",
"physlot_int": 55,
"progif": "01",
"progif_int": 1
},
...
]
$ lspci -nnmmv | jc --lspci -p -r
[
{
"slot": "ff:02:05.0",
"domain": "ff",
"bus": "02",
"dev": "05",
"function": "0",
"class": "SATA controller",
"class_id": "0106",
"vendor": "VMware",
"vendor_id": "15ad",
"device": "SATA AHCI controller",
"device_id": "07e0",
"svendor": "VMware",
"svendor_id": "15ad",
"sdevice": "SATA AHCI controller",
"sdevice_id": "07e0",
"physlot": "37",
"progif": "01"
},
...
]
"""
import re
from typing import List, Dict
from jc.jc_types import JSONDictType
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = '`lspci -mmv` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
magic_commands = ['lspci']
__version__ = info.version
def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]:
"""
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.
"""
int_list: set[str] = {
'domain', 'bus', 'dev', 'function', 'class_id', 'vendor_id', 'device_id',
'svendor_id', 'sdevice_id', 'physlot', 'progif'
}
new_list: List[JSONDictType] = []
for item in proc_data:
output: Dict = {}
for key, val in item.items():
output[key] = val
if key in int_list:
output[key + '_int'] = int(val, 16) # type: ignore
new_list.append(output)
return new_list
def parse(
data: str,
raw: bool = False,
quiet: bool = False
) -> List[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:
List of Dictionaries. Raw or processed structured data.
"""
jc.utils.compatibility(__name__, info.compatible, quiet)
jc.utils.input_type_check(data)
raw_output: List = []
device_output: Dict = {}
if jc.utils.has_data(data):
item_id_p = re.compile(r'(?P<id>^[0-9a-f]{4}$)')
item_id_bracket_p = re.compile(r' \[(?P<id>[0-9a-f]{4})\]$')
for line in filter(None, data.splitlines()):
if line.startswith('Slot:'):
if device_output:
raw_output.append(device_output)
device_output = {}
device_output['slot'] = line.split()[1]
slot_info = line.split()[1]
*domain, bus, dev_fun = slot_info.split(':')
if domain:
dom = domain[0]
else:
dom = "00"
dev, fun = dev_fun.split('.')
device_output['domain'] = dom
device_output['bus'] = bus
device_output['dev'] = dev
device_output['function'] = fun
continue
key, val = line.split(maxsplit=1)
key = key[:-1].lower()
# numeric only (-nmmv)
if item_id_p.match(val):
device_output[key + '_id'] = val
continue
# string and numeric (-nnmmv)
if item_id_bracket_p.search(val):
string, idnum = val.rsplit(maxsplit=1)
device_output[key] = string
device_output[key + '_id'] = idnum[1:-1]
continue
# string only (-mmv)
device_output[key] = val
continue
if device_output:
raw_output.append(device_output)
return raw_output if raw else _process(raw_output)

231
jc/parsers/pci_ids.py Normal file
View File

@@ -0,0 +1,231 @@
"""jc - JSON Convert `pci.ids` file parser
This parser converts the pci.ids database file.
https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids
A nested schema allows straightforward queries with tools like `jq`. Hex id
numbers are prefixed with an underscore (`_`) so bracket notation is not
necessary when referencing. For example:
$ cat pci.ids | jc --pci-ids | jq '.vendors._9005._0053._9005._ffff.subsystem_name'
"AIC-7896 SCSI Controller mainboard implementation"
Here are the vendor and class mappings:
jq '.vendors._001c._0001._001c._0005.subsystem_name'
| | | |
| | | subdevice
| | subvendor
| device
vendor
jq '.classes._0c._03._40'
| | |
| | prog_if
| subclass
class
Usage (cli):
$ cat pci.ids | jc --pci-ids
Usage (module):
import jc
result = jc.parse('pci_ids', pci_ids_file_output)
Schema:
{
"vendors": {
"_<vendor_id>": {
"vendor_name": string,
"_<device_id>": {
"device_name": string,
"_<subvendor_id>": {
"_<subdevice_id": string
}
}
}
},
"classes": {
"_<class_id>": {
"class_name": string,
"_<subclass_id>": {
"subclass_name": string,
"_<prog_if>": string
}
}
}
}
Examples:
$ cat pci.ids | jc --pci-ids | jq '.vendors._001c._0001._001c._0005.subsystem_name'
"2 Channel CAN Bus SJC1000 (Optically Isolated)"
$ cat pci.ids | jc --pci-ids | jq '.classes._0c._03._40'
"USB4 Host Interface"
"""
import re
from typing import Dict
from jc.jc_types import JSONDictType
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = '`pci.ids` file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd']
__version__ = info.version
def _process(proc_data: JSONDictType) -> JSONDictType:
"""
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
Dictionary. Structured to conform to the schema.
"""
return proc_data
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.
"""
jc.utils.compatibility(__name__, info.compatible, quiet)
jc.utils.input_type_check(data)
raw_output: Dict = {}
vdc_obj: Dict = {}
vendor_id: str = ''
device_id: str = ''
class_obj: Dict = {}
class_id: str = ''
subclass_id: str = ''
if jc.utils.has_data(data):
vdc_header_p = re.compile(r'^(?P<vendor_id>[0-9a-f]{4})\s+(?P<vendor_name>.+)')
vdc_device_p = re.compile(r'^\t(?P<device_id>[0-9a-f]{4})\s+(?P<device_name>.+)')
vdc_subvendor_p = re.compile(r'^\t\t(?P<subvendor>[0-9a-f]{4})\s+(?P<subdevice>[0-9a-f]{4})\s+(?P<subsystem_name>.+)')
class_header_p = re.compile(r'^C\s+(?P<class_id>[0-9a-f]{2})\s+(?P<class_name>.+)')
class_sub_p = re.compile(r'^\t(?P<subclass_id>[0-9a-f]{2})\s+(?P<subclass_name>.+)')
class_progif_p = re.compile(r'^\t\t(?P<prog_if_id>[0-9a-f]{2})\s+(?P<prog_if_name>.+)')
for line in filter(None, data.splitlines()):
vdc_header = vdc_header_p.match(line)
vdc_device = vdc_device_p.match(line)
vdc_subvendor = vdc_subvendor_p.match(line)
class_header = class_header_p.match(line)
class_sub = class_sub_p.match(line)
class_progif = class_progif_p.match(line)
# Vendors, devices and subsystems
# Syntax:
# vendor vendor_name
# device device_name <-- single tab
# subvendor subdevice subsystem_name <-- two tabs
# Example:
# 001c PEAK-System Technik GmbH
# 0001 PCAN-PCI CAN-Bus controller
# 001c 0004 2 Channel CAN Bus SJC1000
if vdc_header:
if vdc_obj:
if 'vendors' not in raw_output:
raw_output['vendors'] = {}
raw_output['vendors'][vendor_id] = vdc_obj[vendor_id]
vdc_obj = {}
vendor_id = '_' + vdc_header.groupdict()['vendor_id']
vdc_obj[vendor_id] = {}
vdc_obj[vendor_id]['vendor_name'] = vdc_header.groupdict()['vendor_name']
continue
if vdc_device:
device_id = '_' + vdc_device.groupdict()['device_id']
vdc_obj[vendor_id][device_id] = {}
vdc_obj[vendor_id][device_id]['device_name'] = vdc_device.groupdict()['device_name']
continue
if vdc_subvendor:
subvendor = '_' + vdc_subvendor.groupdict()['subvendor']
subdevice = '_' + vdc_subvendor.groupdict()['subdevice']
vdc_obj[vendor_id][device_id][subvendor] = {}
vdc_obj[vendor_id][device_id][subvendor][subdevice] = {}
vdc_obj[vendor_id][device_id][subvendor][subdevice]['subsystem_name'] = vdc_subvendor.groupdict()['subsystem_name']
continue
# List of known device classes, subclasses and programming interfaces
# Syntax:
# C class class_name
# subclass subclass_name <-- single tab
# prog-if prog-if_name <-- two tabs
# Example:
# C 01 Mass storage controller
# 01 IDE interface
# 00 ISA Compatibility mode-only controller
if class_header:
if class_obj:
if 'classes' not in raw_output:
raw_output['classes'] = {}
raw_output['classes'][class_id] = class_obj[class_id]
class_obj = {}
class_id = '_' + class_header.groupdict()['class_id']
class_obj[class_id] = {}
class_obj[class_id]['class_name'] = class_header.groupdict()['class_name']
continue
if class_sub:
subclass_id = '_' + class_sub.groupdict()['subclass_id']
class_obj[class_id][subclass_id] = {}
class_obj[class_id][subclass_id]['subclass_name'] = class_sub.groupdict()['subclass_name']
continue
if class_progif:
prog_if_id = '_' + class_progif.groupdict()['prog_if_id']
class_obj[class_id][subclass_id][prog_if_id] = class_progif.groupdict()['prog_if_name']
continue
if vdc_obj:
if 'vendors' not in raw_output:
raw_output['vendors'] = {}
raw_output['vendors'][vendor_id] = vdc_obj[vendor_id]
if class_obj:
if 'classes' not in raw_output:
raw_output['classes'] = {}
raw_output['classes'][class_id] = class_obj[class_id]
return raw_output if raw else _process(raw_output)

View File

@@ -1,15 +1,15 @@
"""jc - JSON Convert `pidstat -h` command output parser
"""jc - JSON Convert `pidstat -H` command output parser
Must use the `-h` option in `pidstat`. All other `pidstat` options are
supported in combination with `-h`.
Must use the `-H` (or `-h`, if `-H` is not available) option in `pidstat`.
All other `pidstat` options are supported in combination with this option.
Usage (cli):
$ pidstat -h | jc --pidstat
$ pidstat -H | jc --pidstat
or
$ jc pidstat -h
$ jc pidstat -H
Usage (module):
@@ -46,7 +46,7 @@ Schema:
Examples:
$ pidstat -hl | jc --pidstat -p
$ pidstat -Hl | jc --pidstat -p
[
{
"time": 1646859134,
@@ -83,7 +83,7 @@ Examples:
}
]
$ pidstat -hl | jc --pidstat -p -r
$ pidstat -Hl | jc --pidstat -p -r
[
{
"time": "1646859134",
@@ -129,7 +129,7 @@ from jc.exceptions import ParseError
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.1'
description = '`pidstat -h` command parser'
description = '`pidstat -H` command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
@@ -210,7 +210,7 @@ def parse(
.replace('%', 'percent_')\
.lower()
# remove remaining header lines (e.g. pidstat -h 2 5)
# remove remaining header lines (e.g. pidstat -H 2 5)
data_list = [i for i in data_list if not i.startswith('#')]
raw_output = simple_table_parse(data_list)

View File

@@ -1,14 +1,14 @@
"""jc - JSON Convert `pidstat -h` command output streaming parser
"""jc - JSON Convert `pidstat -H` command output streaming parser
> This streaming parser outputs JSON Lines (cli) or returns an Iterable of
> Dictionaries (module)
Must use the `-h` option in `pidstat`. All other `pidstat` options are
supported in combination with `-h`.
Must use the `-H` (or `-h`, if `-H` is not available) option in `pidstat`.
All other `pidstat` options are supported in combination with this option.
Usage (cli):
$ pidstat | jc --pidstat-s
$ pidstat -H | jc --pidstat-s
> Note: When piping `jc` converted `pidstat` output to other processes it
> may appear the output is hanging due to the OS pipe buffers. This is
@@ -60,13 +60,13 @@ Schema:
Examples:
$ pidstat -hl | jc --pidstat-s
$ pidstat -Hl | jc --pidstat-s
{"time":1646859134,"uid":0,"pid":1,"percent_usr":0.0,"percent_syste...}
{"time":1646859134,"uid":0,"pid":6,"percent_usr":0.0,"percent_syste...}
{"time":1646859134,"uid":0,"pid":9,"percent_usr":0.0,"percent_syste...}
...
$ pidstat -hl | jc --pidstat-s -r
$ pidstat -Hl | jc --pidstat-s -r
{"time":"1646859134","uid":"0","pid":"1","percent_usr":"0.00","perc...}
{"time":"1646859134","uid":"0","pid":"6","percent_usr":"0.00","perc...}
{"time":"1646859134","uid":"0","pid":"9","percent_usr":"0.00","perc...}
@@ -84,7 +84,7 @@ from jc.exceptions import ParseError
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.1'
description = '`pidstat -h` command streaming parser'
description = '`pidstat -H` command streaming parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']

277
jc/parsers/proc.py Normal file
View File

@@ -0,0 +1,277 @@
"""jc - JSON Convert Proc file output parser
This parser automatically identifies the Proc file and calls the
corresponding parser to peform the parsing.
Magic syntax for converting `/proc` files is also supported by running
`jc /proc/<path to file>`. Any `jc` options must be specified before the
`/proc` path.
specific Proc file parsers can also be called directly, if desired and have
a naming convention of `proc-<name>` (cli) or `proc_<name>` (module).
Usage (cli):
$ cat /proc/meminfo | jc --proc
or
$ jc /proc/meminfo
or
$ cat /proc/meminfo | jc --proc-memifno
Usage (module):
import jc
result = jc.parse('proc', proc_file)
Schema:
See the specific Proc parser for the schema:
$ jc --help --proc-<name>
For example:
$ jc --help --proc-meminfo
Specific Proc file parser names can be found with `jc -hh` or `jc -a`.
Schemas can also be found online at:
https://kellyjonbrazil.github.io/jc/docs/parsers/proc_<name>
For example:
https://kellyjonbrazil.github.io/jc/docs/parsers/proc_meminfo
Examples:
$ cat /proc/modules | jc --proc -p
[
{
"module": "binfmt_misc",
"size": 24576,
"used": 1,
"used_by": [],
"status": "Live",
"location": "0xffffffffc0ab4000"
},
{
"module": "vsock_loopback",
"size": 16384,
"used": 0,
"used_by": [],
"status": "Live",
"location": "0xffffffffc0a14000"
},
{
"module": "vmw_vsock_virtio_transport_common",
"size": 36864,
"used": 1,
"used_by": [
"vsock_loopback"
],
"status": "Live",
"location": "0xffffffffc0a03000"
},
...
]
$ proc_modules | jc --proc_modules -p -r
[
{
"module": "binfmt_misc",
"size": "24576",
"used": "1",
"used_by": [],
"status": "Live",
"location": "0xffffffffc0ab4000"
},
{
"module": "vsock_loopback",
"size": "16384",
"used": "0",
"used_by": [],
"status": "Live",
"location": "0xffffffffc0a14000"
},
{
"module": "vmw_vsock_virtio_transport_common",
"size": "36864",
"used": "1",
"used_by": [
"vsock_loopback"
],
"status": "Live",
"location": "0xffffffffc0a03000"
},
...
]
"""
import re
import importlib
from typing import List, Dict
import jc.utils
from jc.exceptions import ParseError
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = '`/proc/` file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
__version__ = info.version
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.input_type_check(data)
if jc.utils.has_data(data):
# signatures
buddyinfo_p = re.compile(r'^Node \d+, zone\s+\w+\s+(?:\d+\s+){11}\n')
consoles_p = re.compile(r'^\w+\s+[\-WUR]{3} \([ECBpba ]+\)\s+\d+:\d+\n')
cpuinfo_p = re.compile(r'^processor\t+: \d+.*bogomips\t+: \d+.\d\d\n', re.DOTALL)
crypto_p = re.compile(r'^name\s+:.*\ndriver\s+:.*\nmodule\s+:.*\n')
devices_p = re.compile(r'^Character devices:\n\s+\d+ .*\n')
diskstats_p = re.compile(r'^\s*\d+\s+\d\s\w+\s(?:\d+\s){10,16}\d+\n')
filesystems_p = re.compile(r'^(?:(?:nodev\t|\t)\w+\n){3}')
interrupts_p = re.compile(r'^\s+(?:CPU\d+ +)+\n\s*\d+:\s+\d+')
iomem_p = re.compile(r'^00000000-[0-9a-f]{8} : .*\n[0-9a-f]{8}-[0-9a-f]{8} : ')
ioports_p = re.compile(r'^0000-[0-9a-f]{4} : .*\n\s*0000-[0-9a-f]{4} : ')
loadavg_p = re.compile(r'^\d+.\d\d \d+.\d\d \d+.\d\d \d+/\d+ \d+$')
locks_p = re.compile(r'^\d+: (?:POSIX|FLOCK|OFDLCK)\s+(?:ADVISORY|MANDATORY)\s+(?:READ|WRITE) ')
meminfo_p = re.compile(r'^MemTotal:.*\nMemFree:.*\nMemAvailable:.*\n')
modules_p = re.compile(r'^\w+ \d+ \d+ (?:-|\w+,).*0x[0-9a-f]{16}\n')
mtrr_p = re.compile(r'^reg\d+: base=0x[0-9a-f]+ \(')
pagetypeinfo_p = re.compile(r'^Page block order:\s+\d+\nPages per block:\s+\d+\n\n')
partitions_p = re.compile(r'^major minor #blocks name\n\n\s*\d+\s+\d+\s+\d+ \w+\n')
slabinfo_p = re.compile(r'^slabinfo - version: \d+.\d+\n')
softirqs_p = re.compile(r'^\s+(CPU\d+\s+)+\n\s+HI:\s+\d')
stat_p = re.compile(r'^cpu\s+(?: \d+){7,10}.*intr ', re.DOTALL)
swaps_p = re.compile(r'^Filename\t\t\t\tType\t\tSize\t\tUsed\t\tPriority\n')
uptime_p = re.compile(r'^\d+.\d\d \d+.\d\d$')
version_p = re.compile(r'^.+\sversion\s[^\n]+$')
vmallocinfo_p = re.compile(r'^0x[0-9a-f]{16}-0x[0-9a-f]{16}\s+\d+ \w+\+\w+/\w+ ')
vmstat_p = re.compile(r'nr_free_pages \d+\n.* \d$', re.DOTALL)
zoneinfo_p = re.compile(r'^Node \d+, zone\s+\w+\n')
driver_rtc_p = re.compile(r'^rtc_time\t: .*\nrtc_date\t: .*\nalrm_time\t: .*\n')
net_arp_p = re.compile(r'^IP address\s+HW type\s+Flags\s+HW address\s+Mask\s+Device\n')
net_dev_p = re.compile(r'^Inter-\|\s+Receive\s+\|\s+Transmit\n')
net_dev_mcast_p = re.compile(r'^\d+\s+\w+\s+\d+\s+\d+\s+[0-9a-f]{12}')
net_if_inet6_p = re.compile(r'^[0-9a-f]{32} \d\d \d\d \d\d \d\d\s+\w+')
net_igmp_p = re.compile(r'^Idx\tDevice\s+:\s+Count\s+Querier\tGroup\s+Users\s+Timer\tReporter\n')
net_igmp6_p = re.compile(r'^\d+\s+\w+\s+[0-9a-f]{32}\s+\d+\s+[0-9A-F]{8}\s+\d+')
net_ipv6_route_p = re.compile(r'^[0-9a-f]{32} \d\d [0-9a-f]{32} \d\d [0-9a-f]{32} (?:[0-9a-f]{8} ){4}\s+\w+')
net_netlink_p = re.compile(r'^sk\s+Eth Pid\s+Groups\s+Rmem\s+Wmem')
net_netstat_p = re.compile(r'^TcpExt: SyncookiesSent SyncookiesRecv SyncookiesFailed')
net_packet_p = re.compile(r'^sk RefCnt Type Proto Iface R Rmem User Inode\n')
net_protocols_p = re.compile(r'^protocol size sockets memory press maxhdr slab module cl co di ac io in de sh ss gs se re sp bi br ha uh gp em\n')
net_route_p = re.compile(r'^Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU\tWindow\tIRTT\s+\n')
net_unix_p = re.compile(r'^Num RefCount Protocol Flags Type St Inode Path\n')
pid_fdinfo_p = re.compile(r'^pos:\t\d+\nflags:\t\d+\nmnt_id:\t\d+\n')
pid_io_p = re.compile(r'^rchar: \d+\nwchar: \d+\nsyscr: \d+\n')
pid_maps_p = re.compile(r'^[0-9a-f]{12}-[0-9a-f]{12} [rwxsp\-]{4} [0-9a-f]{8} [0-9a-f]{2}:[0-9a-f]{2} \d+ ')
pid_mountinfo_p = re.compile(r'^\d+ \d+ \d+:\d+ /.+\n')
pid_numa_maps_p = re.compile(r'^[a-f0-9]{12} default [^\n]+\n')
pid_smaps_p = re.compile(r'^[0-9a-f]{12}-[0-9a-f]{12} [rwxsp\-]{4} [0-9a-f]{8} [0-9a-f]{2}:[0-9a-f]{2} \d+ [^\n]+\nSize:\s+\d+ \S\S\n')
pid_stat_p = re.compile(r'^\d+ \(.{1,15}\) \S \d+ \d+ \d+ \d+ -?\d+ (?:\d+ ){43}\d+$', re.DOTALL)
pid_statm_p = re.compile(r'^\d+ \d+ \d+\s\d+\s\d+\s\d+\s\d+$')
pid_status_p = re.compile(r'^Name:\t.+\nUmask:\t\d+\nState:\t.+\nTgid:\t\d+\n')
# scsi_device_info = re.compile(r"^'\w+' '.+' 0x\d+")
# scsi_scsi_p = re.compile(r'^Attached devices:\nHost: \w+ ')
procmap = {
buddyinfo_p: 'proc_buddyinfo',
consoles_p: 'proc_consoles',
cpuinfo_p: 'proc_cpuinfo',
crypto_p: 'proc_crypto',
devices_p: 'proc_devices',
diskstats_p: 'proc_diskstats',
filesystems_p: 'proc_filesystems',
interrupts_p: 'proc_interrupts',
iomem_p: 'proc_iomem',
ioports_p: 'proc_ioports',
loadavg_p: 'proc_loadavg',
locks_p: 'proc_locks',
meminfo_p: 'proc_meminfo',
modules_p: 'proc_modules',
mtrr_p: 'proc_mtrr',
pagetypeinfo_p: 'proc_pagetypeinfo',
partitions_p: 'proc_partitions',
slabinfo_p: 'proc_slabinfo',
softirqs_p: 'proc_softirqs',
stat_p: 'proc_stat',
swaps_p: 'proc_swaps',
uptime_p: 'proc_uptime',
version_p: 'proc_version',
vmallocinfo_p: 'proc_vmallocinfo',
zoneinfo_p: 'proc_zoneinfo', # before vmstat
vmstat_p: 'proc_vmstat', # after zoneinfo
driver_rtc_p: 'proc_driver_rtc',
net_arp_p: 'proc_net_arp',
net_dev_p: 'proc_net_dev',
net_if_inet6_p: 'proc_net_if_inet6',
net_igmp_p: 'proc_net_igmp',
net_igmp6_p: 'proc_net_igmp6',
net_netlink_p: 'proc_net_netlink',
net_netstat_p: 'proc_net_netstat',
net_packet_p: 'proc_net_packet',
net_protocols_p: 'proc_net_protocols',
net_route_p: 'proc_net_route',
net_unix_p: 'proc_net_unix',
net_ipv6_route_p: 'proc_net_ipv6_route', # before net_dev_mcast
net_dev_mcast_p: 'proc_net_dev_mcast', # after net_ipv6_route
pid_fdinfo_p: 'proc_pid_fdinfo',
pid_io_p: 'proc_pid_io',
pid_mountinfo_p: 'proc_pid_mountinfo',
pid_numa_maps_p: 'proc_pid_numa_maps',
pid_stat_p: 'proc_pid_stat',
pid_statm_p: 'proc_pid_statm',
pid_status_p: 'proc_pid_status',
pid_smaps_p: 'proc_pid_smaps', # before pid_maps
pid_maps_p: 'proc_pid_maps', # after pid_smaps
# scsi_device_info: 'proc_scsi_device_info',
# scsi_scsi_p: 'proc_scsi_scsi'
}
for reg_pattern, parse_mod in procmap.items():
if reg_pattern.search(data):
try:
procparser = importlib.import_module('jc.parsers.' + parse_mod)
return procparser.parse(data, quiet=quiet, raw=raw)
except ModuleNotFoundError:
raise ParseError('Proc file type not yet implemented.')
raise ParseError('Proc file could not be identified.')

View File

@@ -0,0 +1,179 @@
"""jc - JSON Convert `/proc/buddyinfo` file parser
Usage (cli):
$ cat /proc/buddyinfo | jc --proc
or
$ jc /proc/buddyinfo
or
$ cat /proc/buddyinfo | jc --proc-buddyinfo
Usage (module):
import jc
result = jc.parse('proc', proc_buddyinfo_file)
or
import jc
result = jc.parse('proc_buddyinfo', proc_buddyinfo_file)
Schema:
All values are integers.
[
{
"node": integer,
"zone": string,
"free_chunks": [
integer # [0]
]
}
]
[0] array index correlates to the Order number.
E.g. free_chunks[0] is the value for Order 0
Examples:
$ cat /proc/buddyinfo | jc --proc -p
[
{
"node": 0,
"zone": "DMA",
"free_chunks": [
0,
0,
0,
1,
1,
1,
1,
1,
0,
1,
3
]
},
{
"node": 0,
"zone": "DMA32",
"free_chunks": [
78,
114,
82,
52,
38,
25,
13,
9,
3,
4,
629
]
},
{
"node": 0,
"zone": "Normal",
"free_chunks": [
0,
22,
8,
10,
1,
1,
2,
11,
13,
0,
0
]
}
]
"""
from typing import List, Dict
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = '`/proc/buddyinfo` file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
hidden = True
__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.
"""
int_list = {'node'}
for entry in proc_data:
for key in entry:
if key in int_list:
entry[key] = jc.utils.convert_to_int(entry[key])
if 'free_chunks' in entry:
entry['free_chunks'] = [int(x) for x in entry['free_chunks']]
return proc_data
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):
for line in filter(None, data.splitlines()):
buddy_list = line.split()
raw_output.append(
{
'node': buddy_list[1][:-1],
'zone': buddy_list[3],
'free_chunks': buddy_list[4:]
}
)
return raw_output if raw else _process(raw_output)

188
jc/parsers/proc_consoles.py Normal file
View File

@@ -0,0 +1,188 @@
"""jc - JSON Convert `/proc/consoles` file parser
Usage (cli):
$ cat /proc/consoles | jc --proc
or
$ jc /proc/consoles
or
$ cat /proc/consoles | jc --proc-consoles
Usage (module):
import jc
result = jc.parse('proc', proc_consoles_file)
or
import jc
result = jc.parse('proc_consoles', proc_consoles_file)
Schema:
[
{
"device": string,
"operations": string,
"operations_list": [
string # [0]
],
"flags": string,
"flags_list": [
string # [1]
],
"major": integer,
"minor": integer
}
]
[0] Values: read, write, unblank
[1] Values: enabled, preferred, primary boot, prink buffer,
braille device, safe when CPU offline
Examples:
$ cat /proc/consoles | jc --proc -p
[
{
"device": "tty0",
"operations": "-WU",
"operations_list": [
"write",
"unblank"
],
"flags": "ECp",
"flags_list": [
"enabled",
"preferred",
"printk buffer"
],
"major": 4,
"minor": 7
},
{
"device": "ttyS0",
"operations": "-W-",
"operations_list": [
"write"
],
"flags": "Ep",
"flags_list": [
"enabled",
"printk buffer"
],
"major": 4,
"minor": 64
}
]
"""
import shlex
from typing import List, Dict
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = '`/proc/consoles` file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
hidden = True
__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.
"""
int_list = {'major', 'minor'}
for entry in proc_data:
for key in entry:
if key in int_list:
entry[key] = jc.utils.convert_to_int(entry[key])
return proc_data
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 = []
operations_map = {
'R': 'read',
'W': 'write',
'U': 'unblank'
}
flags_map = {
'E': 'enabled',
'C': 'preferred',
'B': 'primary boot',
'p': 'printk buffer',
'b': 'braille device',
'a': 'safe when CPU offline'
}
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
# since parens are acting like quotation marks, use shlex.split()
# after converting parens to quotes.
line = line.replace('(', '"'). replace(')', '"')
device, operations, flags, maj_min = shlex.split(line)
operations_str = operations.replace('-', '')
operations_list = [operations_map[i] for i in operations_str]
flags_str = flags.replace (' ', '')
flags_list = [flags_map[i] for i in flags_str]
raw_output.append(
{
'device': device,
'operations': operations,
'operations_list': operations_list,
'flags': flags,
'flags_list': flags_list,
'major': maj_min.split(':')[0],
'minor': maj_min.split(':')[1]
}
)
return raw_output if raw else _process(raw_output)

329
jc/parsers/proc_cpuinfo.py Normal file
View File

@@ -0,0 +1,329 @@
"""jc - JSON Convert `/proc/cpuinfo` file parser
Usage (cli):
$ cat /proc/cpuinfo | jc --proc
or
$ jc /proc/cpuinfo
or
$ cat /proc/cpuinfo | jc --proc-cpuinfo
Usage (module):
import jc
result = jc.parse('proc', proc_cpuinfo_file)
or
import jc
result = jc.parse('proc_cpuinfo', proc_cpuinfo_file)
Schema:
Integer, float, and boolean ("yes"/"no") conversions are attempted. Blank
strings are converted to `null`.
"Well-known" keys like `cache size`, `address types`, `bugs`, and `flags`
are processed into sensible data types. (see below)
If this is not desired, then use the `--raw` (CLI) or `raw=True` (Module)
option.
[
{
"processor": integer,
"address sizes": string,
"address_size_physical": integer, # in bits
"address_size_virtual": integer, # in bits
"cache size": string,
"cache_size_num": integer,
"cache_size_unit": string,
"flags": [
string
],
"bugs": [
string
],
"bogomips": float,
<key>: string/int/float/boolean/null
}
]
Examples:
$ cat /proc/cpuinfo | jc --proc -p
[
{
"processor": 0,
"vendor_id": "GenuineIntel",
"cpu family": 6,
"model": 142,
"model name": "Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz",
"stepping": 10,
"cpu MHz": 2400.0,
"cache size": "6144 KB",
"physical id": 0,
"siblings": 1,
"core id": 0,
"cpu cores": 1,
"apicid": 0,
"initial apicid": 0,
"fpu": true,
"fpu_exception": true,
"cpuid level": 22,
"wp": true,
"bogomips": 4800.0,
"clflush size": 64,
"cache_alignment": 64,
"address sizes": "45 bits physical, 48 bits virtual",
"power management": null,
"address_size_physical": 45,
"address_size_virtual": 48,
"cache_size_num": 6144,
"cache_size_unit": "KB",
"flags": [
"fpu",
"vme",
"de",
"pse",
"tsc",
"msr",
"pae",
"mce",
"cx8",
"apic",
"sep",
"mtrr",
"pge",
"mca",
"cmov",
"pat",
"pse36",
"clflush",
"mmx",
"fxsr",
"sse",
"sse2",
"ss",
"syscall",
"nx",
"pdpe1gb",
"rdtscp",
"lm",
"constant_tsc",
"arch_perfmon",
"nopl",
"xtopology",
"tsc_reliable",
"nonstop_tsc",
"cpuid",
"pni",
"pclmulqdq",
"ssse3",
"fma",
"cx16",
"pcid",
"sse4_1",
"sse4_2",
"x2apic",
"movbe",
"popcnt",
"tsc_deadline_timer",
"aes",
"xsave",
"avx",
"f16c",
"rdrand",
"hypervisor",
"lahf_lm",
"abm",
"3dnowprefetch",
"cpuid_fault",
"invpcid_single",
"pti",
"ssbd",
"ibrs",
"ibpb",
"stibp",
"fsgsbase",
"tsc_adjust",
"bmi1",
"avx2",
"smep",
"bmi2",
"invpcid",
"rdseed",
"adx",
"smap",
"clflushopt",
"xsaveopt",
"xsavec",
"xgetbv1",
"xsaves",
"arat",
"md_clear",
"flush_l1d",
"arch_capabilities"
],
"bugs": [
"cpu_meltdown",
"spectre_v1",
"spectre_v2",
"spec_store_bypass",
"l1tf",
"mds",
"swapgs",
"itlb_multihit",
"srbds"
]
},
...
]
$ cat /proc/cpuinfo | jc --proc_cpuinfo -p -r
[
{
"processor": "0",
"vendor_id": "GenuineIntel",
"cpu family": "6",
"model": "142",
"model name": "Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz",
"stepping": "10",
"cpu MHz": "2400.000",
"cache size": "6144 KB",
"physical id": "0",
"siblings": "1",
"core id": "0",
"cpu cores": "1",
"apicid": "0",
"initial apicid": "0",
"fpu": "yes",
"fpu_exception": "yes",
"cpuid level": "22",
"wp": "yes",
"flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge ...",
"bugs": "cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass ...",
"bogomips": "4800.00",
"clflush size": "64",
"cache_alignment": "64",
"address sizes": "45 bits physical, 48 bits virtual",
"power management": ""
},
...
]
"""
from typing import List, Dict
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = '`/proc/cpuinfo` file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
hidden = True
__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:
if entry[key] == '':
entry[key] = None
try:
entry[key] = int(entry[key])
except Exception:
pass
try:
if isinstance(entry[key], str) and (entry[key] == 'yes' or entry[key] == 'no'):
entry[key] = jc.utils.convert_to_bool(entry[key])
except Exception:
pass
try:
if isinstance(entry[key], str) and '.' in entry[key]:
entry[key] = float(entry[key])
except Exception:
pass
if 'address sizes' in entry:
phy = int(entry['address sizes'].split()[0])
virt = int(entry['address sizes'].split()[3])
entry['address_size_physical'] = phy
entry['address_size_virtual'] = virt
if 'cache size' in entry:
cache_size_int, unit = entry['cache size'].split()
entry['cache_size_num'] = int(cache_size_int)
entry['cache_size_unit'] = unit
if 'flags' in entry:
entry['flags'] = entry['flags'].split()
if 'bugs' in entry:
entry['bugs'] = entry['bugs'].split()
return proc_data
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 = []
output_line: Dict = {}
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
if line.startswith('processor'):
if output_line:
raw_output.append(output_line)
output_line = {}
key, val = line.split(':', maxsplit=1)
output_line[key.strip()] = val.strip()
if output_line:
raw_output.append(output_line)
return raw_output if raw else _process(raw_output)

196
jc/parsers/proc_crypto.py Normal file
View File

@@ -0,0 +1,196 @@
"""jc - JSON Convert `/proc/crypto` file parser
Usage (cli):
$ cat /proc/crypto | jc --proc
or
$ jc /proc/crypto
or
$ cat /proc/crypto | jc --proc-crypto
Usage (module):
import jc
result = jc.parse('proc', proc_crypto_file)
or
import jc
result = jc.parse('proc_crypto', proc_crypto_file)
Schema:
"Well-known" keys like `priority` and `refcnt` are converted to integers.
Also, keynames ending in "size" are converted to integers.
If this is not desired, then use the `--raw` (CLI) or `raw=True` (Module)
option.
[
{
"name": string,
"driver": string,
"module": string,
"priority": integer,
"refcnt": integer,
"selftest": string,
"internal": string,
"type": string,
"*size": integer
}
]
Examples:
$ cat /proc/crypto | jc --proc -p
[
{
"name": "ecdh",
"driver": "ecdh-generic",
"module": "ecdh_generic",
"priority": 100,
"refcnt": 1,
"selftest": "passed",
"internal": "no",
"type": "kpp"
},
{
"name": "blake2b-512",
"driver": "blake2b-512-generic",
"module": "blake2b_generic",
"priority": 100,
"refcnt": 1,
"selftest": "passed",
"internal": "no",
"type": "shash",
"blocksize": 128,
"digestsize": 64
},
...
]
$ cat /proc/crypto | jc --proc_crypto -p -r
[
{
"name": "ecdh",
"driver": "ecdh-generic",
"module": "ecdh_generic",
"priority": "100",
"refcnt": "1",
"selftest": "passed",
"internal": "no",
"type": "kpp"
},
{
"name": "blake2b-512",
"driver": "blake2b-512-generic",
"module": "blake2b_generic",
"priority": "100",
"refcnt": "1",
"selftest": "passed",
"internal": "no",
"type": "shash",
"blocksize": "128",
"digestsize": "64"
},
{
"name": "blake2b-384",
"driver": "blake2b-384-generic",
"module": "blake2b_generic",
"priority": "100",
"refcnt": "1",
"selftest": "passed",
"internal": "no",
"type": "shash",
"blocksize": "128",
"digestsize": "48"
},
...
]
"""
from typing import List, Dict
import jc.utils
class info():
"""Provides parser metadata (version, author, etc.)"""
version = '1.0'
description = '`/proc/crypto` file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
compatible = ['linux']
hidden = True
__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.
"""
int_list = {'priority', 'refcnt'}
for entry in proc_data:
for key in entry:
if key in int_list or key.endswith('size'):
try:
entry[key] = int(entry[key])
except Exception:
pass
return proc_data
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 = []
output_line: Dict = {}
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
if line.startswith('name'):
if output_line:
raw_output.append(output_line)
output_line = {}
key, val = line.split(':', maxsplit=1)
output_line[key.strip()] = val.strip()
if output_line:
raw_output.append(output_line)
return raw_output if raw else _process(raw_output)

Some files were not shown because too many files have changed in this diff Show More