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

Compare commits

...

290 Commits

Author SHA1 Message Date
Kelly Brazil
1e18dd30a8 Merge pull request #102 from kellyjonbrazil/dev
Dev v1.14.4
2021-03-05 11:50:37 -08:00
Kelly Brazil
cc6a19adcc fix typo in comments 2021-03-05 09:41:17 -08:00
Kelly Brazil
2a5588b177 packaging fix for yaml parser and pyoxidizer 2021-03-05 09:38:22 -08:00
Kelly Brazil
20f9b7f88b fix typo 2021-02-25 11:09:56 -08:00
Kelly Brazil
d7e32313cd fix typo 2021-02-25 11:09:14 -08:00
Kelly Brazil
fb5654d3c4 formatting 2021-02-11 11:27:54 -08:00
Kelly Brazil
258f1433b3 add locale info to readme 2021-02-11 11:27:01 -08:00
Kelly Brazil
fb723ae8bd Merge pull request #101 from kellyjonbrazil/dev
Dev v1.14.3
2021-02-10 11:01:57 -08:00
Kelly Brazil
283b89e37c simplify answer data logic 2021-02-10 10:55:53 -08:00
Kelly Brazil
f450f9eb8b add hciconfig tests 2021-02-10 10:47:56 -08:00
Kelly Brazil
b3f8cf99a4 work for both tabs and spaces 2021-02-10 08:03:36 -08:00
Kelly Brazil
4301ea8cae remove debug line 2021-02-09 16:12:36 -08:00
Kelly Brazil
c672d1c174 initial working hciconfig parser 2021-02-09 16:03:00 -08:00
Kelly Brazil
229e953a38 initial add of hciconfig parser 2021-02-09 13:26:24 -08:00
Kelly Brazil
87b506dc9b fix for spaces in dig answer data 2021-02-05 06:55:06 -08:00
Kelly Brazil
15c9002d9e simplify logic by taking out 'not' in JC_COLORS parsing 2021-01-08 11:56:56 -08:00
Kelly Brazil
042aaa61b9 minor updates 2021-01-08 08:23:29 -08:00
Kelly Brazil
ef856c6ba5 clarify -q option 2021-01-07 12:09:41 -08:00
Kelly Brazil
9cf5be73e3 typo fix 2021-01-06 16:19:47 -08:00
Kelly Brazil
63fc149e2a typo fix 2021-01-06 16:17:25 -08:00
Kelly Brazil
3c25839350 Merge pull request #98 from kellyjonbrazil/dev
Dev v1.14.1
2021-01-06 14:37:24 -08:00
Kelly Brazil
58246e33b7 update compatibility info and changelog date 2021-01-06 14:33:38 -08:00
Kelly Brazil
8b1407c706 pull env-specific tests from CI/CD and run locally only 2021-01-06 14:22:26 -08:00
Kelly Brazil
2fde4a4e22 doc updates 2021-01-06 12:07:58 -08:00
Kelly Brazil
60b9e97982 last parser enhancements: augment hostname with CONSOLE for GUI login, add convenience fields when -F is used: login_epoch, logout_epoch, duration_seconds, calculate duration to hours:minutes 2021-01-06 12:02:47 -08:00
Kelly Brazil
0adac79c0f Add last parser enhancements 2021-01-06 11:09:59 -08:00
Kelly Brazil
9f485b5981 change mac_address fieldname to bssid. Add credit to Phillip 2021-01-06 11:09:37 -08:00
Kelly Brazil
db17d21b8f Merge pull request #97 from pschmitt/iw_scan_fix_space_detection
iw_scan: Improve detection of lines starting with spaces
2021-01-06 10:42:30 -08:00
Philipp Schmitt
996d394e89 iw_scan: Improve detection of lines starting with spaces 2021-01-06 10:32:17 +01:00
Kelly Brazil
5885b960f9 doc updates 2021-01-05 22:12:13 -08:00
Kelly Brazil
79987b35f3 formatting 2021-01-05 22:07:22 -08:00
Kelly Brazil
661b3ef311 doc updates 2021-01-05 22:04:44 -08:00
Kelly Brazil
fb422726a8 update test to add 'down' condition 2021-01-05 21:55:06 -08:00
Kelly Brazil
4fb6f3ea59 add support for down in addition to crash 2021-01-05 21:51:30 -08:00
Kelly Brazil
f78fe771e1 add iw-scan tests 2021-01-05 21:38:51 -08:00
Kelly Brazil
567b887253 doc updates 2021-01-05 21:26:43 -08:00
Kelly Brazil
e516e6b946 fix country/environment fields and process int/float conversions 2021-01-05 21:17:40 -08:00
Kelly Brazil
62748676aa initial iw-scan parser 2021-01-05 20:44:22 -08:00
Kelly Brazil
7351c72e45 add fixes and tests for entries that contain 'crash' 2021-01-05 15:16:40 -08:00
Kelly Brazil
2b7405c5e2 doc updates 2021-01-05 13:58:38 -08:00
Kelly Brazil
e2c77cb935 add test for last -F output 2021-01-05 13:00:38 -08:00
Kelly Brazil
7ac621e4c9 add -F support 2021-01-05 12:29:29 -08:00
Kelly Brazil
d8b5d6c66c version bump to 1.14.1 2021-01-05 09:45:37 -08:00
Kelly Brazil
22b461eb4b Add period field for en_US.UTF-8 locale 2021-01-05 09:42:05 -08:00
Kelly Brazil
b37ee8555a changelog update 2021-01-04 18:02:07 -08:00
Kelly Brazil
1d0ad2f045 doc fixes 2021-01-04 18:01:16 -08:00
Kelly Brazil
ceccfb2c81 add test output for iw-scan and date on ubuntu 20.04 2021-01-04 17:05:26 -08:00
Kelly Brazil
03c02953cd add wc doc 2021-01-01 12:01:56 -08:00
Kelly Brazil
f254a0eaa1 version bump 2020-12-31 16:45:10 -08:00
Kelly Brazil
9e3b88727c Merge pull request #91 from kellyjonbrazil/dev
Dev v1.14.0
2020-12-31 16:40:36 -08:00
Kelly Brazil
b12217466e spelling 2020-12-31 16:37:47 -08:00
Kelly Brazil
8b9c932f9b update date 2020-12-31 16:37:14 -08:00
Kelly Brazil
5986ce03db add printenv info 2020-12-31 16:36:27 -08:00
Kelly Brazil
a7b0e936e4 add vdir and printenv info 2020-12-31 14:21:24 -08:00
Kelly Brazil
cb02211424 add wc tests 2020-12-31 14:19:45 -08:00
Kelly Brazil
bd443bf392 add printenv to env docs 2020-12-31 14:11:25 -08:00
Kelly Brazil
1f547edd36 add printenv to env docs 2020-12-31 14:10:56 -08:00
Kelly Brazil
e4bac3a493 add wc parser 2020-12-31 14:10:37 -08:00
Kelly Brazil
5e6bfa681a add vdir info 2020-12-31 13:18:53 -08:00
Kelly Brazil
276160125e add new commands to README 2020-12-30 14:04:49 -08:00
Kelly Brazil
d4ae5543f2 add hash tests 2020-12-30 13:11:13 -08:00
Kelly Brazil
55f360e267 add hash command parser 2020-12-30 12:58:52 -08:00
Kelly Brazil
fdedab2a0c description updates 2020-12-30 11:33:29 -08:00
Kelly Brazil
a9be42e303 specify parser warnings for quiet option 2020-12-30 11:28:42 -08:00
Kelly Brazil
6da9510e46 add cksum tests 2020-12-30 11:22:17 -08:00
Kelly Brazil
0431798178 add cksum parser 2020-12-30 11:02:02 -08:00
Kelly Brazil
62432f3c48 update hashsum description 2020-12-30 09:59:54 -08:00
Kelly Brazil
9fbbc30906 add supported commands to docs 2020-12-29 13:09:03 -08:00
Kelly Brazil
d1567d1f62 add hashsum documentation 2020-12-29 13:05:04 -08:00
Kelly Brazil
6ca1f5970b Merge branch 'dev' of https://github.com/kellyjonbrazil/jc into dev 2020-12-29 12:59:02 -08:00
Kelly Brazil
1c880b9e24 force git tests 2020-12-29 12:58:04 -08:00
Kelly Brazil
3b7d54c720 add python 3.9 2020-12-29 12:55:30 -08:00
Kelly Brazil
44a7406057 add hashsum tests 2020-12-29 12:51:43 -08:00
Kelly Brazil
8157dcfdb1 fix for files with spaces in the name 2020-12-29 12:25:20 -08:00
Kelly Brazil
28762aea15 add hashsum parser 2020-12-29 11:36:20 -08:00
Kelly Brazil
439871ea9f add ubuntu 2020-11-19 07:07:30 -08:00
Kelly Brazil
c9180b005c formatting 2020-08-30 11:58:42 -07:00
Kelly Brazil
b14e0725f8 add ansible plugin blog post link 2020-08-30 11:57:55 -07:00
Kelly Brazil
70fe3dcb4d formatting 2020-08-26 15:21:45 -07:00
Kelly Brazil
8c554604a4 formatting 2020-08-26 14:41:01 -07:00
Kelly Brazil
a0a35454bd add link to the web demo 2020-08-26 14:39:40 -07:00
Kelly Brazil
e8467e2af5 remove extra space 2020-08-20 10:57:13 -07:00
Kelly Brazil
7515deb566 add ansible install command 2020-08-20 10:39:34 -07:00
Kelly Brazil
ed9e52af24 spelling 2020-08-20 10:37:15 -07:00
Kelly Brazil
592a380410 add Ansible note 2020-08-20 10:35:49 -07:00
Kelly Brazil
1a458d2d5b update link 2020-08-11 07:00:07 -07:00
Kelly Brazil
0e4cf53b92 add parser docs link 2020-08-11 06:36:30 -07:00
Kelly Brazil
e2f06ccb33 formatting 2020-08-06 13:00:33 -07:00
Kelly Brazil
8abff004cd indentation fix 2020-08-06 12:59:30 -07:00
Kelly Brazil
c4a0e2e3fe fix indentation 2020-08-06 12:58:53 -07:00
Kelly Brazil
4f10f79c73 standardize doc 2020-08-06 12:55:24 -07:00
Kelly Brazil
69e7a560fd add output info to docs 2020-08-06 07:48:08 -07:00
Kelly Brazil
59b1055808 enhance docs 2020-08-05 16:51:58 -07:00
Kelly Brazil
6ed48c6289 enhance docs 2020-08-05 15:34:17 -07:00
Kelly Brazil
f2fb4d3f41 improve docs 2020-08-05 15:10:48 -07:00
Kelly Brazil
6aeea59ea8 doc updates 2020-08-05 15:08:42 -07:00
Kelly Brazil
d016f3bbb3 improve documentation 2020-08-05 15:07:33 -07:00
Kelly Brazil
7131c29718 add module usage info to docs 2020-08-05 13:32:59 -07:00
Kelly Brazil
7432442983 add usage 2020-08-05 13:31:52 -07:00
Kelly Brazil
5344883394 spelling/add ping parser update 2020-08-05 11:35:52 -07:00
Kelly Brazil
3fcd2f6c2e version bump 2020-08-05 11:34:29 -07:00
Kelly Brazil
f3d84bd5bf tighten crontab and crontab-u parser variable detection 2020-08-05 11:28:37 -07:00
Kelly Brazil
549780c232 add debian/apt-get info 2020-08-05 11:04:07 -07:00
Kelly Brazil
2a6da69b82 improve linux/bsd check 2020-08-05 09:58:01 -07:00
Kelly Brazil
5c538816cf ping parser fix for raspberry pi 2020-08-04 17:36:35 -07:00
Kelly Brazil
7b8b378a7d add pydoc-markdown version requirement 2020-08-03 12:39:18 -07:00
Kelly Brazil
e30a75e25c Merge pull request #76 from kellyjonbrazil/dev
Dev v1.13.2
2020-08-03 10:18:39 -07:00
Kelly Brazil
85ad5cfd0b date change 2020-08-03 10:14:13 -07:00
Kelly Brazil
88b9d5068c finish date parser 2020-08-03 09:26:37 -07:00
Kelly Brazil
f8c4948a09 remove comment 2020-07-31 16:52:48 -07:00
Kelly Brazil
412322447f add month_num and weekday_num fields 2020-07-31 16:51:05 -07:00
Kelly Brazil
d4f289e40f documentation fixup 2020-07-31 14:47:06 -07:00
Kelly Brazil
e1f3feb8f5 cover empty data case in process 2020-07-31 14:45:30 -07:00
Kelly Brazil
37d3bc699c add date parser 2020-07-31 14:39:02 -07:00
Kelly Brazil
672fd18016 date bump 2020-07-31 12:59:44 -07:00
Kelly Brazil
bc2c23a2a0 version bump 2020-07-31 12:58:58 -07:00
Kelly Brazil
865f7e7812 add kv parser to man page 2020-07-31 12:58:11 -07:00
Kelly Brazil
720212b552 fixup traceroute example with new behavior 2020-07-31 11:02:24 -07:00
Kelly Brazil
d3be61f608 version bump 2020-07-31 10:59:46 -07:00
Kelly Brazil
13418b16b8 doc update 2020-07-31 10:56:51 -07:00
Kelly Brazil
42d2017cd6 traceroute updates: handle missing header row, add annotations, don't print timeouts as probes 2020-07-31 10:53:47 -07:00
Kelly Brazil
4345e76ead change to use --kv for key/value files 2020-07-30 16:49:38 -07:00
Kelly Brazil
741431322b update tests for kv parser 2020-07-30 16:45:36 -07:00
Kelly Brazil
980beaaf41 fix docgen issue 2020-07-30 16:21:03 -07:00
Kelly Brazil
2205034e09 add kv parser 2020-07-30 16:20:51 -07:00
Kelly Brazil
82b9c87a66 update docs 2020-07-30 16:20:24 -07:00
Kelly Brazil
dda517a937 shorten more examples 2020-07-29 14:36:20 -07:00
Kelly Brazil
4e6d283b9e shorten netstat example 2020-07-29 14:27:13 -07:00
Kelly Brazil
55acab05aa change name to CHANGELOG 2020-07-29 11:55:16 -07:00
Kelly Brazil
ed38a18d23 remove more examples 2020-07-29 11:49:00 -07:00
Kelly Brazil
95b3c11203 remove more examples 2020-07-29 11:43:22 -07:00
Kelly Brazil
dce318f4fd remove examples to reduce file size 2020-07-29 11:40:47 -07:00
Kelly Brazil
85127f0fb8 move examples to root 2020-07-29 11:34:43 -07:00
Kelly Brazil
fb45058244 add examples file 2020-07-29 11:32:18 -07:00
Kelly Brazil
45bb5ae389 spelling 2020-07-28 11:03:41 -07:00
Kelly Brazil
339238ab36 version bump and add route -6 tests 2020-07-27 20:37:33 -07:00
Kelly Brazil
032cda8b3d Merge pull request #74 from kellyjonbrazil/dev
Dev v1.13.0
2020-07-27 19:12:21 -07:00
Kelly Brazil
6badd3fb1e add parser count test 2020-07-27 19:02:23 -07:00
Kelly Brazil
724d825745 add tracepath parser 2020-07-27 19:02:11 -07:00
Kelly Brazil
ff1e32ad2e version bump 2020-07-27 16:49:34 -07:00
Kelly Brazil
a5f97febd3 update traceroute, tracepath, and uname tests 2020-07-27 16:47:41 -07:00
Kelly Brazil
5baa6cc865 add route parser update 2020-07-27 15:44:13 -07:00
Kelly Brazil
7a4f30b843 fix for iface issue 2020-07-27 15:37:44 -07:00
Kelly Brazil
b2c385dc4f change 'if' to 'iface' 2020-07-27 15:30:09 -07:00
Kelly Brazil
5d5da8d33f more fixes for ipv6 fix 2020-07-27 15:27:11 -07:00
Kelly Brazil
e604571578 fix next_hop fix 2020-07-27 15:20:51 -07:00
Kelly Brazil
f9dacc3f95 fixup for ipv6 2020-07-27 15:18:13 -07:00
Kelly Brazil
6086920332 update ParseError message 2020-07-27 15:13:32 -07:00
Kelly Brazil
f52f3163bc add tracepath example 2020-07-27 13:57:58 -07:00
Kelly Brazil
d18ff73e88 update author info 2020-07-27 13:51:51 -07:00
Kelly Brazil
1e5d602cae working tracepath parser 2020-07-27 13:48:46 -07:00
Kelly Brazil
12912521ec doc update 2020-07-27 11:04:27 -07:00
Kelly Brazil
842ea3a94b add tracepath parser skeleton 2020-07-27 11:02:13 -07:00
Kelly Brazil
a8560dbc15 add tracepath 2020-07-27 11:01:57 -07:00
Kelly Brazil
a65e27540a update docs 2020-07-27 11:01:45 -07:00
Kelly Brazil
c3c5ed11e6 change name from tr to trparse 2020-07-27 10:33:40 -07:00
Kelly Brazil
ce24149335 formatting 2020-07-27 10:33:25 -07:00
Kelly Brazil
0314ca8c48 add trparse acknowledgement 2020-07-27 10:33:15 -07:00
Kelly Brazil
ebd8ee49a9 add key/value info to ini example 2020-07-27 10:28:15 -07:00
Kelly Brazil
38d10c9781 add ping and traceroute examples 2020-07-27 09:29:30 -07:00
Kelly Brazil
360106c24d add tracepath 2020-07-27 09:23:01 -07:00
Kelly Brazil
ca470a5d02 add tracepath fixtures 2020-07-27 09:20:00 -07:00
Kelly Brazil
57f66e6b1d add exception with hint to use "uname -a" 2020-07-27 09:19:48 -07:00
Kelly Brazil
e774f67924 turn off interpolation and coerce None to '' 2020-07-24 16:53:17 -07:00
Kelly Brazil
ac10e576c1 spelling 2020-07-24 16:29:27 -07:00
Kelly Brazil
bcae0a99cd add key/value to ini description 2020-07-24 16:23:45 -07:00
Kelly Brazil
c73c2ff879 add ping, traceroute, and ini update 2020-07-24 16:23:30 -07:00
Kelly Brazil
c39b1a3356 add ping, traceroute and update ini description 2020-07-24 16:17:51 -07:00
Kelly Brazil
125dc2d9e0 add info about key/value files to doc 2020-07-24 16:17:16 -07:00
Kelly Brazil
b7d4ddc7ce add tests for key/value files 2020-07-24 16:16:54 -07:00
Kelly Brazil
f5e546c6fa add support for simple key/value pairs 2020-07-24 16:16:24 -07:00
Kelly Brazil
928e39cd10 add generic traceroute tests 2020-07-24 14:16:41 -07:00
Kelly Brazil
d0b7ea68a0 check for key in dictionary 2020-07-24 13:47:47 -07:00
Kelly Brazil
8444690133 add traceroute 2020-07-24 13:47:29 -07:00
Kelly Brazil
c03c42d767 add traceroute tests 2020-07-24 13:47:23 -07:00
Kelly Brazil
ab67688a00 add test skeleton 2020-07-23 16:45:09 -07:00
Kelly Brazil
5dcb7166da add traceroute doc 2020-07-23 16:44:57 -07:00
Kelly Brazil
14697b86d7 add MIT license 2020-07-23 15:48:08 -07:00
Kelly Brazil
4f4b6276d4 update docstring 2020-07-23 15:46:22 -07:00
Kelly Brazil
7bc497e129 updated process() function to set integers and floats 2020-07-23 15:42:33 -07:00
Kelly Brazil
68a37a6a5a remove unused function load() 2020-07-23 12:48:33 -07:00
Kelly Brazil
6f5cd1d7c5 change to use f-string 2020-07-23 12:03:21 -07:00
Kelly Brazil
126b1b121c add traceroute6 example 2020-07-23 11:31:56 -07:00
Kelly Brazil
2341e456a0 use ParseError instead of generic Exception 2020-07-23 11:31:35 -07:00
Kelly Brazil
72d80e95bb remove unused regex patterns 2020-07-23 10:52:40 -07:00
Kelly Brazil
f5ec82440c simplify regex patterns 2020-07-23 10:19:56 -07:00
Kelly Brazil
c8e526ead3 fixes for bsd-style ipv6 output 2020-07-22 17:23:24 -07:00
Kelly Brazil
066adfb764 handle warning lines in the traceroute output 2020-07-22 15:02:02 -07:00
Kelly Brazil
5b444d4717 add traceroute parser 2020-07-22 12:19:27 -07:00
Kelly Brazil
69c95adc8d add osx ipv6 ping dup test 2020-07-22 09:06:11 -07:00
Kelly Brazil
2b0e0d8f5c add ipv6 dup test 2020-07-21 17:34:30 -07:00
Kelly Brazil
778d1bacbf update docs to add "duplicates" fields 2020-07-21 15:16:39 -07:00
Kelly Brazil
7e1b041016 add duplicate replies tests 2020-07-21 15:12:43 -07:00
Kelly Brazil
313b9b329c update fixtures for added 'duplicate' fields 2020-07-21 15:05:54 -07:00
Kelly Brazil
6830062256 add support for duplicate replies 2020-07-21 14:47:25 -07:00
Kelly Brazil
323072c982 add source_ip to schema doc 2020-07-21 09:02:44 -07:00
Kelly Brazil
8719d96bdd change description 2020-07-20 16:54:43 -07:00
Kelly Brazil
dd5d318ab5 version bump and add ping command 2020-07-20 16:25:20 -07:00
Kelly Brazil
d6dc7f5e65 add osx ping tests 2020-07-20 16:11:18 -07:00
Kelly Brazil
c203664eb5 freebsd ping tests 2020-07-20 15:46:27 -07:00
Kelly Brazil
19ecf1fa19 add Fedora32 tests 2020-07-20 14:35:41 -07:00
Kelly Brazil
b8deb0426c add ubuntu ping tests 2020-07-20 13:51:39 -07:00
Kelly Brazil
3b8371f020 add centos ping tests 2020-07-20 12:49:05 -07:00
Kelly Brazil
20bb1cdf39 add TypeError to except for None values 2020-07-20 11:53:06 -07:00
Kelly Brazil
301daa48d0 update documentation 2020-07-19 15:30:54 -07:00
Kelly Brazil
8421ec8803 remove cygwin compatibility 2020-07-19 15:19:47 -07:00
Kelly Brazil
74211eb012 add examples 2020-07-19 15:16:04 -07:00
Kelly Brazil
60bd42f298 add process() logic 2020-07-19 15:13:52 -07:00
Kelly Brazil
14bdd74526 add ping test fixtures 2020-07-19 14:46:02 -07:00
Kelly Brazil
fb0f3eda04 add ping commands 2020-07-19 14:45:50 -07:00
Kelly Brazil
91ee6e6701 add osx ping test fixtures 2020-07-19 14:18:56 -07:00
Kelly Brazil
51f4e6927c add support for pattern in osx/bsd 2020-07-19 14:18:40 -07:00
Kelly Brazil
94988d8667 add fedora ping fixtures 2020-07-19 13:50:40 -07:00
Kelly Brazil
fe36f5a98c add fixtures for ping 2020-07-19 12:56:53 -07:00
Kelly Brazil
f9eb18b927 change 'request_timeout' field to 'type', fix compatibility, other formatting fixes 2020-07-19 12:56:34 -07:00
Kelly Brazil
cc60f36748 add ping parser 2020-07-18 12:35:46 -07:00
Kelly Brazil
604ade791f add ping parser 2020-07-17 15:57:07 -07:00
Kelly Brazil
690ac52a91 add man page 2020-07-13 07:18:48 -07:00
Kelly Brazil
34ed772775 version bump 2020-07-11 09:46:47 -07:00
Kelly Brazil
d5ab95571f fix tests when using older versions of pygments 2020-07-11 09:44:08 -07:00
Kelly Brazil
ffb3a0ee5f Merge pull request #73 from kellyjonbrazil/dev
Dev v1.12.0
2020-07-10 16:34:56 -07:00
Kelly Brazil
94b12b57aa spelling 2020-07-10 16:30:08 -07:00
Kelly Brazil
6d149e8457 version bump 2020-07-10 16:25:03 -07:00
Kelly Brazil
1ad89c90d8 add pacman 2020-07-10 15:58:02 -07:00
Kelly Brazil
fb71c7b020 function name spelling 2020-07-10 15:49:35 -07:00
Kelly Brazil
28ed17ad3b add parser_count test to test_cli_about_jc 2020-07-10 15:45:21 -07:00
Kelly Brazil
0c2a4e2bf7 add cli tests 2020-07-10 15:35:05 -07:00
Kelly Brazil
62bec30de2 add json_out tests 2020-07-10 14:44:50 -07:00
Kelly Brazil
3fced77e4e add set_env_colors tests 2020-07-10 12:23:48 -07:00
Kelly Brazil
a09d1d8b76 move environment variable assignment to main() to simplify tests 2020-07-10 12:23:25 -07:00
Kelly Brazil
8f4243fbd8 formatting 2020-07-10 10:54:34 -07:00
Kelly Brazil
47aaf20549 add sysctl command parser 2020-07-10 10:50:51 -07:00
Kelly Brazil
0c5289ea50 add sysctl tests 2020-07-10 10:47:23 -07:00
Kelly Brazil
3e53323514 don't filter out empty lines 2020-07-10 09:58:56 -07:00
Kelly Brazil
a5ee9861b9 update fixtures 2020-07-10 09:28:32 -07:00
Kelly Brazil
feb8ca7654 spelling 2020-07-10 09:28:20 -07:00
Kelly Brazil
a7abe4473b spelling 2020-07-10 09:03:04 -07:00
Kelly Brazil
780b9b61de specify IndexError exception in try/except block 2020-07-10 08:30:31 -07:00
Kelly Brazil
19ace36ffa add fixtures 2020-07-10 08:21:30 -07:00
Kelly Brazil
5fff8afc9f add fixes for freebsd where values can be on separate lines under the key 2020-07-10 08:21:15 -07:00
Kelly Brazil
4ad230c927 doc update and add test fixtures 2020-07-09 16:35:36 -07:00
Kelly Brazil
dd98eb1ec8 append duplicate key values to original key instead of adding unique keys 2020-07-09 16:25:41 -07:00
Kelly Brazil
c6baf42e72 doc updates 2020-07-09 16:18:33 -07:00
Kelly Brazil
e2bac97d56 fix for multiple identical keys in sysctl output 2020-07-09 14:51:15 -07:00
Kelly Brazil
d112ee94d0 use try/except and add support for floats in process() 2020-07-09 14:26:35 -07:00
Kelly Brazil
27b21b2faf formatting and docstring updates 2020-07-09 11:11:29 -07:00
Kelly Brazil
8c96d5cd20 reduce pygments version requirement 2020-07-09 10:59:36 -07:00
Kelly Brazil
c29ed3fd69 formatting of quotation marks and docstrings 2020-07-09 10:54:49 -07:00
Kelly Brazil
cedf603f12 minor formatting 2020-07-09 09:59:00 -07:00
Kelly Brazil
279161c36f Merge pull request #72 from duelafn/pygments-2.3
Support older pygments
2020-07-09 09:48:58 -07:00
Dean Serenevy
ce0b43d919 Remove dependency on 3rd party packaging library 2020-07-09 12:44:41 -04:00
Dean Serenevy
ddafa5bf06 Support older pygments 2020-07-09 11:39:34 -04:00
Kelly Brazil
bc7116c31b fix JC_COLORS env bug and simplify set_env_colors() 2020-07-09 08:30:10 -07:00
Kelly Brazil
53b7092721 remove side-effects from functions and print in main() 2020-07-08 16:40:28 -07:00
Kelly Brazil
beb9174b1b add sysctl parser 2020-07-08 15:42:06 -07:00
Kelly Brazil
aea41ed341 move verbose_debug enable earlier in code to catch more issues. add sysctl and version bump 2020-07-08 15:41:46 -07:00
Kelly Brazil
d789494cb1 change type check to use isinstance 2020-07-08 05:59:19 -07:00
Kelly Brazil
608e7b4cff add license info 2020-07-06 10:52:12 -07:00
Kelly Brazil
4ee199c02a use tracebackplus instead of cgitb since cgitb is depricated 2020-07-06 10:41:01 -07:00
Kelly Brazil
fbf47d4085 add arch linux 2020-07-01 13:28:58 -07:00
Kelly Brazil
5a238e4b42 remove updates-testing from fedora command 2020-07-01 09:11:32 -07:00
Kelly Brazil
f852b8246a wrap warning message 2020-06-30 11:50:37 -07:00
Kelly Brazil
88140d929a wrap error message in code 2020-06-30 11:37:33 -07:00
Kelly Brazil
45f7268240 add -dd to error message 2020-06-30 11:34:08 -07:00
Kelly Brazil
3a3c8e4d4a move verbose_debug under debug check 2020-06-30 11:31:08 -07:00
Kelly Brazil
c1ac183a04 simplify debug option 2020-06-30 11:26:09 -07:00
Kelly Brazil
18bb779ee5 formatting: double quotes to single quotes 2020-06-30 09:39:05 -07:00
Kelly Brazil
8b6612fe79 move JC_COLORS parsing error message 2020-06-30 07:56:34 -07:00
Kelly Brazil
fde0bc8534 improve package install info 2020-06-27 18:53:19 -07:00
Kelly Brazil
e661a78939 Merge pull request #71 from wigust/guix
add guix package info
2020-06-27 18:43:02 -07:00
Oleg Pykhalov
847e346602 add guix package info 2020-06-27 13:01:56 +03:00
Kelly Brazil
b969751688 add other references 2020-06-26 09:53:57 -07:00
Kelly Brazil
ad6f2ba03a formatting 2020-06-25 21:16:52 -07:00
Kelly Brazil
63c6a5edc0 formatting 2020-06-25 21:12:30 -07:00
Kelly Brazil
9f4cf9dd5e formatting 2020-06-25 21:11:21 -07:00
Kelly Brazil
51331b6dc0 formatting 2020-06-25 13:01:10 -07:00
Kelly Brazil
efb6761033 formatting 2020-06-25 12:59:56 -07:00
Kelly Brazil
6a4f737a0f update json syntax highlighting 2020-06-25 12:56:06 -07:00
Kelly Brazil
be6864b778 add syntax highlighting tags 2020-06-25 12:28:23 -07:00
Kelly Brazil
de3b91a36c add -dd option 2020-06-25 07:38:39 -07:00
Kelly Brazil
ef5482c3b5 add verbose debug option 2020-06-25 07:29:28 -07:00
Kelly Brazil
d20b795137 Merge pull request #70 from kellyjonbrazil/dev
Dev v1.11.7
2020-06-22 11:28:23 -07:00
Kelly Brazil
8a134065df update fixtures for last chain fix 2020-06-22 11:23:37 -07:00
Kelly Brazil
22aee1bfa4 version bump 2020-06-22 11:23:15 -07:00
Kelly Brazil
b282820fd6 fix to include the final chain in output 2020-06-22 11:09:09 -07:00
Kelly Brazil
3ee098306d version bump 2020-06-22 10:48:51 -07:00
Kelly Brazil
09e8f379a6 iptables code optimizations 2020-06-22 10:47:34 -07:00
Kelly Brazil
69018cdb3a fix date 2020-06-14 17:39:14 -07:00
Kelly Brazil
d0d7254c6a add docstring 2020-06-14 17:23:10 -07:00
Kelly Brazil
cc0f0971d7 Improve and standardize empty data check for all parsers 2020-06-14 17:17:40 -07:00
409 changed files with 24937 additions and 3152 deletions

View File

@@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2

View File

@@ -1,5 +1,78 @@
jc changelog
20210305 v1.14.4
- Packaging fix only for binaries and RPMs hosted on https://github.com/kellyjonbrazil/jc-packaging.
Packages from PyPi and OS repositories are not affected. This fixes an issue that kept the YAML
parser from initializing.
20210210 v1.14.3
- Add hciconfig parser tested on linux
- Update dig parser to simplify answer data logic
20210205 v1.14.2
- Update dig parser to fix cases where there are spaces in the answer data (e.g. TXT records)
20210106 v1.14.1
- Add iw-scan parser tested on linux (beta)
- Update date parser for Ubuntu 20.04 support
- Update last parser for last -F support
- Update last parser to add convenience fields and augment data for easier parsing
- Update man page
- Minor documentation updates
20201231 v1.14.0
- Add hashsum parser tested on linux, macos
- Add hash parser tested on linux, macos
- Add cksum parser tested on linux, macos
- Add wc parser tested on linux, macos
- Add printenv support under env parser
- Add vdir support under ls parser
- Add python 3.9 to github automation tests
20200805 v1.13.4
- Update crontab and crontab-u parsers to tighten up variable detection
- Update ping parser to tighten linux/bsd detection
20200804 v1.13.3
- Update ping parser for Raspberry Pi compatibility
20200803 v1.13.2
- Add key/value file parser (wrapper for ini parser)
- Add date command parser
- Update traceroute parser to more gracefully handle missing header row
- Update traceroute parser to handle annotations
- Update traceroute parser to only return successful probes
20200727 v1.13.1
- Add route -6 tests
20200727 v1.13.0
- Add ping and ping6 command parser tested on linux, macos, and freebsd
- Add traceroute and traceroute6 command parser tested on linux, macos, and freebsd
- Add tracepath command parser tested on linux
- Update ini parser to support files only containing key/value pairs
- Update uname parser exception with a hint to use "uname -a"
- Update route parser to support IPv6 tables
20200711 v1.12.1
- Fix tests when using older version of pygments library
20200710 v1.12.0
- Add sysctl command parser tested on linux, macOS, and freebsd
- Update the cli code to allow older versions of the pygments library (2.3.0) for debian packaging
- Code cleanup on the cli
- Add tests for the cli
- Vendorize cgitb as tracebackplus for verbose debug messages
20200625 v1.11.8
- Add verbose debug option using -dd argument
20200622 v1.11.7
- Fix iptables parser issue which would not output the last chain
20200614 v1.11.6
- Improve and standardize empty data check for all parsers
20200612 v1.11.5
- Update airport_s parser to fix error on parsing empty data
- Update arp parser to fix error on parsing empty data

2966
EXAMPLES.md Normal file

File diff suppressed because it is too large Load Diff

2120
README.md

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
#!/bin/bash
# Generate docs.md
# requires pydoc-markdown 2.1.0.post1
cd jc
pydocmd simple jc+ > ../docs/readme.md
@@ -8,9 +9,11 @@ pydocmd simple jc.parsers.airport+ > ../docs/parsers/airport.md
pydocmd simple jc.parsers.airport_s+ > ../docs/parsers/airport_s.md
pydocmd simple jc.parsers.arp+ > ../docs/parsers/arp.md
pydocmd simple jc.parsers.blkid+ > ../docs/parsers/blkid.md
pydocmd simple jc.parsers.cksum+ > ../docs/parsers/cksum.md
pydocmd simple jc.parsers.crontab+ > ../docs/parsers/crontab.md
pydocmd simple jc.parsers.crontab_u+ > ../docs/parsers/crontab_u.md
pydocmd simple jc.parsers.csv+ > ../docs/parsers/csv.md
pydocmd simple jc.parsers.date+ > ../docs/parsers/date.md
pydocmd simple jc.parsers.df+ > ../docs/parsers/df.md
pydocmd simple jc.parsers.dig+ > ../docs/parsers/dig.md
pydocmd simple jc.parsers.dmidecode+ > ../docs/parsers/dmidecode.md
@@ -21,13 +24,18 @@ pydocmd simple jc.parsers.free+ > ../docs/parsers/free.md
pydocmd simple jc.parsers.fstab+ > ../docs/parsers/fstab.md
pydocmd simple jc.parsers.group+ > ../docs/parsers/group.md
pydocmd simple jc.parsers.gshadow+ > ../docs/parsers/gshadow.md
pydocmd simple jc.parsers.hash+ > ../docs/parsers/hash.md
pydocmd simple jc.parsers.hashsum+ > ../docs/parsers/hashsum.md
pydocmd simple jc.parsers.hciconfig+ > ../docs/parsers/hciconfig.md
pydocmd simple jc.parsers.history+ > ../docs/parsers/history.md
pydocmd simple jc.parsers.hosts+ > ../docs/parsers/hosts.md
pydocmd simple jc.parsers.id+ > ../docs/parsers/id.md
pydocmd simple jc.parsers.ifconfig+ > ../docs/parsers/ifconfig.md
pydocmd simple jc.parsers.ini+ > ../docs/parsers/ini.md
pydocmd simple jc.parsers.iptables+ > ../docs/parsers/iptables.md
pydocmd simple jc.parsers.iw_scan+ > ../docs/parsers/iw_scan.md
pydocmd simple jc.parsers.jobs+ > ../docs/parsers/jobs.md
pydocmd simple jc.parsers.kv+ > ../docs/parsers/kv.md
pydocmd simple jc.parsers.last+ > ../docs/parsers/last.md
pydocmd simple jc.parsers.ls+ > ../docs/parsers/ls.md
pydocmd simple jc.parsers.lsblk+ > ../docs/parsers/lsblk.md
@@ -37,6 +45,7 @@ pydocmd simple jc.parsers.mount+ > ../docs/parsers/mount.md
pydocmd simple jc.parsers.netstat+ > ../docs/parsers/netstat.md
pydocmd simple jc.parsers.ntpq+ > ../docs/parsers/ntpq.md
pydocmd simple jc.parsers.passwd+ > ../docs/parsers/passwd.md
pydocmd simple jc.parsers.ping+ > ../docs/parsers/ping.md
pydocmd simple jc.parsers.pip_list+ > ../docs/parsers/pip_list.md
pydocmd simple jc.parsers.pip_show+ > ../docs/parsers/pip_show.md
pydocmd simple jc.parsers.ps+ > ../docs/parsers/ps.md
@@ -44,14 +53,18 @@ pydocmd simple jc.parsers.route+ > ../docs/parsers/route.md
pydocmd simple jc.parsers.shadow+ > ../docs/parsers/shadow.md
pydocmd simple jc.parsers.ss+ > ../docs/parsers/ss.md
pydocmd simple jc.parsers.stat+ > ../docs/parsers/stat.md
pydocmd simple jc.parsers.sysctl+ > ../docs/parsers/sysctl.md
pydocmd simple jc.parsers.systemctl+ > ../docs/parsers/systemctl.md
pydocmd simple jc.parsers.systemctl_lj+ > ../docs/parsers/systemctl_lj.md
pydocmd simple jc.parsers.systemctl_ls+ > ../docs/parsers/systemctl_ls.md
pydocmd simple jc.parsers.systemctl_luf+ > ../docs/parsers/systemctl_luf.md
pydocmd simple jc.parsers.timedatectl+ > ../docs/parsers/timedatectl.md
pydocmd simple jc.parsers.tracepath+ > ../docs/parsers/tracepath.md
pydocmd simple jc.parsers.traceroute+ > ../docs/parsers/traceroute.md
pydocmd simple jc.parsers.uname+ > ../docs/parsers/uname.md
pydocmd simple jc.parsers.uptime+ > ../docs/parsers/uptime.md
pydocmd simple jc.parsers.w+ > ../docs/parsers/w.md
pydocmd simple jc.parsers.wc+ > ../docs/parsers/wc.md
pydocmd simple jc.parsers.who+ > ../docs/parsers/who.md
pydocmd simple jc.parsers.xml+ > ../docs/parsers/xml.md
pydocmd simple jc.parsers.yaml+ > ../docs/parsers/yaml.md

View File

@@ -1,12 +1,21 @@
# jc.parsers.airport
jc - JSON CLI output utility airport -I Parser
jc - JSON CLI output utility `airport -I` command output parser
Usage:
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
specify --airport as the first argument if the piped input is coming from airport -I (OSX)
Usage (cli):
This program can be found at:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
$ airport -I | jc --airport
or
$ jc airport -I
Usage (module):
import jc.parsers.airport
result = jc.parsers.airport.parse(airport_command_output)
Compatibility:
@@ -52,11 +61,13 @@ Examples:
"channel": "48,80"
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -66,7 +77,7 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -90,6 +101,7 @@ Returns:
"channel": string
}
## parse
```python
parse(data, raw=False, quiet=False)

View File

@@ -1,12 +1,21 @@
# jc.parsers.airport_s
jc - JSON CLI output utility airport -s Parser
jc - JSON CLI output utility `airport -s` command output parser
Usage:
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
specify --airport as the first argument if the piped input is coming from airport -s (OSX)
Usage (cli):
This program can be found at:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
$ airport -s | jc --airport-s
or
$ jc airport -s
Usage (module):
import jc.parsers.airport_s
result = jc.parsers.airport_s.parse(airport_s_command_output)
Compatibility:
@@ -84,11 +93,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -98,11 +109,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
"ssid": string,
@@ -117,6 +128,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -132,5 +144,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,13 +1,21 @@
# jc.parsers.arp
jc - JSON CLI output utility arp Parser
jc - JSON CLI output utility `arp` command output parser
Usage:
Supports `arp` and `arp -a` output.
specify --arp as the first argument if the piped input is coming from:
Usage (cli):
arp
or
arp -a
$ arp | jc --arp
or
$ jc arp
Usage (module):
import jc.parsers.arp
result = jc.parsers.arp.parse(arp_command_output)
Compatibility:
@@ -95,11 +103,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -109,11 +119,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -128,6 +138,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -143,5 +154,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.blkid
jc - JSON CLI output utility blkid Parser
jc - JSON CLI output utility `blkid` command output parser
Usage:
Usage (cli):
specify --blkid as the first argument if the piped input is coming from blkid
$ blkid | jc --blkid
or
$ jc blkid
Usage (module):
import jc.parsers.blkid
result = jc.parsers.blkid.parse(blkid_command_output)
Compatibility:
@@ -75,11 +85,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -89,11 +101,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -129,6 +141,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -144,5 +157,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

95
docs/parsers/cksum.md Normal file
View File

@@ -0,0 +1,95 @@
# jc.parsers.cksum
jc - JSON CLI output utility `cksum` command output parser
This parser works with the following checksum calculation utilities:
- `sum`
- `cksum`
Usage (cli):
$ cksum file.txt | jc --cksum
or
$ jc cksum file.txt
Usage (module):
import jc.parsers.cksum
result = jc.parsers.cksum.parse(cksum_command_output)
Compatibility:
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
Examples:
$ cksum * | jc --cksum -p
[
{
"filename": "__init__.py",
"checksum": 4294967295,
"blocks": 0
},
{
"filename": "airport.py",
"checksum": 2208551092,
"blocks": 3745
},
{
"filename": "airport_s.py",
"checksum": 1113817598,
"blocks": 4572
},
...
]
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"filename": string,
"checksum": integer,
"blocks": integer
}
]
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,21 @@
# jc.parsers.crontab
jc - JSON CLI output utility crontab command and file Parser
jc - JSON CLI output utility `crontab -l` command output and crontab file parser
Usage:
Supports `crontab -l` command output and crontab files.
specify --crontab as the first argument if the piped input is coming from crontab -l or a crontab file
Usage (cli):
$ crontab -l | jc --crontab
or
$ jc crontab -l
Usage (module):
import jc.parsers.crontab
result = jc.parsers.crontab.parse(crontab_output)
Compatibility:
@@ -128,11 +140,13 @@ Examples:
]
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -142,7 +156,7 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -178,6 +192,7 @@ Returns:
}
## parse
```python
parse(data, raw=False, quiet=False)

View File

@@ -1,9 +1,17 @@
# jc.parsers.crontab_u
jc - JSON CLI output utility crontab file Parser
jc - JSON CLI output utility `crontab -l` command output and crontab file parser
Usage:
This version of the `crontab -l` parser supports output that contains user information for processes.
specify --crontab-u as the first argument if the piped input is coming from a crontab file with User specified
Usage (cli):
$ crontab -l | jc --crontab-u
Usage (module):
import jc.parsers.crontab_u
result = jc.parsers.crontab_u.parse(crontab_u_output)
Compatibility:
@@ -129,11 +137,13 @@ Examples:
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -143,7 +153,7 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -180,6 +190,7 @@ Returns:
}
## parse
```python
parse(data, raw=False, quiet=False)

View File

@@ -1,12 +1,17 @@
# jc.parsers.csv
jc - JSON CLI output utility csv Parser
jc - JSON CLI output utility `csv` file parser
Usage:
The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. The first row of the file must be a header row.
specify --csv as the first argument if the piped input is coming from a csv file.
the csv parser will attempt to automatically detect the delimiter character.
if the delimiter cannot be detected it will default to comma.
the first row of the file must be a header row.
Usage (cli):
$ cat file.csv | jc --csv
Usage (module):
import jc.parsers.csv
result = jc.parsers.csv.parse(csv_output)
Compatibility:
@@ -59,11 +64,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -73,11 +80,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Each dictionary represents a row in the csv file:
List of Dictionaries. Each Dictionary represents a row in the csv file:
[
{
@@ -86,6 +93,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -101,5 +109,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

104
docs/parsers/date.md Normal file
View File

@@ -0,0 +1,104 @@
# jc.parsers.date
jc - JSON CLI output utility `date` command output parser
Usage (cli):
$ date | jc --date
or
$ jc date
Usage (module):
import jc.parsers.date
result = jc.parsers.date.parse(date_command_output)
Compatibility:
'linux', 'darwin', 'freebsd'
Examples:
$ date | jc --date -p
{
"year": 2020,
"month_num": 7,
"day": 31,
"hour": 16,
"minute": 48,
"second": 11,
"period": null,
"month": "Jul",
"weekday": "Fri",
"weekday_num": 6,
"timezone": "PDT"
}
$ date | jc --date -p -r
{
"year": "2020",
"month": "Jul",
"day": "31",
"weekday": "Fri",
"hour": "16",
"minute": "50",
"second": "01",
"timezone": "PDT"
}
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary. Structured data with the following schema:
{
"year": integer,
"month_num": integer,
"day": integer,
"hour": integer,
"minute": integer,
"second": integer,
"period": string,
"month": string,
"weekday": string,
"weekday_num": integer,
"timezone": string
}
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.df
jc - JSON CLI output utility df Parser
jc - JSON CLI output utility `df` command output parser
Usage:
Usage (cli):
specify --df as the first argument if the piped input is coming from df
$ df | jc --df
or
$ jc df
Usage (module):
import jc.parsers.df
result = jc.parsers.df.parse(df_command_output)
Compatibility:
@@ -69,11 +79,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -83,11 +95,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -106,6 +118,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -121,5 +134,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.dig
jc - JSON CLI output utility dig Parser
jc - JSON CLI output utility `dig` command output parser
Usage:
Usage (cli):
Specify --dig as the first argument if the piped input is coming from dig
$ dig example.com | jc --dig
or
$ jc dig example.com
Usage (module):
import jc.parsers.dig
result = jc.parsers.dig.parse(dig_command_output)
Compatibility:
@@ -321,11 +331,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -335,11 +347,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -393,6 +405,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -408,5 +421,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.dmidecode
jc - JSON CLI output utility dmidecode Parser
jc - JSON CLI output utility `dmidecode` command output parser
Usage:
Usage (cli):
specify --dmidecode as the first argument if the piped input is coming from dmidecode
$ dmidecode | jc --dmidecode
or
$ jc dmidecode
Usage (module):
import jc.parsers.dmidecode
result = jc.parsers.dmidecode.parse(dmidecode_command_output)
Compatibility:
@@ -99,11 +109,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -113,11 +125,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -134,6 +146,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -149,5 +162,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.du
jc - JSON CLI output utility du Parser
jc - JSON CLI output utility `du` command output parser
Usage:
Usage (cli):
specify --du as the first argument if the piped input is coming from du
$ du | jc --du
or
$ jc du
Usage (module):
import jc.parsers.du
result = jc.parsers.du.parse(du_command_output)
Compatibility:
@@ -69,11 +79,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -83,11 +95,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -96,6 +108,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -111,5 +124,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,21 @@
# jc.parsers.env
jc - JSON CLI output utility env Parser
jc - JSON CLI output utility `env` and `printenv` command output parser
Usage:
This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
specify --env as the first argument if the piped input is coming from env
Usage (cli):
$ env | jc --env
or
$ jc env
Usage (module):
import jc.parsers.env
result = jc.parsers.env.parse(env_command_output)
Compatibility:
@@ -49,11 +61,13 @@ Examples:
"_": "/usr/bin/env"
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -63,11 +77,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -76,6 +90,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -92,5 +107,5 @@ Parameters:
Returns:
Dictionary of raw structured data or
list of dictionaries of processed structured data
List of Dictionaries of processed structured data

View File

@@ -1,9 +1,19 @@
# jc.parsers.file
jc - JSON CLI output utility file command Parser
jc - JSON CLI output utility `file` command output parser
Usage:
Usage (cli):
specify --file as the first argument if the piped input is coming from file.
$ file * | jc --file
or
$ jc file *
Usage (module):
import jc.parsers.file
result = jc.parsers.file.parse(file_command_output)
Compatibility:
@@ -44,11 +54,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -58,11 +70,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -71,6 +83,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -86,5 +99,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.free
jc - JSON CLI output utility free Parser
jc - JSON CLI output utility `free` command output parser
Usage:
Usage (cli):
specify --free as the first argument if the piped input is coming from free
$ free | jc --free
or
$ jc free
Usage (module):
import jc.parsers.free
result = jc.parsers.free.parse(free_command_output)
Compatibility:
@@ -49,11 +59,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -63,11 +75,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -81,6 +93,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -96,5 +109,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,15 @@
# jc.parsers.fstab
jc - JSON CLI output utility fstab Parser
jc - JSON CLI output utility `fstab` file parser
Usage:
Usage (cli):
specify --fstab as the first argument if the piped input is coming from a fstab file
$ cat /etc/fstab | jc --fstab
Usage (module):
import jc.parsers.fstab
result = jc.parsers.fstab.parse(fstab_command_output)
Compatibility:
@@ -67,11 +73,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -81,11 +89,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -98,6 +106,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -113,5 +122,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,15 @@
# jc.parsers.group
jc - JSON CLI output utility /etc/group file Parser
jc - JSON CLI output utility `/etc/group` file parser
Usage:
Usage (cli):
specify --group as the first argument if the piped input is coming from /etc/group
$ cat /etc/group | jc --group
Usage (module):
import jc.parsers.group
result = jc.parsers.group.parse(group_file_output)
Compatibility:
@@ -91,11 +97,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -105,11 +113,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -122,6 +130,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -137,5 +146,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,15 @@
# jc.parsers.gshadow
jc - JSON CLI output utility /etc/gshadow file Parser
jc - JSON CLI output utility `/etc/gshadow` file parser
Usage:
Usage (cli):
specify --gshadow as the first argument if the piped input is coming from /etc/gshadow
$ cat /etc/gshadow | jc --gshadow
Usage (module):
import jc.parsers.gshadow
result = jc.parsers.gshadow.parse(gshadow_file_output)
Compatibility:
@@ -57,11 +63,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -71,11 +79,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -90,6 +98,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -105,5 +114,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

78
docs/parsers/hash.md Normal file
View File

@@ -0,0 +1,78 @@
# jc.parsers.hash
jc - JSON CLI output utility `hash` command output parser
Usage (cli):
$ hash | jc --hash
Usage (module):
import jc.parsers.hash
result = jc.parsers.hash.parse(hash_command_output)
Compatibility:
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
Examples:
$ hash | jc --hash -p
[
{
"hits": 2,
"command": "/bin/cat"
},
{
"hits": 1,
"command": "/bin/ls"
}
]
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"command": string,
"hits": integer
}
]
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.

109
docs/parsers/hashsum.md Normal file
View File

@@ -0,0 +1,109 @@
# jc.parsers.hashsum
jc - JSON CLI output utility `hash sum` command output parser
This parser works with the following hash calculation utilities:
- `md5`
- `md5sum`
- `shasum`
- `sha1sum`
- `sha224sum`
- `sha256sum`
- `sha384sum`
- `sha512sum`
Usage (cli):
$ md5sum file.txt | jc --hashsum
or
$ jc md5sum file.txt
Usage (module):
import jc.parsers.hashsum
result = jc.parsers.hashsum.parse(md5sum_command_output)
Compatibility:
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
Examples:
$ md5sum * | jc --hashsum -p
[
{
"filename": "devtoolset-3-gcc-4.9.2-6.el7.x86_64.rpm",
"hash": "65fc958c1add637ec23c4b137aecf3d3"
},
{
"filename": "digout",
"hash": "5b9312ee5aff080927753c63a347707d"
},
{
"filename": "dmidecode.out",
"hash": "716fd11c2ac00db109281f7110b8fb9d"
},
{
"filename": "file with spaces in the name",
"hash": "d41d8cd98f00b204e9800998ecf8427e"
},
{
"filename": "id-centos.out",
"hash": "4295be239a14ad77ef3253103de976d2"
},
{
"filename": "ifcfg.json",
"hash": "01fda0d9ba9a75618b072e64ff512b43"
},
...
]
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"filename": string,
"hash": string,
}
]
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.

358
docs/parsers/hciconfig.md Normal file
View File

@@ -0,0 +1,358 @@
# jc.parsers.hciconfig
jc - JSON CLI output utility `hciconfig` command output parser
Usage (cli):
$ hciconfig | jc --hciconfig
or
$ jc hciconfig
Usage (module):
import jc.parsers.hciconfig
result = jc.parsers.hciconfig.parse(hciconfig_command_output)
Compatibility:
'linux'
Examples:
$ hciconfig -a | jc --hciconfig -p
[
{
"device": "hci0",
"type": "Primary",
"bus": "USB",
"bd_address": "00:1A:7D:DA:71:13",
"acl_mtu": 310,
"acl_mtu_packets": 10,
"sco_mtu": 64,
"sco_mtu_packets": 8,
"state": [
"UP",
"RUNNING"
],
"rx_bytes": 13905869,
"rx_acl": 0,
"rx_sco": 0,
"rx_events": 393300,
"rx_errors": 0,
"tx_bytes": 62629,
"tx_acl": 0,
"tx_sco": 0,
"tx_commands": 3893,
"tx_errors": 0,
"features": [
"0xff",
"0xff",
"0x8f",
"0xfe",
"0xdb",
"0xff",
"0x5b",
"0x87"
],
"packet_type": [
"DM1",
"DM3",
"DM5",
"DH1",
"DH3",
"DH5",
"HV1",
"HV2",
"HV3"
],
"link_policy": [
"RSWITCH",
"HOLD",
"SNIFF",
"PARK"
],
"link_mode": [
"SLAVE",
"ACCEPT"
],
"name": "CSR8510 A10",
"class": "0x000000",
"service_classes": null,
"device_class": "Miscellaneous",
"hci_version": "4.0 (0x6)",
"hci_revision": "0x22bb",
"lmp_version": "4.0 (0x6)",
"lmp_subversion": "0x22bb",
"manufacturer": "Cambridge Silicon Radio (10)"
},
{
"device": "hci1",
"type": "Primary",
"bus": "USB",
"bd_address": "00:1A:7D:DA:71:13",
"acl_mtu": 310,
"acl_mtu_packets": 10,
"sco_mtu": 64,
"sco_mtu_packets": 8,
"state": [
"DOWN"
],
"rx_bytes": 4388363,
"rx_acl": 0,
"rx_sco": 0,
"rx_events": 122021,
"rx_errors": 0,
"tx_bytes": 52350,
"tx_acl": 0,
"tx_sco": 0,
"tx_commands": 3480,
"tx_errors": 2,
"features": [
"0xff",
"0xff",
"0x8f",
"0xfe",
"0xdb",
"0xff",
"0x5b",
"0x87"
],
"packet_type": [
"DM1",
"DM3",
"DM5",
"DH1",
"DH3",
"DH5",
"HV1",
"HV2",
"HV3"
],
"link_policy": [
"RSWITCH",
"HOLD",
"SNIFF",
"PARK"
],
"link_mode": [
"SLAVE",
"ACCEPT"
]
}
]
$ hciconfig -a | jc --hciconfig -p -r
[
{
"device": "hci0",
"type": "Primary",
"bus": "USB",
"bd_address": "00:1A:7D:DA:71:13",
"acl_mtu": "310",
"acl_mtu_packets": "10",
"sco_mtu": "64",
"sco_mtu_packets": "8",
"state": [
"UP",
"RUNNING"
],
"rx_bytes": "13905869",
"rx_acl": "0",
"rx_sco": "0",
"rx_events": "393300",
"rx_errors": "0",
"tx_bytes": "62629",
"tx_acl": "0",
"tx_sco": "0",
"tx_commands": "3893",
"tx_errors": "0",
"features": [
"0xff",
"0xff",
"0x8f",
"0xfe",
"0xdb",
"0xff",
"0x5b",
"0x87"
],
"packet_type": [
"DM1",
"DM3",
"DM5",
"DH1",
"DH3",
"DH5",
"HV1",
"HV2",
"HV3"
],
"link_policy": [
"RSWITCH",
"HOLD",
"SNIFF",
"PARK"
],
"link_mode": [
"SLAVE",
"ACCEPT"
],
"name": "CSR8510 A10",
"class": "0x000000",
"service_classes": [
"Unspecified"
],
"device_class": "Miscellaneous",
"hci_version": "4.0 (0x6)",
"hci_revision": "0x22bb",
"lmp_version": "4.0 (0x6)",
"lmp_subversion": "0x22bb",
"manufacturer": "Cambridge Silicon Radio (10)"
},
{
"device": "hci1",
"type": "Primary",
"bus": "USB",
"bd_address": "00:1A:7D:DA:71:13",
"acl_mtu": "310",
"acl_mtu_packets": "10",
"sco_mtu": "64",
"sco_mtu_packets": "8",
"state": [
"DOWN"
],
"rx_bytes": "4388363",
"rx_acl": "0",
"rx_sco": "0",
"rx_events": "122021",
"rx_errors": "0",
"tx_bytes": "52350",
"tx_acl": "0",
"tx_sco": "0",
"tx_commands": "3480",
"tx_errors": "2",
"features": [
"0xff",
"0xff",
"0x8f",
"0xfe",
"0xdb",
"0xff",
"0x5b",
"0x87"
],
"packet_type": [
"DM1",
"DM3",
"DM5",
"DH1",
"DH3",
"DH5",
"HV1",
"HV2",
"HV3"
],
"link_policy": [
"RSWITCH",
"HOLD",
"SNIFF",
"PARK"
],
"link_mode": [
"SLAVE",
"ACCEPT"
]
}
]
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"device": string,
"type": string,
"bus": string,
"bd_address": string,
"acl_mtu": integer,
"acl_mtu_packets": integer,
"sco_mtu": integer,
"sco_mtu_packets": integer,
"state": [
string
],
"rx_bytes": integer,
"rx_acl": integer,
"rx_sco": integer,
"rx_events": integer,
"rx_errors": integer,
"tx_bytes": integer,
"tx_acl": integer,
"tx_sco": integer,
"tx_commands": integer,
"tx_errors": integer,
"features": [
string
],
"packet_type": [
string
],
"link_policy": [
string
],
"link_mode": [
string
],
"name": string,
"class": string,
"service_classes": [
string # 'Unspecified' is null
],
"device_class": string,
"hci_version": string,
"hci_revision": string,
"lmp_version": string,
"lmp_subversion": string,
"manufacturer": string
}
]
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,17 @@
# jc.parsers.history
jc - JSON CLI output utility history Parser
jc - JSON CLI output utility `history` command output parser
Usage:
This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
specify --history as the first argument if the piped input is coming from history
Usage (cli):
$ history | jc --history
Usage (module):
import jc.parsers.history
result = jc.parsers.history.parse(history_command_output)
Compatibility:
@@ -41,11 +49,13 @@ Examples:
...
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -55,11 +65,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -68,6 +78,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -84,5 +95,5 @@ Parameters:
Returns:
Dictionary of raw structured data or
list of dictionaries of processed structured data
List of Dictionaries of processed structured data

View File

@@ -1,9 +1,15 @@
# jc.parsers.hosts
jc - JSON CLI output utility hosts Parser
jc - JSON CLI output utility `/etc/hosts` file parser
Usage:
Usage (cli):
specify --hosts as the first argument if the piped input is coming from a hosts file
$ cat /etc/hosts | jc --hosts
Usage (module):
import jc.parsers.hosts
result = jc.parsers.hosts.parse(hosts_file_output)
Compatibility:
@@ -58,11 +64,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -72,11 +80,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -87,6 +95,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -102,5 +111,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.id
jc - JSON CLI output utility id Parser
jc - JSON CLI output utility `id` command output parser
Usage:
Usage (cli):
specify --id as the first argument if the piped input is coming from id
$ id | jc --id
or
$ jc id
Usage (module):
import jc.parsers.id
result = jc.parsers.id.parse(id_command_output)
Compatibility:
@@ -67,11 +77,13 @@ Examples:
}
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -81,7 +93,7 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -114,6 +126,7 @@ Returns:
}
}
## parse
```python
parse(data, raw=False, quiet=False)
@@ -129,5 +142,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
Dictionary. Raw or processed structured data.

View File

@@ -1,11 +1,21 @@
# jc.parsers.ifconfig
jc - JSON CLI output utility ifconfig Parser
jc - JSON CLI output utility `ifconfig` command output parser
Usage:
Note: No `ifconfig` options are supported.
specify --ifconfig as the first argument if the piped input is coming from ifconfig
Usage (cli):
no ifconfig options are supported.
$ ifconfig | jc --ifconfig
or
$ jc ifconfig
Usage (module):
import jc.parsers.ifconfig
result = jc.parsers.ifconfig.parse(ifconfig_command_output)
Compatibility:
@@ -142,19 +152,16 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## IfconfigParser
```python
IfconfigParser(self, console_output)
```
## InterfaceNotFound
```python
InterfaceNotFound(self, /, *args, **kwargs)
IfconfigParser(console_output)
```
@@ -167,11 +174,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -206,6 +213,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -221,5 +229,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.ini
jc - JSON CLI output utility INI Parser
jc - JSON CLI output utility `INI` file parser
Usage:
Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. Comments must be on their own line.
specify --ini as the first argument if the piped input is coming from an INI file
Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
Usage (cli):
$ cat foo.ini | jc --ini
Usage (module):
import jc.parsers.ini
result = jc.parsers.ini.parse(ini_file_output)
Compatibility:
@@ -43,11 +53,13 @@ Examples:
}
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -57,17 +69,21 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary representing an ini document:
Dictionary representing an ini or simple key/value pair document:
{
ini document converted to a dictionary
see configparser standard library documentation for more details
ini or key/value document converted to a dictionary - see configparser standard
library documentation for more details.
Note: Values starting and ending with quotation marks will have the marks removed.
If you would like to keep the quotation marks, use the -r or raw=True argument.
}
## parse
```python
parse(data, raw=False, quiet=False)

View File

@@ -1,11 +1,21 @@
# jc.parsers.iptables
jc - JSON CLI output utility ipables Parser
jc - JSON CLI output utility `ipables` command output parser
Usage:
Supports `-vLn` and `--line-numbers` for all tables.
Specify --iptables as the first argument if the piped input is coming from iptables
Usage (cli):
Supports -vLn and --line-numbers for all tables
$ sudo iptables -L -t nat | jc --iptables
or
$ jc iptables -L -t nat
Usage (module):
import jc.parsers.iptables
result = jc.parsers.iptables.parse(iptables_command_output)
Compatibility:
@@ -131,11 +141,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -145,11 +157,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -172,6 +184,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -187,5 +200,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

160
docs/parsers/iw_scan.md Normal file
View File

@@ -0,0 +1,160 @@
# jc.parsers.iw_scan
jc - JSON CLI output utility `iw dev <device> scan` command output parser
This parser is considered beta quality. Not all fields are parsed.
Usage (cli):
$ iw dev wlan0 scan | jc --iw-scan
or
$ jc iw dev wlan0 scan
Usage (module):
import jc.parsers.iw-scan
result = jc.parsers.iw-scan.parse(iw-scan_command_output)
Compatibility:
'linux'
Examples:
$ iw dev wlan0 scan | jc --iw-scan -p
[
{
"bssid": "71:31:72:65:e1:a2",
"interface": "wlan0",
"freq": 2462,
"capability": "ESS Privacy ShortSlotTime (0x0411)",
"ssid": "WLAN-1234",
"supported_rates": [
1.0,
2.0,
5.5,
11.0,
18.0,
24.0,
36.0,
54.0
],
"erp": "<no flags>",
"erp_d4.0": "<no flags>",
"rsn": "Version: 1",
"group_cipher": "CCMP",
"pairwise_ciphers": "CCMP",
"authentication_suites": "PSK",
"capabilities": "0x186c",
"extended_supported_rates": [
6.0,
9.0,
12.0,
48.0
],
"ht_rx_mcs_rate_indexes_supported": "0-15",
"primary_channel": 11,
"secondary_channel_offset": "no secondary",
"rifs": 1,
"ht_protection": "no",
"non-gf_present": 1,
"obss_non-gf_present": 0,
"dual_beacon": 0,
"dual_cts_protection": 0,
"stbc_beacon": 0,
"l-sig_txop_prot": 0,
"pco_active": 0,
"pco_phase": 0,
"bss_width_channel_transition_delay_factor": 5,
"extended_capabilities": "HT Information Exchange Supported",
"wmm": "Parameter version 1",
"be": "CW 15-1023, AIFSN 3",
"bk": "CW 15-1023, AIFSN 7",
"vi": "CW 7-15, AIFSN 2, TXOP 3008 usec",
"vo": "CW 3-7, AIFSN 2, TXOP 1504 usec",
"wps": "Version: 1.0",
"wi-fi_protected_setup_state": "2 (Configured)",
"selected_registrar": "0x0",
"response_type": "3 (AP)",
"uuid": "00000000-0000-0003-0000-75317074f1a2",
"manufacturer": "Corporation",
"model": "VGV8539JW",
"model_number": "1.47.000",
"serial_number": "J144024542",
"primary_device_type": "6-0050f204-1",
"device_name": "Wireless Router(WFA)",
"config_methods": "Label, PBC",
"rf_bands": "0x3",
"tsf_usec": 212098649788,
"sta_channel_width_mhz": 20,
"passive_dwell_tus": 20,
"active_dwell_tus": 10,
"channel_width_trigger_scan_interval_s": 300,
"scan_passive_total_per_channel_tus": 200,
"scan_active_total_per_channel_tus": 20,
"beacon_interval_tus": 100,
"signal_dbm": -80.0,
"last_seen_ms": 11420,
"selected_rates": [
1.0,
2.0,
5.5,
11.0
],
"obss_scan_activity_threshold_percent": 0.25,
"ds_parameter_set_channel": 11,
"max_amsdu_length_bytes": 7935,
"minimum_rx_ampdu_time_spacing_usec": 16
},
...
]
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"foo": string/integer/float, # best guess based on value
"bar": string/integer/float,
"baz": string/integer/float
}
]
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,11 +1,21 @@
# jc.parsers.jobs
jc - JSON CLI output utility jobs Parser
jc - JSON CLI output utility `jobs` command output parser
Usage:
Also supports the `-l` option.
specify --jobs as the first argument if the piped input is coming from jobs
Usage (cli):
Also supports the -l option
$ jobs | jc --jobs
or
$ jc jobs
Usage (module):
import jc.parsers.jobs
result = jc.parsers.jobs.parse(jobs_command_output)
Compatibility:
@@ -73,11 +83,13 @@ Example:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -87,11 +99,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -103,6 +115,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -118,5 +131,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

69
docs/parsers/kv.md Normal file
View File

@@ -0,0 +1,69 @@
# jc.parsers.kv
jc - JSON CLI output utility `Key/Value` file parser
Supports files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. Comments must be on their own line.
Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
Usage (cli):
$ cat foo.txt | jc --kv
Usage (module):
import jc.parsers.kv
result = jc.parsers.kv.parse(kv_file_output)
Compatibility:
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
Examples:
$ cat keyvalue.txt
# this file contains key/value pairs
name = John Doe
address=555 California Drive
age: 34
; comments can include # or ;
# delimiter can be = or :
# quoted values have quotation marks stripped by default
# but can be preserved with the -r argument
occupation:"Engineer"
$ cat keyvalue.txt | jc --ini -p
{
"name": "John Doe",
"address": "555 California Drive",
"age": "34",
"occupation": "Engineer"
}
## info
```python
info()
```
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Note: this is just a wrapper for jc.parsers.ini
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary representing the key/value file

View File

@@ -1,9 +1,21 @@
# jc.parsers.last
jc - JSON CLI output utility last Parser
jc - JSON CLI output utility `last` and `lastb` command output parser
Usage:
Supports -w and -F options.
specify --last as the first argument if the piped input is coming from last or lastb
Usage (cli):
$ last | jc --last
or
$ jc last
Usage (module):
import jc.parsers.last
result = jc.parsers.last.parse(last_command_output)
Compatibility:
@@ -11,30 +23,36 @@ Compatibility:
Examples:
$ last | jc --last -p
$ last -F | jc --last -p
[
{
"user": "kbrazil",
"tty": "ttys002",
"hostname": null,
"login": "Thu Feb 27 14:31",
"login": "Mon Dec 28 17:24:10 2020",
"logout": "still logged in"
},
{
"user": "kbrazil",
"tty": "ttys003",
"hostname": null,
"login": "Thu Feb 27 10:38",
"logout": "10:38",
"duration": "00:00"
"login": "Mon Dec 28 17:24:10 2020",
"logout": "Mon Dec 28 17:25:01 2020",
"duration": "00:00",
"login_epoch": 1565891826,
"logout_epoch": 1565895404,
"duration_seconds": 3578
},
{
"user": "kbrazil",
"tty": "ttys003",
"hostname": null,
"login": "Thu Feb 27 10:18",
"logout": "10:18",
"duration": "00:00"
"login": "Mon Dec 28 17:24:10 2020",
"logout": "Mon Dec 28 17:25:01 2020",
"duration": "00:00",
"login_epoch": 1565891826,
"logout_epoch": 1565895404,
"duration_seconds": 3578
},
...
]
@@ -68,11 +86,13 @@ Examples:
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -82,23 +102,27 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
"user": string,
"tty": string,
"hostname": string,
"login": string,
"logout": string,
"duration": string
"user": string,
"tty": string,
"hostname": string,
"login": string,
"logout": string,
"duration": string,
"login_epoch": integer, # available with last -F option
"logout_epoch": integer, # available with last -F option
"duration_seconds": integer # available with last -F option
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -114,5 +138,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,21 +1,26 @@
# jc.parsers.ls
jc - JSON CLI output utility ls Parser
jc - JSON CLI output utility `ls` and `vdir` command output parser
Note: The -l or -b option of ls should be used to correctly parse filenames that include newline characters.
Since ls does not encode newlines in filenames when outputting to a pipe it will cause jc to see
multiple files instead of a single file if -l or -b is not used.
Options supported:
- `lbaR`
- `--time-style=full-iso`
- `-h`: File sizes will be available in text form with `-r` but larger file sizes with human readable suffixes will be converted to `Null` in the default view since the parser attempts to convert this field to an integer.
Usage:
Note: The `-l` or `-b` option of `ls` should be used to correctly parse filenames that include newline characters. Since `ls` does not encode newlines in filenames when outputting to a pipe it will cause `jc` to see multiple files instead of a single file if `-l` or `-b` is not used. Alternatively, `vdir` can be used, which is the same as running `ls -lb`.
specify --ls as the first argument if the piped input is coming from ls
Usage (cli):
ls options supported:
$ ls | jc --ls
-lbaR
--time-style=full-iso
-h file sizes will be available in text form with -r but larger file sizes
with human readable suffixes will be converted to Null in default view
since the parser attempts to convert this field to an integer.
or
$ jc ls
Usage (module):
import jc.parsers.ls
result = jc.parsers.ls.parse(ls_command_output)
Compatibility:
@@ -145,11 +150,13 @@ Examples:
"date": "May 3 2019"
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -159,11 +166,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -178,6 +185,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -193,5 +201,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.lsblk
jc - JSON CLI output utility lsblk Parser
jc - JSON CLI output utility `lsblk` command output parser
Usage:
Usage (cli):
specify --lsblk as the first argument if the piped input is coming from lsblk
$ lsblk | jc --lsblk
or
$ jc lsblk
Usage (module):
import jc.parsers.lsblk
result = jc.parsers.lsblk.parse(lsblk_command_output)
Compatibility:
@@ -212,11 +222,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -226,11 +238,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -277,6 +289,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -292,5 +305,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.lsmod
jc - JSON CLI output utility lsmod Parser
jc - JSON CLI output utility `lsmod` command output parser
Usage:
Usage (cli):
specify --lsmod as the first argument if the piped input is coming from lsmod
$ lsmod | jc --lsmod
or
$ jc lsmod
Usage (module):
import jc.parsers.lsmod
result = jc.parsers.lsmod.parse(lsmod_command_output)
Compatibility:
@@ -103,11 +113,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -117,11 +129,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -134,6 +146,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -149,5 +162,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.lsof
jc - JSON CLI output utility lsof Parser
jc - JSON CLI output utility `lsof` command output parser
Usage:
Usage (cli):
specify --lsof as the first argument if the piped input is coming from lsof
$ lsof | jc --lsof
or
$ jc lsof
Usage (module):
import jc.parsers.lsof
result = jc.parsers.lsof.parse(lsof_command_output)
Compatibility:
@@ -93,11 +103,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -107,11 +119,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -128,6 +140,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -143,5 +156,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.mount
jc - JSON CLI output utility mount Parser
jc - JSON CLI output utility `mount` command output parser
Usage:
Usage (cli):
specify --mount as the first argument if the piped input is coming from mount
$ mount | jc --mount
or
$ jc mount
Usage (module):
import jc.parsers.mount
result = jc.parsers.mount.parse(mount_command_output)
Compatibility:
@@ -53,11 +63,13 @@ Example:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -67,11 +79,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -84,6 +96,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -99,5 +112,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,14 +1,23 @@
# jc.parsers.netstat
jc - JSON CLI output utility netstat Parser
Usage:
Specify --netstat as the first argument if the piped input is coming from netstat
jc - JSON CLI output utility `netstat` command output parser
Caveats:
- Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`)
- Use of the `A` option is not supported on OSX when using the `r` option (e.g. `netstat -rA`)
- Use of multiple 'l' options is not supported on OSX (e.g. 'netstat -rlll')
- Use of the 'A' option is not supported on OSX when using the 'r' option (e.g. netstat -rA)
Usage (cli):
$ netstat | jc --netstat
or
$ jc netstat
Usage (module):
import jc.parsers.netstat
result = jc.parsers.netstat.parse(netstat_command_output)
Compatibility:
@@ -245,11 +254,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -259,11 +270,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -364,6 +375,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -379,5 +391,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.ntpq
jc - JSON CLI output utility ntpq Parser
jc - JSON CLI output utility `ntpq -p` command output parser
Usage:
Usage (cli):
specify --ntpq as the first argument if the piped input is coming from ntpq -p
$ ntpq -p | jc --ntpq
or
$ jc ntpq -p
Usage (module):
import jc.parsers.ntpq
result = jc.parsers.ntpq.parse(ntpq_command_output)
Compatibility:
@@ -179,11 +189,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -193,11 +205,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -216,6 +228,7 @@ Returns:
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -231,5 +244,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,15 @@
# jc.parsers.passwd
jc - JSON CLI output utility /etc/passwd file Parser
jc - JSON CLI output utility `/etc/passwd` file Parser
Usage:
Usage (cli):
specify --passwd as the first argument if the piped input is coming from /etc/passwd
$ cat /etc/passwd | jc --passwd
Usage (module):
import jc.parsers.passwd
result = jc.parsers.passwd.parse(passwd_file_output)
Compatibility:
@@ -75,11 +81,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -89,11 +97,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -107,6 +115,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -122,5 +131,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

186
docs/parsers/ping.md Normal file
View File

@@ -0,0 +1,186 @@
# jc.parsers.ping
jc - JSON CLI output utility `ping` command output parser
Supports `ping` and `ping6` output.
Usage (cli):
Note: Use the ping `-c` (count) option, otherwise data will not be piped to `jc`.
$ ping -c 3 1.2.3.4 | jc --ping
or
$ jc ping -c 3 1.2.3.4
Usage (module):
import jc.parsers.ping
result = jc.parsers.ping.parse(ping_command_output)
Compatibility:
'linux', 'darwin', 'freebsd'
Examples:
$ ping -c 3 -p ff cnn.com | jc --ping -p
{
"destination_ip": "151.101.1.67",
"data_bytes": 56,
"pattern": "0xff",
"destination": "cnn.com",
"packets_transmitted": 3,
"packets_received": 3,
"packet_loss_percent": 0.0,
"duplicates": 0,
"round_trip_ms_min": 28.015,
"round_trip_ms_avg": 32.848,
"round_trip_ms_max": 39.376,
"round_trip_ms_stddev": 4.79,
"responses": [
{
"type": "reply",
"bytes": 64,
"response_ip": "151.101.1.67",
"icmp_seq": 0,
"ttl": 59,
"time_ms": 28.015,
"duplicate": false
},
{
"type": "reply",
"bytes": 64,
"response_ip": "151.101.1.67",
"icmp_seq": 1,
"ttl": 59,
"time_ms": 39.376,
"duplicate": false
},
{
"type": "reply",
"bytes": 64,
"response_ip": "151.101.1.67",
"icmp_seq": 2,
"ttl": 59,
"time_ms": 31.153,
"duplicate": false
}
]
}
$ ping -c 3 -p ff cnn.com | jc --ping -p -r
{
"destination_ip": "151.101.129.67",
"data_bytes": "56",
"pattern": "0xff",
"destination": "cnn.com",
"packets_transmitted": "3",
"packets_received": "3",
"packet_loss_percent": "0.0",
"duplicates": "0",
"round_trip_ms_min": "25.078",
"round_trip_ms_avg": "29.543",
"round_trip_ms_max": "32.553",
"round_trip_ms_stddev": "3.221",
"responses": [
{
"type": "reply",
"bytes": "64",
"response_ip": "151.101.129.67",
"icmp_seq": "0",
"ttl": "59",
"time_ms": "25.078",
"duplicate": false
},
{
"type": "reply",
"bytes": "64",
"response_ip": "151.101.129.67",
"icmp_seq": "1",
"ttl": "59",
"time_ms": "30.999",
"duplicate": false
},
{
"type": "reply",
"bytes": "64",
"response_ip": "151.101.129.67",
"icmp_seq": "2",
"ttl": "59",
"time_ms": "32.553",
"duplicate": false
}
]
}
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary. Structured data with the following schema:
{
"source_ip": string,
"destination_ip": string,
"data_bytes": integer,
"pattern": string, (null if not set)
"destination": string,
"packets_transmitted": integer,
"packets_received": integer,
"packet_loss_percent": float,
"duplicates": integer,
"round_trip_ms_min": float,
"round_trip_ms_avg": float,
"round_trip_ms_max": float,
"round_trip_ms_stddev": float,
"responses": [
{
"type": string, ('reply' or 'timeout')
"timestamp": float,
"bytes": integer,
"response_ip": string,
"icmp_seq": integer,
"ttl": integer,
"time_ms": float,
"duplicate": boolean
}
]
}
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.pip_list
jc - JSON CLI output utility pip-list Parser
jc - JSON CLI output utility `pip-list` command output parser
Usage:
Usage (cli):
specify --pip-list as the first argument if the piped input is coming from pip list
$ pip list | jc --pip-list
or
$ jc pip list
Usage (module):
import jc.parsers.pip_list
result = jc.parsers.pip_list.parse(pip_list_command_output)
Compatibility:
@@ -28,11 +38,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -42,11 +54,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -56,6 +68,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -71,5 +84,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.pip_show
jc - JSON CLI output utility pip-show Parser
jc - JSON CLI output utility `pip-show` command output parser
Usage:
Usage (cli):
specify --pip-show as the first argument if the piped input is coming from pip show
$ pip show | jc --pip-show
or
$ jc pip show
Usage (module):
import jc.parsers.pip_show
result = jc.parsers.pip_show.parse(pip_show_command_output)
Compatibility:
@@ -39,11 +49,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -53,11 +65,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -75,6 +87,7 @@ Returns:
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -90,5 +103,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,13 +1,23 @@
# jc.parsers.ps
jc - JSON CLI output utility ps Parser
jc - JSON CLI output utility `ps` command output parser
Usage:
`ps` options supported:
- `ef`
- `axu`
specify --ps as the first argument if the piped input is coming from ps
Usage (cli):
ps options supported:
- ef
- axu
$ ps | jc --ps
or
$ jc ps
Usage (module):
import jc.parsers.ps
result = jc.parsers.ps.parse(ps_command_output)
Compatibility:
@@ -173,11 +183,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -187,11 +199,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -215,6 +227,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -230,5 +243,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.route
jc - JSON CLI output utility route Parser
jc - JSON CLI output utility `route` command output parser
Usage:
Usage (cli):
specify --route as the first argument if the piped input is coming from route
$ route | jc --route
or
$ jc route
Usage (module):
import jc.parsers.route
result = jc.parsers.route.parse(route_command_output)
Compatibility:
@@ -80,11 +90,13 @@ Examples:
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -94,11 +106,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -119,6 +131,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -134,5 +147,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,15 @@
# jc.parsers.shadow
jc - JSON CLI output utility /etc/shadow file Parser
jc - JSON CLI output utility `/etc/shadow` file parser
Usage:
Usage (cli):
specify --shadow as the first argument if the piped input is coming from /etc/shadow
$ sudo cat /etc/shadow | jc --shadow
Usage (module):
import jc.parsers.shadow
result = jc.parsers.shadow.parse(shadow_file_output)
Compatibility:
@@ -81,11 +87,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -95,11 +103,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -114,6 +122,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -129,5 +138,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.ss
jc - JSON CLI output utility ss Parser
jc - JSON CLI output utility `ss` command output parser
Usage:
Usage (cli):
specify --ss as the first argument if the piped input is coming from ss
$ ss | jc --ss
or
$ jc ss
Usage (module):
import jc.parsers.ss
result = jc.parsers.ss.parse(ss_command_output)
Limitations:
@@ -247,11 +257,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -261,11 +273,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -289,6 +301,7 @@ Returns:
Information from https://www.cyberciti.biz/files/ss.html used to define field names
## parse
```python
parse(data, raw=False, quiet=False)
@@ -304,5 +317,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.stat
jc - JSON CLI output utility stat Parser
jc - JSON CLI output utility `stat` command output parser
Usage:
Usage (cli):
specify --stat as the first argument if the piped input is coming from stat
$ stat * | jc --stat
or
$ jc stat *
Usage (module):
import jc.parsers.stat
result = jc.parsers.stat.parse(stat_command_output)
Compatibility:
@@ -101,11 +111,13 @@ Examples:
..
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -115,11 +127,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -149,6 +161,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -164,5 +177,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

95
docs/parsers/sysctl.md Normal file
View File

@@ -0,0 +1,95 @@
# jc.parsers.sysctl
jc - JSON CLI output utility `sysctl -a` command output parser
Note: Since `sysctl` output is not easily parsable only a very simple key/value object will be output. An attempt is made to convert obvious integers and floats. If no conversion is desired, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
Usage (cli):
$ sysctl -a | jc --sysctl
or
$ jc sysctl -a
Usage (module):
import jc.parsers.sysctl
result = jc.parsers.sysctl.parse(sysctl_command_output)
Compatibility:
'linux', 'darwin', 'freebsd'
Examples:
$ sysctl -a | jc --sysctl -p
{
"user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin",
"user.bc_base_max": 99,
"user.bc_dim_max": 2048,
"user.bc_scale_max": 99,
"user.bc_string_max": 1000,
"user.coll_weights_max": 2,
"user.expr_nest_max": 32
...
}
$ sysctl -a | jc --sysctl -p -r
{
"user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin",
"user.bc_base_max": "99",
"user.bc_dim_max": "2048",
"user.bc_scale_max": "99",
"user.bc_string_max": "1000",
"user.coll_weights_max": "2",
"user.expr_nest_max": "32",
...
}
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary. Structured data with the following schema:
{
"foo": string/integer/float, # best guess based on value
"bar": string/integer/float,
"baz": string/integer/float
}
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.systemctl
jc - JSON CLI output utility systemctl Parser
jc - JSON CLI output utility `systemctl` command output parser
Usage:
Usage (cli):
specify --systemctl as the first argument if the piped input is coming from systemctl
$ systemctl | jc --systemctl
or
$ jc systemctl
Usage (module):
import jc.parsers.systemctl
result = jc.parsers.systemctl.parse(systemctl_command_output)
Compatibility:
@@ -37,11 +47,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -51,11 +63,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -67,6 +79,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -82,5 +95,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.systemctl_lj
jc - JSON CLI output utility systemctl-lj Parser
jc - JSON CLI output utility `systemctl list-jobs` command output parser
Usage:
Usage (cli):
specify --systemctl-lj as the first argument if the piped input is coming from systemctl list-jobs
$ systemctl list-jobs | jc --systemctl-lj
or
$ jc systemctl list-jobs
Usage (module):
import jc.parsers.systemctl_lj
result = jc.parsers.systemctl_lj.parse(systemctl_lj_command_output)
Compatibility:
@@ -56,11 +66,13 @@ Examples:
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -70,11 +82,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -85,6 +97,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -100,5 +113,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.systemctl_ls
jc - JSON CLI output utility systemctl-ls Parser
jc - JSON CLI output utility `systemctl list-sockets` command output parser
Usage:
Usage (cli):
specify --systemctl-ls as the first argument if the piped input is coming from systemctl list-sockets
$ systemctl list-sockets | jc --systemctl-ls
or
$ jc systemctl list-sockets
Usage (module):
import jc.parsers.systemctl_ls
result = jc.parsers.systemctl_ls.parse(systemctl_ls_command_output)
Compatibility:
@@ -31,11 +41,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -45,11 +57,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -59,6 +71,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -74,5 +87,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.systemctl_luf
jc - JSON CLI output utility systemctl-luf Parser
jc - JSON CLI output utility `systemctl list-unit-files` command output parser
Usage:
Usage (cli):
specify --systemctl-luf as the first argument if the piped input is coming from systemctl list-unit-files
$ systemctl list-unit-files | jc --systemctl-luf
or
$ jc systemctl list-unit-files
Usage (module):
import jc.parsers.systemctl_luf
result = jc.parsers.systemctl_luf.parse(systemctl_luf_command_output)
Compatibility:
@@ -28,11 +38,13 @@ Examples:
...
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -42,11 +54,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -55,6 +67,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -70,5 +83,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,19 @@
# jc.parsers.timedatectl
jc - JSON CLI output utility timedatectl Parser
jc - JSON CLI output utility `timedatectl` command output parser
Usage:
Usage (cli):
specify --timedatectl as the first argument if the piped input is coming from timedatectl or timedatectl status
$ timedatectl | jc --timedatectl
or
$ jc timedatectl
Usage (module):
import jc.parsers.timedatectl
result = jc.parsers.timedatectl.parse(timedatectl_command_output)
Compatibility:
@@ -35,11 +45,13 @@ Examples:
"dst_active": "yes"
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -49,7 +61,7 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -68,6 +80,7 @@ Returns:
"dst_active": boolean
}
## parse
```python
parse(data, raw=False, quiet=False)

173
docs/parsers/tracepath.md Normal file
View File

@@ -0,0 +1,173 @@
# jc.parsers.tracepath
jc - JSON CLI output utility `tracepath` command output parser
Supports `tracepath` and `tracepath6` output.
Usage (cli):
$ tracepath 1.2.3.4 | jc --tracepath
or
$ jc tracepath 1.2.3.4
Usage (module):
import jc.parsers.tracepath
result = jc.parsers.tracepath.parse(tracepath_command_output)
Compatibility:
'linux'
Examples:
$ tracepath6 3ffe:2400:0:109::2 | jc --tracepath -p
{
"pmtu": 1480,
"forward_hops": 2,
"return_hops": 2,
"hops": [
{
"ttl": 1,
"guess": true,
"host": "[LOCALHOST]",
"reply_ms": null,
"pmtu": 1500,
"asymmetric_difference": null,
"reached": false
},
{
"ttl": 1,
"guess": false,
"host": "dust.inr.ac.ru",
"reply_ms": 0.411,
"pmtu": null,
"asymmetric_difference": null,
"reached": false
},
{
"ttl": 2,
"guess": false,
"host": "dust.inr.ac.ru",
"reply_ms": 0.39,
"pmtu": 1480,
"asymmetric_difference": 1,
"reached": false
},
{
"ttl": 2,
"guess": false,
"host": "3ffe:2400:0:109::2",
"reply_ms": 463.514,
"pmtu": null,
"asymmetric_difference": null,
"reached": true
}
]
}
$ tracepath6 3ffe:2400:0:109::2 | jc --tracepath -p -r
{
"pmtu": "1480",
"forward_hops": "2",
"return_hops": "2",
"hops": [
{
"ttl": "1",
"guess": true,
"host": "[LOCALHOST]",
"reply_ms": null,
"pmtu": "1500",
"asymmetric_difference": null,
"reached": false
},
{
"ttl": "1",
"guess": false,
"host": "dust.inr.ac.ru",
"reply_ms": "0.411",
"pmtu": null,
"asymmetric_difference": null,
"reached": false
},
{
"ttl": "2",
"guess": false,
"host": "dust.inr.ac.ru",
"reply_ms": "0.390",
"pmtu": "1480",
"asymmetric_difference": "1",
"reached": false
},
{
"ttl": "2",
"guess": false,
"host": "3ffe:2400:0:109::2",
"reply_ms": "463.514",
"pmtu": null,
"asymmetric_difference": null,
"reached": true
}
]
}
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary. Structured data with the following schema:
{
"pmtu": integer,
"forward_hops": integer,
"return_hops": integer,
"hops": [
{
"ttl": integer,
"guess": boolean,
"host": string,
"reply_ms": float,
"pmtu": integer,
"asymmetric_difference": integer,
"reached": boolean
}
]
}
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.

164
docs/parsers/traceroute.md Normal file
View File

@@ -0,0 +1,164 @@
# jc.parsers.traceroute
jc - JSON CLI output utility `traceroute` command output parser
Supports `traceroute` and `traceroute6` output.
Note: On some operating systems you will need to redirect `STDERR` to `STDOUT` for destination info since the header line is sent to `STDERR`. A warning message will be printed to `STDERR` if the header row is not found.
e.g. `$ traceroute 8.8.8.8 2>&1 | jc --traceroute`
Usage (cli):
$ traceroute 1.2.3.4 | jc --traceroute
or
$ jc traceroute 1.2.3.4
Usage (module):
import jc.parsers.traceroute
result = jc.parsers.traceroute.parse(traceroute_command_output)
Compatibility:
'linux', 'darwin', 'freebsd'
Examples:
$ traceroute google.com | jc --traceroute -p
{
"destination_ip": "216.58.194.46",
"destination_name": "google.com",
"hops": [
{
"hop": 1,
"probes": [
{
"annotation": null,
"asn": null,
"ip": "216.230.231.141",
"name": "216-230-231-141.static.houston.tx.oplink.net",
"rtt": 198.574
},
{
"annotation": null,
"asn": null,
"ip": "216.230.231.141",
"name": "216-230-231-141.static.houston.tx.oplink.net",
"rtt": null
},
{
"annotation": null,
"asn": null,
"ip": "216.230.231.141",
"name": "216-230-231-141.static.houston.tx.oplink.net",
"rtt": 198.65
}
]
},
...
]
}
$ traceroute google.com | jc --traceroute -p -r
{
"destination_ip": "216.58.194.46",
"destination_name": "google.com",
"hops": [
{
"hop": "1",
"probes": [
{
"annotation": null,
"asn": null,
"ip": "216.230.231.141",
"name": "216-230-231-141.static.houston.tx.oplink.net",
"rtt": "198.574"
},
{
"annotation": null,
"asn": null,
"ip": "216.230.231.141",
"name": "216-230-231-141.static.houston.tx.oplink.net",
"rtt": null
},
{
"annotation": null,
"asn": null,
"ip": "216.230.231.141",
"name": "216-230-231-141.static.houston.tx.oplink.net",
"rtt": "198.650"
}
]
},
...
]
}
## info
```python
info()
```
## Hop
```python
Hop(idx)
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary. Structured data with the following schema:
{
"destination_ip": string,
"destination_name": string,
"hops": [
{
"hop": integer,
"probes": [
{
"annotation": string,
"asn": integer,
"ip": string,
"name": string,
"rtt": float
}
]
}
]
}
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.

View File

@@ -1,13 +1,21 @@
# jc.parsers.uname
jc - JSON CLI output utility uname Parser
jc - JSON CLI output utility `uname -a` command output parser
Usage:
Note: Must use `uname -a`
specify --uname as the first argument if the piped input is coming from uname
Usage (cli):
Limitations:
$ uname -a | jc --uname
must use 'uname -a'
or
$ jc uname -a
Usage (module):
import jc.parsers.uname
result = jc.parsers.uname.parse(uname_command_output)
Compatibility:
@@ -27,11 +35,13 @@ Example:
"kernel_version": "#74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019"
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -41,7 +51,7 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -58,6 +68,7 @@ Returns:
"kernel_version": string
}
## parse
```python
parse(data, raw=False, quiet=False)

View File

@@ -1,9 +1,19 @@
# jc.parsers.uptime
jc - JSON CLI output utility uptime Parser
jc - JSON CLI output utility `uptime` command output parser
Usage:
Usage (cli):
specify --uptime as the first argument if the piped input is coming from uptime
$ uptime | jc --uptime
or
$ jc uptime
Usage (module):
import jc.parsers.uptime
result = jc.parsers.uptime.parse(uptime_command_output)
Compatibility:
@@ -31,11 +41,13 @@ Example:
"load_15m": "0.05"
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -45,7 +57,7 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -60,6 +72,7 @@ Returns:
"load_15m": float
}
## parse
```python
parse(data, raw=False, quiet=False)

View File

@@ -1,9 +1,19 @@
# jc.parsers.w
jc - JSON CLI output utility w Parser
jc - JSON CLI output utility `w` command output parser
Usage:
Usage (cli):
specify --w as the first argument if the piped input is coming from w
$ w | jc --w
or
$ jc w
Usage (module):
import jc.parsers.w
result = jc.parsers.w.parse(w_command_output)
Compatibility:
@@ -79,11 +89,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -93,11 +105,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -112,6 +124,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -127,5 +140,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

95
docs/parsers/wc.md Normal file
View File

@@ -0,0 +1,95 @@
# jc.parsers.wc
jc - JSON CLI output utility `wc` command output parser
Usage (cli):
$ wc file.txt | jc --wc
or
$ jc wc file.txt
Usage (module):
import jc.parsers.wc
result = jc.parsers.wc.parse(wc_command_output)
Compatibility:
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
Examples:
$ wc * | jc --wc -p
[
{
"filename": "airport-I.json",
"lines": 1,
"words": 30,
"characters": 307
},
{
"filename": "airport-I.out",
"lines": 15,
"words": 33,
"characters": 348
},
{
"filename": "airport-s.json",
"lines": 1,
"words": 202,
"characters": 2152
},
...
]
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"filename": string,
"lines": integer,
"words": integer,
"characters": integer
}
]
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,11 +1,21 @@
# jc.parsers.who
jc - JSON CLI output utility who Parser
jc - JSON CLI output utility `who` command output parser
Usage:
Accepts any of the following who options (or no options): `-aTH`
specify --who as the first argument if the piped input is coming from who
Usage (cli):
accepts any of the following who options (or no options): -aTH
$ who | jc --who
or
$ jc who
Usage (module):
import jc.parsers.who
result = jc.parsers.who.parse(who_command_output)
Compatibility:
@@ -99,11 +109,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -113,11 +125,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -133,6 +145,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -148,5 +161,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.

View File

@@ -1,9 +1,15 @@
# jc.parsers.xml
jc - JSON CLI output utility XML Parser
jc - JSON CLI output utility `XML` file parser
Usage:
Usage (cli):
specify --xml as the first argument if the piped input is coming from an XML file
$ cat foo.xml | jc --xml
Usage (module):
import jc.parsers.xml
result = jc.parsers.xml.parse(xml_file_output)
Compatibility:
@@ -55,11 +61,13 @@ Examples:
...
}
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -69,7 +77,7 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -80,6 +88,7 @@ Returns:
See https://github.com/martinblech/xmltodict for details
}
## parse
```python
parse(data, raw=False, quiet=False)

View File

@@ -1,9 +1,15 @@
# jc.parsers.yaml
jc - JSON CLI output utility YAML Parser
jc - JSON CLI output utility `YAML` file parser
Usage:
Usage (cli):
specify --yaml as the first argument if the piped input is coming from a YAML file
$ cat foo.yaml | jc --yaml
Usage (module):
import jc.parsers.yaml
result = jc.parsers.yaml.parse(yaml_file_output)
Compatibility:
@@ -67,11 +73,13 @@ Examples:
}
]
## info
```python
info(self, /, *args, **kwargs)
info()
```
## process
```python
process(proc_data)
@@ -81,11 +89,11 @@ Final processing to conform to the schema.
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Each dictionary represents a YAML document:
List of Dictionaries. Each dictionary represents a YAML document:
[
{
@@ -94,6 +102,7 @@ Returns:
}
]
## parse
```python
parse(data, raw=False, quiet=False)
@@ -109,5 +118,5 @@ Parameters:
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries representing the YAML documents.

View File

@@ -1,3 +1,4 @@
# jc
JC - JSON CLI output utility
@@ -5,6 +6,8 @@ JC - JSON CLI output utility
This package serializes the output of many standard unix command line tools to JSON format.
For documentation on each parser, see [docs/parsers](https://github.com/kellyjonbrazil/jc/tree/master/docs/parsers).
CLI Example:
$ ls -l /usr/bin | jc --ls -p

View File

@@ -1,5 +1,7 @@
# utils
jc - JSON CLI output utility utils
## warning_message
```python
warning_message(message)
@@ -15,6 +17,7 @@ Returns:
no return, just prints output to STDERR
## error_message
```python
error_message(message)
@@ -30,6 +33,7 @@ Returns:
no return, just prints output to STDERR
## compatibility
```python
compatibility(mod_name, compatible)
@@ -48,3 +52,19 @@ Returns:
no return, just prints output to STDERR
## has_data
```python
has_data(data)
```
Checks if the input contains data. If there are any non-whitespace characters then return True, else return False
Parameters:
data: (string) input to check whether it contains data
Returns:
Boolean True if input string (data) contains non-whitespace characters, otherwise False

View File

@@ -4,6 +4,8 @@
This package serializes the output of many standard unix command line tools to JSON format.
For documentation on each parser, see [docs/parsers](https://github.com/kellyjonbrazil/jc/tree/master/docs/parsers).
CLI Example:
$ ls -l /usr/bin | jc --ls -p

193
jc/cli.py
View File

@@ -11,18 +11,18 @@ import importlib
import textwrap
import signal
import json
import pygments
from pygments import highlight
from pygments.style import Style
from pygments.token import (Name, Number, String, Keyword)
from pygments.lexers import JsonLexer
from pygments.formatters import Terminal256Formatter
import jc.utils
import jc.appdirs as appdirs
class info():
version = '1.11.5'
description = 'jc cli output JSON conversion tool'
version = '1.14.4'
description = 'JSON CLI output utility'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -34,9 +34,11 @@ parsers = [
'airport-s',
'arp',
'blkid',
'cksum',
'crontab',
'crontab-u',
'csv',
'date',
'df',
'dig',
'dmidecode',
@@ -47,13 +49,18 @@ parsers = [
'fstab',
'group',
'gshadow',
'hash',
'hashsum',
'hciconfig',
'history',
'hosts',
'id',
'ifconfig',
'ini',
'iptables',
'iw-scan',
'jobs',
'kv',
'last',
'ls',
'lsblk',
@@ -63,6 +70,7 @@ parsers = [
'netstat',
'ntpq',
'passwd',
'ping',
'pip-list',
'pip-show',
'ps',
@@ -70,14 +78,18 @@ parsers = [
'shadow',
'ss',
'stat',
'sysctl',
'systemctl',
'systemctl-lj',
'systemctl-ls',
'systemctl-luf',
'timedatectl',
'tracepath',
'traceroute',
'uname',
'uptime',
'w',
'wc',
'who',
'xml',
'yaml'
@@ -86,8 +98,8 @@ parsers = [
# List of custom or override parsers.
# Allow any <user_data_dir>/jc/jcparsers/*.py
local_parsers = []
data_dir = appdirs.user_data_dir("jc", "jc")
local_parsers_dir = os.path.join(data_dir, "jcparsers")
data_dir = appdirs.user_data_dir('jc', 'jc')
local_parsers_dir = os.path.join(data_dir, 'jcparsers')
if os.path.isdir(local_parsers_dir):
sys.path.append(data_dir)
for name in os.listdir(local_parsers_dir):
@@ -98,8 +110,52 @@ if os.path.isdir(local_parsers_dir):
parsers.append(plugin_name)
def set_env_colors():
# We only support 2.3.0+, pygments changed color names in 2.4.0.
# startswith is sufficient and avoids potential exceptions from split and int.
if pygments.__version__.startswith('2.3.'):
PYGMENT_COLOR = {
'black': '#ansiblack',
'red': '#ansidarkred',
'green': '#ansidarkgreen',
'yellow': '#ansibrown',
'blue': '#ansidarkblue',
'magenta': '#ansipurple',
'cyan': '#ansiteal',
'gray': '#ansilightgray',
'brightblack': '#ansidarkgray',
'brightred': '#ansired',
'brightgreen': '#ansigreen',
'brightyellow': '#ansiyellow',
'brightblue': '#ansiblue',
'brightmagenta': '#ansifuchsia',
'brightcyan': '#ansiturquoise',
'white': '#ansiwhite',
}
else:
PYGMENT_COLOR = {
'black': 'ansiblack',
'red': 'ansired',
'green': 'ansigreen',
'yellow': 'ansiyellow',
'blue': 'ansiblue',
'magenta': 'ansimagenta',
'cyan': 'ansicyan',
'gray': 'ansigray',
'brightblack': 'ansibrightblack',
'brightred': 'ansibrightred',
'brightgreen': 'ansibrightgreen',
'brightyellow': 'ansibrightyellow',
'brightblue': 'ansibrightblue',
'brightmagenta': 'ansibrightmagenta',
'brightcyan': 'ansibrightcyan',
'white': 'ansiwhite',
}
def set_env_colors(env_colors=None):
"""
Return a dictionary to be used in Pygments custom style class.
Grab custom colors from JC_COLORS environment variable. JC_COLORS env variable takes 4 comma
separated string values and should be in the format of:
@@ -115,40 +171,36 @@ def set_env_colors():
JC_COLORS=default,default,default,default
"""
env_colors = os.getenv('JC_COLORS')
input_error = False
if env_colors:
color_list = env_colors.split(',')
else:
color_list = ['default', 'default', 'default', 'default']
if len(color_list) != 4:
input_error = True
if env_colors and len(color_list) != 4:
print('jc: Warning: could not parse JC_COLORS environment variable\n', file=sys.stderr)
input_error = True
if env_colors:
for color in color_list:
if color not in ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'gray', 'brightblack', 'brightred',
'brightgreen', 'brightyellow', 'brightblue', 'brightmagenta', 'brightcyan', 'white', 'default']:
print('jc: Warning: could not parse JC_COLORS environment variable\n', file=sys.stderr)
input_error = True
for color in color_list:
if color != 'default' and color not in PYGMENT_COLOR:
input_error = True
# if there is an issue with the env variable, just set all colors to default and move on
if input_error:
print('jc: Warning: could not parse JC_COLORS environment variable\n', file=sys.stderr)
color_list = ['default', 'default', 'default', 'default']
# Try the color set in the JC_COLORS env variable first. If it is set to default, then fall back to default colors
return {
Name.Tag: f'bold ansi{color_list[0]}' if not color_list[0] == 'default' else 'bold ansiblue', # key names
Keyword: f'ansi{color_list[1]}' if not color_list[1] == 'default' else 'ansibrightblack', # true, false, null
Number: f'ansi{color_list[2]}' if not color_list[2] == 'default' else 'ansimagenta', # numbers
String: f'ansi{color_list[3]}' if not color_list[3] == 'default' else 'ansigreen' # strings
Name.Tag: f'bold {PYGMENT_COLOR[color_list[0]]}' if color_list[0] != 'default' else f"bold {PYGMENT_COLOR['blue']}", # key names
Keyword: PYGMENT_COLOR[color_list[1]] if color_list[1] != 'default' else PYGMENT_COLOR['brightblack'], # true, false, null
Number: PYGMENT_COLOR[color_list[2]] if color_list[2] != 'default' else PYGMENT_COLOR['magenta'], # numbers
String: PYGMENT_COLOR[color_list[3]] if color_list[3] != 'default' else PYGMENT_COLOR['green'] # strings
}
def piped_output():
"""returns False if stdout is a TTY. True if output is being piped to another program"""
"""Return False if stdout is a TTY. True if output is being piped to another program"""
if sys.stdout.isatty():
return False
else:
@@ -156,34 +208,34 @@ def piped_output():
def ctrlc(signum, frame):
"""exit with error on SIGINT"""
"""Exit with error on SIGINT"""
sys.exit(1)
def parser_shortname(parser_argument):
"""short name of the parser with dashes and no -- prefix"""
"""Return short name of the parser with dashes and no -- prefix"""
return parser_argument[2:]
def parser_argument(parser):
"""short name of the parser with dashes and with -- prefix"""
"""Return short name of the parser with dashes and with -- prefix"""
return f'--{parser}'
def parser_mod_shortname(parser):
"""short name of the parser's module name (no -- prefix and dashes converted to underscores)"""
"""Return short name of the parser's module name (no -- prefix and dashes converted to underscores)"""
return parser.replace('--', '').replace('-', '_')
def parser_module(parser):
"""import the module just in time and return the module object"""
"""Import the module just in time and return the module object"""
shortname = parser_mod_shortname(parser)
path = ('jcparsers.' if shortname in local_parsers else 'jc.parsers.')
return importlib.import_module(path + shortname)
def parsers_text(indent=0, pad=0):
"""return the argument and description information from each parser"""
"""Return the argument and description information from each parser"""
ptext = ''
for parser in parsers:
parser_arg = parser_argument(parser)
@@ -201,7 +253,7 @@ def parsers_text(indent=0, pad=0):
def about_jc():
"""return jc info and the contents of each parser.info as a dictionary"""
"""Return jc info and the contents of each parser.info as a dictionary"""
parser_list = []
for parser in parsers:
@@ -231,7 +283,7 @@ def about_jc():
def helptext(message):
"""return the help text with the list of parsers"""
"""Return the help text with the list of parsers"""
parsers_string = parsers_text(indent=12, pad=17)
helptext_string = f'''
@@ -247,10 +299,10 @@ def helptext(message):
{parsers_string}
Options:
-a about jc
-d debug - show trace messages
-d debug - show traceback (-dd for verbose traceback)
-m monochrome output
-p pretty print output
-q quiet - suppress warnings
-q quiet - suppress parser warnings
-r raw JSON output
Example:
@@ -260,30 +312,30 @@ def helptext(message):
jc -p ls -al
'''
print(textwrap.dedent(helptext_string), file=sys.stderr)
def json_out(data, pretty=False, mono=False, piped_out=False):
# set colors
class JcStyle(Style):
styles = set_env_colors()
return textwrap.dedent(helptext_string)
def json_out(data, pretty=False, env_colors=None, mono=False, piped_out=False):
"""Return a JSON formatted string. String may include color codes or be pretty printed."""
if not mono and not piped_out:
# set colors
class JcStyle(Style):
styles = set_env_colors(env_colors)
if pretty:
print(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
return str(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
else:
print(highlight(json.dumps(data), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
return str(highlight(json.dumps(data), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
else:
if pretty:
print(json.dumps(data, indent=2))
return json.dumps(data, indent=2)
else:
print(json.dumps(data))
return json.dumps(data)
def generate_magic_command(args):
"""
Returns a tuple with a boolean and a command, where the boolean signifies that
Return a tuple with a boolean and a command, where the boolean signifies that
the command is valid, and the command is either a command string or None.
"""
@@ -316,7 +368,7 @@ def generate_magic_command(args):
magic_dict = {}
parser_info = about_jc()['parsers']
# Create a dictionary of magic_commands to their respective parsers.
# create a dictionary of magic_commands to their respective parsers.
for entry in parser_info:
# Update the dict with all of the magic commands for this parser, if they exist.
magic_dict.update({mc: entry['argument'] for mc in entry.get('magic_commands', [])})
@@ -325,7 +377,7 @@ def generate_magic_command(args):
one_word_command = args_given[0]
two_word_command = ' '.join(args_given[0:2])
# Try to get a parser for two_word_command, otherwise get one for one_word_command
# try to get a parser for two_word_command, otherwise get one for one_word_command
found_parser = magic_dict.get(two_word_command, magic_dict.get(one_word_command))
# construct a new command line using the standard syntax: COMMAND | jc --PARSER -OPTIONS
@@ -338,6 +390,7 @@ def generate_magic_command(args):
def magic():
"""Runs the command generated by generate_magic_command() to support magic syntax"""
valid_command, run_command = generate_magic_command(sys.argv)
if valid_command:
os.system(run_command)
@@ -345,7 +398,7 @@ def magic():
elif run_command is None:
return
else:
helptext(f'parser not found for "{run_command}"')
print(helptext(f'parser not found for "{run_command}"'), file=sys.stderr)
sys.exit(1)
@@ -359,6 +412,8 @@ def main():
except AttributeError:
pass
jc_colors = os.getenv('JC_COLORS')
# try magic syntax first: e.g. jc -p ls -al
magic()
@@ -370,54 +425,54 @@ def main():
options.extend(opt[1:])
debug = 'd' in options
verbose_debug = True if options.count('d') > 1 else False
mono = 'm' in options
pretty = 'p' in options
quiet = 'q' in options
raw = 'r' in options
if verbose_debug:
import jc.tracebackplus
jc.tracebackplus.enable(context=11)
if 'a' in options:
json_out(about_jc(), pretty=pretty, mono=mono, piped_out=piped_output())
print(json_out(about_jc(), pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
sys.exit(0)
if sys.stdin.isatty():
helptext('missing piped data')
print(helptext('missing piped data'), file=sys.stderr)
sys.exit(1)
data = sys.stdin.read()
found = False
if debug:
for arg in sys.argv:
parser_name = parser_shortname(arg)
for arg in sys.argv:
parser_name = parser_shortname(arg)
if parser_name in parsers:
# load parser module just in time so we don't need to load all modules
parser = parser_module(arg)
if parser_name in parsers:
# load parser module just in time so we don't need to load all modules
parser = parser_module(arg)
try:
result = parser.parse(data, raw=raw, quiet=quiet)
found = True
break
else:
for arg in sys.argv:
parser_name = parser_shortname(arg)
if parser_name in parsers:
# load parser module just in time so we don't need to load all modules
parser = parser_module(arg)
try:
result = parser.parse(data, raw=raw, quiet=quiet)
found = True
break
except Exception:
except Exception:
if debug:
raise
else:
import jc.utils
jc.utils.error_message(
f'{parser_name} parser could not parse the input data. Did you use the correct parser?\n For details use the -d option.')
f'{parser_name} parser could not parse the input data. Did you use the correct parser?\n'
' For details use the -d or -dd option.')
sys.exit(1)
if not found:
helptext('missing or incorrect arguments')
print(helptext('missing or incorrect arguments'), file=sys.stderr)
sys.exit(1)
json_out(result, pretty=pretty, mono=mono, piped_out=piped_output())
print(json_out(result, pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
if __name__ == '__main__':

View File

@@ -1,11 +1,19 @@
"""jc - JSON CLI output utility airport -I Parser
"""jc - JSON CLI output utility `airport -I` command output parser
Usage:
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
specify --airport as the first argument if the piped input is coming from airport -I (OSX)
Usage (cli):
This program can be found at:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
$ airport -I | jc --airport
or
$ jc airport -I
Usage (module):
import jc.parsers.airport
result = jc.parsers.airport.parse(airport_command_output)
Compatibility:
@@ -55,7 +63,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'airport -I command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -75,7 +83,7 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -131,9 +139,11 @@ def parse(data, raw=False, quiet=False):
raw_output = {}
for line in filter(None, data.splitlines()):
linedata = line.split(':', maxsplit=1)
raw_output[linedata[0].strip().lower().replace(' ', '_').replace('.', '_')] = linedata[1].strip()
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
linedata = line.split(':', maxsplit=1)
raw_output[linedata[0].strip().lower().replace(' ', '_').replace('.', '_')] = linedata[1].strip()
if raw:
return raw_output

View File

@@ -1,11 +1,19 @@
"""jc - JSON CLI output utility airport -s Parser
"""jc - JSON CLI output utility `airport -s` command output parser
Usage:
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
specify --airport as the first argument if the piped input is coming from airport -s (OSX)
Usage (cli):
This program can be found at:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
$ airport -s | jc --airport-s
or
$ jc airport -s
Usage (module):
import jc.parsers.airport_s
result = jc.parsers.airport_s.parse(airport_s_command_output)
Compatibility:
@@ -88,7 +96,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'airport -s command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -108,11 +116,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
"ssid": string,
@@ -165,7 +173,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -173,7 +181,7 @@ def parse(data, raw=False, quiet=False):
raw_output = []
cleandata = list(filter(None, data.splitlines()))
if cleandata:
if jc.utils.has_data(data):
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')

View File

@@ -1,12 +1,19 @@
"""jc - JSON CLI output utility arp Parser
"""jc - JSON CLI output utility `arp` command output parser
Usage:
Supports `arp` and `arp -a` output.
specify --arp as the first argument if the piped input is coming from:
Usage (cli):
arp
or
arp -a
$ arp | jc --arp
or
$ jc arp
Usage (module):
import jc.parsers.arp
result = jc.parsers.arp.parse(arp_command_output)
Compatibility:
@@ -99,7 +106,7 @@ import jc.parsers.universal
class info():
version = '1.5'
version = '1.6'
description = 'arp command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -118,11 +125,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -166,7 +173,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -174,7 +181,7 @@ def parse(data, raw=False, quiet=False):
raw_output = []
cleandata = list(filter(None, data.splitlines()))
if cleandata:
if jc.utils.has_data(data):
# remove final Entries row if -v was used
if cleandata[-1].startswith('Entries:'):

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility blkid Parser
"""jc - JSON CLI output utility `blkid` command output parser
Usage:
Usage (cli):
specify --blkid as the first argument if the piped input is coming from blkid
$ blkid | jc --blkid
or
$ jc blkid
Usage (module):
import jc.parsers.blkid
result = jc.parsers.blkid.parse(blkid_command_output)
Compatibility:
@@ -79,7 +88,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'blkid command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -99,11 +108,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -169,14 +178,15 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
if list(filter(None, data.splitlines())):
if jc.utils.has_data(data):
# if the first field is a device, use normal parsing:
if data.split(maxsplit=1)[0][-1] == ':':
linedata = data.splitlines()

128
jc/parsers/cksum.py Normal file
View File

@@ -0,0 +1,128 @@
"""jc - JSON CLI output utility `cksum` command output parser
This parser works with the following checksum calculation utilities:
- `sum`
- `cksum`
Usage (cli):
$ cksum file.txt | jc --cksum
or
$ jc cksum file.txt
Usage (module):
import jc.parsers.cksum
result = jc.parsers.cksum.parse(cksum_command_output)
Compatibility:
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
Examples:
$ cksum * | jc --cksum -p
[
{
"filename": "__init__.py",
"checksum": 4294967295,
"blocks": 0
},
{
"filename": "airport.py",
"checksum": 2208551092,
"blocks": 3745
},
{
"filename": "airport_s.py",
"checksum": 1113817598,
"blocks": 4572
},
...
]
"""
import jc.utils
class info():
version = '1.0'
description = 'cksum command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
details = 'Parses cksum and sum program output'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
magic_commands = ['cksum', 'sum']
__version__ = info.version
def process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"filename": string,
"checksum": integer,
"blocks": integer
}
]
"""
for entry in proc_data:
int_list = ['checksum', 'blocks']
for key in int_list:
if key in entry:
try:
entry[key] = int(entry[key])
except (ValueError):
entry[key] = None
return proc_data
def parse(data, raw=False, quiet=False):
"""
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
item = {
'filename': line.split(maxsplit=2)[2],
'checksum': line.split(maxsplit=2)[0],
'blocks': line.split(maxsplit=2)[1]
}
raw_output.append(item)
if raw:
return raw_output
else:
return process(raw_output)

View File

@@ -1,8 +1,19 @@
"""jc - JSON CLI output utility crontab command and file Parser
"""jc - JSON CLI output utility `crontab -l` command output and crontab file parser
Usage:
Supports `crontab -l` command output and crontab files.
specify --crontab as the first argument if the piped input is coming from crontab -l or a crontab file
Usage (cli):
$ crontab -l | jc --crontab
or
$ jc crontab -l
Usage (module):
import jc.parsers.crontab
result = jc.parsers.crontab.parse(crontab_output)
Compatibility:
@@ -132,7 +143,7 @@ import jc.parsers.universal
class info():
version = '1.3'
version = '1.4'
description = 'crontab command and file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -152,7 +163,7 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -225,7 +236,8 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
if cleandata:
if jc.utils.has_data(data):
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
@@ -234,7 +246,7 @@ def parse(data, raw=False, quiet=False):
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
if '=' in line and not line.strip()[0].isdigit() and not line.strip()[0] == '@':
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()

View File

@@ -1,8 +1,15 @@
"""jc - JSON CLI output utility crontab file Parser
"""jc - JSON CLI output utility `crontab -l` command output and crontab file parser
Usage:
This version of the `crontab -l` parser supports output that contains user information for processes.
specify --crontab-u as the first argument if the piped input is coming from a crontab file with User specified
Usage (cli):
$ crontab -l | jc --crontab-u
Usage (module):
import jc.parsers.crontab_u
result = jc.parsers.crontab_u.parse(crontab_u_output)
Compatibility:
@@ -133,7 +140,7 @@ import jc.parsers.universal
class info():
version = '1.2'
version = '1.5'
description = 'crontab file parser with user support'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -152,7 +159,7 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -226,7 +233,8 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
if cleandata:
if jc.utils.has_data(data):
# Clear any commented lines
for i, line in reversed(list(enumerate(cleandata))):
if line.strip().startswith('#'):
@@ -235,7 +243,7 @@ def parse(data, raw=False, quiet=False):
# Pop any variable assignment lines
cron_var = []
for i, line in reversed(list(enumerate(cleandata))):
if '=' in line:
if '=' in line and not line.strip()[0].isdigit() and not line.strip()[0] == '@':
var_line = cleandata.pop(i)
var_name = var_line.split('=', maxsplit=1)[0].strip()
var_value = var_line.split('=', maxsplit=1)[1].strip()

View File

@@ -1,11 +1,15 @@
"""jc - JSON CLI output utility csv Parser
"""jc - JSON CLI output utility `csv` file parser
Usage:
The `csv` parser will attempt to automatically detect the delimiter character. If the delimiter cannot be detected it will default to comma. The first row of the file must be a header row.
specify --csv as the first argument if the piped input is coming from a csv file.
the csv parser will attempt to automatically detect the delimiter character.
if the delimiter cannot be detected it will default to comma.
the first row of the file must be a header row.
Usage (cli):
$ cat file.csv | jc --csv
Usage (module):
import jc.parsers.csv
result = jc.parsers.csv.parse(csv_output)
Compatibility:
@@ -63,7 +67,7 @@ import csv
class info():
version = '1.0'
version = '1.1'
description = 'CSV file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -82,11 +86,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Each dictionary represents a row in the csv file:
List of Dictionaries. Each Dictionary represents a row in the csv file:
[
{
@@ -112,7 +116,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -123,7 +127,8 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
if cleandata:
if jc.utils.has_data(data):
dialect = None
try:
dialect = csv.Sniffer().sniff(data[:1024])

187
jc/parsers/date.py Normal file
View File

@@ -0,0 +1,187 @@
"""jc - JSON CLI output utility `date` command output parser
Usage (cli):
$ date | jc --date
or
$ jc date
Usage (module):
import jc.parsers.date
result = jc.parsers.date.parse(date_command_output)
Compatibility:
'linux', 'darwin', 'freebsd'
Examples:
$ date | jc --date -p
{
"year": 2020,
"month_num": 7,
"day": 31,
"hour": 16,
"minute": 48,
"second": 11,
"period": null,
"month": "Jul",
"weekday": "Fri",
"weekday_num": 6,
"timezone": "PDT"
}
$ date | jc --date -p -r
{
"year": "2020",
"month": "Jul",
"day": "31",
"weekday": "Fri",
"hour": "16",
"minute": "50",
"second": "01",
"timezone": "PDT"
}
"""
import jc.utils
class info():
version = '1.1'
description = 'date command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin', 'freebsd']
magic_commands = ['date']
__version__ = info.version
def process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary. Structured data with the following schema:
{
"year": integer,
"month_num": integer,
"day": integer,
"hour": integer,
"minute": integer,
"second": integer,
"period": string,
"month": string,
"weekday": string,
"weekday_num": integer,
"timezone": string
}
"""
month_map = {
"Jan": 1,
"Feb": 2,
"Mar": 3,
"Apr": 4,
"May": 5,
"Jun": 6,
"Jul": 7,
"Aug": 8,
"Sep": 9,
"Oct": 10,
"Nov": 11,
"Dec": 12
}
weekday_map = {
"Sun": 1,
"Mon": 2,
"Tue": 3,
"Wed": 4,
"Thu": 5,
"Fri": 6,
"Sat": 7
}
if proc_data:
return {
"year": int(proc_data['year']),
'month_num': month_map[proc_data['month']],
"day": int(proc_data['day']),
"hour": int(proc_data['hour']),
"minute": int(proc_data['minute']),
"second": int(proc_data['second']),
"period": proc_data['period'] if 'period' in proc_data else None,
"month": proc_data['month'],
"weekday": proc_data['weekday'],
"weekday_num": weekday_map[proc_data['weekday']],
"timezone": proc_data['timezone']
}
else:
return {}
def parse(data, raw=False, quiet=False):
"""
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
Dictionary. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = {}
if jc.utils.has_data(data):
data = data.replace(':', ' ')
split_data = data.split()
# date v8.32 uses a different format depending on locale, so need to support LANG=en_US.UTF-8
if len(split_data) == 9 and ('AM' in split_data or 'am' in split_data or 'PM' in split_data or 'pm' in split_data):
raw_output = {
"year": split_data[8],
"month": split_data[1],
"day": split_data[2],
"weekday": split_data[0],
"hour": split_data[3],
"minute": split_data[4],
"second": split_data[5],
"period": split_data[6],
"timezone": split_data[7]
}
else:
# standard LANG=C date output
raw_output = {
"year": split_data[7],
"month": split_data[1],
"day": split_data[2],
"weekday": split_data[0],
"hour": split_data[3],
"minute": split_data[4],
"second": split_data[5],
"timezone": split_data[6]
}
if raw:
return raw_output
else:
return process(raw_output)

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility df Parser
"""jc - JSON CLI output utility `df` command output parser
Usage:
Usage (cli):
specify --df as the first argument if the piped input is coming from df
$ df | jc --df
or
$ jc df
Usage (module):
import jc.parsers.df
result = jc.parsers.df.parse(df_command_output)
Compatibility:
@@ -73,7 +82,7 @@ import jc.parsers.universal
class info():
version = '1.4'
version = '1.5'
description = 'df command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -92,11 +101,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -177,7 +186,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
@@ -186,7 +195,8 @@ def parse(data, raw=False, quiet=False):
cleandata = data.splitlines()
raw_output = []
if list(filter(None, cleandata)):
if jc.utils.has_data(data):
# fix headers
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('-', '_')

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility dig Parser
"""jc - JSON CLI output utility `dig` command output parser
Usage:
Usage (cli):
Specify --dig as the first argument if the piped input is coming from dig
$ dig example.com | jc --dig
or
$ jc dig example.com
Usage (module):
import jc.parsers.dig
result = jc.parsers.dig.parse(dig_command_output)
Compatibility:
@@ -324,7 +333,7 @@ import jc.utils
class info():
version = '1.2'
version = '1.5'
description = 'dig command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -343,11 +352,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -512,13 +521,17 @@ def parse_authority(authority):
def parse_answer(answer):
# www.cnn.com. 5 IN CNAME turner-tls.map.fastly.net.
answer = answer.split()
answer = answer.split(maxsplit=4)
answer_name = answer[0]
answer_class = answer[2]
answer_type = answer[3]
answer_ttl = answer[1]
answer_data = answer[4]
# remove surrounding quotation marks from answer_data if they exist
if answer_data.startswith('"') and answer_data.endswith('"'):
answer_data = answer_data[1:-1]
return {'name': answer_name,
'class': answer_class,
'type': answer_type,
@@ -557,7 +570,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
@@ -574,100 +587,103 @@ def parse(data, raw=False, quiet=False):
axfr = False
output_entry = {}
for line in cleandata:
if line.startswith('; <<>> ') and ' axfr ' in line.lower():
question = False
authority = False
answer = False
axfr = True
axfr_list = []
continue
if jc.utils.has_data(data):
for line in cleandata:
if ';' not in line and axfr:
axfr_list.append(parse_axfr(line))
output_entry.update({'axfr': axfr_list})
continue
if line.startswith('; <<>> ') and ' axfr ' in line.lower():
question = False
authority = False
answer = False
axfr = True
axfr_list = []
continue
if line.startswith(';; ->>HEADER<<-'):
output_entry = {}
output_entry.update(parse_header(line))
continue
if ';' not in line and axfr:
axfr_list.append(parse_axfr(line))
output_entry.update({'axfr': axfr_list})
continue
if line.startswith(';; flags:'):
output_entry.update(parse_flags_line(line))
continue
if line.startswith(';; ->>HEADER<<-'):
output_entry = {}
output_entry.update(parse_header(line))
continue
if line.startswith(';; QUESTION SECTION:'):
question = True
authority = False
answer = False
axfr = False
continue
if line.startswith(';; flags:'):
output_entry.update(parse_flags_line(line))
continue
if question:
output_entry['question'] = parse_question(line)
question = False
authority = False
answer = False
axfr = False
continue
if line.startswith(';; QUESTION SECTION:'):
question = True
authority = False
answer = False
axfr = False
continue
if line.startswith(';; AUTHORITY SECTION:'):
question = False
authority = True
answer = False
axfr = False
authority_list = []
continue
if question:
output_entry['question'] = parse_question(line)
question = False
authority = False
answer = False
axfr = False
continue
if ';' not in line and authority:
authority_list.append(parse_authority(line))
output_entry.update({'authority': authority_list})
continue
if line.startswith(';; AUTHORITY SECTION:'):
question = False
authority = True
answer = False
axfr = False
authority_list = []
continue
if line.startswith(';; ANSWER SECTION:'):
question = False
authority = False
answer = True
axfr = False
answer_list = []
continue
if ';' not in line and authority:
authority_list.append(parse_authority(line))
output_entry.update({'authority': authority_list})
continue
if ';' not in line and answer:
answer_list.append(parse_answer(line))
output_entry.update({'answer': answer_list})
continue
if line.startswith(';; ANSWER SECTION:'):
question = False
authority = False
answer = True
axfr = False
answer_list = []
continue
# footer consists of 4 lines
# footer line 1
if line.startswith(';; Query time:'):
output_entry.update({'query_time': line.split(':')[1].lstrip()})
continue
if ';' not in line and answer:
answer_list.append(parse_answer(line))
output_entry.update({'answer': answer_list})
continue
# footer line 2
if line.startswith(';; SERVER:'):
output_entry.update({'server': line.split(':')[1].lstrip()})
continue
# footer consists of 4 lines
# footer line 1
if line.startswith(';; Query time:'):
output_entry.update({'query_time': line.split(':')[1].lstrip()})
continue
# footer line 3
if line.startswith(';; WHEN:'):
output_entry.update({'when': line.split(':', maxsplit=1)[1].lstrip()})
continue
# footer line 2
if line.startswith(';; SERVER:'):
output_entry.update({'server': line.split(':')[1].lstrip()})
continue
# footer line 4 (last line)
if line.startswith(';; MSG SIZE rcvd:'):
output_entry.update({'rcvd': line.split(':')[1].lstrip()})
# footer line 3
if line.startswith(';; WHEN:'):
output_entry.update({'when': line.split(':', maxsplit=1)[1].lstrip()})
continue
if output_entry:
raw_output.append(output_entry)
elif line.startswith(';; XFR size:'):
output_entry.update({'size': line.split(':')[1].lstrip()})
# footer line 4 (last line)
if line.startswith(';; MSG SIZE rcvd:'):
output_entry.update({'rcvd': line.split(':')[1].lstrip()})
if output_entry:
raw_output.append(output_entry)
if output_entry:
raw_output.append(output_entry)
elif line.startswith(';; XFR size:'):
output_entry.update({'size': line.split(':')[1].lstrip()})
if output_entry:
raw_output.append(output_entry)
raw_output = list(filter(None, raw_output))
raw_output = list(filter(None, raw_output))
if raw:
return raw_output
else:

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility dmidecode Parser
"""jc - JSON CLI output utility `dmidecode` command output parser
Usage:
Usage (cli):
specify --dmidecode as the first argument if the piped input is coming from dmidecode
$ dmidecode | jc --dmidecode
or
$ jc dmidecode
Usage (module):
import jc.parsers.dmidecode
result = jc.parsers.dmidecode.parse(dmidecode_command_output)
Compatibility:
@@ -102,7 +111,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'dmidecode command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -122,11 +131,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -171,7 +180,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -190,148 +199,150 @@ def parse(data, raw=False, quiet=False):
raw_output = []
data = data.splitlines()
if jc.utils.has_data(data):
# remove header rows
for row in data.copy():
if row:
data.pop(0)
else:
break
data = data.splitlines()
# main parsing loop
for line in data:
# new item
if not line:
item_header = True
item_values = False
value_list = False
# remove header rows
for row in data.copy():
if row:
data.pop(0)
else:
break
# main parsing loop
for line in data:
# new item
if not line:
item_header = True
item_values = False
value_list = False
if item:
if values:
item['values'][attribute] = values
if key_data:
item['values'][f'{key}_data'] = key_data
raw_output.append(item)
item = {}
header = None
key = None
val = None
attribute = None
values = []
key_data = []
continue
# header
if line.startswith('Handle ') and line.endswith('bytes'):
# Handle 0x0000, DMI type 0, 24 bytes
header = line.replace(',', ' ').split()
item = {
'handle': header[1],
'type': header[4],
'bytes': header[5]
}
continue
# description
if item_header:
item_header = False
item_values = True
value_list = False
item['description'] = line
item['values'] = {}
continue
# new item if multiple descriptions in handle
if not item_header and not line.startswith('\t'):
item_header = False
item_values = True
value_list = False
if item:
if values:
item['values'][attribute] = values
if key_data:
item['values'][f'{key}_data'] = key_data
raw_output.append(item)
item = {
'handle': header[1],
'type': header[4],
'bytes': header[5],
'description': line,
'values': {}
}
key = None
val = None
attribute = None
values = []
key_data = []
continue
# keys and values
if item_values \
and len(line.split(':', maxsplit=1)) == 2 \
and line.startswith('\t') \
and not line.startswith('\t\t') \
and not line.strip().endswith(':'):
item_header = False
item_values = True
value_list = False
if item:
if values:
item['values'][attribute] = values
values = []
if key_data:
item['values'][f'{key}_data'] = key_data
raw_output.append(item)
key_data = []
item = {}
header = None
key = None
val = None
attribute = None
values = []
key_data = []
continue
key = line.split(':', maxsplit=1)[0].strip().lower().replace(' ', '_')
val = line.split(':', maxsplit=1)[1].strip()
item['values'].update({key: val})
continue
# header
if line.startswith('Handle ') and line.endswith('bytes'):
# multi-line key
if item_values \
and line.startswith('\t') \
and not line.startswith('\t\t') \
and line.strip().endswith(':'):
item_header = False
item_values = True
value_list = True
# Handle 0x0000, DMI type 0, 24 bytes
header = line.replace(',', ' ').split()
item = {
'handle': header[1],
'type': header[4],
'bytes': header[5]
}
continue
# description
if item_header:
item_header = False
item_values = True
value_list = False
item['description'] = line
item['values'] = {}
continue
# new item if multiple descriptions in handle
if not item_header and not line.startswith('\t'):
item_header = False
item_values = True
value_list = False
if item:
if values:
item['values'][attribute] = values
values = []
if key_data:
item['values'][f'{key}_data'] = key_data
raw_output.append(item)
key_data = []
item = {
'handle': header[1],
'type': header[4],
'bytes': header[5],
'description': line,
'values': {}
}
key = None
val = None
attribute = None
values = []
key_data = []
continue
# keys and values
if item_values \
and len(line.split(':', maxsplit=1)) == 2 \
and line.startswith('\t') \
and not line.startswith('\t\t') \
and not line.strip().endswith(':'):
item_header = False
item_values = True
value_list = False
if values:
item['values'][attribute] = values
attribute = line[:-1].strip().lower().replace(' ', '_')
values = []
if key_data:
item['values'][f'{key}_data'] = key_data
key_data = []
continue
key = line.split(':', maxsplit=1)[0].strip().lower().replace(' ', '_')
val = line.split(':', maxsplit=1)[1].strip()
item['values'].update({key: val})
continue
# multi-line values
if value_list \
and line.startswith('\t\t'):
values.append(line.strip())
continue
# multi-line key
if item_values \
and line.startswith('\t') \
and not line.startswith('\t\t') \
and line.strip().endswith(':'):
item_header = False
item_values = True
value_list = True
# data for hybrid multi-line objects
if item_values \
and not value_list \
and line.startswith('\t\t'):
if f'{key}_data' not in item['values']:
item['values'][f'{key}_data'] = []
key_data.append(line.strip())
continue
if values:
item['values'][attribute] = values
values = []
if key_data:
item['values'][f'{key}_data'] = key_data
key_data = []
attribute = line[:-1].strip().lower().replace(' ', '_')
values = []
continue
# multi-line values
if value_list \
and line.startswith('\t\t'):
values.append(line.strip())
continue
# data for hybrid multi-line objects
if item_values \
and not value_list \
and line.startswith('\t\t'):
if f'{key}_data' not in item['values']:
item['values'][f'{key}_data'] = []
key_data.append(line.strip())
continue
if item:
raw_output.append(item)
if item:
raw_output.append(item)
if raw:
return raw_output

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility du Parser
"""jc - JSON CLI output utility `du` command output parser
Usage:
Usage (cli):
specify --du as the first argument if the piped input is coming from du
$ du | jc --du
or
$ jc du
Usage (module):
import jc.parsers.du
result = jc.parsers.du.parse(du_command_output)
Compatibility:
@@ -73,7 +82,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'du command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -93,11 +102,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -131,18 +140,18 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
cleandata = data.splitlines()
# Clear any blank lines
cleandata = list(filter(None, cleandata))
cleandata = list(filter(None, data.splitlines()))
if jc.utils.has_data(data):
if cleandata:
cleandata.insert(0, 'size name')
raw_output = jc.parsers.universal.simple_table_parse(cleandata)

View File

@@ -1,8 +1,19 @@
"""jc - JSON CLI output utility env Parser
"""jc - JSON CLI output utility `env` and `printenv` command output parser
Usage:
This parser will output a list of dictionaries each containing `name` and `value` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
specify --env as the first argument if the piped input is coming from env
Usage (cli):
$ env | jc --env
or
$ jc env
Usage (module):
import jc.parsers.env
result = jc.parsers.env.parse(env_command_output)
Compatibility:
@@ -52,14 +63,14 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = 'env command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd']
magic_commands = ['env']
magic_commands = ['env', 'printenv']
__version__ = info.version
@@ -71,11 +82,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -109,19 +120,17 @@ def parse(data, raw=False, quiet=False):
Returns:
Dictionary of raw structured data or
list of dictionaries of processed structured data
List of Dictionaries of processed structured data
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = {}
linedata = data.splitlines()
# Clear any blank lines
cleandata = list(filter(None, linedata))
cleandata = list(filter(None, data.splitlines()))
if cleandata:
if jc.utils.has_data(data):
for entry in cleandata:
parsed_line = entry.split('=', maxsplit=1)

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility file command Parser
"""jc - JSON CLI output utility `file` command output parser
Usage:
Usage (cli):
specify --file as the first argument if the piped input is coming from file.
$ file * | jc --file
or
$ jc file *
Usage (module):
import jc.parsers.file
result = jc.parsers.file.parse(file_command_output)
Compatibility:
@@ -48,7 +57,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'file command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -67,11 +76,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -96,7 +105,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -104,23 +113,26 @@ def parse(data, raw=False, quiet=False):
raw_output = []
warned = False
for line in filter(None, data.splitlines()):
linedata = line.rsplit(': ', maxsplit=1)
try:
filename = linedata[0].strip()
filetype = linedata[1].strip()
if jc.utils.has_data(data):
raw_output.append(
{
'filename': filename,
'type': filetype
}
)
except IndexError:
if not warned:
jc.utils.warning_message('Filenames with newline characters detected. Some filenames may be truncated.')
warned = True
for line in filter(None, data.splitlines()):
linedata = line.rsplit(': ', maxsplit=1)
try:
filename = linedata[0].strip()
filetype = linedata[1].strip()
raw_output.append(
{
'filename': filename,
'type': filetype
}
)
except IndexError:
if not warned:
jc.utils.warning_message('Filenames with newline characters detected. Some filenames may be truncated.')
warned = True
if raw:
return raw_output

View File

@@ -1,8 +1,19 @@
"""jc - JSON CLI output utility foo Parser
"""jc - JSON CLI output utility `foo` command output parser
Usage:
<<Short foo description and caveats>>
specify --foo as the first argument if the piped input is coming from foo
Usage (cli):
$ foo | jc --foo
or
$ jc foo
Usage (module):
import jc.parsers.foo
result = jc.parsers.foo.parse(foo_command_output)
Compatibility:
@@ -40,11 +51,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -71,16 +82,18 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
for line in filter(None, data.splitlines()):
# parse the content
pass
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
# parse the content
pass
if raw:
return raw_output

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility free Parser
"""jc - JSON CLI output utility `free` command output parser
Usage:
Usage (cli):
specify --free as the first argument if the piped input is coming from free
$ free | jc --free
or
$ jc free
Usage (module):
import jc.parsers.free
result = jc.parsers.free.parse(free_command_output)
Compatibility:
@@ -53,7 +62,7 @@ import jc.parsers.universal
class info():
version = '1.1'
version = '1.2'
description = 'free command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -72,11 +81,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -116,7 +125,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -124,7 +133,8 @@ def parse(data, raw=False, quiet=False):
cleandata = data.splitlines()
raw_output = []
if cleandata:
if jc.utils.has_data(data):
cleandata[0] = cleandata[0].lower()
cleandata[0] = cleandata[0].replace('buff/cache', 'buff_cache')
cleandata[0] = 'type ' + cleandata[0]

View File

@@ -1,8 +1,13 @@
"""jc - JSON CLI output utility fstab Parser
"""jc - JSON CLI output utility `fstab` file parser
Usage:
Usage (cli):
specify --fstab as the first argument if the piped input is coming from a fstab file
$ cat /etc/fstab | jc --fstab
Usage (module):
import jc.parsers.fstab
result = jc.parsers.fstab.parse(fstab_command_output)
Compatibility:
@@ -70,7 +75,7 @@ import jc.utils
class info():
version = '1.2'
version = '1.3'
description = 'fstab file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -88,11 +93,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -130,7 +135,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -141,7 +146,8 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
if cleandata:
if jc.utils.has_data(data):
for line in cleandata:
output_line = {}
# ignore commented lines

View File

@@ -1,8 +1,13 @@
"""jc - JSON CLI output utility /etc/group file Parser
"""jc - JSON CLI output utility `/etc/group` file parser
Usage:
Usage (cli):
specify --group as the first argument if the piped input is coming from /etc/group
$ cat /etc/group | jc --group
Usage (module):
import jc.parsers.group
result = jc.parsers.group.parse(group_file_output)
Compatibility:
@@ -94,7 +99,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = '/etc/group file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -113,11 +118,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -158,7 +163,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -169,7 +174,8 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
if cleandata:
if jc.utils.has_data(data):
for entry in cleandata:
if entry.startswith('#'):
continue

View File

@@ -1,8 +1,13 @@
"""jc - JSON CLI output utility /etc/gshadow file Parser
"""jc - JSON CLI output utility `/etc/gshadow` file parser
Usage:
Usage (cli):
specify --gshadow as the first argument if the piped input is coming from /etc/gshadow
$ cat /etc/gshadow | jc --gshadow
Usage (module):
import jc.parsers.gshadow
result = jc.parsers.gshadow.parse(gshadow_file_output)
Compatibility:
@@ -60,7 +65,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = '/etc/gshadow file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -79,11 +84,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -120,7 +125,7 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
@@ -131,7 +136,8 @@ def parse(data, raw=False, quiet=False):
# Clear any blank lines
cleandata = list(filter(None, cleandata))
if cleandata:
if jc.utils.has_data(data):
for entry in cleandata:
if entry.startswith('#'):
continue

108
jc/parsers/hash.py Normal file
View File

@@ -0,0 +1,108 @@
"""jc - JSON CLI output utility `hash` command output parser
Usage (cli):
$ hash | jc --hash
Usage (module):
import jc.parsers.hash
result = jc.parsers.hash.parse(hash_command_output)
Compatibility:
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
Examples:
$ hash | jc --hash -p
[
{
"hits": 2,
"command": "/bin/cat"
},
{
"hits": 1,
"command": "/bin/ls"
}
]
"""
import jc.utils
import jc.parsers.universal
class info():
version = '1.0'
description = 'hash command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
__version__ = info.version
def process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"command": string,
"hits": integer
}
]
"""
for entry in proc_data:
# change to int
int_list = ['hits']
for key in int_list:
if key in entry:
try:
key_int = int(entry[key])
entry[key] = key_int
except (ValueError):
entry[key] = None
return proc_data
def parse(data, raw=False, quiet=False):
"""
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
cleandata = data.splitlines()
raw_output = []
if jc.utils.has_data(data):
cleandata[0] = cleandata[0].lower()
raw_output = jc.parsers.universal.simple_table_parse(cleandata)
if raw:
return raw_output
else:
return process(raw_output)

145
jc/parsers/hashsum.py Normal file
View File

@@ -0,0 +1,145 @@
"""jc - JSON CLI output utility `hash sum` command output parser
This parser works with the following hash calculation utilities:
- `md5`
- `md5sum`
- `shasum`
- `sha1sum`
- `sha224sum`
- `sha256sum`
- `sha384sum`
- `sha512sum`
Usage (cli):
$ md5sum file.txt | jc --hashsum
or
$ jc md5sum file.txt
Usage (module):
import jc.parsers.hashsum
result = jc.parsers.hashsum.parse(md5sum_command_output)
Compatibility:
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
Examples:
$ md5sum * | jc --hashsum -p
[
{
"filename": "devtoolset-3-gcc-4.9.2-6.el7.x86_64.rpm",
"hash": "65fc958c1add637ec23c4b137aecf3d3"
},
{
"filename": "digout",
"hash": "5b9312ee5aff080927753c63a347707d"
},
{
"filename": "dmidecode.out",
"hash": "716fd11c2ac00db109281f7110b8fb9d"
},
{
"filename": "file with spaces in the name",
"hash": "d41d8cd98f00b204e9800998ecf8427e"
},
{
"filename": "id-centos.out",
"hash": "4295be239a14ad77ef3253103de976d2"
},
{
"filename": "ifcfg.json",
"hash": "01fda0d9ba9a75618b072e64ff512b43"
},
...
]
"""
import jc.utils
class info():
version = '1.0'
description = 'hashsum command parser (md5sum, shasum, etc.)'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
details = 'Parses MD5 and SHA hash program output'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux', 'darwin', 'cygwin', 'aix', 'freebsd']
magic_commands = ['md5sum', 'md5', 'shasum', 'sha1sum', 'sha224sum', 'sha256sum', 'sha384sum', 'sha512sum']
__version__ = info.version
def process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"filename": string,
"hash": string,
}
]
"""
# no further processing for this parser
return proc_data
def parse(data, raw=False, quiet=False):
"""
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
# check for legacy md5 command output
if line.startswith('MD5 ('):
file_hash = line.split('=', maxsplit=1)[1].strip()
file_name = line.split('=', maxsplit=1)[0].strip()
file_name = file_name[5:]
file_name = file_name[:-1]
# standard md5sum and shasum command output
else:
file_hash = line.split(maxsplit=1)[0]
file_name = line.split(maxsplit=1)[1]
item = {
'filename': file_name,
'hash': file_hash
}
raw_output.append(item)
if raw:
return raw_output
else:
return process(raw_output)

529
jc/parsers/hciconfig.py Normal file
View File

@@ -0,0 +1,529 @@
"""jc - JSON CLI output utility `hciconfig` command output parser
Usage (cli):
$ hciconfig | jc --hciconfig
or
$ jc hciconfig
Usage (module):
import jc.parsers.hciconfig
result = jc.parsers.hciconfig.parse(hciconfig_command_output)
Compatibility:
'linux'
Examples:
$ hciconfig -a | jc --hciconfig -p
[
{
"device": "hci0",
"type": "Primary",
"bus": "USB",
"bd_address": "00:1A:7D:DA:71:13",
"acl_mtu": 310,
"acl_mtu_packets": 10,
"sco_mtu": 64,
"sco_mtu_packets": 8,
"state": [
"UP",
"RUNNING"
],
"rx_bytes": 13905869,
"rx_acl": 0,
"rx_sco": 0,
"rx_events": 393300,
"rx_errors": 0,
"tx_bytes": 62629,
"tx_acl": 0,
"tx_sco": 0,
"tx_commands": 3893,
"tx_errors": 0,
"features": [
"0xff",
"0xff",
"0x8f",
"0xfe",
"0xdb",
"0xff",
"0x5b",
"0x87"
],
"packet_type": [
"DM1",
"DM3",
"DM5",
"DH1",
"DH3",
"DH5",
"HV1",
"HV2",
"HV3"
],
"link_policy": [
"RSWITCH",
"HOLD",
"SNIFF",
"PARK"
],
"link_mode": [
"SLAVE",
"ACCEPT"
],
"name": "CSR8510 A10",
"class": "0x000000",
"service_classes": null,
"device_class": "Miscellaneous",
"hci_version": "4.0 (0x6)",
"hci_revision": "0x22bb",
"lmp_version": "4.0 (0x6)",
"lmp_subversion": "0x22bb",
"manufacturer": "Cambridge Silicon Radio (10)"
},
{
"device": "hci1",
"type": "Primary",
"bus": "USB",
"bd_address": "00:1A:7D:DA:71:13",
"acl_mtu": 310,
"acl_mtu_packets": 10,
"sco_mtu": 64,
"sco_mtu_packets": 8,
"state": [
"DOWN"
],
"rx_bytes": 4388363,
"rx_acl": 0,
"rx_sco": 0,
"rx_events": 122021,
"rx_errors": 0,
"tx_bytes": 52350,
"tx_acl": 0,
"tx_sco": 0,
"tx_commands": 3480,
"tx_errors": 2,
"features": [
"0xff",
"0xff",
"0x8f",
"0xfe",
"0xdb",
"0xff",
"0x5b",
"0x87"
],
"packet_type": [
"DM1",
"DM3",
"DM5",
"DH1",
"DH3",
"DH5",
"HV1",
"HV2",
"HV3"
],
"link_policy": [
"RSWITCH",
"HOLD",
"SNIFF",
"PARK"
],
"link_mode": [
"SLAVE",
"ACCEPT"
]
}
]
$ hciconfig -a | jc --hciconfig -p -r
[
{
"device": "hci0",
"type": "Primary",
"bus": "USB",
"bd_address": "00:1A:7D:DA:71:13",
"acl_mtu": "310",
"acl_mtu_packets": "10",
"sco_mtu": "64",
"sco_mtu_packets": "8",
"state": [
"UP",
"RUNNING"
],
"rx_bytes": "13905869",
"rx_acl": "0",
"rx_sco": "0",
"rx_events": "393300",
"rx_errors": "0",
"tx_bytes": "62629",
"tx_acl": "0",
"tx_sco": "0",
"tx_commands": "3893",
"tx_errors": "0",
"features": [
"0xff",
"0xff",
"0x8f",
"0xfe",
"0xdb",
"0xff",
"0x5b",
"0x87"
],
"packet_type": [
"DM1",
"DM3",
"DM5",
"DH1",
"DH3",
"DH5",
"HV1",
"HV2",
"HV3"
],
"link_policy": [
"RSWITCH",
"HOLD",
"SNIFF",
"PARK"
],
"link_mode": [
"SLAVE",
"ACCEPT"
],
"name": "CSR8510 A10",
"class": "0x000000",
"service_classes": [
"Unspecified"
],
"device_class": "Miscellaneous",
"hci_version": "4.0 (0x6)",
"hci_revision": "0x22bb",
"lmp_version": "4.0 (0x6)",
"lmp_subversion": "0x22bb",
"manufacturer": "Cambridge Silicon Radio (10)"
},
{
"device": "hci1",
"type": "Primary",
"bus": "USB",
"bd_address": "00:1A:7D:DA:71:13",
"acl_mtu": "310",
"acl_mtu_packets": "10",
"sco_mtu": "64",
"sco_mtu_packets": "8",
"state": [
"DOWN"
],
"rx_bytes": "4388363",
"rx_acl": "0",
"rx_sco": "0",
"rx_events": "122021",
"rx_errors": "0",
"tx_bytes": "52350",
"tx_acl": "0",
"tx_sco": "0",
"tx_commands": "3480",
"tx_errors": "2",
"features": [
"0xff",
"0xff",
"0x8f",
"0xfe",
"0xdb",
"0xff",
"0x5b",
"0x87"
],
"packet_type": [
"DM1",
"DM3",
"DM5",
"DH1",
"DH3",
"DH5",
"HV1",
"HV2",
"HV3"
],
"link_policy": [
"RSWITCH",
"HOLD",
"SNIFF",
"PARK"
],
"link_mode": [
"SLAVE",
"ACCEPT"
]
}
]
"""
import jc.utils
class info():
version = '1.0'
description = 'hciconfig command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
# details = 'enter any other details here'
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
compatible = ['linux']
magic_commands = ['hciconfig']
__version__ = info.version
def process(proc_data):
"""
Final processing to conform to the schema.
Parameters:
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of Dictionaries. Structured data with the following schema:
[
{
"device": string,
"type": string,
"bus": string,
"bd_address": string,
"acl_mtu": integer,
"acl_mtu_packets": integer,
"sco_mtu": integer,
"sco_mtu_packets": integer,
"state": [
string
],
"rx_bytes": integer,
"rx_acl": integer,
"rx_sco": integer,
"rx_events": integer,
"rx_errors": integer,
"tx_bytes": integer,
"tx_acl": integer,
"tx_sco": integer,
"tx_commands": integer,
"tx_errors": integer,
"features": [
string
],
"packet_type": [
string
],
"link_policy": [
string
],
"link_mode": [
string
],
"name": string,
"class": string,
"service_classes": [
string # 'Unspecified' is null
],
"device_class": string,
"hci_version": string,
"hci_revision": string,
"lmp_version": string,
"lmp_subversion": string,
"manufacturer": string
}
]
"""
for entry in proc_data:
# integers
int_list = ['acl_mtu', 'acl_mtu_packets', 'sco_mtu', 'sco_mtu_packets', 'rx_bytes', 'rx_acl', 'rx_sco',
'rx_events', 'rx_errors', 'tx_bytes', 'tx_acl', 'tx_sco', 'tx_commands', 'tx_errors']
for key in int_list:
if key in entry:
try:
entry[key] = int(entry[key])
except (ValueError):
entry[key] = None
if 'service_classes' in entry and len(entry['service_classes']) == 1 and 'Unspecified' in entry['service_classes']:
entry['service_classes'] = None
return proc_data
def parse(data, raw=False, quiet=False):
"""
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
device_object = {}
line_count = 0
if jc.utils.has_data(data):
for line in filter(None, data.splitlines()):
line_count += 1
# start of a new device object
# hci0: Type: Primary Bus: USB
if not line[0].isspace():
if device_object:
raw_output.append(device_object)
device_object = {}
line_count = 1
line = line.replace(':', '')
line = line.split()
device_object['device'] = line[0]
device_object['type'] = line[2]
device_object['bus'] = line[4]
continue
# BD Address: 00:50:56:E7:46:1A ACL MTU: 8192:128 SCO MTU: 64:128
if line[0].isspace() and line.lstrip().startswith('BD Address:'):
line = line.split()
device_object['bd_address'] = line[2]
device_object['acl_mtu'] = line[5].split(':')[0]
device_object['acl_mtu_packets'] = line[5].split(':')[1]
device_object['sco_mtu'] = line[8].split(':')[0]
device_object['sco_mtu_packets'] = line[8].split(':')[1]
continue
# UP RUNNING (always line 3)
if line_count == 3:
device_object['state'] = line.split()
continue
# RX bytes:1307 acl:0 sco:0 events:51 errors:0
if line[0].isspace() and line.lstrip().startswith('RX bytes:'):
line = line.replace(':', ' ')
line = line.split()
device_object['rx_bytes'] = line[2]
device_object['rx_acl'] = line[4]
device_object['rx_sco'] = line[6]
device_object['rx_events'] = line[8]
device_object['rx_errors'] = line[10]
continue
# TX bytes:1200 acl:0 sco:0 commands:51 errors:0
if line[0].isspace() and line.lstrip().startswith('TX bytes:'):
line = line.replace(':', ' ')
line = line.split()
device_object['tx_bytes'] = line[2]
device_object['tx_acl'] = line[4]
device_object['tx_sco'] = line[6]
device_object['tx_commands'] = line[8]
device_object['tx_errors'] = line[10]
continue
# Features: 0xff 0xff 0x8f 0xfe 0x83 0xe1 0x08 0x80
if line[0].isspace() and line.lstrip().startswith('Features:'):
device_object['features'] = line.split()[1:]
continue
# Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
if line[0].isspace() and line.lstrip().startswith('Packet type:'):
device_object['packet_type'] = line.split()[2:]
continue
# Link policy: RSWITCH HOLD SNIFF PARK
if line[0].isspace() and line.lstrip().startswith('Link policy:'):
device_object['link_policy'] = line.split()[2:]
continue
# Link mode: SLAVE ACCEPT
if line[0].isspace() and line.lstrip().startswith('Link mode:'):
device_object['link_mode'] = line.split()[2:]
continue
# Name: 'kbrazil-ubuntu'
if line[0].isspace() and line.lstrip().startswith('Name:'):
device_object['name'] = line.split(maxsplit=1)[1][1:-1]
continue
# Class: 0x000000
if line[0].isspace() and line.lstrip().startswith('Class:'):
device_object['class'] = line.split(maxsplit=1)[1]
continue
# Service Classes: Unspecified
if line[0].isspace() and line.lstrip().startswith('Service Classes:'):
device_object['service_classes'] = line.split()[2:]
continue
# Device Class: Miscellaneous,
if line[0].isspace() and line.lstrip().startswith('Device Class:'):
dev_class = line.split()[2]
if dev_class.endswith(','):
dev_class = dev_class[0:-1]
device_object['device_class'] = dev_class
continue
# HCI Version: 4.0 (0x6) Revision: 0x22bb
if line[0].isspace() and line.lstrip().startswith('HCI Version:'):
line = line.split()
device_object['hci_version'] = ' '.join(line[2:4])
device_object['hci_revision'] = line[5]
continue
# LMP Version: 4.0 (0x6) Subversion: 0x22bb
if line[0].isspace() and line.lstrip().startswith('LMP Version:'):
line = line.split()
device_object['lmp_version'] = ' '.join(line[2:4])
device_object['lmp_subversion'] = line[5]
continue
# Manufacturer: Cambridge Silicon Radio (10)
if line[0].isspace() and line.lstrip().startswith('Manufacturer:'):
device_object['manufacturer'] = line.split(maxsplit=1)[1]
continue
if device_object:
raw_output.append(device_object)
if raw:
return raw_output
else:
return process(raw_output)

View File

@@ -1,8 +1,15 @@
"""jc - JSON CLI output utility history Parser
"""jc - JSON CLI output utility `history` command output parser
Usage:
This parser will output a list of dictionaries each containing `line` and `command` keys. If you would like a simple dictionary output, then use the `-r` command-line option or the `raw=True` argument in the `parse()` function.
specify --history as the first argument if the piped input is coming from history
Usage (cli):
$ history | jc --history
Usage (module):
import jc.parsers.history
result = jc.parsers.history.parse(history_command_output)
Compatibility:
@@ -44,7 +51,7 @@ import jc.utils
class info():
version = '1.2'
version = '1.3'
description = 'history command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -63,11 +70,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -101,24 +108,26 @@ def parse(data, raw=False, quiet=False):
Returns:
Dictionary of raw structured data or
list of dictionaries of processed structured data
List of Dictionaries of processed structured data
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = {}
# split lines and clear out any non-ascii chars
linedata = data.encode('ascii', errors='ignore').decode().splitlines()
if jc.utils.has_data(data):
# Skip any blank lines
for entry in filter(None, linedata):
try:
parsed_line = entry.split(maxsplit=1)
raw_output[parsed_line[0]] = parsed_line[1]
except IndexError:
# need to catch indexerror in case there is weird input from prior commands
pass
# split lines and clear out any non-ascii chars
linedata = data.encode('ascii', errors='ignore').decode().splitlines()
# Skip any blank lines
for entry in filter(None, linedata):
try:
parsed_line = entry.split(maxsplit=1)
raw_output[parsed_line[0]] = parsed_line[1]
except IndexError:
# need to catch indexerror in case there is weird input from prior commands
pass
if raw:
return raw_output

View File

@@ -1,8 +1,13 @@
"""jc - JSON CLI output utility hosts Parser
"""jc - JSON CLI output utility `/etc/hosts` file parser
Usage:
Usage (cli):
specify --hosts as the first argument if the piped input is coming from a hosts file
$ cat /etc/hosts | jc --hosts
Usage (module):
import jc.parsers.hosts
result = jc.parsers.hosts.parse(hosts_file_output)
Compatibility:
@@ -61,7 +66,7 @@ import jc.utils
class info():
version = '1.1'
version = '1.2'
description = '/etc/hosts file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -79,11 +84,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -111,18 +116,18 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
cleandata = data.splitlines()
# Clear any blank lines
cleandata = list(filter(None, cleandata))
cleandata = list(filter(None, data.splitlines()))
if jc.utils.has_data(data):
if cleandata:
for line in cleandata:
output_line = {}
# ignore commented lines

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility id Parser
"""jc - JSON CLI output utility `id` command output parser
Usage:
Usage (cli):
specify --id as the first argument if the piped input is coming from id
$ id | jc --id
or
$ jc id
Usage (module):
import jc.parsers.id
result = jc.parsers.id.parse(id_command_output)
Compatibility:
@@ -70,7 +79,7 @@ import jc.utils
class info():
version = '1.0'
version = '1.1'
description = 'id command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -90,7 +99,7 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
@@ -160,18 +169,18 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
Dictionary. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = {}
cleandata = data.split()
# Clear any blank lines
cleandata = list(filter(None, cleandata))
cleandata = list(filter(None, data.split()))
if jc.utils.has_data(data):
if cleandata:
for section in cleandata:
if section.startswith('uid'):
uid_parsed = section.replace('(', '=').replace(')', '=')

View File

@@ -1,10 +1,19 @@
"""jc - JSON CLI output utility ifconfig Parser
"""jc - JSON CLI output utility `ifconfig` command output parser
Usage:
Note: No `ifconfig` options are supported.
specify --ifconfig as the first argument if the piped input is coming from ifconfig
Usage (cli):
no ifconfig options are supported.
$ ifconfig | jc --ifconfig
or
$ jc ifconfig
Usage (module):
import jc.parsers.ifconfig
result = jc.parsers.ifconfig.parse(ifconfig_command_output)
Compatibility:
@@ -147,7 +156,7 @@ import jc.utils
class info():
version = '1.7'
version = '1.8'
description = 'ifconfig command parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -372,8 +381,6 @@ class IfconfigParser(object):
class InterfaceNotFound(Exception):
"""
"""
pass
@@ -383,11 +390,11 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (List of Dictionaries) raw structured data to process
Returns:
List of dictionaries. Structured data with the following schema:
List of Dictionaries. Structured data with the following schema:
[
{
@@ -468,21 +475,23 @@ def parse(data, raw=False, quiet=False):
Returns:
List of dictionaries. Raw or processed structured data.
List of Dictionaries. Raw or processed structured data.
"""
if not quiet:
jc.utils.compatibility(__name__, info.compatible)
raw_output = []
parsed = IfconfigParser(console_output=data)
interfaces = parsed.get_interfaces()
if jc.utils.has_data(data):
# convert ifconfigparser output to a dictionary
for iface in interfaces:
d = interfaces[iface]._asdict()
dct = dict(d)
raw_output.append(dct)
parsed = IfconfigParser(console_output=data)
interfaces = parsed.get_interfaces()
# convert ifconfigparser output to a dictionary
for iface in interfaces:
d = interfaces[iface]._asdict()
dct = dict(d)
raw_output.append(dct)
if raw:
return raw_output

View File

@@ -1,8 +1,17 @@
"""jc - JSON CLI output utility INI Parser
"""jc - JSON CLI output utility `INI` file parser
Usage:
Parses standard `INI` files and files containing simple key/value pairs. Delimiter can be `=` or `:`. Missing values are supported. Comment prefix can be `#` or `;`. Comments must be on their own line.
specify --ini as the first argument if the piped input is coming from an INI file
Note: Values starting and ending with quotation marks will have the marks removed. If you would like to keep the quotation marks, use the `-r` command-line argument or the `raw=True` argument in `parse()`.
Usage (cli):
$ cat foo.ini | jc --ini
Usage (module):
import jc.parsers.ini
result = jc.parsers.ini.parse(ini_file_output)
Compatibility:
@@ -47,7 +56,7 @@ import configparser
class info():
version = '1.0'
version = '1.3'
description = 'INI file parser'
author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com'
@@ -66,19 +75,37 @@ def process(proc_data):
Parameters:
proc_data: (dictionary) raw structured data to process
proc_data: (Dictionary) raw structured data to process
Returns:
Dictionary representing an ini document:
Dictionary representing an ini or simple key/value pair document:
{
ini document converted to a dictionary
see configparser standard library documentation for more details
ini or key/value document converted to a dictionary - see configparser standard
library documentation for more details.
Note: Values starting and ending with quotation marks will have the marks removed.
If you would like to keep the quotation marks, use the -r or raw=True argument.
}
"""
# remove quotation marks from beginning and end of values
for heading in proc_data:
# standard ini files with headers
if isinstance(proc_data[heading], dict):
for key, value in proc_data[heading].items():
if value is not None and value.startswith('"') and value.endswith('"'):
proc_data[heading][key] = value.lstrip('"').rstrip('"')
elif value is None:
proc_data[heading][key] = ''
# simple key/value files with no headers
else:
if proc_data[heading] is not None and proc_data[heading].startswith('"') and proc_data[heading].endswith('"'):
proc_data[heading] = proc_data[heading].lstrip('"').rstrip('"')
elif proc_data[heading] is None:
proc_data[heading] = ''
# No further processing
return proc_data
@@ -101,10 +128,19 @@ def parse(data, raw=False, quiet=False):
raw_output = {}
if data:
ini = configparser.ConfigParser()
ini.read_string(data)
raw_output = {s: dict(ini.items(s)) for s in ini.sections()}
if jc.utils.has_data(data):
ini = configparser.ConfigParser(allow_no_value=True, interpolation=None)
try:
ini.read_string(data)
raw_output = {s: dict(ini.items(s)) for s in ini.sections()}
except configparser.MissingSectionHeaderError:
data = '[data]\n' + data
ini.read_string(data)
output_dict = {s: dict(ini.items(s)) for s in ini.sections()}
for key, value in output_dict['data'].items():
raw_output[key] = value
if raw:
return raw_output

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