mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2026-04-03 17:44:07 +02:00
Compare commits
414 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcc7e52949 | ||
|
|
3ab9d48014 | ||
|
|
7eddf41c5f | ||
|
|
27a196c938 | ||
|
|
e4324f05fb | ||
|
|
d36b332bd7 | ||
|
|
1f034826f6 | ||
|
|
246c707c98 | ||
|
|
b5d8968144 | ||
|
|
f7b9fbefdd | ||
|
|
b1fc453383 | ||
|
|
7581c8d0f4 | ||
|
|
32bf8ad6f4 | ||
|
|
b083bcc10f | ||
|
|
4f6fdd120d | ||
|
|
eb0038be24 | ||
|
|
7ecdf819fa | ||
|
|
c6aa4d0835 | ||
|
|
7c584b89a6 | ||
|
|
c166c0bfda | ||
|
|
a8dd3f7802 | ||
|
|
3b0e2f03f3 | ||
|
|
8390ae48c8 | ||
|
|
2db82c0a7e | ||
|
|
6147954075 | ||
|
|
691df271fc | ||
|
|
89f52b95f7 | ||
|
|
146acc1bf6 | ||
|
|
c4a345f59a | ||
|
|
dfd2703f75 | ||
|
|
325fab2de7 | ||
|
|
f3d00cf38a | ||
|
|
14838f7f5d | ||
|
|
af74047b81 | ||
|
|
660c59129c | ||
|
|
89a88e186e | ||
|
|
f861cf95b9 | ||
|
|
ee8f06cbdb | ||
|
|
a2e8b3c7b6 | ||
|
|
6c83846075 | ||
|
|
e0681eebb9 | ||
|
|
e5732d1cea | ||
|
|
6e7ae3cd3f | ||
|
|
f95632d1aa | ||
|
|
2f8b7b26e5 | ||
|
|
10292f7502 | ||
|
|
aef54705f5 | ||
|
|
bba5980fa5 | ||
|
|
977425abfb | ||
|
|
37a3565a1b | ||
|
|
13deb8bfb6 | ||
|
|
a3ed9d075a | ||
|
|
fb0ced549e | ||
|
|
7eb31bc7d2 | ||
|
|
6a06a39142 | ||
|
|
bdcdaee6c5 | ||
|
|
605353fdce | ||
|
|
490c9e1769 | ||
|
|
6ebebb659d | ||
|
|
0e70c5ee12 | ||
|
|
cd531acf60 | ||
|
|
908ac1f61c | ||
|
|
f5c7e7e404 | ||
|
|
001c700b5b | ||
|
|
9b41e9bef0 | ||
|
|
34bd6e32dc | ||
|
|
c5d058490b | ||
|
|
dd1ae6d9a7 | ||
|
|
d8ea9bde82 | ||
|
|
125edc9c90 | ||
|
|
15ea43e394 | ||
|
|
b55b02687c | ||
|
|
da611f0ac6 | ||
|
|
b8b8dfead4 | ||
|
|
4290a3cbd1 | ||
|
|
a5e2203cee | ||
|
|
e28c08b136 | ||
|
|
a4b6846f63 | ||
|
|
2bc8307861 | ||
|
|
9b39917c79 | ||
|
|
57c13cc0a3 | ||
|
|
b7355fd30d | ||
|
|
93ae309e40 | ||
|
|
5d8f8365e2 | ||
|
|
f26909eefb | ||
|
|
55bfbb2797 | ||
|
|
8970b8342a | ||
|
|
5285e699c3 | ||
|
|
275f3860d5 | ||
|
|
a73fdb7478 | ||
|
|
f2d746403a | ||
|
|
b7dbf2c49b | ||
|
|
21f3c97788 | ||
|
|
14b727cc71 | ||
|
|
abee226591 | ||
|
|
293ad39f4b | ||
|
|
9244302581 | ||
|
|
753cac25fb | ||
|
|
0548263e89 | ||
|
|
53776a9bf8 | ||
|
|
cc7def9b76 | ||
|
|
11a4422c25 | ||
|
|
3a44785260 | ||
|
|
e0d430c26c | ||
|
|
417b70020a | ||
|
|
7b29c464b7 | ||
|
|
26d5529d86 | ||
|
|
852103c478 | ||
|
|
26a115421b | ||
|
|
755b941a9a | ||
|
|
fd1ca82d86 | ||
|
|
6fe175344f | ||
|
|
3590cda13a | ||
|
|
2f1011dd85 | ||
|
|
2b155261b3 | ||
|
|
02f4d606d0 | ||
|
|
577811f00b | ||
|
|
b4098d67a3 | ||
|
|
88bd7554ae | ||
|
|
b5ec16c5ca | ||
|
|
68fcb60a14 | ||
|
|
e4781d60ce | ||
|
|
6201fb346a | ||
|
|
f88c8343f9 | ||
|
|
25410d3316 | ||
|
|
4ff9952938 | ||
|
|
5e3f63a412 | ||
|
|
e1f57be69e | ||
|
|
2c65d5eecc | ||
|
|
aa621f2f1e | ||
|
|
ac932c6e59 | ||
|
|
029f79da16 | ||
|
|
153b2b4a7a | ||
|
|
709b2fe4ee | ||
|
|
09c1fccc58 | ||
|
|
fd254d99b7 | ||
|
|
88bd2c1722 | ||
|
|
d03e2f0fc1 | ||
|
|
3f12a393bd | ||
|
|
8c21284c50 | ||
|
|
e7d396c215 | ||
|
|
f238fac0eb | ||
|
|
017228f80d | ||
|
|
286c5fa943 | ||
|
|
74cfc13abe | ||
|
|
0ee4a6c377 | ||
|
|
283433578d | ||
|
|
9559c85057 | ||
|
|
c5c020f565 | ||
|
|
95ec79bceb | ||
|
|
8f8be8aa33 | ||
|
|
5b60c7445a | ||
|
|
d9dbcc8b52 | ||
|
|
79bc525970 | ||
|
|
9dae1091dd | ||
|
|
74d3ac686a | ||
|
|
cf3cc636ba | ||
|
|
a720441e1d | ||
|
|
0a7ed0959d | ||
|
|
eb83c9b86d | ||
|
|
5c0142dd19 | ||
|
|
c326c8dc83 | ||
|
|
fc4082a03f | ||
|
|
c8655565ff | ||
|
|
638f879f16 | ||
|
|
1d221bf7e6 | ||
|
|
60ea71f0ef | ||
|
|
d8bdd35a3f | ||
|
|
7463891c53 | ||
|
|
7537aec76f | ||
|
|
62234e39a8 | ||
|
|
be004b7b3f | ||
|
|
82539444b2 | ||
|
|
a571d3cbaf | ||
|
|
a038c14c23 | ||
|
|
25a85d874c | ||
|
|
884c36ff42 | ||
|
|
b98e72b8b4 | ||
|
|
05885c0096 | ||
|
|
4c9761231a | ||
|
|
656eaa1508 | ||
|
|
1560dcddcf | ||
|
|
08d4cd4870 | ||
|
|
9767a50ced | ||
|
|
cd86890ed1 | ||
|
|
ba0dd3b9ca | ||
|
|
8d7fa07ffd | ||
|
|
cade1bfe6e | ||
|
|
daec4ab0a7 | ||
|
|
3c96bc3196 | ||
|
|
7f7d8d4bd6 | ||
|
|
47263661a4 | ||
|
|
4c42a086d2 | ||
|
|
5d2541a5c4 | ||
|
|
d91d170b49 | ||
|
|
6d1f4584a9 | ||
|
|
1d76d96bcf | ||
|
|
e8847c998c | ||
|
|
da88e49bae | ||
|
|
65c3a12e54 | ||
|
|
d8d600cc36 | ||
|
|
507999b117 | ||
|
|
8ad164eb34 | ||
|
|
a507df140b | ||
|
|
8912a99986 | ||
|
|
1953f98828 | ||
|
|
7515218ddd | ||
|
|
36c1120136 | ||
|
|
8fa0fe64d8 | ||
|
|
c1a8201b14 | ||
|
|
398bbac48c | ||
|
|
ea71a42bbd | ||
|
|
1c16d25b17 | ||
|
|
9d12ded889 | ||
|
|
5312701515 | ||
|
|
808c7bc0a9 | ||
|
|
4d394015f4 | ||
|
|
3638298af8 | ||
|
|
5f00973e40 | ||
|
|
0f6e2c14fc | ||
|
|
51813da619 | ||
|
|
e7751322ea | ||
|
|
26ef298437 | ||
|
|
badaf8ce73 | ||
|
|
b123a62203 | ||
|
|
cfd77e4252 | ||
|
|
38f814072e | ||
|
|
a0db7754e3 | ||
|
|
f07620afc7 | ||
|
|
c1b0d27752 | ||
|
|
430a5108aa | ||
|
|
111ce92fc9 | ||
|
|
c851e8a58d | ||
|
|
39f4bcd9b4 | ||
|
|
4a610c4c81 | ||
|
|
89ee11945d | ||
|
|
dadb09b74a | ||
|
|
1b1f638b97 | ||
|
|
794fc4ed44 | ||
|
|
72f735bf92 | ||
|
|
912877f25a | ||
|
|
2772c5ae43 | ||
|
|
a7ad24d2cb | ||
|
|
a364a6a9fa | ||
|
|
7b2dc86a8d | ||
|
|
ad645636d0 | ||
|
|
2f2f297b29 | ||
|
|
099ae3fde0 | ||
|
|
e9febe98ac | ||
|
|
5fbd07cccf | ||
|
|
5fed4698c2 | ||
|
|
ed7eb0983a | ||
|
|
90c7e18e5f | ||
|
|
953ab5c3bd | ||
|
|
699c97d8a0 | ||
|
|
e4ca0de92a | ||
|
|
04745a36b8 | ||
|
|
5936940532 | ||
|
|
b3eb064b67 | ||
|
|
e4b41057e3 | ||
|
|
1d41c46cc7 | ||
|
|
a5c444587b | ||
|
|
a56f471be9 | ||
|
|
6a6b26ed8d | ||
|
|
f62446c152 | ||
|
|
56011f1f17 | ||
|
|
6d44091c80 | ||
|
|
440c458eb4 | ||
|
|
798250af61 | ||
|
|
c762de29c6 | ||
|
|
0701e65e97 | ||
|
|
209d54e8b5 | ||
|
|
2b38462de7 | ||
|
|
1e8e553316 | ||
|
|
ab42e6bb15 | ||
|
|
6802884540 | ||
|
|
7cb8577b96 | ||
|
|
55810ccd1f | ||
|
|
f9921720cd | ||
|
|
cda1ebd271 | ||
|
|
6901e4a23a | ||
|
|
6bc21d3c73 | ||
|
|
1ef231e26a | ||
|
|
3cd43f0f98 | ||
|
|
1565019966 | ||
|
|
0a4de2d3a1 | ||
|
|
a058f6c174 | ||
|
|
d8e5d03b01 | ||
|
|
9dc62eff2e | ||
|
|
d4fea17c57 | ||
|
|
3dd7a5b77e | ||
|
|
d77c90a3ba | ||
|
|
01f0c20df0 | ||
|
|
aafbe576b3 | ||
|
|
bd68ad4034 | ||
|
|
bfee017c13 | ||
|
|
61f532cfd0 | ||
|
|
58dbbb75b6 | ||
|
|
8d88b91fcf | ||
|
|
ad39fc6029 | ||
|
|
89f1fd96e6 | ||
|
|
bd425f2493 | ||
|
|
46962ff02a | ||
|
|
e4cb88b051 | ||
|
|
32840703dc | ||
|
|
1f7aafd041 | ||
|
|
7378d5dce4 | ||
|
|
84f76866cd | ||
|
|
322da9ea6a | ||
|
|
58645301ec | ||
|
|
1e18dd30a8 | ||
|
|
cc6a19adcc | ||
|
|
2a5588b177 | ||
|
|
20f9b7f88b | ||
|
|
d7e32313cd | ||
|
|
fb5654d3c4 | ||
|
|
258f1433b3 | ||
|
|
fb723ae8bd | ||
|
|
283b89e37c | ||
|
|
f450f9eb8b | ||
|
|
b3f8cf99a4 | ||
|
|
4301ea8cae | ||
|
|
c672d1c174 | ||
|
|
229e953a38 | ||
|
|
87b506dc9b | ||
|
|
15c9002d9e | ||
|
|
042aaa61b9 | ||
|
|
ef856c6ba5 | ||
|
|
9cf5be73e3 | ||
|
|
63fc149e2a | ||
|
|
3c25839350 | ||
|
|
58246e33b7 | ||
|
|
8b1407c706 | ||
|
|
2fde4a4e22 | ||
|
|
60b9e97982 | ||
|
|
0adac79c0f | ||
|
|
9f485b5981 | ||
|
|
db17d21b8f | ||
|
|
996d394e89 | ||
|
|
5885b960f9 | ||
|
|
79987b35f3 | ||
|
|
661b3ef311 | ||
|
|
fb422726a8 | ||
|
|
4fb6f3ea59 | ||
|
|
f78fe771e1 | ||
|
|
567b887253 | ||
|
|
e516e6b946 | ||
|
|
62748676aa | ||
|
|
7351c72e45 | ||
|
|
2b7405c5e2 | ||
|
|
e2c77cb935 | ||
|
|
7ac621e4c9 | ||
|
|
d8b5d6c66c | ||
|
|
22b461eb4b | ||
|
|
b37ee8555a | ||
|
|
1d0ad2f045 | ||
|
|
ceccfb2c81 | ||
|
|
03c02953cd | ||
|
|
f254a0eaa1 | ||
|
|
9e3b88727c | ||
|
|
b12217466e | ||
|
|
8b9c932f9b | ||
|
|
5986ce03db | ||
|
|
a7b0e936e4 | ||
|
|
cb02211424 | ||
|
|
bd443bf392 | ||
|
|
1f547edd36 | ||
|
|
e4bac3a493 | ||
|
|
5e6bfa681a | ||
|
|
276160125e | ||
|
|
d4ae5543f2 | ||
|
|
55f360e267 | ||
|
|
fdedab2a0c | ||
|
|
a9be42e303 | ||
|
|
6da9510e46 | ||
|
|
0431798178 | ||
|
|
62432f3c48 | ||
|
|
9fbbc30906 | ||
|
|
d1567d1f62 | ||
|
|
6ca1f5970b | ||
|
|
1c880b9e24 | ||
|
|
3b7d54c720 | ||
|
|
44a7406057 | ||
|
|
8157dcfdb1 | ||
|
|
28762aea15 | ||
|
|
439871ea9f | ||
|
|
c9180b005c | ||
|
|
b14e0725f8 | ||
|
|
70fe3dcb4d | ||
|
|
8c554604a4 | ||
|
|
a0a35454bd | ||
|
|
e8467e2af5 | ||
|
|
7515deb566 | ||
|
|
ed9e52af24 | ||
|
|
592a380410 | ||
|
|
1a458d2d5b | ||
|
|
0e4cf53b92 | ||
|
|
e2f06ccb33 | ||
|
|
8abff004cd | ||
|
|
c4a0e2e3fe | ||
|
|
4f10f79c73 | ||
|
|
69e7a560fd | ||
|
|
59b1055808 | ||
|
|
6ed48c6289 | ||
|
|
f2fb4d3f41 | ||
|
|
6aeea59ea8 | ||
|
|
d016f3bbb3 | ||
|
|
7131c29718 | ||
|
|
7432442983 | ||
|
|
5344883394 | ||
|
|
3fcd2f6c2e | ||
|
|
f3d84bd5bf | ||
|
|
549780c232 | ||
|
|
2a6da69b82 |
8
.github/workflows/pythonapp.yml
vendored
8
.github/workflows/pythonapp.yml
vendored
@@ -14,10 +14,16 @@ 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
|
||||
- name: "Set up timezone to America/Los_Angeles"
|
||||
uses: szenius/set-timezone@v1.0
|
||||
with:
|
||||
timezoneLinux: "America/Los_Angeles"
|
||||
timezoneMacos: "America/Los_Angeles"
|
||||
timezoneWindows: "Pacific Standard Time"
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
|
||||
82
CHANGELOG
82
CHANGELOG
@@ -1,7 +1,87 @@
|
||||
jc changelog
|
||||
|
||||
20210418 v1.15.2
|
||||
- Add systeminfo parser tested on Windows
|
||||
- Update dig parser to fix an issue with IPv6 addresses in the server field
|
||||
- Update dig parser to fix an issue when axfr entries contain a semicolon
|
||||
- Update dig parser to add support for Additional Section and Opt Pseudosection
|
||||
- Update dig parser to add query_size field
|
||||
- Use dig parser as the main example in readme, documentation, and man page
|
||||
- Standardize int, float, and boolean conversion rules with functions in jc.utils
|
||||
|
||||
20210413 v1.15.1
|
||||
- New feature to show parser documentation interactively with -h --parser_name
|
||||
for example: $ jc -h --arp
|
||||
- Add man page to pypi package for easier packaging in homebrew
|
||||
- Update rpm-qi parser to add two calculated timestamp fields: install_date_epoch and install_date_epoch_utc
|
||||
- Clean up documentation and autogenerate the Parser Information section from metadata
|
||||
|
||||
20210407 v1.15.0
|
||||
- Add acpi command parser tested on linux
|
||||
- Add upower command parser tested on linux
|
||||
- Add /usr/bin/time command parser tested on linux and macOS
|
||||
- Add dpkg -l command parser tested on linux
|
||||
- Add rpm -qi command parser tested on linux
|
||||
- Add finger command parser tested on linux and macOS
|
||||
- Add dir command parser tested on Windows 10
|
||||
- Update date parser: complete rewrite (v2.0) providing many enhancements:
|
||||
- Make weekday numbering ISO 8601 compliant
|
||||
- Add a calculated naive timestamp field
|
||||
- Add a calculated UTC timestamp field (only if date output is in UTC)
|
||||
- Add several fields, including: hour_24, utc_offset, day_of_year, week_of_year, iso, and timezone_aware
|
||||
- Update uptime parser to add uptime_days, uptime_hours, uptime_minutes, uptime_total_seconds, time_hour,
|
||||
time_minute, and time_second fields
|
||||
- Update last parser to use new timestamp function
|
||||
- Update stat parser to add access_time_epoch, access_time_epoch_utc, modify_time_epoch, modify_time_epoch_utc,
|
||||
change_time_epoch, change_time_epoch_utc, birth_time_epoch, birth_time_epoch_utc fields
|
||||
- Update timedatectl parser to add epoch_utc field
|
||||
- Update who parser to add epoch field
|
||||
- Update dig parser to add when_epoch and when_epoch_utc fields
|
||||
- Update ls parser to add epoch and epoch_utc fields
|
||||
- Add -h option to display the help text. Piping errors no longer show the help text.
|
||||
- Add -v option to display version information.
|
||||
- Add contributing information to project root
|
||||
- Make all external python library dependencies optional: pygments, ruamel.yaml, xmltodict
|
||||
- JSON output now supports unencoded unicode characters
|
||||
- JSON output is now more compact unless the -p (pretty) option is used
|
||||
- Developer scripts added and enhanced to automate documentation and man page creation
|
||||
- Enhanced man page
|
||||
|
||||
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
|
||||
- Updae ping parser for Raspberry Pi compatibility
|
||||
- Update ping parser for Raspberry Pi compatibility
|
||||
|
||||
20200803 v1.13.2
|
||||
- Add key/value file parser (wrapper for ini parser)
|
||||
|
||||
83
CONTRIBUTING.md
Normal file
83
CONTRIBUTING.md
Normal file
@@ -0,0 +1,83 @@
|
||||
# Contributing to jc
|
||||
We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:
|
||||
|
||||
- Reporting a bug
|
||||
- Discussing the current state of the code
|
||||
- Submitting a fix
|
||||
- Proposing new features
|
||||
- Proposing a new parser
|
||||
|
||||
## We Develop with Github
|
||||
We use github to host code, to track issues and feature requests, as well as accept pull requests.
|
||||
|
||||
## We Use Github Flow, So All Code Changes Happen Through Pull Requests
|
||||
Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:
|
||||
|
||||
1. Open an issue to discuss the new feature, bug fix, or parser before opening a pull request. For new parsers, it is important to agree upon a schema before developing the parser.
|
||||
2. Fork the repo and create your branch from `dev`, if available, otherwise `master`.
|
||||
3. If you've added code that should be tested, add tests. All new parsers should have several sample outputs and tests.
|
||||
4. Documentation is auto-generated from docstrings, so ensure they are clear and accurate.
|
||||
5. Ensure the test suite passes.
|
||||
6. Make sure your code lints.
|
||||
7. Issue that pull request!
|
||||
|
||||
## Parser Schema Guidelines
|
||||
- Try to keep the schema as flat as possible - typically a list of flat dictionaries
|
||||
- Keys should be lowercase, contain no special characters, and spaces should be converted to underscores
|
||||
- Keys should be static, if possible. If they have to be dynamic, then they should not contain lists or dictionaries
|
||||
|
||||
This will make it easier to use tools like `jq` without requiring escaping of special characters, encapsulating key names in [""], keeps paths predictable, and makes iterating and searching for values easier.
|
||||
|
||||
**Examples**
|
||||
|
||||
Bad:
|
||||
```
|
||||
{
|
||||
"Interface 1": [
|
||||
192.168.1.1,
|
||||
172.16.1.1
|
||||
],
|
||||
"Wifi Interface 1": [
|
||||
10.1.1.1
|
||||
]
|
||||
}
|
||||
```
|
||||
Good:
|
||||
```
|
||||
[
|
||||
{
|
||||
"interface": "Interface 1",
|
||||
"ip_addresses": [
|
||||
192.168.1.1,
|
||||
172.16.1.1
|
||||
]
|
||||
},
|
||||
{
|
||||
"interface": "Wifi Interface 1",
|
||||
"ip_addresses": [
|
||||
10.1.1.1
|
||||
]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## Any contributions you make will be under the MIT Software License
|
||||
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
|
||||
|
||||
## Report bugs using Github's Issues
|
||||
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/kellyjonbrazil/jc/issues); it's that easy!
|
||||
|
||||
## Write bug reports with detail, background, and sample code
|
||||
**Great Bug Reports** tend to have:
|
||||
|
||||
- A quick summary and/or background
|
||||
- Steps to reproduce
|
||||
- Be specific!
|
||||
- Give sample code if you can.
|
||||
- What you expected would happen
|
||||
- What actually happens
|
||||
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
|
||||
|
||||
## Use a Consistent Coding Style
|
||||
* 4 spaces for indentation rather than tabs
|
||||
* Use a Python linter that will enforce PEP 8 and other best practices
|
||||
986
EXAMPLES.md
986
EXAMPLES.md
File diff suppressed because it is too large
Load Diff
1
MANIFEST.in
Normal file
1
MANIFEST.in
Normal file
@@ -0,0 +1 @@
|
||||
include jc/man/jc.1.gz
|
||||
318
README.md
318
README.md
@@ -1,72 +1,74 @@
|
||||

|
||||

|
||||
|
||||
> Try the new `jc` [web demo](https://jc-web-demo.herokuapp.com/)!
|
||||
|
||||
> JC is [now available](https://galaxy.ansible.com/community/general) as an Ansible filter plugin in the `community.general` collection! See this [blog post](https://blog.kellybrazil.com/2020/08/30/parsing-command-output-in-ansible-with-jc/) for an example.
|
||||
|
||||
# JC
|
||||
JSON CLI output utility
|
||||
|
||||
`jc` JSONifies the output of many CLI tools and file-types for easier parsing in scripts. See the [**Parsers**](#parsers) section for supported commands and file-types.
|
||||
|
||||
This allows further command-line processing of output with tools like `jq` by piping commands:
|
||||
```bash
|
||||
ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)'
|
||||
dig example.com | jc --dig
|
||||
```
|
||||
```json
|
||||
{
|
||||
"filename": "docker",
|
||||
"flags": "-rwxr-xr-x",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 68677120,
|
||||
"date": "Aug 14 19:41"
|
||||
}
|
||||
[{"id":38052,"opcode":"QUERY","status":"NOERROR","flags":["qr","rd","ra"],"query_num":1,"answer_num":1,
|
||||
"authority_num":0,"additional_num":1,"opt_pseudosection":{"edns":{"version":0,"flags":[],"udp":4096}},"question":
|
||||
{"name":"example.com.","class":"IN","type":"A"},"answer":[{"name":"example.com.","class":"IN","type":"A","ttl":
|
||||
39049,"data":"93.184.216.34"}],"query_time":49,"server":"2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)","when":
|
||||
"Fri Apr 16 16:09:00 PDT 2021","rcvd":56,"when_epoch":1618614540,"when_epoch_utc":null}]
|
||||
```
|
||||
This allows further command-line processing of output with tools like `jq` by piping commands:
|
||||
```bash
|
||||
$ dig example.com | jc --dig | jq -r '.[].answer[].data'
|
||||
93.184.216.34
|
||||
```
|
||||
or using the alternative "magic" syntax:
|
||||
```bash
|
||||
jc ls -l /usr/bin | jq '.[] | select(.size > 50000000)'
|
||||
```
|
||||
```json
|
||||
{
|
||||
"filename": "docker",
|
||||
"flags": "-rwxr-xr-x",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 68677120,
|
||||
"date": "Aug 14 19:41"
|
||||
}
|
||||
$ jc dig example.com | jq -r '.[].answer[].data'
|
||||
93.184.216.34
|
||||
```
|
||||
The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary, or list of dictionaries, instead of JSON:
|
||||
```python
|
||||
>>> import jc.parsers.ls
|
||||
>>> import jc.parsers.dig
|
||||
>>>
|
||||
>>> data='''-rwxr-xr-x 1 root wheel 23648 May 3 22:26 cat
|
||||
... -rwxr-xr-x 1 root wheel 30016 May 3 22:26 chmod
|
||||
... -rwxr-xr-x 1 root wheel 29024 May 3 22:26 cp
|
||||
... -rwxr-xr-x 1 root wheel 375824 May 3 22:26 csh
|
||||
... -rwxr-xr-x 1 root wheel 28608 May 3 22:26 date
|
||||
... -rwxr-xr-x 1 root wheel 32000 May 3 22:26 dd
|
||||
... -rwxr-xr-x 1 root wheel 23392 May 3 22:26 df
|
||||
... -rwxr-xr-x 1 root wheel 18128 May 3 22:26 echo'''
|
||||
>>> data = '''; <<>> DiG 9.10.6 <<>> example.com
|
||||
... ;; global options: +cmd
|
||||
... ;; Got answer:
|
||||
... ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64612
|
||||
... ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
|
||||
...
|
||||
... ;; OPT PSEUDOSECTION:
|
||||
... ; EDNS: version: 0, flags:; udp: 4096
|
||||
... ;; QUESTION SECTION:
|
||||
... ;example.com. IN A
|
||||
...
|
||||
... ;; ANSWER SECTION:
|
||||
... example.com. 29658 IN A 93.184.216.34
|
||||
...
|
||||
... ;; Query time: 52 msec
|
||||
... ;; SERVER: 2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)
|
||||
... ;; WHEN: Fri Apr 16 16:13:00 PDT 2021
|
||||
... ;; MSG SIZE rcvd: 56'''
|
||||
>>>
|
||||
>>> jc.parsers.ls.parse(data)
|
||||
[{'filename': 'cat', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 23648,
|
||||
'date': 'May 3 22:26'}, {'filename': 'chmod', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root',
|
||||
'group': 'wheel', 'size': 30016, 'date': 'May 3 22:26'}, {'filename': 'cp', 'flags': '-rwxr-xr-x',
|
||||
'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 29024, 'date': 'May 3 22:26'}, {'filename': 'csh',
|
||||
'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 375824, 'date': 'May 3
|
||||
22:26'}, {'filename': 'date', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel',
|
||||
'size': 28608, 'date': 'May 3 22:26'}, {'filename': 'dd', 'flags': '-rwxr-xr-x', 'links': 1, 'owner':
|
||||
'root', 'group': 'wheel', 'size': 32000, 'date': 'May 3 22:26'}, {'filename': 'df', 'flags':
|
||||
'-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 23392, 'date': 'May 3 22:26'},
|
||||
{'filename': 'echo', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 18128,
|
||||
'date': 'May 3 22:26'}]
|
||||
>>> jc.parsers.dig.parse(data)
|
||||
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num':
|
||||
1, 'authority_num': 0, 'additional_num': 1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp':
|
||||
4096}}, 'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': [{'name': 'example.com.',
|
||||
'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': '93.184.216.34'}], 'query_time': 52, 'server':
|
||||
'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': 'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56,
|
||||
'when_epoch': 1618614780, 'when_epoch_utc': None}]
|
||||
```
|
||||
Two representations of the data are possible. The default representation uses a strict schema per parser and converts known numbers to int/float JSON values. Certain known values of `None` are converted to JSON `null`, known boolean values are converted, and, in some cases, additional semantic context fields are added.
|
||||
|
||||
> Note: Some parsers have calculated epoch timestamp fields added to the output. Unless a timestamp field name has a `_utc` suffix it is considered naive. (i.e. based on the local timezone of the system the `jc` parser was run on).
|
||||
>
|
||||
> If a UTC timezone can be detected in the text of the command output, the timestamp will be timezone aware and have a `_utc` suffix on the key name. (e.g. `epoch_utc`) No other timezones are supported for aware timestamps.
|
||||
|
||||
To access the raw, pre-processed JSON, use the `-r` cli option or the `raw=True` function parameter in `parse()`.
|
||||
|
||||
Schemas for each parser can be found in the [`docs/parsers`](https://github.com/kellyjonbrazil/jc/tree/master/docs/parsers) folder.
|
||||
Schemas for each parser can be found at the documentation link beside each parser below.
|
||||
|
||||
Release notes can be found [here](https://blog.kellybrazil.com/category/jc-news/).
|
||||
|
||||
@@ -79,7 +81,7 @@ See also:
|
||||
- [blog: linux apps should have a json flag](https://thomashunter.name/posts/2012-06-06-linux-cli-apps-should-have-a-json-flag)
|
||||
|
||||
## Installation
|
||||
There are several ways to get `jc`. You can install via `pip`; other OS package repositories like `dnf`, `zypper`, `pacman`, `nix-env`, `guix`, `brew`, or `portsnap`; via DEB/RPM packages; or by downloading the correct binary for your architecture and running it anywhere on your filesystem.
|
||||
There are several ways to get `jc`. You can install via `pip`; other OS package repositories like `apt-get`, `dnf`, `zypper`, `pacman`, `nix-env`, `guix`, `brew`, or `portsnap`; via DEB/RPM packages; or by downloading the correct binary for your architecture and running it anywhere on your filesystem.
|
||||
|
||||
### Pip (macOS, linux, unix, Windows)
|
||||
```bash
|
||||
@@ -90,13 +92,15 @@ pip3 install jc
|
||||
|
||||
| OS | Command |
|
||||
|-----------------------|-------------------------------------------------------------------------------|
|
||||
| Debian/Ubuntu linux | `apt-get install jc` |
|
||||
| Fedora linux | `dnf install jc` |
|
||||
| openSUSE linux | `zypper install jc` |
|
||||
| Arch linux | `pacman -S jc` |
|
||||
| NixOS linux | `nix-env -iA nixpkgs.jc` |
|
||||
| NixOS linux | `nix-env -iA nixpkgs.jc` or `nix-env -iA nixos.jc` |
|
||||
| Guix System linux | `guix install jc` |
|
||||
| MacOS | `brew install jc` |
|
||||
| FreeBSD | `portsnap fetch update && cd /usr/ports/textproc/py-jc && make install clean` |
|
||||
| Ansible filter plugin | `ansible-galaxy collection install community.general` |
|
||||
|
||||
> For more packages and binaries, see https://kellyjonbrazil.github.io/jc-packaging/.
|
||||
|
||||
@@ -105,78 +109,97 @@ pip3 install jc
|
||||
```bash
|
||||
COMMAND | jc PARSER [OPTIONS]
|
||||
```
|
||||
Alternatively, the "magic" syntax can be used by prepending `jc` to the command to be converted. Options can be passed to `jc` immediately before the command is given. (Note: command aliases are not supported)
|
||||
Alternatively, the "magic" syntax can be used by prepending `jc` to the command to be converted. Options can be passed to `jc` immediately before the command is given. (Note: command aliases and shell builtins are not supported)
|
||||
```bash
|
||||
jc [OPTIONS] COMMAND
|
||||
```
|
||||
The JSON output can be compact (default) or pretty formatted with the `-p` option.
|
||||
|
||||
> Note: For best results set the `LANG` locale environment variable to `C`. For example, either by setting directly on the command-line: `$ LANG=C date | jc --date`, or by exporting to the environment before running commands: `$ export LANG=C`.
|
||||
|
||||
### Parsers
|
||||
- `--airport` enables the `airport -I` command parser (OSX)
|
||||
- `--airport-s` enables the `airport -s` command parser (OSX)
|
||||
- `--arp` enables the `arp` command parser
|
||||
- `--blkid` enables the `blkid` command parser
|
||||
- `--crontab` enables the `crontab` command and file parser
|
||||
- `--crontab-u` enables the `crontab` file parser with user support
|
||||
- `--csv` enables the `CSV` file parser
|
||||
- `--date` enables the `date` command parser
|
||||
- `--df` enables the `df` command parser
|
||||
- `--dig` enables the `dig` command parser
|
||||
- `--dmidecode` enables the `dmidecode` command parser
|
||||
- `--du` enables the `du` command parser
|
||||
- `--env` enables the `env` command parser
|
||||
- `--file` enables the `file` command parser
|
||||
- `--free` enables the `free` command parser
|
||||
- `--fstab` enables the `/etc/fstab` file parser
|
||||
- `--group` enables the `/etc/group` file parser
|
||||
- `--gshadow` enables the `/etc/gshadow` file parser
|
||||
- `--history` enables the `history` command parser
|
||||
- `--hosts` enables the `/etc/hosts` file parser
|
||||
- `--id` enables the `id` command parser
|
||||
- `--ifconfig` enables the `ifconfig` command parser
|
||||
- `--ini` enables the `INI` file parser
|
||||
- `--iptables` enables the `iptables` command parser
|
||||
- `--jobs` enables the `jobs` command parser
|
||||
- `--kv` enables the `Key/Value` file parser
|
||||
- `--last` enables the `last` and `lastb` command parser
|
||||
- `--ls` enables the `ls` command parser
|
||||
- `--lsblk` enables the `lsblk` command parser
|
||||
- `--lsmod` enables the `lsmod` command parser
|
||||
- `--lsof` enables the `lsof` command parser
|
||||
- `--mount` enables the `mount` command parser
|
||||
- `--netstat` enables the `netstat` command parser
|
||||
- `--ntpq` enables the `ntpq -p` command parser
|
||||
- `--passwd` enables the `/etc/passwd` file parser
|
||||
- `--ping` enables the `ping` and `ping6` command parser
|
||||
- `--pip-list` enables the `pip list` command parser
|
||||
- `--pip-show` enables the `pip show` command parser
|
||||
- `--ps` enables the `ps` command parser
|
||||
- `--route` enables the `route` command parser
|
||||
- `--shadow` enables the `/etc/shadow` file parser
|
||||
- `--ss` enables the `ss` command parser
|
||||
- `--stat` enables the `stat` command parser
|
||||
- `--sysctl` enables the `sysctl -a` command parser
|
||||
- `--systemctl` enables the `systemctl` command parser
|
||||
- `--systemctl-lj` enables the `systemctl list-jobs` command parser
|
||||
- `--systemctl-ls` enables the `systemctl list-sockets` command parser
|
||||
- `--systemctl-luf` enables the `systemctl list-unit-files` command parser
|
||||
- `--timedatectl` enables the `timedatectl status` command parser
|
||||
- `--tracepath` enables the `tracepath` and `tracepath6` command parser
|
||||
- `--traceroute` enables the `traceroute` and `traceroute6` command parser
|
||||
- `--uname` enables the `uname -a` command parser
|
||||
- `--uptime` enables the `uptime` command parser
|
||||
- `--w` enables the `w` command parser
|
||||
- `--who` enables the `who` command parser
|
||||
- `--xml` enables the `XML` file parser
|
||||
- `--yaml` enables the `YAML` file parser
|
||||
|
||||
- `--acpi` enables the `acpi` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/acpi))
|
||||
- `--airport` enables the `airport -I` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/airport))
|
||||
- `--airport-s` enables the `airport -s` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/airport_s))
|
||||
- `--arp` enables the `arp` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/arp))
|
||||
- `--blkid` enables the `blkid` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/blkid))
|
||||
- `--cksum` enables the `cksum` and `sum` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/cksum))
|
||||
- `--crontab` enables the `crontab` command and file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/crontab))
|
||||
- `--crontab-u` enables the `crontab` file parser with user support ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/crontab_u))
|
||||
- `--csv` enables the CSV file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/csv))
|
||||
- `--date` enables the `date` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/date))
|
||||
- `--df` enables the `df` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/df))
|
||||
- `--dig` enables the `dig` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/dig))
|
||||
- `--dir` enables the `dir` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/dir))
|
||||
- `--dmidecode` enables the `dmidecode` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/dmidecode))
|
||||
- `--dpkg-l` enables the `dpkg -l` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/dpkg_l))
|
||||
- `--du` enables the `du` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/du))
|
||||
- `--env` enables the `env` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/env))
|
||||
- `--file` enables the `file` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/file))
|
||||
- `--finger` enables the `finger` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/finger))
|
||||
- `--free` enables the `free` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/free))
|
||||
- `--fstab` enables the `/etc/fstab` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/fstab))
|
||||
- `--group` enables the `/etc/group` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/group))
|
||||
- `--gshadow` enables the `/etc/gshadow` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/gshadow))
|
||||
- `--hash` enables the `hash` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/hash))
|
||||
- `--hashsum` enables the hashsum command parser (`md5sum`, `shasum`, etc.) ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/hashsum))
|
||||
- `--hciconfig` enables the `hciconfig` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/hciconfig))
|
||||
- `--history` enables the `history` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/history))
|
||||
- `--hosts` enables the `/etc/hosts` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/hosts))
|
||||
- `--id` enables the `id` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/id))
|
||||
- `--ifconfig` enables the `ifconfig` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ifconfig))
|
||||
- `--ini` enables the INI file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ini))
|
||||
- `--iptables` enables the `iptables` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/iptables))
|
||||
- `--iw-scan` enables the `iw dev [device] scan` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/iw_scan))
|
||||
- `--jobs` enables the `jobs` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/jobs))
|
||||
- `--kv` enables the Key/Value file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/kv))
|
||||
- `--last` enables the `last` and `lastb` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/last))
|
||||
- `--ls` enables the `ls` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ls))
|
||||
- `--lsblk` enables the `lsblk` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsblk))
|
||||
- `--lsmod` enables the `lsmod` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsmod))
|
||||
- `--lsof` enables the `lsof` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsof))
|
||||
- `--mount` enables the `mount` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mount))
|
||||
- `--netstat` enables the `netstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat))
|
||||
- `--ntpq` enables the `ntpq -p` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq))
|
||||
- `--passwd` enables the `/etc/passwd` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd))
|
||||
- `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping))
|
||||
- `--pip-list` enables the `pip list` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_list))
|
||||
- `--pip-show` enables the `pip show` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/pip_show))
|
||||
- `--ps` enables the `ps` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ps))
|
||||
- `--route` enables the `route` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/route))
|
||||
- `--rpm-qi` enables the `rpm -qi` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/rpm_qi))
|
||||
- `--shadow` enables the `/etc/shadow` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/shadow))
|
||||
- `--ss` enables the `ss` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ss))
|
||||
- `--stat` enables the `stat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/stat))
|
||||
- `--sysctl` enables the `sysctl` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/sysctl))
|
||||
- `--systemctl` enables the `systemctl` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/systemctl))
|
||||
- `--systemctl-lj` enables the `systemctl list-jobs` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/systemctl_lj))
|
||||
- `--systemctl-ls` enables the `systemctl list-sockets` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/systemctl_ls))
|
||||
- `--systemctl-luf` enables the `systemctl list-unit-files` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/systemctl_luf))
|
||||
- `--systeminfo` enables the `systeminfo` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/systeminfo))
|
||||
- `--time` enables the `/usr/bin/time` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/time))
|
||||
- `--timedatectl` enables the `timedatectl status` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/timedatectl))
|
||||
- `--tracepath` enables the `tracepath` and `tracepath6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/tracepath))
|
||||
- `--traceroute` enables the `traceroute` and `traceroute6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/traceroute))
|
||||
- `--uname` enables the `uname -a` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/uname))
|
||||
- `--upower` enables the `upower` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/upower))
|
||||
- `--uptime` enables the `uptime` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/uptime))
|
||||
- `--w` enables the `w` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/w))
|
||||
- `--wc` enables the `wc` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/wc))
|
||||
- `--who` enables the `who` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/who))
|
||||
- `--xml` enables the XML file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/xml))
|
||||
- `--yaml` enables the YAML file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/yaml))
|
||||
|
||||
### Options
|
||||
- `-a` about `jc`. Prints information about `jc` and the parsers (in JSON, of course!)
|
||||
- `-d` debug mode. Prints trace messages if parsing issues encountered (use `-dd` for verbose debugging)
|
||||
- `-d` debug mode. Prints trace messages if parsing issues are encountered (use `-dd` for verbose debugging)
|
||||
- `-h` `jc` help. Use `jc -h --parser_name` for parser documentation
|
||||
- `-m` monochrome JSON output
|
||||
- `-p` pretty format the JSON output
|
||||
- `-q` quiet mode. Suppresses warning messages
|
||||
- `-r` raw output. Provides a more literal JSON output with all values as strings and no additional semantic processing
|
||||
- `-q` quiet mode. Suppresses parser warning messages
|
||||
- `-r` raw output. Provides a more literal JSON output, typically with string values and no additional semantic processing
|
||||
- `-v` version information
|
||||
|
||||
### Setting Custom Colors via Environment Variable
|
||||
You can specify custom colors via the `JC_COLORS` environment variable. The `JC_COLORS` environment variable takes four comma separated string values in the following format:
|
||||
@@ -210,7 +233,7 @@ Local plugin filenames must be valid python module names, therefore must consist
|
||||
## Compatibility
|
||||
Some parsers like `ls`, `ps`, `dig`, etc. will work on any platform. Other parsers that are platform-specific will generate a warning message if they are used on an unsupported platform. To see all parser information, including compatibility, run `jc -ap`.
|
||||
|
||||
You may still use a parser on an unsupported platform - for example, you may want to parse a file with linux `lsof` output on an OSX laptop. In that case you can suppress the warning message with the `-q` cli option or the `quiet=True` function parameter in `parse()`:
|
||||
You may still use a parser on an unsupported platform - for example, you may want to parse a file with linux `lsof` output on an macOS laptop. In that case you can suppress the warning message with the `-q` cli option or the `quiet=True` function parameter in `parse()`:
|
||||
|
||||
```bash
|
||||
cat lsof.out | jc --lsof -q
|
||||
@@ -218,16 +241,20 @@ cat lsof.out | jc --lsof -q
|
||||
|
||||
Tested on:
|
||||
- Centos 7.7
|
||||
- Ubuntu 18.4
|
||||
- Ubuntu 18.04
|
||||
- Ubuntu 20.04
|
||||
- Fedora32
|
||||
- OSX 10.11.6
|
||||
- OSX 10.14.6
|
||||
- macOS 10.11.6
|
||||
- macOS 10.14.6
|
||||
- NixOS
|
||||
- FreeBSD12
|
||||
- Windows 10
|
||||
|
||||
## Contributions
|
||||
Feel free to add/improve code or parsers! You can use the [`jc/parsers/foo.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/foo.py) parser as a template and submit your parser with a pull request.
|
||||
|
||||
Please see the [Contributing Guidelines](https://github.com/kellyjonbrazil/jc/blob/master/CONTRIBUTING.md) for more information.
|
||||
|
||||
## Acknowledgments
|
||||
- Local parser plugin feature contributed by [Dean Serenevy](https://github.com/duelafn)
|
||||
- CI automation and code optimizations by [philippeitis](https://github.com/philippeitis)
|
||||
@@ -239,7 +266,7 @@ Feel free to add/improve code or parsers! You can use the [`jc/parsers/foo.py`](
|
||||
- Excellent constructive feedback from [Ilya Sher](https://github.com/ilyash-b)
|
||||
|
||||
## Examples
|
||||
Here are some examples of `jc` output. For more examples, see [EXAMPLES.md](https://github.com/kellyjonbrazil/jc/blob/master/EXAMPLES.md) or the [parser documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs/parsers).
|
||||
Here are some examples of `jc` output. For more examples, see [here](https://kellyjonbrazil.github.io/jc/EXAMPLES) or the parser documentation.
|
||||
### arp
|
||||
```bash
|
||||
arp | jc --arp -p # or: jc -p arp
|
||||
@@ -320,46 +347,6 @@ cat homes.csv | jc --csv -p
|
||||
}
|
||||
]
|
||||
```
|
||||
### dig
|
||||
```bash
|
||||
dig cnn.com @205.251.194.64 | jc --dig -p # or: jc -p dig cnn.com @205.251.194.64
|
||||
```
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": 5509,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
"qr",
|
||||
"rd",
|
||||
"ra"
|
||||
],
|
||||
"query_num": 1,
|
||||
"answer_num": 1,
|
||||
"authority_num": 0,
|
||||
"additional_num": 1,
|
||||
"question": {
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.129.67"
|
||||
}
|
||||
],
|
||||
"query_time": 28,
|
||||
"server": "2600",
|
||||
"when": "Tue Nov 12 07:13:03 PST 2019",
|
||||
"rcvd": 100
|
||||
}
|
||||
]
|
||||
```
|
||||
### /etc/hosts file
|
||||
```bash
|
||||
cat /etc/hosts | jc --hosts -p
|
||||
@@ -787,12 +774,19 @@ uptime | jc --uptime -p # or: jc -p uptime
|
||||
```
|
||||
```json
|
||||
{
|
||||
"time": "11:30:44",
|
||||
"uptime": "1 day, 21:17",
|
||||
"users": 1,
|
||||
"load_1m": 0.01,
|
||||
"load_5m": 0.04,
|
||||
"load_15m": 0.05
|
||||
"time": "11:35",
|
||||
"uptime": "3 days, 4:03",
|
||||
"users": 5,
|
||||
"load_1m": 1.88,
|
||||
"load_5m": 2.0,
|
||||
"load_15m": 1.94,
|
||||
"time_hour": 11,
|
||||
"time_minute": 35,
|
||||
"time_second": null,
|
||||
"uptime_days": 3,
|
||||
"uptime_hours": 4,
|
||||
"uptime_minutes": 3,
|
||||
"uptime_total_seconds": 273780
|
||||
}
|
||||
```
|
||||
### XML files
|
||||
@@ -909,4 +903,6 @@ cat istio.yaml | jc --yaml -p
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
```
|
||||
|
||||
© 2019-2021 Kelly Brazil
|
||||
87
docgen.sh
87
docgen.sh
@@ -3,62 +3,35 @@
|
||||
# requires pydoc-markdown 2.1.0.post1
|
||||
|
||||
cd jc
|
||||
echo Building docs for: package
|
||||
pydocmd simple jc+ > ../docs/readme.md
|
||||
echo Building docs for: utils
|
||||
pydocmd simple utils+ > ../docs/utils.md
|
||||
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.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
|
||||
pydocmd simple jc.parsers.du+ > ../docs/parsers/du.md
|
||||
pydocmd simple jc.parsers.env+ > ../docs/parsers/env.md
|
||||
pydocmd simple jc.parsers.file+ > ../docs/parsers/file.md
|
||||
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.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.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
|
||||
pydocmd simple jc.parsers.lsmod+ > ../docs/parsers/lsmod.md
|
||||
pydocmd simple jc.parsers.lsof+ > ../docs/parsers/lsof.md
|
||||
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
|
||||
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.who+ > ../docs/parsers/who.md
|
||||
pydocmd simple jc.parsers.xml+ > ../docs/parsers/xml.md
|
||||
pydocmd simple jc.parsers.yaml+ > ../docs/parsers/yaml.md
|
||||
|
||||
# a bit of inception here... jc is being used to help
|
||||
# automate the generation of its own documentation. :)
|
||||
|
||||
# pull jc parser objects into a bash array from jq
|
||||
parsers=()
|
||||
while read -r value
|
||||
do
|
||||
parsers+=("$value")
|
||||
done < <(jc -a | jq -c '.parsers[]')
|
||||
|
||||
# iterate over the bash array
|
||||
for parser in "${parsers[@]}"
|
||||
do
|
||||
parser_name=$(jq -r '.name' <<< "$parser")
|
||||
compatible=$(jq -r '.compatible | join(", ")' <<< "$parser")
|
||||
version=$(jq -r '.version' <<< "$parser")
|
||||
author=$(jq -r '.author' <<< "$parser")
|
||||
author_email=$(jq -r '.author_email' <<< "$parser")
|
||||
|
||||
echo "Building docs for: ${parser_name}"
|
||||
echo "[Home](https://kellyjonbrazil.github.io/jc/)" > ../docs/parsers/"${parser_name}".md
|
||||
pydocmd simple jc.parsers."${parser_name}"+ >> ../docs/parsers/"${parser_name}".md
|
||||
echo "## Parser Information" >> ../docs/parsers/"${parser_name}".md
|
||||
echo "Compatibility: ${compatible}" >> ../docs/parsers/"${parser_name}".md
|
||||
echo >> ../docs/parsers/"${parser_name}".md
|
||||
echo "Version ${version} by ${author} (${author_email})" >> ../docs/parsers/"${parser_name}".md
|
||||
done
|
||||
|
||||
1
docs/_config.yml
Normal file
1
docs/_config.yml
Normal file
@@ -0,0 +1 @@
|
||||
theme: jekyll-theme-cayman
|
||||
255
docs/parsers/acpi.md
Normal file
255
docs/parsers/acpi.md
Normal file
@@ -0,0 +1,255 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.acpi
|
||||
jc - JSON CLI output utility `acpi` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ acpi -V | jc --acpi
|
||||
|
||||
or
|
||||
|
||||
$ jc acpi -V
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.acpi
|
||||
result = jc.parsers.acpi.parse(acpi_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"type": string,
|
||||
"id": integer,
|
||||
"state": string,
|
||||
"charge_percent": integer,
|
||||
"until_charged": string,
|
||||
"until_charged_hours": integer,
|
||||
"until_charged_minuts": integer,
|
||||
"until_charged_seconds": integer,
|
||||
"until_charged_total_seconds": integer,
|
||||
"charge_remaining": string,
|
||||
"charge_remaining_hours": integer,
|
||||
"charge_remaining_minutes": integer,
|
||||
"charge_remaining_seconds": integer,
|
||||
"charge_remaining_total_seconds": integer,
|
||||
"design_capacity_mah": integer,
|
||||
"last_full_capacity": integer,
|
||||
"last_full_capacity_percent": integer,
|
||||
"on-line": boolean,
|
||||
"mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string,
|
||||
"trip_points": [
|
||||
{
|
||||
"id": integer,
|
||||
"switches_to_mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ acpi -V | jc --acpi -p
|
||||
[
|
||||
{
|
||||
"type": "Battery",
|
||||
"id": 0,
|
||||
"state": "Charging",
|
||||
"charge_percent": 71,
|
||||
"until_charged": "00:29:20",
|
||||
"design_capacity_mah": 2110,
|
||||
"last_full_capacity": 2271,
|
||||
"last_full_capacity_percent": 100,
|
||||
"until_charged_hours": 0,
|
||||
"until_charged_minutes": 29,
|
||||
"until_charged_seconds": 20,
|
||||
"until_charged_total_seconds": 1760
|
||||
},
|
||||
{
|
||||
"type": "Adapter",
|
||||
"id": 0,
|
||||
"on-line": true
|
||||
},
|
||||
{
|
||||
"type": "Thermal",
|
||||
"id": 0,
|
||||
"mode": "ok",
|
||||
"temperature": 46.0,
|
||||
"temperature_unit": "C",
|
||||
"trip_points": [
|
||||
{
|
||||
"id": 0,
|
||||
"switches_to_mode": "critical",
|
||||
"temperature": 127.0,
|
||||
"temperature_unit": "C"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"switches_to_mode": "hot",
|
||||
"temperature": 127.0,
|
||||
"temperature_unit": "C"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 0,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 1,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 2,
|
||||
"messages": [
|
||||
"x86_pkg_temp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 3,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 4,
|
||||
"messages": [
|
||||
"intel_powerclamp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 5,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
$ acpi -V | jc --acpi -p -r
|
||||
[
|
||||
{
|
||||
"type": "Battery",
|
||||
"id": "0",
|
||||
"state": "Charging",
|
||||
"charge_percent": "71",
|
||||
"until_charged": "00:29:20",
|
||||
"design_capacity_mah": "2110",
|
||||
"last_full_capacity": "2271",
|
||||
"last_full_capacity_percent": "100"
|
||||
},
|
||||
{
|
||||
"type": "Adapter",
|
||||
"id": "0",
|
||||
"on-line": true
|
||||
},
|
||||
{
|
||||
"type": "Thermal",
|
||||
"id": "0",
|
||||
"mode": "ok",
|
||||
"temperature": "46.0",
|
||||
"temperature_unit": "C",
|
||||
"trip_points": [
|
||||
{
|
||||
"id": "0",
|
||||
"switches_to_mode": "critical",
|
||||
"temperature": "127.0",
|
||||
"temperature_unit": "C"
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"switches_to_mode": "hot",
|
||||
"temperature": "127.0",
|
||||
"temperature_unit": "C"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "0",
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "1",
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "2",
|
||||
"messages": [
|
||||
"x86_pkg_temp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "3",
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "4",
|
||||
"messages": [
|
||||
"intel_powerclamp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "5",
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,17 +1,42 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'darwin'
|
||||
$ jc airport -I
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.airport
|
||||
result = jc.parsers.airport.parse(airport_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"agrctlrssi": integer,
|
||||
"agrextrssi": integer,
|
||||
"agrctlnoise": integer,
|
||||
"agrextnoise": integer,
|
||||
"state": string,
|
||||
"op_mode": string,
|
||||
"lasttxrate": integer,
|
||||
"maxrate": integer,
|
||||
"lastassocstatus": integer,
|
||||
"802_11_auth": string,
|
||||
"link_auth": string,
|
||||
"bssid": string,
|
||||
"ssid": string,
|
||||
"mcs": integer,
|
||||
"channel": string
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -58,41 +83,7 @@ Examples:
|
||||
```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:
|
||||
|
||||
{
|
||||
"agrctlrssi": integer,
|
||||
"agrextrssi": integer,
|
||||
"agrctlnoise": integer,
|
||||
"agrextnoise": integer,
|
||||
"state": string,
|
||||
"op_mode": string,
|
||||
"lasttxrate": integer,
|
||||
"maxrate": integer,
|
||||
"lastassocstatus": integer,
|
||||
"802_11_auth": string,
|
||||
"link_auth": string,
|
||||
"bssid": string,
|
||||
"ssid": string,
|
||||
"mcs": integer,
|
||||
"channel": string
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -111,3 +102,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: darwin
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,17 +1,38 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'darwin'
|
||||
$ jc airport -s
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.airport_s
|
||||
result = jc.parsers.airport_s.parse(airport_s_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"ssid": string,
|
||||
"bssid": string,
|
||||
"rssi": integer,
|
||||
"channel": string,
|
||||
"ht": boolean,
|
||||
"cc": string,
|
||||
"security": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -90,36 +111,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
[
|
||||
{
|
||||
"ssid": string,
|
||||
"bssid": string,
|
||||
"rssi": integer,
|
||||
"channel": string,
|
||||
"ht": boolean,
|
||||
"cc": string,
|
||||
"security": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -136,5 +128,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: darwin
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,18 +1,37 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'aix', 'freebsd', 'darwin'
|
||||
$ jc arp
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.arp
|
||||
result = jc.parsers.arp.parse(arp_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"address": string,
|
||||
"hwtype": string,
|
||||
"hwaddress": string,
|
||||
"flags_mask": string,
|
||||
"iface": string,
|
||||
"permanent": boolean,
|
||||
"expires": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -101,36 +120,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"address": string,
|
||||
"hwtype": string,
|
||||
"hwaddress": string,
|
||||
"flags_mask": string,
|
||||
"iface": string,
|
||||
"permanent": boolean,
|
||||
"expires": integer
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -147,5 +137,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, aix, freebsd, darwin
|
||||
|
||||
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,56 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc blkid
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.blkid
|
||||
result = jc.parsers.blkid.parse(blkid_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"device": string,
|
||||
"uuid": string,
|
||||
"type": string,
|
||||
"usage": string,
|
||||
"part_entry_scheme": string,
|
||||
"part_entry_type": string,
|
||||
"part_entry_flags": string,
|
||||
"part_entry_number": integer,
|
||||
"part_entry_offset": integer,
|
||||
"part_entry_size": integer,
|
||||
"part_entry_disk": string,
|
||||
"id_fs_uuid": string,
|
||||
"id_fs_uuid_enc": string,
|
||||
"id_fs_version": string,
|
||||
"id_fs_type": string,
|
||||
"id_fs_usage": string,
|
||||
"id_part_entry_scheme": string,
|
||||
"id_part_entry_type": string,
|
||||
"id_part_entry_flags": string,
|
||||
"id_part_entry_number": integer,
|
||||
"id_part_entry_offset": integer,
|
||||
"id_part_entry_size": integer,
|
||||
"id_iolimit_minimum_io_size": integer,
|
||||
"id_iolimit_physical_sector_size": integer,
|
||||
"id_iolimit_logical_sector_size": integer,
|
||||
"id_part_entry_disk": string,
|
||||
"minimum_io_size": integer,
|
||||
"physical_sector_size": integer,
|
||||
"logical_sector_size": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -81,57 +123,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"device": string,
|
||||
"uuid": string,
|
||||
"type": string,
|
||||
"usage": string,
|
||||
"part_entry_scheme": string,
|
||||
"part_entry_type": string,
|
||||
"part_entry_flags": string,
|
||||
"part_entry_number": integer,
|
||||
"part_entry_offset": integer,
|
||||
"part_entry_size": integer,
|
||||
"part_entry_disk": string,
|
||||
"id_fs_uuid": string,
|
||||
"id_fs_uuid_enc": string,
|
||||
"id_fs_version": string,
|
||||
"id_fs_type": string,
|
||||
"id_fs_usage": string,
|
||||
"id_part_entry_scheme": string,
|
||||
"id_part_entry_type": string,
|
||||
"id_part_entry_flags": string,
|
||||
"id_part_entry_number": integer,
|
||||
"id_part_entry_offset": integer,
|
||||
"id_part_entry_size": integer,
|
||||
"id_iolimit_minimum_io_size": integer,
|
||||
"id_iolimit_physical_sector_size": integer,
|
||||
"id_iolimit_logical_sector_size": integer,
|
||||
"id_part_entry_disk": string,
|
||||
"minimum_io_size": integer,
|
||||
"physical_sector_size": integer,
|
||||
"logical_sector_size": integer
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -148,5 +140,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
82
docs/parsers/cksum.md
Normal file
82
docs/parsers/cksum.md
Normal file
@@ -0,0 +1,82 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"checksum": integer,
|
||||
"blocks": integer
|
||||
}
|
||||
]
|
||||
|
||||
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()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,14 +1,53 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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):
|
||||
|
||||
Compatibility:
|
||||
$ crontab -l | jc --crontab
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
or
|
||||
|
||||
$ jc crontab -l
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.crontab
|
||||
result = jc.parsers.crontab.parse(crontab_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"variables": [
|
||||
"name": string,
|
||||
"value": string
|
||||
],
|
||||
"schedule": [
|
||||
{
|
||||
"occurrence" string,
|
||||
"minute": [
|
||||
string
|
||||
],
|
||||
"hour": [
|
||||
string
|
||||
],
|
||||
"day_of_month": [
|
||||
string
|
||||
],
|
||||
"month": [
|
||||
string
|
||||
],
|
||||
"day_of_week": [
|
||||
string
|
||||
],
|
||||
"occurrence": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -134,53 +173,7 @@ Examples:
|
||||
```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:
|
||||
|
||||
{
|
||||
"variables": [
|
||||
"name": string,
|
||||
"value": string
|
||||
],
|
||||
"schedule": [
|
||||
{
|
||||
"occurrence" string,
|
||||
"minute": [
|
||||
string
|
||||
],
|
||||
"hour": [
|
||||
string
|
||||
],
|
||||
"day_of_month": [
|
||||
string
|
||||
],
|
||||
"month": [
|
||||
string
|
||||
],
|
||||
"day_of_week": [
|
||||
string
|
||||
],
|
||||
"occurrence": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -199,3 +192,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, aix, freebsd
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,50 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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):
|
||||
|
||||
Compatibility:
|
||||
$ crontab -l | jc --crontab-u
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.crontab_u
|
||||
result = jc.parsers.crontab_u.parse(crontab_u_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"variables": [
|
||||
"name": string,
|
||||
"value": string
|
||||
],
|
||||
"schedule": [
|
||||
{
|
||||
"occurrence" string,
|
||||
"minute": [
|
||||
string
|
||||
],
|
||||
"hour": [
|
||||
string
|
||||
],
|
||||
"day_of_month": [
|
||||
string
|
||||
],
|
||||
"month": [
|
||||
string
|
||||
],
|
||||
"day_of_week": [
|
||||
string
|
||||
],
|
||||
"occurrence": string,
|
||||
"user": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -129,60 +165,11 @@ Examples:
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
{
|
||||
"variables": [
|
||||
"name": string,
|
||||
"value": string
|
||||
],
|
||||
"schedule": [
|
||||
{
|
||||
"occurrence" string,
|
||||
"minute": [
|
||||
string
|
||||
],
|
||||
"hour": [
|
||||
string
|
||||
],
|
||||
"day_of_month": [
|
||||
string
|
||||
],
|
||||
"month": [
|
||||
string
|
||||
],
|
||||
"day_of_week": [
|
||||
string
|
||||
],
|
||||
"occurrence": string,
|
||||
"user": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -201,3 +188,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, aix, freebsd
|
||||
|
||||
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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):
|
||||
|
||||
Compatibility:
|
||||
$ cat file.csv | jc --csv
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.csv
|
||||
result = jc.parsers.csv.parse(csv_output)
|
||||
|
||||
Schema:
|
||||
|
||||
csv file converted to a Dictionary: https://docs.python.org/3/library/csv.html
|
||||
|
||||
[
|
||||
{
|
||||
"column_name1": string,
|
||||
"column_name2": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -65,30 +77,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Each dictionary represents a row in the csv file:
|
||||
|
||||
[
|
||||
{
|
||||
csv file converted to a Dictionary
|
||||
https://docs.python.org/3/library/csv.html
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -105,5 +94,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,41 +1,72 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.date
|
||||
jc - JSON CLI output utility date Parser
|
||||
jc - JSON CLI output utility `date` command output parser
|
||||
|
||||
Usage:
|
||||
The `epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
specify --date as the first argument if the piped input is coming from date
|
||||
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
|
||||
|
||||
Compatibility:
|
||||
Usage (cli):
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
$ date | jc --date
|
||||
|
||||
or
|
||||
|
||||
$ jc date
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.date
|
||||
result = jc.parsers.date.parse(date_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"year": integer,
|
||||
"month": string,
|
||||
"month_num": integer,
|
||||
"day": integer,
|
||||
"weekday": string,
|
||||
"weekday_num": integer,
|
||||
"hour": integer,
|
||||
"hour_24": integer,
|
||||
"minute": integer,
|
||||
"second": integer,
|
||||
"period": string,
|
||||
"timezone": string,
|
||||
"utc_offset": string, # null if timezone field is not UTC
|
||||
"day_of_year": integer,
|
||||
"week_of_year": integer,
|
||||
"iso": string,
|
||||
"epoch": integer, # naive timestamp
|
||||
"epoch_utc": integer, # timezone-aware timestamp. Only available if timezone field is UTC
|
||||
"timezone_aware": boolean # if true, all fields are correctly based on UTC
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
$ date | jc --date -p
|
||||
{
|
||||
"year": 2020,
|
||||
"month_num": 7,
|
||||
"day": 31,
|
||||
"hour": 16,
|
||||
"minute": 48,
|
||||
"second": 11,
|
||||
"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"
|
||||
"year": 2021,
|
||||
"month": "Mar",
|
||||
"month_num": 3,
|
||||
"day": 25,
|
||||
"weekday": "Thu",
|
||||
"weekday_num": 4,
|
||||
"hour": 2,
|
||||
"hour_24": 2,
|
||||
"minute": 2,
|
||||
"second": 26,
|
||||
"period": "AM",
|
||||
"timezone": "UTC",
|
||||
"utc_offset": "+0000",
|
||||
"day_of_year": 84,
|
||||
"week_of_year": 12,
|
||||
"iso": "2021-03-25T02:02:26+00:00",
|
||||
"epoch": 1616662946,
|
||||
"epoch_utc": 1616637746,
|
||||
"timezone_aware": true
|
||||
}
|
||||
|
||||
|
||||
@@ -43,36 +74,7 @@ Examples:
|
||||
```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,
|
||||
"month": string,
|
||||
"weekday": string,
|
||||
"weekday_num": integer,
|
||||
"timezone": string
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -91,3 +93,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 2.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
$ jc df
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.df
|
||||
result = jc.parsers.df.parse(df_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filesystem": string,
|
||||
"size": string,
|
||||
"1k_blocks": integer,
|
||||
"512_blocks": integer,
|
||||
"used": integer,
|
||||
"available": integer,
|
||||
"capacity_percent": integer,
|
||||
"ifree": integer,
|
||||
"iused": integer,
|
||||
"use_percent": integer,
|
||||
"iused_percent": integer,
|
||||
"mounted_on": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -75,40 +100,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filesystem": string,
|
||||
"size": string,
|
||||
"1k_blocks": integer,
|
||||
"512_blocks": integer,
|
||||
"used": integer,
|
||||
"available": integer,
|
||||
"capacity_percent": integer,
|
||||
"ifree": integer,
|
||||
"iused": integer,
|
||||
"use_percent": integer,
|
||||
"iused_percent": integer,
|
||||
"mounted_on": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -125,5 +117,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,21 +1,107 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.dig
|
||||
jc - JSON CLI output utility dig Parser
|
||||
jc - JSON CLI output utility `dig` command output parser
|
||||
|
||||
Usage:
|
||||
The `when_epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
Specify --dig as the first argument if the piped input is coming from dig
|
||||
The `when_epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
|
||||
|
||||
Compatibility:
|
||||
Usage (cli):
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
$ dig example.com | jc --dig
|
||||
|
||||
or
|
||||
|
||||
$ jc dig example.com
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dig
|
||||
result = jc.parsers.dig.parse(dig_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"id": integer,
|
||||
"opcode": string,
|
||||
"status": string,
|
||||
"flags": [
|
||||
string
|
||||
],
|
||||
"query_num": integer,
|
||||
"answer_num": integer,
|
||||
"authority_num": integer,
|
||||
"additional_num": integer,
|
||||
"axfr": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": integer,
|
||||
"flags": [
|
||||
string
|
||||
],
|
||||
"udp": integer
|
||||
},
|
||||
"cookie": string
|
||||
},
|
||||
"question": {
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"additional": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"authority": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"query_size": integer,
|
||||
"query_time": integer, # in msec
|
||||
"server": string,
|
||||
"when": string,
|
||||
"when_epoch": integer, # naive timestamp if when field is parsable, else null
|
||||
"when_epoch_utc": integer, # timezone aware timestamp availabe for UTC, else null
|
||||
"rcvd": integer
|
||||
"size": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p
|
||||
$ dig example.com | jc --dig -p
|
||||
[
|
||||
{
|
||||
"id": 34128,
|
||||
"id": 2951,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
@@ -24,117 +110,43 @@ Examples:
|
||||
"ra"
|
||||
],
|
||||
"query_num": 1,
|
||||
"answer_num": 4,
|
||||
"answer_num": 1,
|
||||
"authority_num": 0,
|
||||
"additional_num": 1,
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": 0,
|
||||
"flags": [],
|
||||
"udp": 4096
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "cnn.com.",
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.65.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.193.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.1.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.129.67"
|
||||
"ttl": 39302,
|
||||
"data": "93.184.216.34"
|
||||
}
|
||||
],
|
||||
"query_time": 37,
|
||||
"server": "2600",
|
||||
"when": "Tue Nov 12 07:14:42 PST 2019",
|
||||
"rcvd": 100
|
||||
},
|
||||
{
|
||||
"id": 15273,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
"qr",
|
||||
"aa",
|
||||
"rd"
|
||||
],
|
||||
"query_num": 1,
|
||||
"answer_num": 1,
|
||||
"authority_num": 4,
|
||||
"additional_num": 1,
|
||||
"question": {
|
||||
"name": "www.cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "www.cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "CNAME",
|
||||
"ttl": 300,
|
||||
"data": "turner-tls.map.fastly.net."
|
||||
}
|
||||
],
|
||||
"authority": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": 3600,
|
||||
"data": "ns-1086.awsdns-07.org."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": 3600,
|
||||
"data": "ns-1630.awsdns-11.co.uk."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": 3600,
|
||||
"data": "ns-47.awsdns-05.com."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": 3600,
|
||||
"data": "ns-576.awsdns-08.net."
|
||||
}
|
||||
],
|
||||
"query_time": 23,
|
||||
"server": "205.251.194.64#53(205.251.194.64)",
|
||||
"when": "Tue Nov 12 07:14:42 PST 2019",
|
||||
"rcvd": 212
|
||||
"query_time": 49,
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Fri Apr 16 16:05:10 PDT 2021",
|
||||
"rcvd": 56,
|
||||
"when_epoch": 1618614310,
|
||||
"when_epoch_utc": null
|
||||
}
|
||||
]
|
||||
|
||||
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p -r
|
||||
[
|
||||
{
|
||||
"id": "23843",
|
||||
"id": "46052",
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
@@ -143,117 +155,41 @@ Examples:
|
||||
"ra"
|
||||
],
|
||||
"query_num": "1",
|
||||
"answer_num": "4",
|
||||
"answer_num": "1",
|
||||
"authority_num": "0",
|
||||
"additional_num": "1",
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": "0",
|
||||
"flags": [],
|
||||
"udp": "4096"
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "cnn.com.",
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": "30",
|
||||
"data": "151.101.193.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": "30",
|
||||
"data": "151.101.1.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": "30",
|
||||
"data": "151.101.65.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": "30",
|
||||
"data": "151.101.129.67"
|
||||
"ttl": "40426",
|
||||
"data": "93.184.216.34"
|
||||
}
|
||||
],
|
||||
"query_time": "24 msec",
|
||||
"server": "192.168.1.254#53(192.168.1.254)",
|
||||
"when": "Tue Nov 12 07:16:19 PST 2019",
|
||||
"rcvd": "100"
|
||||
},
|
||||
{
|
||||
"id": "8266",
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
"qr",
|
||||
"aa",
|
||||
"rd"
|
||||
],
|
||||
"query_num": "1",
|
||||
"answer_num": "1",
|
||||
"authority_num": "4",
|
||||
"additional_num": "1",
|
||||
"question": {
|
||||
"name": "www.cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "www.cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "CNAME",
|
||||
"ttl": "300",
|
||||
"data": "turner-tls.map.fastly.net."
|
||||
}
|
||||
],
|
||||
"authority": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": "3600",
|
||||
"data": "ns-1086.awsdns-07.org."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": "3600",
|
||||
"data": "ns-1630.awsdns-11.co.uk."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": "3600",
|
||||
"data": "ns-47.awsdns-05.com."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": "3600",
|
||||
"data": "ns-576.awsdns-08.net."
|
||||
}
|
||||
],
|
||||
"query_time": "26 msec",
|
||||
"server": "205.251.194.64#53(205.251.194.64)",
|
||||
"when": "Tue Nov 12 07:16:19 PST 2019",
|
||||
"rcvd": "212"
|
||||
"query_time": "48 msec",
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Fri Apr 16 16:06:12 PDT 2021",
|
||||
"rcvd": "56"
|
||||
}
|
||||
]
|
||||
|
||||
$ dig -x 1.1.1.1 | jc --dig -p
|
||||
[
|
||||
{
|
||||
"id": 34898,
|
||||
"id": 20785,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
@@ -265,6 +201,13 @@ Examples:
|
||||
"answer_num": 1,
|
||||
"authority_num": 0,
|
||||
"additional_num": 1,
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": 0,
|
||||
"flags": [],
|
||||
"udp": 4096
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "1.1.1.1.in-addr.arpa.",
|
||||
"class": "IN",
|
||||
@@ -275,21 +218,23 @@ Examples:
|
||||
"name": "1.1.1.1.in-addr.arpa.",
|
||||
"class": "IN",
|
||||
"type": "PTR",
|
||||
"ttl": 952,
|
||||
"ttl": 1800,
|
||||
"data": "one.one.one.one."
|
||||
}
|
||||
],
|
||||
"query_time": 103,
|
||||
"server": "2600",
|
||||
"when": "Tue Nov 12 07:15:33 PST 2019",
|
||||
"rcvd": 78
|
||||
"query_time": 40,
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Sat Apr 17 14:50:50 PDT 2021",
|
||||
"rcvd": 78,
|
||||
"when_epoch": 1618696250,
|
||||
"when_epoch_utc": null
|
||||
}
|
||||
]
|
||||
|
||||
$ dig -x 1.1.1.1 | jc --dig -p -r
|
||||
[
|
||||
{
|
||||
"id": "50986",
|
||||
"id": "32644",
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
@@ -301,6 +246,13 @@ Examples:
|
||||
"answer_num": "1",
|
||||
"authority_num": "0",
|
||||
"additional_num": "1",
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": "0",
|
||||
"flags": [],
|
||||
"udp": "4096"
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "1.1.1.1.in-addr.arpa.",
|
||||
"class": "IN",
|
||||
@@ -315,9 +267,9 @@ Examples:
|
||||
"data": "one.one.one.one."
|
||||
}
|
||||
],
|
||||
"query_time": "38 msec",
|
||||
"server": "2600",
|
||||
"when": "Tue Nov 12 07:17:19 PST 2019",
|
||||
"query_time": "52 msec",
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Sat Apr 17 14:51:46 PDT 2021",
|
||||
"rcvd": "78"
|
||||
}
|
||||
]
|
||||
@@ -327,75 +279,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"id": integer,
|
||||
"opcode": string,
|
||||
"status": string,
|
||||
"flags": [
|
||||
string
|
||||
],
|
||||
"query_num": integer,
|
||||
"answer_num": integer,
|
||||
"authority_num": integer,
|
||||
"additional_num": integer,
|
||||
"axfr": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"question": {
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"authority": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"query_time": integer, # in msec
|
||||
"server": string,
|
||||
"when": string,
|
||||
"rcvd": integer
|
||||
"size": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -412,5 +296,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, aix, freebsd, darwin
|
||||
|
||||
Version 2.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
148
docs/parsers/dir.md
Normal file
148
docs/parsers/dir.md
Normal file
@@ -0,0 +1,148 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.dir
|
||||
jc - JSON CLI output utility `dir` command output parser
|
||||
|
||||
Options supported:
|
||||
- `/T timefield`
|
||||
- `/O sortorder`
|
||||
- `/C, /-C`
|
||||
- `/S`
|
||||
|
||||
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
Usage (cli):
|
||||
|
||||
C:> dir | jc --dir
|
||||
|
||||
or
|
||||
|
||||
C:> jc dir
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dir
|
||||
result = jc.parsers.dir.parse(dir_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"date": string,
|
||||
"time": string,
|
||||
"epoch": integer, # naive timestamp
|
||||
"dir": boolean,
|
||||
"size": integer,
|
||||
"filename: string,
|
||||
"parent": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
C:> dir | jc --dir -p
|
||||
[
|
||||
{
|
||||
"date": "03/24/2021",
|
||||
"time": "03:15 PM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": ".",
|
||||
"parent": "C:\Program Files\Internet Explorer",
|
||||
"epoch": 1616624100
|
||||
},
|
||||
{
|
||||
"date": "03/24/2021",
|
||||
"time": "03:15 PM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": "..",
|
||||
"parent": "C:\Program Files\Internet Explorer",
|
||||
"epoch": 1616624100
|
||||
},
|
||||
{
|
||||
"date": "12/07/2019",
|
||||
"time": "02:49 AM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": "en-US",
|
||||
"parent": "C:\Program Files\Internet Explorer",
|
||||
"epoch": 1575715740
|
||||
},
|
||||
{
|
||||
"date": "12/07/2019",
|
||||
"time": "02:09 AM",
|
||||
"dir": false,
|
||||
"size": 54784,
|
||||
"filename": "ExtExport.exe",
|
||||
"parent": "C:\Program Files\Internet Explorer",
|
||||
"epoch": 1575713340
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
C:> dir | jc --dir -p -r
|
||||
[
|
||||
{
|
||||
"date": "03/24/2021",
|
||||
"time": "03:15 PM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": ".",
|
||||
"parent": "C:\Program Files\Internet Explorer"
|
||||
},
|
||||
{
|
||||
"date": "03/24/2021",
|
||||
"time": "03:15 PM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": "..",
|
||||
"parent": "C:\Program Files\Internet Explorer"
|
||||
},
|
||||
{
|
||||
"date": "12/07/2019",
|
||||
"time": "02:49 AM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": "en-US",
|
||||
"parent": "C:\Program Files\Internet Explorer"
|
||||
},
|
||||
{
|
||||
"date": "12/07/2019",
|
||||
"time": "02:09 AM",
|
||||
"dir": false,
|
||||
"size": "54,784",
|
||||
"filename": "ExtExport.exe",
|
||||
"parent": "C:\Program Files\Internet Explorer"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: win32
|
||||
|
||||
Version 1.2 by Rasheed Elsaleh (rasheed@rebelliondefense.com)
|
||||
@@ -1,14 +1,37 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc dmidecode
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dmidecode
|
||||
result = jc.parsers.dmidecode.parse(dmidecode_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"handle": string,
|
||||
"type": integer,
|
||||
"bytes": integer,
|
||||
"description": string,
|
||||
"values": { (null if empty)
|
||||
"lowercase_no_spaces_keys": string,
|
||||
"multiline_key_values": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -105,38 +128,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"handle": string,
|
||||
"type": integer,
|
||||
"bytes": integer,
|
||||
"description": string,
|
||||
"values": { (null if empty)
|
||||
"lowercase_no_spaces_keys": string,
|
||||
"multiline_key_values": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -153,5 +145,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
158
docs/parsers/dpkg_l.md
Normal file
158
docs/parsers/dpkg_l.md
Normal file
@@ -0,0 +1,158 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.dpkg_l
|
||||
jc - JSON CLI output utility `dpkg -l` command output parser
|
||||
|
||||
Set the `COLUMNS` environment variable to a large value to avoid field truncation. For example:
|
||||
|
||||
$ COLUMNS=500 dpkg -l | jc --dpkg-l
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ dpkg -l | jc --dpkg-l
|
||||
|
||||
or
|
||||
|
||||
$ jc dpkg -l
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dpkg_l
|
||||
result = jc.parsers.dpkg_l.parse(dpkg_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"codes": string,
|
||||
"name": string,
|
||||
"version": string,
|
||||
"architecture": string,
|
||||
"description": string,
|
||||
"desired": string,
|
||||
"status": string,
|
||||
"error": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ dpkg -l | jc --dpkg-l -p
|
||||
[
|
||||
{
|
||||
"codes": "ii",
|
||||
"name": "accountsservice",
|
||||
"version": "0.6.45-1ubuntu1.3",
|
||||
"architecture": "amd64",
|
||||
"description": "query and manipulate user account information",
|
||||
"desired": "install",
|
||||
"status": "installed"
|
||||
},
|
||||
{
|
||||
"codes": "rc",
|
||||
"name": "acl",
|
||||
"version": "2.2.52-3build1",
|
||||
"architecture": "amd64",
|
||||
"description": "Access control list utilities",
|
||||
"desired": "remove",
|
||||
"status": "config-files"
|
||||
},
|
||||
{
|
||||
"codes": "uWR",
|
||||
"name": "acpi",
|
||||
"version": "1.7-1.1",
|
||||
"architecture": "amd64",
|
||||
"description": "displays information on ACPI devices",
|
||||
"desired": "unknown",
|
||||
"status": "trigger await",
|
||||
"error": "reinstall required"
|
||||
},
|
||||
{
|
||||
"codes": "rh",
|
||||
"name": "acpid",
|
||||
"version": "1:2.0.28-1ubuntu1",
|
||||
"architecture": "amd64",
|
||||
"description": "Advanced Configuration and Power Interface event daemon",
|
||||
"desired": "remove",
|
||||
"status": "half installed"
|
||||
},
|
||||
{
|
||||
"codes": "pn",
|
||||
"name": "adduser",
|
||||
"version": "3.116ubuntu1",
|
||||
"architecture": "all",
|
||||
"description": "add and remove users and groups",
|
||||
"desired": "purge",
|
||||
"status": "not installed"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ dpkg -l | jc --dpkg-l -p -r
|
||||
[
|
||||
{
|
||||
"codes": "ii",
|
||||
"name": "accountsservice",
|
||||
"version": "0.6.45-1ubuntu1.3",
|
||||
"architecture": "amd64",
|
||||
"description": "query and manipulate user account information"
|
||||
},
|
||||
{
|
||||
"codes": "rc",
|
||||
"name": "acl",
|
||||
"version": "2.2.52-3build1",
|
||||
"architecture": "amd64",
|
||||
"description": "Access control list utilities"
|
||||
},
|
||||
{
|
||||
"codes": "uWR",
|
||||
"name": "acpi",
|
||||
"version": "1.7-1.1",
|
||||
"architecture": "amd64",
|
||||
"description": "displays information on ACPI devices"
|
||||
},
|
||||
{
|
||||
"codes": "rh",
|
||||
"name": "acpid",
|
||||
"version": "1:2.0.28-1ubuntu1",
|
||||
"architecture": "amd64",
|
||||
"description": "Advanced Configuration and Power Interface event daemon"
|
||||
},
|
||||
{
|
||||
"codes": "pn",
|
||||
"name": "adduser",
|
||||
"version": "3.116ubuntu1",
|
||||
"architecture": "all",
|
||||
"description": "add and remove users and groups"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,14 +1,29 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
$ jc du
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.du
|
||||
result = jc.parsers.du.parse(du_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"size": integer,
|
||||
"name": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -75,30 +90,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"size": integer,
|
||||
"name": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -115,5 +107,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, aix, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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):
|
||||
|
||||
Compatibility:
|
||||
$ env | jc --env
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
or
|
||||
|
||||
$ jc env
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.env
|
||||
result = jc.parsers.env.parse(env_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"value": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -55,30 +72,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"value": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -96,5 +90,9 @@ Parameters:
|
||||
Returns:
|
||||
|
||||
Dictionary of raw structured data or
|
||||
list of dictionaries of processed structured data
|
||||
List of Dictionaries of processed structured data
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'aix', 'freebsd', 'darwin'
|
||||
$ jc file *
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.file
|
||||
result = jc.parsers.file.parse(file_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"type ": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -50,30 +65,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"type ": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -90,5 +82,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, aix, freebsd, darwin
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
118
docs/parsers/finger.md
Normal file
118
docs/parsers/finger.md
Normal file
@@ -0,0 +1,118 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.finger
|
||||
jc - JSON CLI output utility `finger` command output parser
|
||||
|
||||
Supports `-s` output option. Does not support the `-l` detail option.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ finger | jc --finger
|
||||
|
||||
or
|
||||
|
||||
$ jc finger
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.finger
|
||||
result = jc.parsers.finger.parse(finger_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"login": string,
|
||||
"name": string,
|
||||
"tty": string,
|
||||
"idle": string, # null if empty
|
||||
"login_time": string,
|
||||
"details": string,
|
||||
"tty_writeable": boolean,
|
||||
"idle_minutes": integer,
|
||||
"idle_hours": integer,
|
||||
"idle_days": integer,
|
||||
"total_idle_minutes": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ finger | jc --finger -p
|
||||
[
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "tty1",
|
||||
"idle": "14d",
|
||||
"login_time": "Mar 22 21:14",
|
||||
"tty_writeable": false,
|
||||
"idle_minutes": 0,
|
||||
"idle_hours": 0,
|
||||
"idle_days": 14,
|
||||
"total_idle_minutes": 20160
|
||||
},
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "pts/0",
|
||||
"idle": null,
|
||||
"login_time": "Apr 5 15:33",
|
||||
"details": "(192.168.1.22)",
|
||||
"tty_writeable": true,
|
||||
"idle_minutes": 0,
|
||||
"idle_hours": 0,
|
||||
"idle_days": 0,
|
||||
"total_idle_minutes": 0
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ finger | jc --finger -p -r
|
||||
[
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "*tty1",
|
||||
"idle": "14d",
|
||||
"login_time": "Mar 22 21:14"
|
||||
},
|
||||
{
|
||||
"login": "jdoe",
|
||||
"name": "John Doe",
|
||||
"tty": "pts/0",
|
||||
"idle": null,
|
||||
"login_time": "Apr 5 15:33",
|
||||
"details": "(192.168.1.22)"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, freebsd
|
||||
|
||||
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,14 +1,34 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc free
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.free
|
||||
result = jc.parsers.free.parse(free_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"type": string,
|
||||
"total": integer,
|
||||
"used": integer,
|
||||
"free": integer,
|
||||
"shared": integer,
|
||||
"buff_cache": integer,
|
||||
"available": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -55,35 +75,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"type": string,
|
||||
"total": integer,
|
||||
"used": integer,
|
||||
"free": integer,
|
||||
"shared": integer,
|
||||
"buff_cache": integer,
|
||||
"available": integer
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -100,5 +92,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
Usage (module):
|
||||
|
||||
'linux', 'freebsd'
|
||||
import jc.parsers.fstab
|
||||
result = jc.parsers.fstab.parse(fstab_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"fs_spec": string,
|
||||
"fs_file": string,
|
||||
"fs_vfstype": string,
|
||||
"fs_mntops": string,
|
||||
"fs_freq": integer,
|
||||
"fs_passno": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -73,34 +88,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"fs_spec": string,
|
||||
"fs_file": string,
|
||||
"fs_vfstype": string,
|
||||
"fs_mntops": string,
|
||||
"fs_freq": integer,
|
||||
"fs_passno": integer
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -117,5 +105,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, freebsd
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
Usage (module):
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
import jc.parsers.group
|
||||
result = jc.parsers.group.parse(group_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"group_name": string,
|
||||
"password": string,
|
||||
"gid": integer,
|
||||
"members": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -97,34 +112,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"group_name": string,
|
||||
"password": string,
|
||||
"gid": integer,
|
||||
"members": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -141,5 +129,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, aix, freebsd
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
Usage (module):
|
||||
|
||||
'linux', 'aix', 'freebsd'
|
||||
import jc.parsers.gshadow
|
||||
result = jc.parsers.gshadow.parse(gshadow_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"group_name": string,
|
||||
"password": string,
|
||||
"administrators": [
|
||||
string
|
||||
],
|
||||
"members": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -63,36 +80,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"group_name": string,
|
||||
"password": string,
|
||||
"administrators": [
|
||||
string
|
||||
],
|
||||
"members": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -109,5 +97,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, aix, freebsd
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
65
docs/parsers/hash.md
Normal file
65
docs/parsers/hash.md
Normal file
@@ -0,0 +1,65 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"command": string,
|
||||
"hits": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ hash | jc --hash -p
|
||||
[
|
||||
{
|
||||
"hits": 2,
|
||||
"command": "/bin/cat"
|
||||
},
|
||||
{
|
||||
"hits": 1,
|
||||
"command": "/bin/ls"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
96
docs/parsers/hashsum.md
Normal file
96
docs/parsers/hashsum.md
Normal file
@@ -0,0 +1,96 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"hash": string,
|
||||
}
|
||||
]
|
||||
|
||||
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()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
345
docs/parsers/hciconfig.md
Normal file
345
docs/parsers/hciconfig.md
Normal file
@@ -0,0 +1,345 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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)
|
||||
|
||||
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
|
||||
}
|
||||
]
|
||||
|
||||
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()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,14 +1,27 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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):
|
||||
|
||||
Compatibility:
|
||||
$ history | jc --history
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.history
|
||||
result = jc.parsers.history.parse(history_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"line": integer,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -47,30 +60,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"line": integer,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -88,5 +78,9 @@ Parameters:
|
||||
Returns:
|
||||
|
||||
Dictionary of raw structured data or
|
||||
list of dictionaries of processed structured data
|
||||
List of Dictionaries of processed structured data
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
Usage (module):
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
import jc.parsers.hosts
|
||||
result = jc.parsers.hosts.parse(hosts_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"ip": string,
|
||||
"hostname": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -64,32 +77,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"ip": string,
|
||||
"hostname": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -106,5 +94,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,49 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
$ jc id
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.id
|
||||
result = jc.parsers.id.parse(id_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"uid": {
|
||||
"id": integer,
|
||||
"name": string
|
||||
},
|
||||
"gid": {
|
||||
"id": integer,
|
||||
"name": string
|
||||
},
|
||||
"groups": [
|
||||
{
|
||||
"id": integer,
|
||||
"name": string
|
||||
},
|
||||
{
|
||||
"id": integer,
|
||||
"name": string
|
||||
}
|
||||
],
|
||||
"context": {
|
||||
"user": string,
|
||||
"role": string,
|
||||
"type": string,
|
||||
"level": string
|
||||
}
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -73,50 +108,7 @@ Examples:
|
||||
```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:
|
||||
|
||||
{
|
||||
"uid": {
|
||||
"id": integer,
|
||||
"name": string
|
||||
},
|
||||
"gid": {
|
||||
"id": integer,
|
||||
"name": string
|
||||
},
|
||||
"groups": [
|
||||
{
|
||||
"id": integer,
|
||||
"name": string
|
||||
},
|
||||
{
|
||||
"id": integer,
|
||||
"name": string
|
||||
}
|
||||
],
|
||||
"context": {
|
||||
"user": string,
|
||||
"role": string,
|
||||
"type": string,
|
||||
"level": string
|
||||
}
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -133,5 +125,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, aix, freebsd
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,16 +1,57 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'aix', 'freebsd', 'darwin'
|
||||
$ jc ifconfig
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ifconfig
|
||||
result = jc.parsers.ifconfig.parse(ifconfig_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"flags": integer,
|
||||
"state": [
|
||||
string
|
||||
],
|
||||
"mtu": integer,
|
||||
"ipv4_addr": string,
|
||||
"ipv4_mask": string,
|
||||
"ipv4_bcast": string,
|
||||
"ipv6_addr": string,
|
||||
"ipv6_mask": integer,
|
||||
"ipv6_scope": string,
|
||||
"mac_addr": string,
|
||||
"type": string,
|
||||
"rx_packets": integer,
|
||||
"rx_bytes": integer,
|
||||
"rx_errors": integer,
|
||||
"rx_dropped": integer,
|
||||
"rx_overruns": integer,
|
||||
"rx_frame": integer,
|
||||
"tx_packets": integer,
|
||||
"tx_bytes": integer,
|
||||
"tx_errors": integer,
|
||||
"tx_dropped": integer,
|
||||
"tx_overruns": integer,
|
||||
"tx_carrier": integer,
|
||||
"tx_collisions": integer,
|
||||
"metric": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -148,62 +189,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## IfconfigParser
|
||||
```python
|
||||
IfconfigParser(console_output)
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"flags": integer,
|
||||
"state": [
|
||||
string
|
||||
],
|
||||
"mtu": integer,
|
||||
"ipv4_addr": string,
|
||||
"ipv4_mask": string,
|
||||
"ipv4_bcast": string,
|
||||
"ipv6_addr": string,
|
||||
"ipv6_mask": integer,
|
||||
"ipv6_scope": string,
|
||||
"mac_addr": string,
|
||||
"type": string,
|
||||
"rx_packets": integer,
|
||||
"rx_bytes": integer,
|
||||
"rx_errors": integer,
|
||||
"rx_dropped": integer,
|
||||
"rx_overruns": integer,
|
||||
"rx_frame": integer,
|
||||
"tx_packets": integer,
|
||||
"tx_bytes": integer,
|
||||
"tx_errors": integer,
|
||||
"tx_dropped": integer,
|
||||
"tx_overruns": integer,
|
||||
"tx_carrier": integer,
|
||||
"tx_collisions": integer,
|
||||
"metric": integer
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -220,5 +206,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, aix, freebsd, darwin
|
||||
|
||||
Version 1.10 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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 or any
|
||||
simple key/value pair file. 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()`.
|
||||
|
||||
Compatibility:
|
||||
Usage (cli):
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
$ cat foo.ini | jc --ini
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ini
|
||||
result = jc.parsers.ini.parse(ini_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
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.
|
||||
|
||||
{
|
||||
"key1": string,
|
||||
"key2": string
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -51,31 +68,7 @@ Examples:
|
||||
```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 representing an ini or simple key/value pair document:
|
||||
|
||||
{
|
||||
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.
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -94,3 +87,7 @@ Returns:
|
||||
|
||||
Dictionary representing the ini file
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,16 +1,45 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc iptables -L -t nat
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.iptables
|
||||
result = jc.parsers.iptables.parse(iptables_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"chain": string,
|
||||
"rules": [
|
||||
{
|
||||
"num" integer,
|
||||
"pkts": integer,
|
||||
"bytes": integer, # converted based on suffix
|
||||
"target": string,
|
||||
"prot": string,
|
||||
"opt": string, # "--" = Null
|
||||
"in": string,
|
||||
"out": string,
|
||||
"source": string,
|
||||
"destination": string,
|
||||
"options": string
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -137,44 +166,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"chain": string,
|
||||
"rules": [
|
||||
{
|
||||
"num" integer,
|
||||
"pkts": integer,
|
||||
"bytes": integer, # converted based on suffix
|
||||
"target": string,
|
||||
"prot": string,
|
||||
"opt": string, # "--" = Null
|
||||
"in": string,
|
||||
"out": string,
|
||||
"source": string,
|
||||
"destination": string,
|
||||
"options": string
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -191,5 +183,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
148
docs/parsers/iw_scan.md
Normal file
148
docs/parsers/iw_scan.md
Normal file
@@ -0,0 +1,148 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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 and there are not enough samples to test.
|
||||
|
||||
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)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"foo": string/integer/float, # best guess based on value
|
||||
"bar": string/integer/float,
|
||||
"baz": string/integer/float
|
||||
}
|
||||
]
|
||||
|
||||
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()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 0.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,16 +1,34 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
$ jc jobs
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.jobs
|
||||
result = jc.parsers.jobs.parse(jobs_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"job_number": integer,
|
||||
"pid": integer,
|
||||
"history": string,
|
||||
"status": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
|
||||
Example:
|
||||
|
||||
@@ -79,33 +97,7 @@ Example:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"job_number": integer,
|
||||
"pid": integer,
|
||||
"history": string,
|
||||
"status": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -122,5 +114,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,16 +1,29 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.kv
|
||||
jc - JSON CLI output utility Key/Value File Parser
|
||||
jc - JSON CLI output utility `Key/Value` file parser
|
||||
|
||||
Usage:
|
||||
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.
|
||||
|
||||
Specify --kv as the first argument if the piped input is coming from a simple
|
||||
key/value pair file. 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()`.
|
||||
|
||||
Compatibility:
|
||||
Usage (cli):
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
$ cat foo.txt | jc --kv
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.kv
|
||||
result = jc.parsers.kv.parse(kv_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
key/value document converted to a dictionary - see configparser standard library documentation for more details.
|
||||
|
||||
{
|
||||
"key1": string,
|
||||
"key2": string
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -38,7 +51,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -59,3 +72,7 @@ Returns:
|
||||
|
||||
Dictionary representing the key/value file
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,41 +1,73 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
Calculated epoch time fields are naive (i.e. based on the local time of the system the parser is run on) since there is no timezone information in the `last` command output.
|
||||
|
||||
Compatibility:
|
||||
Usage (cli):
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
$ last | jc --last
|
||||
|
||||
or
|
||||
|
||||
$ jc last
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.last
|
||||
result = jc.parsers.last.parse(last_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"user": string,
|
||||
"tty": string,
|
||||
"hostname": string,
|
||||
"login": string,
|
||||
"logout": string,
|
||||
"duration": string,
|
||||
"login_epoch": integer, # (naive) available with last -F option
|
||||
"logout_epoch": integer, # (naive) available with last -F option
|
||||
"duration_seconds": integer # available with last -F option
|
||||
}
|
||||
]
|
||||
|
||||
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
|
||||
},
|
||||
...
|
||||
]
|
||||
@@ -74,34 +106,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"user": string,
|
||||
"tty": string,
|
||||
"hostname": string,
|
||||
"login": string,
|
||||
"logout": string,
|
||||
"duration": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -118,5 +123,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, aix, freebsd
|
||||
|
||||
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,26 +1,47 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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:
|
||||
- `lbaR1`
|
||||
- `--time-style=full-iso`
|
||||
|
||||
Usage:
|
||||
Note: The `-1`, `-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 `-1`, `-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
|
||||
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
ls options supported:
|
||||
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
|
||||
|
||||
-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.
|
||||
Usage (cli):
|
||||
|
||||
Compatibility:
|
||||
$ ls | jc --ls
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
or
|
||||
|
||||
$ jc ls
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ls
|
||||
result = jc.parsers.ls.parse(ls_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"flags": string,
|
||||
"links": integer,
|
||||
"parent": string,
|
||||
"owner": string,
|
||||
"group": string,
|
||||
"size": integer,
|
||||
"date": string,
|
||||
"epoch": integer, # naive timestamp if date field exists and can be converted
|
||||
"epoch_utc": integer # timezone aware timestamp if date field is in UTC and can be converted
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -32,12 +53,6 @@ Examples:
|
||||
{
|
||||
"filename": "arch"
|
||||
},
|
||||
{
|
||||
"filename": "awk"
|
||||
},
|
||||
{
|
||||
"filename": "base64"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
@@ -62,15 +77,6 @@ Examples:
|
||||
"size": 62744,
|
||||
"date": "Aug 8 16:14"
|
||||
},
|
||||
{
|
||||
"filename": "arch",
|
||||
"flags": "-rwxr-xr-x.",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 33080,
|
||||
"date": "Aug 19 23:25"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
@@ -95,92 +101,15 @@ Examples:
|
||||
"size": "33080",
|
||||
"date": "Aug 19 23:25"
|
||||
},
|
||||
{
|
||||
"filename": "awk",
|
||||
"link_to": "gawk",
|
||||
"flags": "lrwxrwxrwx.",
|
||||
"links": "1",
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": "4",
|
||||
"date": "Aug 15 10:53"
|
||||
},
|
||||
{
|
||||
"filename": "base64",
|
||||
"flags": "-rwxr-xr-x.",
|
||||
"links": "1",
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": "37360",
|
||||
"date": "Aug 19 23:25"
|
||||
},
|
||||
{
|
||||
"filename": "basename",
|
||||
"flags": "-rwxr-xr-x.",
|
||||
"links": "1",
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": "29032",
|
||||
"date": "Aug 19 23:25"
|
||||
},
|
||||
{
|
||||
"filename": "bash",
|
||||
"flags": "-rwxr-xr-x.",
|
||||
"links": "1",
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": "964600",
|
||||
"date": "Aug 8 05:06"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ ls -l /usr/bin | jc --ls | jq '.[] | select(.size > 50000000)'
|
||||
{
|
||||
"filename": "emacs",
|
||||
"flags": "-r-xr-xr-x",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "wheel",
|
||||
"size": 117164432,
|
||||
"date": "May 3 2019"
|
||||
}
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"flags": string,
|
||||
"links": integer,
|
||||
"parent": string,
|
||||
"owner": string,
|
||||
"group": string,
|
||||
"size": integer,
|
||||
"date": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -197,5 +126,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.9 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,67 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc lsblk
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.lsblk
|
||||
result = jc.parsers.lsblk.parse(lsblk_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"maj_min": string,
|
||||
"rm": boolean,
|
||||
"size": string,
|
||||
"ro": boolean,
|
||||
"type": string,
|
||||
"mountpoint": string,
|
||||
"kname": string,
|
||||
"fstype": string,
|
||||
"label": string,
|
||||
"uuid": string,
|
||||
"partlabel": string,
|
||||
"partuuid": string,
|
||||
"ra": integer,
|
||||
"model": string,
|
||||
"serial": string,
|
||||
"state": string,
|
||||
"owner": string,
|
||||
"group": string,
|
||||
"mode": string,
|
||||
"alignment": integer,
|
||||
"min_io": integer,
|
||||
"opt_io": integer,
|
||||
"phy_sec": integer,
|
||||
"log_sec": integer,
|
||||
"rota": boolean,
|
||||
"sched": string,
|
||||
"rq_size": integer,
|
||||
"disc_aln": integer,
|
||||
"disc_gran": string,
|
||||
"disc_max": string,
|
||||
"disc_zero": boolean,
|
||||
"wsame": string,
|
||||
"wwn": string,
|
||||
"rand": boolean,
|
||||
"pkname": string,
|
||||
"hctl": string,
|
||||
"tran": string,
|
||||
"rev": string,
|
||||
"vendor": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -218,68 +271,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"maj_min": string,
|
||||
"rm": boolean,
|
||||
"size": string,
|
||||
"ro": boolean,
|
||||
"type": string,
|
||||
"mountpoint": string,
|
||||
"kname": string,
|
||||
"fstype": string,
|
||||
"label": string,
|
||||
"uuid": string,
|
||||
"partlabel": string,
|
||||
"partuuid": string,
|
||||
"ra": integer,
|
||||
"model": string,
|
||||
"serial": string,
|
||||
"state": string,
|
||||
"owner": string,
|
||||
"group": string,
|
||||
"mode": string,
|
||||
"alignment": integer,
|
||||
"min_io": integer,
|
||||
"opt_io": integer,
|
||||
"phy_sec": integer,
|
||||
"log_sec": integer,
|
||||
"rota": boolean,
|
||||
"sched": string,
|
||||
"rq_size": integer,
|
||||
"disc_aln": integer,
|
||||
"disc_gran": string,
|
||||
"disc_max": string,
|
||||
"disc_zero": boolean,
|
||||
"wsame": string,
|
||||
"wwn": string,
|
||||
"rand": boolean,
|
||||
"pkname": string,
|
||||
"hctl": string,
|
||||
"tran": string,
|
||||
"rev": string,
|
||||
"vendor": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -296,5 +288,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc lsmod
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.lsmod
|
||||
result = jc.parsers.lsmod.parse(lsmod_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"module": string,
|
||||
"size": integer,
|
||||
"used": integer,
|
||||
"by": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -109,34 +128,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"module": string,
|
||||
"size": integer,
|
||||
"used": integer,
|
||||
"by": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -153,5 +145,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc lsof
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.lsof
|
||||
result = jc.parsers.lsof.parse(lsof_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"command": string,
|
||||
"pid": integer,
|
||||
"tid": integer,
|
||||
"user": string,
|
||||
"fd": string,
|
||||
"type": string,
|
||||
"device": string,
|
||||
"size_off": integer,
|
||||
"node": integer,
|
||||
"name": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -99,38 +122,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"command": string,
|
||||
"pid": integer,
|
||||
"tid": integer,
|
||||
"user": string,
|
||||
"fd": string,
|
||||
"type": string,
|
||||
"device": string,
|
||||
"size_off": integer,
|
||||
"node": integer,
|
||||
"name": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -147,5 +139,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
$ jc mount
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.mount
|
||||
result = jc.parsers.mount.parse(mount_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filesystem": string,
|
||||
"mount_point": string,
|
||||
"type": string,
|
||||
"access": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Example:
|
||||
|
||||
@@ -59,34 +78,7 @@ Example:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filesystem": string,
|
||||
"mount_point": string,
|
||||
"type": string,
|
||||
"access": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -103,5 +95,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,19 +1,125 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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):
|
||||
|
||||
Compatibility:
|
||||
$ netstat | jc --netstat
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
or
|
||||
|
||||
$ jc netstat
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.netstat
|
||||
result = jc.parsers.netstat.parse(netstat_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"proto": string,
|
||||
"recv_q": integer,
|
||||
"send_q": integer,
|
||||
"transport_protocol" string,
|
||||
"network_protocol": string,
|
||||
"local_address": string,
|
||||
"local_port": string,
|
||||
"local_port_num": integer,
|
||||
"foreign_address": string,
|
||||
"foreign_port": string,
|
||||
"foreign_port_num": integer,
|
||||
"state": string,
|
||||
"program_name": string,
|
||||
"pid": integer,
|
||||
"user": string,
|
||||
"security_context": string,
|
||||
"refcnt": integer,
|
||||
"flags": string,
|
||||
"type": string,
|
||||
"inode": integer,
|
||||
"path": string,
|
||||
"kind": string,
|
||||
"address": string,
|
||||
"unix_inode": string,
|
||||
"conn": string,
|
||||
"refs": string,
|
||||
"nextref": string,
|
||||
"name": string,
|
||||
"unit": integer,
|
||||
"vendor": integer,
|
||||
"class": integer,
|
||||
"subcla": integer,
|
||||
"unix_flags": integer,
|
||||
"pcbcount": integer,
|
||||
"rcvbuf": integer,
|
||||
"sndbuf": integer,
|
||||
"rxbytes": integer,
|
||||
"txbytes": integer,
|
||||
"destination": string,
|
||||
"gateway": string,
|
||||
"route_flags": string,
|
||||
"route_flags_pretty": [
|
||||
string,
|
||||
]
|
||||
"route_refs": integer,
|
||||
"use": integer,
|
||||
"mtu": integer,
|
||||
"expire": string,
|
||||
"genmask": string,
|
||||
"mss": integer,
|
||||
"window": integer,
|
||||
"irtt": integer,
|
||||
"iface": string,
|
||||
"metric": integer,
|
||||
"network": string,
|
||||
"address": string,
|
||||
"ipkts": integer, # - = null
|
||||
"ierrs": integer, # - = null
|
||||
"idrop": integer, # - = null
|
||||
"opkts": integer, # - = null
|
||||
"oerrs": integer, # - = null
|
||||
"coll": integer, # - = null
|
||||
"rx_ok": integer,
|
||||
"rx_err": integer,
|
||||
"rx_drp": integer,
|
||||
"rx_ovr": integer,
|
||||
"tx_ok": integer,
|
||||
"tx_err": integer,
|
||||
"tx_drp": integer,
|
||||
"tx_ovr": integer,
|
||||
"flg": string,
|
||||
"ibytes": integer,
|
||||
"obytes": integer,
|
||||
"r_mbuf": integer,
|
||||
"s_mbuf": integer,
|
||||
"r_clus": integer,
|
||||
"s_clus": integer,
|
||||
"r_hiwa": integer,
|
||||
"s_hiwa": integer,
|
||||
"r_lowa": integer,
|
||||
"s_lowa": integer,
|
||||
"r_bcnt": integer,
|
||||
"s_bcnt": integer,
|
||||
"r_bmax": integer,
|
||||
"s_bmax": integer,
|
||||
"rexmit": integer,
|
||||
"ooorcv": integer,
|
||||
"0_win": integer,
|
||||
"rexmt": float,
|
||||
"persist": float,
|
||||
"keep": float,
|
||||
"2msl": float,
|
||||
"delack": float,
|
||||
"rcvtime": float,
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -251,122 +357,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"proto": string,
|
||||
"recv_q": integer,
|
||||
"send_q": integer,
|
||||
"transport_protocol" string,
|
||||
"network_protocol": string,
|
||||
"local_address": string,
|
||||
"local_port": string,
|
||||
"local_port_num": integer,
|
||||
"foreign_address": string,
|
||||
"foreign_port": string,
|
||||
"foreign_port_num": integer,
|
||||
"state": string,
|
||||
"program_name": string,
|
||||
"pid": integer,
|
||||
"user": string,
|
||||
"security_context": string,
|
||||
"refcnt": integer,
|
||||
"flags": string,
|
||||
"type": string,
|
||||
"inode": integer,
|
||||
"path": string,
|
||||
"kind": string,
|
||||
"address": string,
|
||||
"unix_inode": string,
|
||||
"conn": string,
|
||||
"refs": string,
|
||||
"nextref": string,
|
||||
"name": string,
|
||||
"unit": integer,
|
||||
"vendor": integer,
|
||||
"class": integer,
|
||||
"subcla": integer,
|
||||
"unix_flags": integer,
|
||||
"pcbcount": integer,
|
||||
"rcvbuf": integer,
|
||||
"sndbuf": integer,
|
||||
"rxbytes": integer,
|
||||
"txbytes": integer,
|
||||
"destination": string,
|
||||
"gateway": string,
|
||||
"route_flags": string,
|
||||
"route_flags_pretty": [
|
||||
string,
|
||||
]
|
||||
"route_refs": integer,
|
||||
"use": integer,
|
||||
"mtu": integer,
|
||||
"expire": string,
|
||||
"genmask": string,
|
||||
"mss": integer,
|
||||
"window": integer,
|
||||
"irtt": integer,
|
||||
"iface": string,
|
||||
"metric": integer,
|
||||
"network": string,
|
||||
"address": string,
|
||||
"ipkts": integer, - = null
|
||||
"ierrs": integer, - = null
|
||||
"idrop": integer, - = null
|
||||
"opkts": integer, - = null
|
||||
"oerrs": integer, - = null
|
||||
"coll": integer, - = null
|
||||
"rx_ok": integer,
|
||||
"rx_err": integer,
|
||||
"rx_drp": integer,
|
||||
"rx_ovr": integer,
|
||||
"tx_ok": integer,
|
||||
"tx_err": integer,
|
||||
"tx_drp": integer,
|
||||
"tx_ovr": integer,
|
||||
"flg": string,
|
||||
"ibytes": integer,
|
||||
"obytes": integer,
|
||||
"r_mbuf": integer,
|
||||
"s_mbuf": integer,
|
||||
"r_clus": integer,
|
||||
"s_clus": integer,
|
||||
"r_hiwa": integer,
|
||||
"s_hiwa": integer,
|
||||
"r_lowa": integer,
|
||||
"s_lowa": integer,
|
||||
"r_bcnt": integer,
|
||||
"s_bcnt": integer,
|
||||
"r_bmax": integer,
|
||||
"s_bmax": integer,
|
||||
"rexmit": integer,
|
||||
"ooorcv": integer,
|
||||
"0_win": integer,
|
||||
"rexmt": float,
|
||||
"persist": float,
|
||||
"keep": float,
|
||||
"2msl": float,
|
||||
"delack": float,
|
||||
"rcvtime": float,
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -383,5 +374,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 1.10 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,38 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'freebsd'
|
||||
$ jc ntpq -p
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ntpq
|
||||
result = jc.parsers.ntpq.parse(ntpq_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"state": string, # space/~ converted to null
|
||||
"remote": string,
|
||||
"refid": string,
|
||||
"st": integer,
|
||||
"t": string,
|
||||
"when": integer, # - converted to null
|
||||
"poll": integer,
|
||||
"reach": integer,
|
||||
"delay": float,
|
||||
"offset": float,
|
||||
"jitter": float
|
||||
},
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -185,40 +209,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"state": string, # space/~ converted to null
|
||||
"remote": string,
|
||||
"refid": string,
|
||||
"st": integer,
|
||||
"t": string,
|
||||
"when": integer, # - converted to null
|
||||
"poll": integer,
|
||||
"reach": integer,
|
||||
"delay": float,
|
||||
"offset": float,
|
||||
"jitter": float
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -235,5 +226,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, freebsd
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
Usage (module):
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
import jc.parsers.passwd
|
||||
result = jc.parsers.passwd.parse(passwd_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"username": string,
|
||||
"password": string,
|
||||
"uid": integer,
|
||||
"gid": integer,
|
||||
"comment": string,
|
||||
"home": string,
|
||||
"shell": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -81,35 +97,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"username": string,
|
||||
"password": string,
|
||||
"uid": integer,
|
||||
"gid": integer,
|
||||
"comment": string,
|
||||
"home": string,
|
||||
"shell": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -126,5 +114,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, aix, freebsd
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,16 +1,54 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.ping
|
||||
jc - JSON CLI output utility ping Parser
|
||||
jc - JSON CLI output utility `ping` command output parser
|
||||
|
||||
Usage:
|
||||
Supports `ping` and `ping6` output.
|
||||
|
||||
specify --ping as the first argument if the piped input is coming from ping
|
||||
Usage (cli):
|
||||
|
||||
Note: Use the ping -c (count) option, otherwise data will not be piped to jc.
|
||||
Note: Use the ping `-c` (count) option, otherwise data will not be piped to `jc`.
|
||||
|
||||
Compatibility:
|
||||
$ ping -c 3 1.2.3.4 | jc --ping
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
or
|
||||
|
||||
$ jc ping -c 3 1.2.3.4
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ping
|
||||
result = jc.parsers.ping.parse(ping_command_output)
|
||||
|
||||
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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -110,51 +148,7 @@ Examples:
|
||||
```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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -173,3 +167,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
$ jc pip list
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.pip_list
|
||||
result = jc.parsers.pip_list.parse(pip_list_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"package": string,
|
||||
"version": string,
|
||||
"location": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -34,31 +50,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"package": string,
|
||||
"version": string,
|
||||
"location": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -75,5 +67,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
$ jc pip show
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.pip_show
|
||||
result = jc.parsers.pip_show.parse(pip_show_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"version": string,
|
||||
"summary": string,
|
||||
"home_page": string,
|
||||
"author": string,
|
||||
"author_email": string,
|
||||
"license": string,
|
||||
"location": string,
|
||||
"requires": string,
|
||||
"required_by": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -45,39 +68,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"version": string,
|
||||
"summary": string,
|
||||
"home_page": string,
|
||||
"author": string,
|
||||
"author_email": string,
|
||||
"license": string,
|
||||
"location": string,
|
||||
"requires": string,
|
||||
"required_by": string
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -94,5 +85,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,18 +1,48 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
$ jc ps
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ps
|
||||
result = jc.parsers.ps.parse(ps_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"uid": string,
|
||||
"pid": integer,
|
||||
"ppid": integer,
|
||||
"c": integer,
|
||||
"stime": string,
|
||||
"tty": string, # ? or ?? = Null
|
||||
"tt": string, # ?? = Null
|
||||
"time": string,
|
||||
"cmd": string,
|
||||
"user": string,
|
||||
"cpu_percent": float,
|
||||
"mem_percent": float,
|
||||
"vsz": integer,
|
||||
"rss": integer,
|
||||
"stat": string,
|
||||
"start": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -179,45 +209,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"uid": string,
|
||||
"pid": integer,
|
||||
"ppid": integer,
|
||||
"c": integer,
|
||||
"stime": string,
|
||||
"tty": string, # ? or ?? = Null
|
||||
"tt": string, # ?? = Null
|
||||
"time": string,
|
||||
"cmd": string,
|
||||
"user": string,
|
||||
"cpu_percent": float,
|
||||
"mem_percent": float,
|
||||
"vsz": integer,
|
||||
"rss": integer,
|
||||
"stat": string,
|
||||
"start": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -234,5 +226,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,41 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc route
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.route
|
||||
result = jc.parsers.route.parse(route_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"destination": string,
|
||||
"gateway": string,
|
||||
"genmask": string,
|
||||
"flags": string,
|
||||
"flags_pretty": [
|
||||
string,
|
||||
]
|
||||
"metric": integer,
|
||||
"ref": integer,
|
||||
"use": integer,
|
||||
"mss": integer,
|
||||
"window": integer,
|
||||
"irtt": integer,
|
||||
"iface": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -86,42 +113,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"destination": string,
|
||||
"gateway": string,
|
||||
"genmask": string,
|
||||
"flags": string,
|
||||
"flags_pretty": [
|
||||
string,
|
||||
]
|
||||
"metric": integer,
|
||||
"ref": integer,
|
||||
"use": integer,
|
||||
"mss": integer,
|
||||
"window": integer,
|
||||
"irtt": integer,
|
||||
"iface": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -138,5 +130,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
184
docs/parsers/rpm_qi.md
Normal file
184
docs/parsers/rpm_qi.md
Normal file
@@ -0,0 +1,184 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.rpm_qi
|
||||
jc - JSON CLI output utility `rpm -qi` command output parser
|
||||
|
||||
Works with `rpm -qi [package]` or `rpm -qia`.
|
||||
|
||||
The `..._epoch` calculated timestamp fields are naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
The `..._epoch_utc` calculated timestamp fields are timezone-aware and is only available if the timezone field is UTC.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ rpm -qia | jc --rpm-qi
|
||||
|
||||
or
|
||||
|
||||
$ jc rpm -qia
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.rpm_qi
|
||||
result = jc.parsers.rpm_qi.parse(rpm_qi_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"epoch": integer,
|
||||
"version": string,
|
||||
"release": string,
|
||||
"architecture": string,
|
||||
"install_date": string,
|
||||
"install_date_epoch": integer, # naive timestamp
|
||||
"install_date_epoch_utc": integer, # Aware timestamp if timezone is UTC
|
||||
"group": string,
|
||||
"size": integer,
|
||||
"license": string,
|
||||
"signature": string,
|
||||
"source_rpm": string,
|
||||
"build_date": string,
|
||||
"build_epoch": integer, # naive timestamp
|
||||
"build_epoch_utc": integer, # Aware timestamp if timezone is UTC
|
||||
"build_host": string,
|
||||
"relocations": string,
|
||||
"packager": string,
|
||||
"vendor": string,
|
||||
"url": string,
|
||||
"summary": string,
|
||||
"description": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ rpm -qia | jc --rpm-qi -p
|
||||
[
|
||||
{
|
||||
"name": "make",
|
||||
"epoch": 1,
|
||||
"version": "3.82",
|
||||
"release": "24.el7",
|
||||
"architecture": "x86_64",
|
||||
"install_date": "Wed 16 Oct 2019 09:21:42 AM PDT",
|
||||
"group": "Development/Tools",
|
||||
"size": 1160660,
|
||||
"license": "GPLv2+",
|
||||
"signature": "RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ID 24c6a8a7f4a80eb5",
|
||||
"source_rpm": "make-3.82-24.el7.src.rpm",
|
||||
"build_date": "Thu 08 Aug 2019 05:47:25 PM PDT",
|
||||
"build_host": "x86-01.bsys.centos.org",
|
||||
"relocations": "(not relocatable)",
|
||||
"packager": "CentOS BuildSystem <http://bugs.centos.org>",
|
||||
"vendor": "CentOS",
|
||||
"url": "http://www.gnu.org/software/make/",
|
||||
"summary": "A GNU tool which simplifies the build process for users",
|
||||
"description": "A GNU tool for controlling the generation of executables and other...",
|
||||
"build_epoch": 1565311645,
|
||||
"build_epoch_utc": null,
|
||||
"install_date_epoch": 1571242902,
|
||||
"install_date_epoch_utc": null
|
||||
},
|
||||
{
|
||||
"name": "kbd-legacy",
|
||||
"version": "1.15.5",
|
||||
"release": "15.el7",
|
||||
"architecture": "noarch",
|
||||
"install_date": "Thu 15 Aug 2019 10:53:08 AM PDT",
|
||||
"group": "System Environment/Base",
|
||||
"size": 503608,
|
||||
"license": "GPLv2+",
|
||||
"signature": "RSA/SHA256, Mon 12 Nov 2018 07:17:49 AM PST, Key ID 24c6a8a7f4a80eb5",
|
||||
"source_rpm": "kbd-1.15.5-15.el7.src.rpm",
|
||||
"build_date": "Tue 30 Oct 2018 03:40:00 PM PDT",
|
||||
"build_host": "x86-01.bsys.centos.org",
|
||||
"relocations": "(not relocatable)",
|
||||
"packager": "CentOS BuildSystem <http://bugs.centos.org>",
|
||||
"vendor": "CentOS",
|
||||
"url": "http://ftp.altlinux.org/pub/people/legion/kbd",
|
||||
"summary": "Legacy data for kbd package",
|
||||
"description": "The kbd-legacy package contains original keymaps for kbd package...",
|
||||
"build_epoch": 1540939200,
|
||||
"build_epoch_utc": null,
|
||||
"install_date_epoch": 1565891588,
|
||||
"install_date_epoch_utc": null
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ rpm -qia | jc --rpm-qi -p -r
|
||||
[
|
||||
{
|
||||
"name": "make",
|
||||
"epoch": "1",
|
||||
"version": "3.82",
|
||||
"release": "24.el7",
|
||||
"architecture": "x86_64",
|
||||
"install_date": "Wed 16 Oct 2019 09:21:42 AM PDT",
|
||||
"group": "Development/Tools",
|
||||
"size": "1160660",
|
||||
"license": "GPLv2+",
|
||||
"signature": "RSA/SHA256, Thu 22 Aug 2019 02:34:59 PM PDT, Key ID 24c6a8a7f4a80eb5",
|
||||
"source_rpm": "make-3.82-24.el7.src.rpm",
|
||||
"build_date": "Thu 08 Aug 2019 05:47:25 PM PDT",
|
||||
"build_host": "x86-01.bsys.centos.org",
|
||||
"relocations": "(not relocatable)",
|
||||
"packager": "CentOS BuildSystem <http://bugs.centos.org>",
|
||||
"vendor": "CentOS",
|
||||
"url": "http://www.gnu.org/software/make/",
|
||||
"summary": "A GNU tool which simplifies the build process for users",
|
||||
"description": "A GNU tool for controlling the generation of executables and other..."
|
||||
},
|
||||
{
|
||||
"name": "kbd-legacy",
|
||||
"version": "1.15.5",
|
||||
"release": "15.el7",
|
||||
"architecture": "noarch",
|
||||
"install_date": "Thu 15 Aug 2019 10:53:08 AM PDT",
|
||||
"group": "System Environment/Base",
|
||||
"size": "503608",
|
||||
"license": "GPLv2+",
|
||||
"signature": "RSA/SHA256, Mon 12 Nov 2018 07:17:49 AM PST, Key ID 24c6a8a7f4a80eb5",
|
||||
"source_rpm": "kbd-1.15.5-15.el7.src.rpm",
|
||||
"build_date": "Tue 30 Oct 2018 03:40:00 PM PDT",
|
||||
"build_host": "x86-01.bsys.centos.org",
|
||||
"relocations": "(not relocatable)",
|
||||
"packager": "CentOS BuildSystem <http://bugs.centos.org>",
|
||||
"vendor": "CentOS",
|
||||
"url": "http://ftp.altlinux.org/pub/people/legion/kbd",
|
||||
"summary": "Legacy data for kbd package",
|
||||
"description": "The kbd-legacy package contains original keymaps for kbd package..."
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,14 +1,31 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
Usage (module):
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
import jc.parsers.shadow
|
||||
result = jc.parsers.shadow.parse(shadow_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"username": string,
|
||||
"password": string,
|
||||
"last_changed": integer,
|
||||
"minimum": integer,
|
||||
"maximum": integer,
|
||||
"warn": integer,
|
||||
"inactive": integer,
|
||||
"expire": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -87,36 +104,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"username": string,
|
||||
"password": string,
|
||||
"last_changed": integer,
|
||||
"minimum": integer,
|
||||
"maximum": integer,
|
||||
"warn": integer,
|
||||
"inactive": integer,
|
||||
"expire": integer
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -133,5 +121,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, aix, freebsd
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,18 +1,46 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.ss
|
||||
jc - JSON CLI output utility ss Parser
|
||||
jc - JSON CLI output utility `ss` command output parser
|
||||
|
||||
Usage:
|
||||
Extended information options like -e and -p are not supported and may cause parsing irregularities.
|
||||
|
||||
specify --ss as the first argument if the piped input is coming from ss
|
||||
Usage (cli):
|
||||
|
||||
Limitations:
|
||||
$ ss | jc --ss
|
||||
|
||||
Extended information options like -e and -p are not supported and may cause parsing irregularities
|
||||
or
|
||||
|
||||
Compatibility:
|
||||
$ jc ss
|
||||
|
||||
'linux'
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.ss
|
||||
result = jc.parsers.ss.parse(ss_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
Information from https://www.cyberciti.biz/files/ss.html used to define field names
|
||||
|
||||
[
|
||||
{
|
||||
"netid": string,
|
||||
"state": string,
|
||||
"recv_q": integer,
|
||||
"send_q": integer,
|
||||
"local_address": string,
|
||||
"local_port": string,
|
||||
"local_port_num": integer,
|
||||
"peer_address": string,
|
||||
"peer_port": string,
|
||||
"peer_port_num": integer,
|
||||
"interface": string,
|
||||
"link_layer" string,
|
||||
"channel": string,
|
||||
"path": string,
|
||||
"pid": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -253,45 +281,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"netid": string,
|
||||
"state": string,
|
||||
"recv_q": integer,
|
||||
"send_q": integer,
|
||||
"local_address": string,
|
||||
"local_port": string,
|
||||
"local_port_num": integer,
|
||||
"peer_address": string,
|
||||
"peer_port": string,
|
||||
"peer_port_num": integer,
|
||||
"interface": string,
|
||||
"link_layer" string,
|
||||
"channel": string,
|
||||
"path": string,
|
||||
"pid": integer
|
||||
}
|
||||
]
|
||||
|
||||
Information from https://www.cyberciti.biz/files/ss.html used to define field names
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -308,5 +298,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,62 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.stat
|
||||
jc - JSON CLI output utility stat Parser
|
||||
jc - JSON CLI output utility `stat` command output parser
|
||||
|
||||
Usage:
|
||||
The `xxx_epoch` calculated timestamp fields are naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
specify --stat as the first argument if the piped input is coming from stat
|
||||
The `xxx_epoch_utc` calculated timestamp fields are timezone-aware and are only available if the timezone field is UTC.
|
||||
|
||||
Compatibility:
|
||||
Usage (cli):
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
$ stat * | jc --stat
|
||||
|
||||
or
|
||||
|
||||
$ jc stat *
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.stat
|
||||
result = jc.parsers.stat.parse(stat_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"file": string,
|
||||
"link_to" string,
|
||||
"size": integer,
|
||||
"blocks": integer,
|
||||
"io_blocks": integer,
|
||||
"type": string,
|
||||
"device": string,
|
||||
"inode": integer,
|
||||
"links": integer,
|
||||
"access": string,
|
||||
"flags": string,
|
||||
"uid": integer,
|
||||
"user": string,
|
||||
"gid": integer,
|
||||
"group": string,
|
||||
"access_time": string, # - = null
|
||||
"access_time_epoch": integer, # naive timestamp
|
||||
"access_time_epoch_utc": integer, # timezone-aware timestamp
|
||||
"modify_time": string, # - = null
|
||||
"modify_time_epoch": integer, # naive timestamp
|
||||
"modify_time_epoch_utc": integer, # timezone-aware timestamp
|
||||
"change_time": string, # - = null
|
||||
"change_time_epoch": integer, # naive timestamp
|
||||
"change_time_epoch_utc": integer, # timezone-aware timestamp
|
||||
"birth_time": string, # - = null
|
||||
"birth_time_epoch": integer, # naive timestamp
|
||||
"birth_time_epoch_utc": integer, # timezone-aware timestamp
|
||||
"unix_device": integer,
|
||||
"rdev": integer,
|
||||
"block_size": integer,
|
||||
"unix_flags": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -32,7 +80,15 @@ Examples:
|
||||
"access_time": "2019-11-14 08:18:03.509681766 +0000",
|
||||
"modify_time": "2019-06-06 22:28:15.000000000 +0000",
|
||||
"change_time": "2019-08-12 17:21:29.521945390 +0000",
|
||||
"birth_time": null
|
||||
"birth_time": null,
|
||||
"access_time_epoch": 1573748283,
|
||||
"access_time_epoch_utc": 1573719483,
|
||||
"modify_time_epoch": 1559885295,
|
||||
"modify_time_epoch_utc": 1559860095,
|
||||
"change_time_epoch": 1565655689,
|
||||
"change_time_epoch_utc": 1565630489,
|
||||
"birth_time_epoch": null,
|
||||
"birth_time_epoch_utc": null
|
||||
},
|
||||
{
|
||||
"file": "/bin/btrfs",
|
||||
@@ -52,7 +108,15 @@ Examples:
|
||||
"access_time": "2019-11-14 08:18:28.990834276 +0000",
|
||||
"modify_time": "2018-03-12 23:04:27.000000000 +0000",
|
||||
"change_time": "2019-08-12 17:21:29.545944399 +0000",
|
||||
"birth_time": null
|
||||
"birth_time": null,
|
||||
"access_time_epoch": 1573748308,
|
||||
"access_time_epoch_utc": 1573719508,
|
||||
"modify_time_epoch": 1520921067,
|
||||
"modify_time_epoch_utc": 1520895867,
|
||||
"change_time_epoch": 1565655689,
|
||||
"change_time_epoch_utc": 1565630489,
|
||||
"birth_time_epoch": null,
|
||||
"birth_time_epoch_utc": null
|
||||
},
|
||||
...
|
||||
]
|
||||
@@ -99,7 +163,7 @@ Examples:
|
||||
"change_time": "2019-08-12 17:21:29.545944399 +0000",
|
||||
"birth_time": null
|
||||
},
|
||||
..
|
||||
...
|
||||
]
|
||||
|
||||
|
||||
@@ -107,51 +171,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"file": string,
|
||||
"link_to" string,
|
||||
"size": integer,
|
||||
"blocks": integer,
|
||||
"io_blocks": integer,
|
||||
"type": string,
|
||||
"device": string,
|
||||
"inode": integer,
|
||||
"links": integer,
|
||||
"access": string,
|
||||
"flags": string,
|
||||
"uid": integer,
|
||||
"user": string,
|
||||
"gid": integer,
|
||||
"group": string,
|
||||
"access_time": string, # - = null
|
||||
"modify_time": string, # - = null
|
||||
"change_time": string, # - = null
|
||||
"birth_time": string, # - = null
|
||||
"unix_device": integer,
|
||||
"rdev": integer,
|
||||
"block_size": integer,
|
||||
"unix_flags": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -168,5 +188,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 1.8 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,22 +1,34 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.sysctl
|
||||
jc - JSON CLI output utility sysctl -a Parser
|
||||
jc - JSON CLI output utility `sysctl -a` command output parser
|
||||
|
||||
Usage:
|
||||
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()`.
|
||||
|
||||
specify --sysctl as the first argument if the piped input is coming from sysctl -a
|
||||
Usage (cli):
|
||||
|
||||
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 (raw) option.
|
||||
$ sysctl -a | jc --sysctl
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
$ jc sysctl -a
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.sysctl
|
||||
result = jc.parsers.sysctl.parse(sysctl_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"key1": string/integer/float, # best guess based on value
|
||||
"key2": string/integer/float,
|
||||
"key3": string/integer/float
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
$ sysctl | jc --sysctl -p
|
||||
$ sysctl -a | jc --sysctl -p
|
||||
{
|
||||
"user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin",
|
||||
"user.bc_base_max": 99,
|
||||
@@ -28,7 +40,7 @@ Examples:
|
||||
...
|
||||
}
|
||||
|
||||
$ sysctl | jc --sysctl -p -r
|
||||
$ sysctl -a | jc --sysctl -p -r
|
||||
{
|
||||
"user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin",
|
||||
"user.bc_base_max": "99",
|
||||
@@ -45,29 +57,7 @@ Examples:
|
||||
```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
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -86,3 +76,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,32 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc systemctl
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systemctl
|
||||
result = jc.parsers.systemctl.parse(systemctl_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"unit": string,
|
||||
"load": string,
|
||||
"active": string,
|
||||
"sub": string,
|
||||
"description": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -43,33 +61,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"unit": string,
|
||||
"load": string,
|
||||
"active": string,
|
||||
"sub": string,
|
||||
"description": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -86,5 +78,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc systemctl list-jobs
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systemctl_lj
|
||||
result = jc.parsers.systemctl_lj.parse(systemctl_lj_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"job": integer,
|
||||
"unit": string,
|
||||
"type": string,
|
||||
"state": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -57,37 +74,11 @@ Examples:
|
||||
]
|
||||
|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"job": integer,
|
||||
"unit": string,
|
||||
"type": string,
|
||||
"state": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -104,5 +95,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc systemctl list-sockets
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systemctl_ls
|
||||
result = jc.parsers.systemctl_ls.parse(systemctl_ls_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"listen": string,
|
||||
"unit": string,
|
||||
"activates": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -37,31 +53,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"listen": string,
|
||||
"unit": string,
|
||||
"activates": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -78,5 +70,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc systemctl list-unit-files
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systemctl_luf
|
||||
result = jc.parsers.systemctl_luf.parse(systemctl_luf_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"unit_file": string,
|
||||
"state": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -34,30 +49,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"unit_file": string,
|
||||
"state": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -74,5 +66,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
232
docs/parsers/systeminfo.md
Normal file
232
docs/parsers/systeminfo.md
Normal file
@@ -0,0 +1,232 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.systeminfo
|
||||
jc - JSON CLI output utility `systeminfo` command output parser
|
||||
|
||||
Blank or missing elements are set to `null`.
|
||||
|
||||
The `original_install_date_epoch` and `system_boot_time_epoch` calculated timestamp fields are naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
The `original_install_date_epoch_utc` and `system_boot_time_epoch_utc` calculated timestamp fields are timezone-aware and are only available if the timezone field is UTC.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ systeminfo | jc --systeminfo
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.systeminfo
|
||||
result = jc.parsers.systeminfo.parse(systeminfo_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"host_name": string,
|
||||
"os_name": string,
|
||||
"os_version": string,
|
||||
"os_manufacturer": string,
|
||||
"os_configuration": string,
|
||||
"os_build_type": string,
|
||||
"registered_owner": string,
|
||||
"registered_organization": string,
|
||||
"product_id": string,
|
||||
"original_install_date": string,
|
||||
"original_install_date_epoch": integer, # naive timestamp
|
||||
"original_install_date_epoch_utc": integer, # timezone-aware timestamp
|
||||
"system_boot_time": string,
|
||||
"system_boot_time_epoch": integer, # naive timestamp
|
||||
"system_boot_time_epoch_utc": integer, # timezone-aware timestamp
|
||||
"system_manufacturer": string,
|
||||
"system_model": string,
|
||||
"system_type": string,
|
||||
"processors": [
|
||||
string
|
||||
],
|
||||
"bios_version": string,
|
||||
"windows_directory": string,
|
||||
"system_directory": string,
|
||||
"boot_device": string,
|
||||
"system_locale": string,
|
||||
"input_locale": string,
|
||||
"time_zone": string,
|
||||
"total_physical_memory_mb": string,
|
||||
"available_physical_memory_mb": integer,
|
||||
"virtual_memory_max_size_mb": integer,
|
||||
"virtual_memory_available_mb": integer,
|
||||
"virtual_memory_in_use_mb": integer,
|
||||
"page_file_locations": string,
|
||||
"domain": string,
|
||||
"logon_server": string,
|
||||
"hotfixs": [
|
||||
string
|
||||
],
|
||||
"network_cards": [
|
||||
{
|
||||
"name": string,
|
||||
"connection_name": string,
|
||||
"status": string,
|
||||
"dhcp_enabled": boolean,
|
||||
"dhcp_server": string,
|
||||
"ip_addresses": [
|
||||
string
|
||||
]
|
||||
}
|
||||
],
|
||||
"hyperv_requirements": {
|
||||
"vm_monitor_mode_extensions": boolean,
|
||||
"virtualization_enabled_in_firmware": boolean,
|
||||
"second_level_address_translation": boolean,
|
||||
"data_execution_prevention_available": boolean
|
||||
}
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
$ systeminfo | jc --systeminfo -p
|
||||
{
|
||||
"host_name": "TESTLAPTOP",
|
||||
"os_name": "Microsoft Windows 10 Enterprise",
|
||||
"os_version": "10.0.17134 N/A Build 17134",
|
||||
"os_manufacturer": "Microsoft Corporation",
|
||||
"os_configuration": "Member Workstation",
|
||||
"os_build_type": "Multiprocessor Free",
|
||||
"registered_owner": "Test, Inc.",
|
||||
"registered_organization": "Test, Inc.",
|
||||
"product_id": "11111-11111-11111-AA111",
|
||||
"original_install_date": "3/26/2019, 3:51:30 PM",
|
||||
"system_boot_time": "3/30/2021, 6:13:59 AM",
|
||||
"system_manufacturer": "Dell Inc.",
|
||||
"system_model": "Precision 5530",
|
||||
"system_type": "x64-based PC",
|
||||
"processors": [
|
||||
"Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2592 Mhz"
|
||||
],
|
||||
"bios_version": "Dell Inc. 1.16.2, 4/21/2020",
|
||||
"windows_directory": "C:\WINDOWS",
|
||||
"system_directory": "C:\WINDOWS\system32",
|
||||
"boot_device": "\Device\HarddiskVolume2",
|
||||
"system_locale": "en-us;English (United States)",
|
||||
"input_locale": "en-us;English (United States)",
|
||||
"time_zone": "(UTC+00:00) UTC",
|
||||
"total_physical_memory_mb": 32503,
|
||||
"available_physical_memory_mb": 19743,
|
||||
"virtual_memory_max_size_mb": 37367,
|
||||
"virtual_memory_available_mb": 22266,
|
||||
"virtual_memory_in_use_mb": 15101,
|
||||
"page_file_locations": "C:\pagefile.sys",
|
||||
"domain": "test.com",
|
||||
"logon_server": "\\TESTDC01",
|
||||
"hotfixs": [
|
||||
"KB2693643",
|
||||
"KB4601054"
|
||||
],
|
||||
"network_cards": [
|
||||
{
|
||||
"name": "Intel(R) Wireless-AC 9260 160MHz",
|
||||
"connection_name": "Wi-Fi",
|
||||
"status": null,
|
||||
"dhcp_enabled": true,
|
||||
"dhcp_server": "192.168.2.1",
|
||||
"ip_addresses": [
|
||||
"192.168.2.219"
|
||||
]
|
||||
}
|
||||
],
|
||||
"hyperv_requirements": {
|
||||
"vm_monitor_mode_extensions": true,
|
||||
"virtualization_enabled_in_firmware": true,
|
||||
"second_level_address_translation": false,
|
||||
"data_execution_prevention_available": true
|
||||
},
|
||||
"original_install_date_epoch": 1553640690,
|
||||
"original_install_date_epoch_utc": 1553615490,
|
||||
"system_boot_time_epoch": 1617110039,
|
||||
"system_boot_time_epoch_utc": 1617084839
|
||||
}
|
||||
|
||||
$ systeminfo | jc --systeminfo -p -r
|
||||
{
|
||||
"host_name": "TESTLAPTOP",
|
||||
"os_name": "Microsoft Windows 10 Enterprise",
|
||||
"os_version": "10.0.17134 N/A Build 17134",
|
||||
"os_manufacturer": "Microsoft Corporation",
|
||||
"os_configuration": "Member Workstation",
|
||||
"os_build_type": "Multiprocessor Free",
|
||||
"registered_owner": "Test, Inc.",
|
||||
"registered_organization": "Test, Inc.",
|
||||
"product_id": "11111-11111-11111-AA111",
|
||||
"original_install_date": "3/26/2019, 3:51:30 PM",
|
||||
"system_boot_time": "3/30/2021, 6:13:59 AM",
|
||||
"system_manufacturer": "Dell Inc.",
|
||||
"system_model": "Precision 5530",
|
||||
"system_type": "x64-based PC",
|
||||
"processors": [
|
||||
"Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2592 Mhz"
|
||||
],
|
||||
"bios_version": "Dell Inc. 1.16.2, 4/21/2020",
|
||||
"windows_directory": "C:\WINDOWS",
|
||||
"system_directory": "C:\WINDOWS\system32",
|
||||
"boot_device": "\Device\HarddiskVolume2",
|
||||
"system_locale": "en-us;English (United States)",
|
||||
"input_locale": "en-us;English (United States)",
|
||||
"time_zone": "(UTC+00:00) UTC",
|
||||
"total_physical_memory_mb": "32,503 MB",
|
||||
"available_physical_memory_mb": "19,743 MB",
|
||||
"virtual_memory_max_size_mb": "37,367 MB",
|
||||
"virtual_memory_available_mb": "22,266 MB",
|
||||
"virtual_memory_in_use_mb": "15,101 MB",
|
||||
"page_file_locations": "C:\pagefile.sys",
|
||||
"domain": "test.com",
|
||||
"logon_server": "\\TESTDC01",
|
||||
"hotfixs": [
|
||||
"KB2693643",
|
||||
"KB4601054"
|
||||
],
|
||||
"network_cards": [
|
||||
{
|
||||
"name": "Intel(R) Wireless-AC 9260 160MHz",
|
||||
"connection_name": "Wi-Fi",
|
||||
"status": "",
|
||||
"dhcp_enabled": "Yes",
|
||||
"dhcp_server": "192.168.2.1",
|
||||
"ip_addresses": [
|
||||
"192.168.2.219"
|
||||
]
|
||||
}
|
||||
],
|
||||
"hyperv_requirements": {
|
||||
"vm_monitor_mode_extensions": "Yes",
|
||||
"virtualization_enabled_in_firmware": "Yes",
|
||||
"second_level_address_translation": "No",
|
||||
"data_execution_prevention_available": "Yes"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: win32
|
||||
|
||||
Version 1.0 by Jon Smith (jon@rebelliondefense.com)
|
||||
151
docs/parsers/time.md
Normal file
151
docs/parsers/time.md
Normal file
@@ -0,0 +1,151 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.time
|
||||
jc - JSON CLI output utility `/usr/bin/time` command output parser
|
||||
|
||||
Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be used to redirect the output to a file that can be read by `jc`.
|
||||
|
||||
Alternatively, the output from `/usr/bin/time` can be redirected to `STDOUT` so `jc` can receive it.
|
||||
|
||||
Note: `/usr/bin/time` is similar but different from the Bash builtin `time` command.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ /usr/bin/time -o timefile.out sleep 2.5; cat timefile.out | jc --time -p
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.time
|
||||
result = jc.parsers.time.parse(time_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
Source: https://www.freebsd.org/cgi/man.cgi?query=getrusage
|
||||
https://man7.org/linux/man-pages/man1/time.1.html
|
||||
|
||||
{
|
||||
"real_time": float,
|
||||
"user_time": float,
|
||||
"system_time": float,
|
||||
"elapsed_time": string,
|
||||
"elapsed_time_hours": integer,
|
||||
"elapsed_time_minutes": integer,
|
||||
"elapsed_time_seconds": integer,
|
||||
"elapsed_time_centiseconds": integer,
|
||||
"elapsed_time_total_seconds": float,
|
||||
"cpu_percent": integer, # null if ?
|
||||
"average_shared_text_size": integer,
|
||||
"average_unshared_data_size": integer,
|
||||
"average_unshared_stack_size": integer,
|
||||
"average_shared_memory_size": integer,
|
||||
"maximum_resident_set_size": integer,
|
||||
"block_input_operations": integer, # aka File system inputs
|
||||
"block_output_operations": integer, # aka File system outputs
|
||||
"major_pagefaults": integer,
|
||||
"minor_pagefaults": integer,
|
||||
"swaps": integer,
|
||||
"page_reclaims": integer,
|
||||
"page_faults": integer,
|
||||
"messages_sent": integer,
|
||||
"messages_received": integer,
|
||||
"signals_received": integer,
|
||||
"voluntary_context_switches": integer,
|
||||
"involuntary_context_switches": integer
|
||||
"command_being_timed": string,
|
||||
"average_stack_size": integer,
|
||||
"average_total_size": integer,
|
||||
"average_resident_set_size": integer,
|
||||
"signals_delivered": integer,
|
||||
"page_size": integer,
|
||||
"exit_status": integer
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
$ /usr/bin/time --verbose -o timefile.out sleep 2.5; cat timefile.out | jc --time -p
|
||||
{
|
||||
"command_being_timed": "sleep 2.5",
|
||||
"user_time": 0.0,
|
||||
"system_time": 0.0,
|
||||
"cpu_percent": 0,
|
||||
"elapsed_time": "0:02.50",
|
||||
"average_shared_text_size": 0,
|
||||
"average_unshared_data_size": 0,
|
||||
"average_stack_size": 0,
|
||||
"average_total_size": 0,
|
||||
"maximum_resident_set_size": 2084,
|
||||
"average_resident_set_size": 0,
|
||||
"major_pagefaults": 0,
|
||||
"minor_pagefaults": 72,
|
||||
"voluntary_context_switches": 2,
|
||||
"involuntary_context_switches": 1,
|
||||
"swaps": 0,
|
||||
"block_input_operations": 0,
|
||||
"block_output_operations": 0,
|
||||
"messages_sent": 0,
|
||||
"messages_received": 0,
|
||||
"signals_delivered": 0,
|
||||
"page_size": 4096,
|
||||
"exit_status": 0,
|
||||
"elapsed_time_hours": 0,
|
||||
"elapsed_time_minutes": 0,
|
||||
"elapsed_time_seconds": 2,
|
||||
"elapsed_time_centiseconds": 50,
|
||||
"elapsed_time_total_seconds": 2.5
|
||||
}
|
||||
|
||||
$ /usr/bin/time --verbose -o timefile.out sleep 2.5; cat timefile.out | jc --time -p -r
|
||||
{
|
||||
"command_being_timed": ""sleep 2.5"",
|
||||
"user_time": "0.00",
|
||||
"system_time": "0.00",
|
||||
"cpu_percent": "0",
|
||||
"elapsed_time": "0:02.50",
|
||||
"average_shared_text_size": "0",
|
||||
"average_unshared_data_size": "0",
|
||||
"average_stack_size": "0",
|
||||
"average_total_size": "0",
|
||||
"maximum_resident_set_size": "2084",
|
||||
"average_resident_set_size": "0",
|
||||
"major_pagefaults": "0",
|
||||
"minor_pagefaults": "72",
|
||||
"voluntary_context_switches": "2",
|
||||
"involuntary_context_switches": "0",
|
||||
"swaps": "0",
|
||||
"block_input_operations": "0",
|
||||
"block_output_operations": "0",
|
||||
"messages_sent": "0",
|
||||
"messages_received": "0",
|
||||
"signals_delivered": "0",
|
||||
"page_size": "4096",
|
||||
"exit_status": "0"
|
||||
}
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,14 +1,38 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.timedatectl
|
||||
jc - JSON CLI output utility timedatectl Parser
|
||||
jc - JSON CLI output utility `timedatectl` command output parser
|
||||
|
||||
Usage:
|
||||
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the `universal_time` field is available.
|
||||
|
||||
specify --timedatectl as the first argument if the piped input is coming from timedatectl or timedatectl status
|
||||
Usage (cli):
|
||||
|
||||
Compatibility:
|
||||
$ timedatectl | jc --timedatectl
|
||||
|
||||
'linux'
|
||||
or
|
||||
|
||||
$ jc timedatectl
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.timedatectl
|
||||
result = jc.parsers.timedatectl.parse(timedatectl_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"local_time": string,
|
||||
"universal_time": string,
|
||||
"epoch_utc": integer, # timezone-aware timestamp
|
||||
"rtc_time": string,
|
||||
"time_zone": string,
|
||||
"ntp_enabled": boolean,
|
||||
"ntp_synchronized": boolean,
|
||||
"system_clock_synchronized": boolean,
|
||||
"systemd-timesyncd.service_active": boolean,
|
||||
"rtc_in_local_tz": boolean,
|
||||
"dst_active": boolean
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -21,7 +45,8 @@ Examples:
|
||||
"ntp_enabled": true,
|
||||
"ntp_synchronized": true,
|
||||
"rtc_in_local_tz": false,
|
||||
"dst_active": true
|
||||
"dst_active": true,
|
||||
"epoch_utc": 1583888001
|
||||
}
|
||||
|
||||
$ timedatectl | jc --timedatectl -p -r
|
||||
@@ -41,36 +66,7 @@ Examples:
|
||||
```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:
|
||||
|
||||
{
|
||||
"local_time": string,
|
||||
"universal_time": string,
|
||||
"rtc_time": string,
|
||||
"time_zone": string,
|
||||
"ntp_enabled": boolean,
|
||||
"ntp_synchronized": boolean,
|
||||
"system_clock_synchronized": boolean,
|
||||
"systemd-timesyncd.service_active": boolean,
|
||||
"rtc_in_local_tz": boolean,
|
||||
"dst_active": boolean
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -89,3 +85,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,41 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.tracepath
|
||||
jc - JSON CLI output utility tracepath Parser
|
||||
jc - JSON CLI output utility `tracepath` command output parser
|
||||
|
||||
Usage:
|
||||
Supports `tracepath` and `tracepath6` output.
|
||||
|
||||
specify --tracepath as the first argument if the piped input is coming from tracepath
|
||||
Usage (cli):
|
||||
|
||||
Compatibility:
|
||||
$ tracepath 1.2.3.4 | jc --tracepath
|
||||
|
||||
'linux'
|
||||
or
|
||||
|
||||
$ jc tracepath 1.2.3.4
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.tracepath
|
||||
result = jc.parsers.tracepath.parse(tracepath_command_output)
|
||||
|
||||
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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -103,45 +130,11 @@ Examples:
|
||||
}
|
||||
|
||||
|
||||
|
||||
## 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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -160,3 +153,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,20 +1,47 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.traceroute
|
||||
jc - JSON CLI output utility traceroute Parser
|
||||
jc - JSON CLI output utility `traceroute` command output parser
|
||||
|
||||
Usage:
|
||||
Supports `traceroute` and `traceroute6` output.
|
||||
|
||||
specify --traceroute as the first argument if the piped input is coming from traceroute
|
||||
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.
|
||||
|
||||
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`
|
||||
|
||||
e.g. $ traceroute 8.8.8.8 2>&1 | jc --traceroute
|
||||
Usage (cli):
|
||||
|
||||
Compatibility:
|
||||
$ traceroute 1.2.3.4 | jc --traceroute
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
or
|
||||
|
||||
$ jc traceroute 1.2.3.4
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.traceroute
|
||||
result = jc.parsers.traceroute.parse(traceroute_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"destination_ip": string,
|
||||
"destination_name": string,
|
||||
"hops": [
|
||||
{
|
||||
"hop": integer,
|
||||
"probes": [
|
||||
{
|
||||
"annotation": string,
|
||||
"asn": integer,
|
||||
"ip": string,
|
||||
"name": string,
|
||||
"rtt": float
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -93,48 +120,7 @@ Examples:
|
||||
```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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -153,3 +139,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,18 +1,35 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
$ jc uname -a
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.uname
|
||||
result = jc.parsers.uname.parse(uname_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"kernel_name": string,
|
||||
"node_name": string,
|
||||
"kernel_release": string,
|
||||
"operating_system": string,
|
||||
"hardware_platform": string,
|
||||
"processor": string,
|
||||
"machine": string,
|
||||
"kernel_version": string
|
||||
}
|
||||
|
||||
Example:
|
||||
|
||||
@@ -33,34 +50,7 @@ Example:
|
||||
```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:
|
||||
|
||||
{
|
||||
"kernel_name": string,
|
||||
"node_name": string,
|
||||
"kernel_release": string,
|
||||
"operating_system": string,
|
||||
"hardware_platform": string,
|
||||
"processor": string,
|
||||
"machine": string,
|
||||
"kernel_version": string
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -79,3 +69,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, freebsd
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
222
docs/parsers/upower.md
Normal file
222
docs/parsers/upower.md
Normal file
@@ -0,0 +1,222 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# jc.parsers.upower
|
||||
jc - JSON CLI output utility `upower` command output parser
|
||||
|
||||
The `updated_epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
The `updated_epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ upower -d | jc --upower
|
||||
|
||||
or
|
||||
|
||||
$ jc upower -d
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.upower
|
||||
result = jc.parsers.upower.parse(upower_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"type": string,
|
||||
"device_name": string,
|
||||
"native_path": string,
|
||||
"power_supply": boolean,
|
||||
"updated": string,
|
||||
"updated_epoch": integer, # null if date-time conversion fails
|
||||
"updated_epoch_utc": integer, # null if date-time conversion fails
|
||||
"updated_seconds_ago": integer,
|
||||
"has_history": boolean,
|
||||
"has_statistics": boolean,
|
||||
"detail": {
|
||||
"type": string,
|
||||
"warning_level": string, # null if none
|
||||
"online": boolean,
|
||||
"icon_name": string
|
||||
"present": boolean,
|
||||
"rechargeable": boolean,
|
||||
"state": string,
|
||||
"energy": float,
|
||||
"energy_unit": string,
|
||||
"energy_empty": float,
|
||||
"energy_empty_unit": string,
|
||||
"energy_full": float,
|
||||
"energy_full_unit": string,
|
||||
"energy_full_design": float,
|
||||
"energy_full_design_unit": string,
|
||||
"energy_rate": float,
|
||||
"energy_rate_unit": string,
|
||||
"voltage": float,
|
||||
"voltage_unit": string,
|
||||
"time_to_full": float,
|
||||
"time_to_full_unit": string,
|
||||
"percentage": float,
|
||||
"capacity": float,
|
||||
"technology": string
|
||||
},
|
||||
"history_charge": [
|
||||
{
|
||||
"time": integer,
|
||||
"percent_charged": float,
|
||||
"status": string
|
||||
}
|
||||
],
|
||||
"history_rate":[
|
||||
{
|
||||
"time": integer,
|
||||
"percent_charged": float,
|
||||
"status": string
|
||||
}
|
||||
],
|
||||
"daemon_version": string,
|
||||
"on_battery": boolean,
|
||||
"lid_is_closed": boolean,
|
||||
"lid_is_present": boolean,
|
||||
"critical_action": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ upower -i /org/freedesktop/UPower/devices/battery | jc --upower -p
|
||||
[
|
||||
{
|
||||
"native_path": "/sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0",
|
||||
"vendor": "NOTEBOOK",
|
||||
"model": "BAT",
|
||||
"serial": "0001",
|
||||
"power_supply": true,
|
||||
"updated": "Thu 11 Mar 2021 06:28:08 PM UTC",
|
||||
"has_history": true,
|
||||
"has_statistics": true,
|
||||
"detail": {
|
||||
"type": "battery",
|
||||
"present": true,
|
||||
"rechargeable": true,
|
||||
"state": "charging",
|
||||
"energy": 22.3998,
|
||||
"energy_empty": 0.0,
|
||||
"energy_full": 52.6473,
|
||||
"energy_full_design": 62.16,
|
||||
"energy_rate": 31.6905,
|
||||
"voltage": 12.191,
|
||||
"time_to_full": 57.3,
|
||||
"percentage": 42.5469,
|
||||
"capacity": 84.6964,
|
||||
"technology": "lithium-ion",
|
||||
"energy_unit": "Wh",
|
||||
"energy_empty_unit": "Wh",
|
||||
"energy_full_unit": "Wh",
|
||||
"energy_full_design_unit": "Wh",
|
||||
"energy_rate_unit": "W",
|
||||
"voltage_unit": "V",
|
||||
"time_to_full_unit": "minutes"
|
||||
},
|
||||
"history_charge": [
|
||||
{
|
||||
"time": 1328809335,
|
||||
"percent_charged": 42.547,
|
||||
"status": "charging"
|
||||
},
|
||||
{
|
||||
"time": 1328809305,
|
||||
"percent_charged": 42.02,
|
||||
"status": "charging"
|
||||
}
|
||||
],
|
||||
"history_rate": [
|
||||
{
|
||||
"time": 1328809335,
|
||||
"percent_charged": 31.691,
|
||||
"status": "charging"
|
||||
}
|
||||
],
|
||||
"updated_seconds_ago": 441975,
|
||||
"updated_epoch": 1615516088,
|
||||
"updated_epoch_utc": 1615487288
|
||||
}
|
||||
]
|
||||
|
||||
$ upower -i /org/freedesktop/UPower/devices/battery | jc --upower -p -r
|
||||
[
|
||||
{
|
||||
"native_path": "/sys/devices/LNXSYSTM:00/device:00/PNP0C0A:00/power_supply/BAT0",
|
||||
"vendor": "NOTEBOOK",
|
||||
"model": "BAT",
|
||||
"serial": "0001",
|
||||
"power_supply": "yes",
|
||||
"updated": "Thu 11 Mar 2021 06:28:08 PM UTC (441975 seconds ago)",
|
||||
"has_history": "yes",
|
||||
"has_statistics": "yes",
|
||||
"detail": {
|
||||
"type": "battery",
|
||||
"present": "yes",
|
||||
"rechargeable": "yes",
|
||||
"state": "charging",
|
||||
"energy": "22.3998 Wh",
|
||||
"energy_empty": "0 Wh",
|
||||
"energy_full": "52.6473 Wh",
|
||||
"energy_full_design": "62.16 Wh",
|
||||
"energy_rate": "31.6905 W",
|
||||
"voltage": "12.191 V",
|
||||
"time_to_full": "57.3 minutes",
|
||||
"percentage": "42.5469%",
|
||||
"capacity": "84.6964%",
|
||||
"technology": "lithium-ion"
|
||||
},
|
||||
"history_charge": [
|
||||
{
|
||||
"time": "1328809335",
|
||||
"percent_charged": "42.547",
|
||||
"status": "charging"
|
||||
},
|
||||
{
|
||||
"time": "1328809305",
|
||||
"percent_charged": "42.020",
|
||||
"status": "charging"
|
||||
}
|
||||
],
|
||||
"history_rate": [
|
||||
{
|
||||
"time": "1328809335",
|
||||
"percent_charged": "31.691",
|
||||
"status": "charging"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
## info
|
||||
```python
|
||||
info()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,35 +1,66 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
$ jc uptime
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.uptime
|
||||
result = jc.parsers.uptime.parse(uptime_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"time": string,
|
||||
"time_hour": integer,
|
||||
"time_minute": integer,
|
||||
"time_second": integer, # null if not displayed
|
||||
"uptime": string,
|
||||
"uptime_days": integer,
|
||||
"uptime_hours": integer,
|
||||
"uptime_minutes": integer,
|
||||
"uptime_total_seconds": integer,
|
||||
"users": integer,
|
||||
"load_1m": float,
|
||||
"load_5m": float,
|
||||
"load_15m": float
|
||||
}
|
||||
|
||||
Example:
|
||||
|
||||
$ uptime | jc --uptime -p
|
||||
{
|
||||
"time": "11:30:44",
|
||||
"uptime": "1 day, 21:17",
|
||||
"users": 1,
|
||||
"load_1m": 0.01,
|
||||
"load_5m": 0.04,
|
||||
"load_15m": 0.05
|
||||
"time": "11:35",
|
||||
"uptime": "3 days, 4:03",
|
||||
"users": 5,
|
||||
"load_1m": 1.88,
|
||||
"load_5m": 2.0,
|
||||
"load_15m": 1.94,
|
||||
"time_hour": 11,
|
||||
"time_minute": 35,
|
||||
"time_second": null,
|
||||
"uptime_days": 3,
|
||||
"uptime_hours": 4,
|
||||
"uptime_minutes": 3,
|
||||
"uptime_total_seconds": 273780
|
||||
}
|
||||
|
||||
$ uptime | jc --uptime -p -r
|
||||
{
|
||||
"time": "11:31:09",
|
||||
"uptime": "1 day, 21:17",
|
||||
"users": "1",
|
||||
"load_1m": "0.00",
|
||||
"load_5m": "0.04",
|
||||
"load_15m": "0.05"
|
||||
"time": "11:36",
|
||||
"uptime": "3 days, 4:04",
|
||||
"users": "5",
|
||||
"load_1m": "1.88",
|
||||
"load_5m": "1.99",
|
||||
"load_15m": "1.94"
|
||||
}
|
||||
|
||||
|
||||
@@ -37,32 +68,7 @@ Example:
|
||||
```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:
|
||||
|
||||
{
|
||||
"time": string,
|
||||
"uptime": string,
|
||||
"users": integer,
|
||||
"load_1m": float,
|
||||
"load_5m": float,
|
||||
"load_15m": float
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -81,3 +87,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.5 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
$ jc w
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.w
|
||||
result = jc.parsers.w.parse(w_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"user": string, # '-' = null
|
||||
"tty": string, # '-' = null
|
||||
"from": string, # '-' = null
|
||||
"login_at": string, # '-' = null
|
||||
"idle": string, # '-' = null
|
||||
"jcpu": string,
|
||||
"pcpu": string,
|
||||
"what": string # '-' = null
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -85,36 +106,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"user": string, # '-'' = null
|
||||
"tty": string, # '-'' = null
|
||||
"from": string, # '-'' = null
|
||||
"login_at": string, # '-'' = null
|
||||
"idle": string, # '-'' = null
|
||||
"jcpu": string,
|
||||
"pcpu": string,
|
||||
"what": string # '-'' = null
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -131,5 +123,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
82
docs/parsers/wc.md
Normal file
82
docs/parsers/wc.md
Normal file
@@ -0,0 +1,82 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"lines": integer,
|
||||
"words": integer,
|
||||
"characters": integer
|
||||
}
|
||||
]
|
||||
|
||||
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()
|
||||
```
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## 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.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
@@ -1,16 +1,41 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
accepts any of the following who options (or no options): -aTH
|
||||
Usage (cli):
|
||||
|
||||
Compatibility:
|
||||
$ who | jc --who
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'aix', 'freebsd'
|
||||
or
|
||||
|
||||
$ jc who
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.who
|
||||
result = jc.parsers.who.parse(who_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"user": string,
|
||||
"event": string,
|
||||
"writeable_tty": string,
|
||||
"tty": string,
|
||||
"time": string,
|
||||
"epoch": integer, # naive timestamp. null if time cannot be converted
|
||||
"idle": string,
|
||||
"pid": integer,
|
||||
"from": string,
|
||||
"comment": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -19,7 +44,8 @@ Examples:
|
||||
{
|
||||
"event": "reboot",
|
||||
"time": "Feb 7 23:31",
|
||||
"pid": 1
|
||||
"pid": 1,
|
||||
"epoch": null
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
@@ -27,7 +53,8 @@ Examples:
|
||||
"tty": "console",
|
||||
"time": "Feb 7 23:32",
|
||||
"idle": "old",
|
||||
"pid": 105
|
||||
"pid": 105,
|
||||
"epoch": null
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
@@ -36,7 +63,8 @@ Examples:
|
||||
"time": "Feb 13 16:44",
|
||||
"idle": ".",
|
||||
"pid": 51217,
|
||||
"comment": "term=0 exit=0"
|
||||
"comment": "term=0 exit=0",
|
||||
"epoch": null
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
@@ -44,7 +72,8 @@ Examples:
|
||||
"tty": "ttys003",
|
||||
"time": "Feb 28 08:59",
|
||||
"idle": "01:36",
|
||||
"pid": 41402
|
||||
"pid": 41402,
|
||||
"epoch": null
|
||||
},
|
||||
{
|
||||
"user": "joeuser",
|
||||
@@ -53,7 +82,8 @@ Examples:
|
||||
"time": "Mar 1 16:35",
|
||||
"idle": ".",
|
||||
"pid": 15679,
|
||||
"from": "192.168.1.5"
|
||||
"from": "192.168.1.5",
|
||||
"epoch": null
|
||||
}
|
||||
]
|
||||
|
||||
@@ -105,37 +135,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Structured data with the following schema:
|
||||
|
||||
[
|
||||
{
|
||||
"user": string,
|
||||
"event": string,
|
||||
"writeable_tty": string,
|
||||
"tty": string,
|
||||
"time": string,
|
||||
"idle": string,
|
||||
"pid": integer,
|
||||
"from": string,
|
||||
"comment": string
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -152,5 +152,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, aix, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,26 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
Usage (module):
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
import jc.parsers.xml
|
||||
result = jc.parsers.xml.parse(xml_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
XML Document converted to a Dictionary
|
||||
See https://github.com/martinblech/xmltodict for details
|
||||
|
||||
{
|
||||
"key1": string/object,
|
||||
"key2": string/object
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -61,28 +73,7 @@ Examples:
|
||||
```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 representing an XML document:
|
||||
|
||||
{
|
||||
XML Document converted to a Dictionary
|
||||
See https://github.com/martinblech/xmltodict for details
|
||||
}
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -101,3 +92,7 @@ Returns:
|
||||
|
||||
Dictionary. Raw or processed structured data.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
|
||||
# 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
|
||||
|
||||
Compatibility:
|
||||
Usage (module):
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
import jc.parsers.yaml
|
||||
result = jc.parsers.yaml.parse(yaml_file_output)
|
||||
|
||||
Schema:
|
||||
|
||||
YAML Document converted to a Dictionary
|
||||
See https://pypi.org/project/ruamel.yaml for details
|
||||
|
||||
[
|
||||
{
|
||||
"key1": string/int/float/boolean/null/array/object,
|
||||
"key2": string/int/float/boolean/null/array/object
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -73,30 +87,7 @@ Examples:
|
||||
```python
|
||||
info()
|
||||
```
|
||||
|
||||
|
||||
## process
|
||||
```python
|
||||
process(proc_data)
|
||||
```
|
||||
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (dictionary) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Each dictionary represents a YAML document:
|
||||
|
||||
[
|
||||
{
|
||||
YAML Document converted to a Dictionary
|
||||
See https://pypi.org/project/ruamel.yaml for details
|
||||
}
|
||||
]
|
||||
|
||||
Provides parser metadata (version, author, etc.)
|
||||
|
||||
## parse
|
||||
```python
|
||||
@@ -113,5 +104,9 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
List of dictionaries. Raw or processed structured data.
|
||||
List of Dictionaries representing the YAML documents.
|
||||
|
||||
## Parser Information
|
||||
Compatibility: linux, darwin, cygwin, win32, aix, freebsd
|
||||
|
||||
Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
||||
|
||||
119
docs/readme.md
119
docs/readme.md
@@ -6,64 +6,83 @@ 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 the [documentation site](https://kellyjonbrazil.github.io/jc/).
|
||||
|
||||
CLI Example:
|
||||
|
||||
$ ls -l /usr/bin | jc --ls -p
|
||||
$ dig example.com | jc --dig -p
|
||||
[
|
||||
{
|
||||
"filename": "apropos",
|
||||
"link_to": "whatis",
|
||||
"flags": "lrwxrwxrwx.",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 6,
|
||||
"date": "Aug 15 10:53"
|
||||
},
|
||||
{
|
||||
"filename": "ar",
|
||||
"flags": "-rwxr-xr-x.",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 62744,
|
||||
"date": "Aug 8 16:14"
|
||||
},
|
||||
{
|
||||
"filename": "arch",
|
||||
"flags": "-rwxr-xr-x.",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 33080,
|
||||
"date": "Aug 19 23:25"
|
||||
},
|
||||
...
|
||||
"id": 2951,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
"qr",
|
||||
"rd",
|
||||
"ra"
|
||||
],
|
||||
"query_num": 1,
|
||||
"answer_num": 1,
|
||||
"authority_num": 0,
|
||||
"additional_num": 1,
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": 0,
|
||||
"flags": [],
|
||||
"udp": 4096
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 39302,
|
||||
"data": "93.184.216.34"
|
||||
}
|
||||
],
|
||||
"query_time": 49,
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Fri Apr 16 16:05:10 PDT 2021",
|
||||
"rcvd": 56,
|
||||
"when_epoch": 1618614310,
|
||||
"when_epoch_utc": null
|
||||
}
|
||||
]
|
||||
|
||||
Module Example:
|
||||
|
||||
>>> import jc.parsers.ls
|
||||
>>> import jc.parsers.dig
|
||||
>>>
|
||||
>>> data='''-rwxr-xr-x 1 root wheel 23648 May 3 22:26 cat
|
||||
... -rwxr-xr-x 1 root wheel 30016 May 3 22:26 chmod
|
||||
... -rwxr-xr-x 1 root wheel 29024 May 3 22:26 cp
|
||||
... -rwxr-xr-x 1 root wheel 375824 May 3 22:26 csh
|
||||
... -rwxr-xr-x 1 root wheel 28608 May 3 22:26 date
|
||||
... -rwxr-xr-x 1 root wheel 32000 May 3 22:26 dd
|
||||
... -rwxr-xr-x 1 root wheel 23392 May 3 22:26 df
|
||||
... -rwxr-xr-x 1 root wheel 18128 May 3 22:26 echo'''
|
||||
>>> data = '''; <<>> DiG 9.10.6 <<>> example.com
|
||||
... ;; global options: +cmd
|
||||
... ;; Got answer:
|
||||
... ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64612
|
||||
... ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
|
||||
...
|
||||
... ;; OPT PSEUDOSECTION:
|
||||
... ; EDNS: version: 0, flags:; udp: 4096
|
||||
... ;; QUESTION SECTION:
|
||||
... ;example.com. IN A
|
||||
...
|
||||
... ;; ANSWER SECTION:
|
||||
... example.com. 29658 IN A 93.184.216.34
|
||||
...
|
||||
... ;; Query time: 52 msec
|
||||
... ;; SERVER: 2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)
|
||||
... ;; WHEN: Fri Apr 16 16:13:00 PDT 2021
|
||||
... ;; MSG SIZE rcvd: 56'''
|
||||
>>>
|
||||
>>> jc.parsers.ls.parse(data)
|
||||
[{'filename': 'cat', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 23648,
|
||||
'date': 'May 3 22:26'}, {'filename': 'chmod', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root',
|
||||
'group': 'wheel', 'size': 30016, 'date': 'May 3 22:26'}, {'filename': 'cp', 'flags': '-rwxr-xr-x',
|
||||
'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 29024, 'date': 'May 3 22:26'}, {'filename': 'csh',
|
||||
'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 375824, 'date': 'May 3
|
||||
22:26'}, {'filename': 'date', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel',
|
||||
'size': 28608, 'date': 'May 3 22:26'}, {'filename': 'dd', 'flags': '-rwxr-xr-x', 'links': 1, 'owner':
|
||||
'root', 'group': 'wheel', 'size': 32000, 'date': 'May 3 22:26'}, {'filename': 'df', 'flags':
|
||||
'-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 23392, 'date': 'May 3 22:26'},
|
||||
{'filename': 'echo', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 18128,
|
||||
'date': 'May 3 22:26'}]
|
||||
>>> jc.parsers.dig.parse(data)
|
||||
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num':
|
||||
1, 'authority_num': 0, 'additional_num': 1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp':
|
||||
4096}}, 'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': [{'name': 'example.com.',
|
||||
'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': '93.184.216.34'}], 'query_time': 52, 'server':
|
||||
'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': 'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56,
|
||||
'when_epoch': 1618614780, 'when_epoch_utc': None}]
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
no return, just prints output to STDERR
|
||||
None - just prints output to STDERR
|
||||
|
||||
|
||||
## error_message
|
||||
@@ -31,7 +31,7 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
no return, just prints output to STDERR
|
||||
None - just prints output to STDERR
|
||||
|
||||
|
||||
## compatibility
|
||||
@@ -50,7 +50,7 @@ Parameters:
|
||||
|
||||
Returns:
|
||||
|
||||
no return, just prints output to STDERR
|
||||
None - just prints output to STDERR
|
||||
|
||||
|
||||
## has_data
|
||||
@@ -68,3 +68,70 @@ Returns:
|
||||
|
||||
Boolean True if input string (data) contains non-whitespace characters, otherwise False
|
||||
|
||||
|
||||
## convert_to_int
|
||||
```python
|
||||
convert_to_int(value)
|
||||
```
|
||||
|
||||
Converts string input to integer by stripping all non-numeric characters
|
||||
|
||||
Parameters:
|
||||
|
||||
value: (string/integer/float) Input value
|
||||
|
||||
Returns:
|
||||
|
||||
integer/None Integer if successful conversion, otherwise None
|
||||
|
||||
|
||||
## convert_to_float
|
||||
```python
|
||||
convert_to_float(value)
|
||||
```
|
||||
|
||||
Converts string input to float by stripping all non-numeric characters
|
||||
|
||||
Parameters:
|
||||
|
||||
value: (string) Input value
|
||||
|
||||
Returns:
|
||||
|
||||
float/None Float if successful conversion, otherwise None
|
||||
|
||||
|
||||
## convert_to_bool
|
||||
```python
|
||||
convert_to_bool(value)
|
||||
```
|
||||
|
||||
Converts string, integer, or float input to boolean by checking for 'truthy' values
|
||||
|
||||
Parameters:
|
||||
|
||||
value: (string/integer/float) Input value
|
||||
|
||||
Returns:
|
||||
|
||||
True/False False unless a 'truthy' number or string is found ('y', 'yes', 'true', '1', 1, -1, etc.)
|
||||
|
||||
|
||||
## timestamp
|
||||
```python
|
||||
timestamp(datetime_string)
|
||||
```
|
||||
|
||||
Input a date-time text string of several formats and convert to a naive or timezone-aware epoch timestamp in UTC
|
||||
|
||||
Parameters:
|
||||
|
||||
datetime_string: (str) a string representation of a date-time in several supported formats
|
||||
|
||||
Attributes:
|
||||
|
||||
string (str) the input datetime string
|
||||
format (int) the format rule that was used to decode the datetime string
|
||||
naive (int) timestamp based on locally configured timezone. None if conversion fails
|
||||
utc (int) aware timestamp only if UTC timezone detected in datetime string. None if conversion fails
|
||||
|
||||
|
||||
122
jc/__init__.py
122
jc/__init__.py
@@ -4,66 +4,86 @@
|
||||
|
||||
This package serializes the output of many standard unix command line tools to JSON format.
|
||||
|
||||
For documentation on each parser, see the [documentation site](https://kellyjonbrazil.github.io/jc/).
|
||||
|
||||
CLI Example:
|
||||
|
||||
$ ls -l /usr/bin | jc --ls -p
|
||||
$ dig example.com | jc --dig -p
|
||||
[
|
||||
{
|
||||
"filename": "apropos",
|
||||
"link_to": "whatis",
|
||||
"flags": "lrwxrwxrwx.",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 6,
|
||||
"date": "Aug 15 10:53"
|
||||
},
|
||||
{
|
||||
"filename": "ar",
|
||||
"flags": "-rwxr-xr-x.",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 62744,
|
||||
"date": "Aug 8 16:14"
|
||||
},
|
||||
{
|
||||
"filename": "arch",
|
||||
"flags": "-rwxr-xr-x.",
|
||||
"links": 1,
|
||||
"owner": "root",
|
||||
"group": "root",
|
||||
"size": 33080,
|
||||
"date": "Aug 19 23:25"
|
||||
},
|
||||
...
|
||||
"id": 2951,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
"qr",
|
||||
"rd",
|
||||
"ra"
|
||||
],
|
||||
"query_num": 1,
|
||||
"answer_num": 1,
|
||||
"authority_num": 0,
|
||||
"additional_num": 1,
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": 0,
|
||||
"flags": [],
|
||||
"udp": 4096
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 39302,
|
||||
"data": "93.184.216.34"
|
||||
}
|
||||
],
|
||||
"query_time": 49,
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Fri Apr 16 16:05:10 PDT 2021",
|
||||
"rcvd": 56,
|
||||
"when_epoch": 1618614310,
|
||||
"when_epoch_utc": null
|
||||
}
|
||||
]
|
||||
|
||||
Module Example:
|
||||
|
||||
>>> import jc.parsers.ls
|
||||
>>>
|
||||
>>> data='''-rwxr-xr-x 1 root wheel 23648 May 3 22:26 cat
|
||||
... -rwxr-xr-x 1 root wheel 30016 May 3 22:26 chmod
|
||||
... -rwxr-xr-x 1 root wheel 29024 May 3 22:26 cp
|
||||
... -rwxr-xr-x 1 root wheel 375824 May 3 22:26 csh
|
||||
... -rwxr-xr-x 1 root wheel 28608 May 3 22:26 date
|
||||
... -rwxr-xr-x 1 root wheel 32000 May 3 22:26 dd
|
||||
... -rwxr-xr-x 1 root wheel 23392 May 3 22:26 df
|
||||
... -rwxr-xr-x 1 root wheel 18128 May 3 22:26 echo'''
|
||||
>>> import jc.parsers.dig
|
||||
>>>
|
||||
>>> jc.parsers.ls.parse(data)
|
||||
[{'filename': 'cat', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 23648,
|
||||
'date': 'May 3 22:26'}, {'filename': 'chmod', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root',
|
||||
'group': 'wheel', 'size': 30016, 'date': 'May 3 22:26'}, {'filename': 'cp', 'flags': '-rwxr-xr-x',
|
||||
'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 29024, 'date': 'May 3 22:26'}, {'filename': 'csh',
|
||||
'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 375824, 'date': 'May 3
|
||||
22:26'}, {'filename': 'date', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel',
|
||||
'size': 28608, 'date': 'May 3 22:26'}, {'filename': 'dd', 'flags': '-rwxr-xr-x', 'links': 1, 'owner':
|
||||
'root', 'group': 'wheel', 'size': 32000, 'date': 'May 3 22:26'}, {'filename': 'df', 'flags':
|
||||
'-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 23392, 'date': 'May 3 22:26'},
|
||||
{'filename': 'echo', 'flags': '-rwxr-xr-x', 'links': 1, 'owner': 'root', 'group': 'wheel', 'size': 18128,
|
||||
'date': 'May 3 22:26'}]
|
||||
>>> data = '''; <<>> DiG 9.10.6 <<>> example.com
|
||||
... ;; global options: +cmd
|
||||
... ;; Got answer:
|
||||
... ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64612
|
||||
... ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
|
||||
...
|
||||
... ;; OPT PSEUDOSECTION:
|
||||
... ; EDNS: version: 0, flags:; udp: 4096
|
||||
... ;; QUESTION SECTION:
|
||||
... ;example.com. IN A
|
||||
...
|
||||
... ;; ANSWER SECTION:
|
||||
... example.com. 29658 IN A 93.184.216.34
|
||||
...
|
||||
... ;; Query time: 52 msec
|
||||
... ;; SERVER: 2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)
|
||||
... ;; WHEN: Fri Apr 16 16:13:00 PDT 2021
|
||||
... ;; MSG SIZE rcvd: 56'''
|
||||
>>>
|
||||
>>> jc.parsers.dig.parse(data)
|
||||
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num':
|
||||
1, 'authority_num': 0, 'additional_num': 1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp':
|
||||
4096}}, 'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': [{'name': 'example.com.',
|
||||
'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': '93.184.216.34'}], 'query_time': 52, 'server':
|
||||
'2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': 'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56,
|
||||
'when_epoch': 1618614780, 'when_epoch_utc': None}]
|
||||
"""
|
||||
|
||||
name = 'jc'
|
||||
__version__ = '1.15.2'
|
||||
|
||||
232
jc/cli.py
232
jc/cli.py
@@ -11,49 +11,67 @@ 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
|
||||
import jc.appdirs as appdirs
|
||||
# make pygments import optional
|
||||
try:
|
||||
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
|
||||
pygments_installed = True
|
||||
except Exception:
|
||||
pygments_installed = False
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.13.3'
|
||||
version = jc.__version__
|
||||
description = 'JSON CLI output utility'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
website = 'https://github.com/kellyjonbrazil/jc'
|
||||
copyright = '© 2019-2021 Kelly Brazil'
|
||||
license = 'MIT License'
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
parsers = [
|
||||
'acpi',
|
||||
'airport',
|
||||
'airport-s',
|
||||
'arp',
|
||||
'blkid',
|
||||
'cksum',
|
||||
'crontab',
|
||||
'crontab-u',
|
||||
'csv',
|
||||
'date',
|
||||
'df',
|
||||
'dig',
|
||||
'dir',
|
||||
'dmidecode',
|
||||
'dpkg-l',
|
||||
'du',
|
||||
'env',
|
||||
'file',
|
||||
'finger',
|
||||
'free',
|
||||
'fstab',
|
||||
'group',
|
||||
'gshadow',
|
||||
'hash',
|
||||
'hashsum',
|
||||
'hciconfig',
|
||||
'history',
|
||||
'hosts',
|
||||
'id',
|
||||
'ifconfig',
|
||||
'ini',
|
||||
'iptables',
|
||||
'iw-scan',
|
||||
'jobs',
|
||||
'kv',
|
||||
'last',
|
||||
@@ -70,6 +88,7 @@ parsers = [
|
||||
'pip-show',
|
||||
'ps',
|
||||
'route',
|
||||
'rpm-qi',
|
||||
'shadow',
|
||||
'ss',
|
||||
'stat',
|
||||
@@ -78,12 +97,16 @@ parsers = [
|
||||
'systemctl-lj',
|
||||
'systemctl-ls',
|
||||
'systemctl-luf',
|
||||
'systeminfo',
|
||||
'time',
|
||||
'timedatectl',
|
||||
'tracepath',
|
||||
'traceroute',
|
||||
'uname',
|
||||
'upower',
|
||||
'uptime',
|
||||
'w',
|
||||
'wc',
|
||||
'who',
|
||||
'xml',
|
||||
'yaml'
|
||||
@@ -106,44 +129,45 @@ if os.path.isdir(local_parsers_dir):
|
||||
|
||||
# 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',
|
||||
}
|
||||
if pygments_installed:
|
||||
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):
|
||||
@@ -181,15 +205,15 @@ def set_env_colors(env_colors=None):
|
||||
|
||||
# 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)
|
||||
jc.utils.warning_message('could not parse JC_COLORS environment variable')
|
||||
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 {PYGMENT_COLOR[color_list[0]]}' if not color_list[0] == 'default' else f"bold {PYGMENT_COLOR['blue']}", # key names
|
||||
Keyword: PYGMENT_COLOR[color_list[1]] if not color_list[1] == 'default' else PYGMENT_COLOR['brightblack'], # true, false, null
|
||||
Number: PYGMENT_COLOR[color_list[2]] if not color_list[2] == 'default' else PYGMENT_COLOR['magenta'], # numbers
|
||||
String: PYGMENT_COLOR[color_list[3]] if not color_list[3] == 'default' else PYGMENT_COLOR['green'] # 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
|
||||
}
|
||||
|
||||
|
||||
@@ -271,17 +295,20 @@ def about_jc():
|
||||
'description': info.description,
|
||||
'author': info.author,
|
||||
'author_email': info.author_email,
|
||||
'website': info.website,
|
||||
'copyright': info.copyright,
|
||||
'license': info.license,
|
||||
'parser_count': len(parser_list),
|
||||
'parsers': parser_list
|
||||
}
|
||||
|
||||
|
||||
def helptext(message):
|
||||
def helptext():
|
||||
"""Return the help text with the list of parsers"""
|
||||
parsers_string = parsers_text(indent=12, pad=17)
|
||||
|
||||
helptext_string = f'''
|
||||
jc: {message}
|
||||
helptext_string = f'''\
|
||||
jc converts the output of many commands and file-types to JSON
|
||||
|
||||
Usage: COMMAND | jc PARSER [OPTIONS]
|
||||
|
||||
@@ -293,22 +320,59 @@ def helptext(message):
|
||||
{parsers_string}
|
||||
Options:
|
||||
-a about jc
|
||||
-d debug - show traceback (-dd for verbose traceback)
|
||||
-d debug (-dd for verbose debug)
|
||||
-h help (-h --parser_name for parser documentation)
|
||||
-m monochrome output
|
||||
-p pretty print output
|
||||
-q quiet - suppress warnings
|
||||
-q quiet - suppress parser warnings
|
||||
-r raw JSON output
|
||||
-v version info
|
||||
|
||||
Example:
|
||||
ls -al | jc --ls -p
|
||||
Examples:
|
||||
Standard Syntax:
|
||||
$ dig www.google.com | jc --dig -p
|
||||
|
||||
or using the magic syntax:
|
||||
Magic Syntax:
|
||||
$ jc -p dig www.google.com
|
||||
|
||||
jc -p ls -al
|
||||
Parser Documentation:
|
||||
$ jc -h --dig
|
||||
'''
|
||||
return textwrap.dedent(helptext_string)
|
||||
|
||||
|
||||
def help_doc(options):
|
||||
"""
|
||||
Returns the parser documentation if a parser is found in the arguments, otherwise
|
||||
the general help text is returned.
|
||||
"""
|
||||
for arg in options:
|
||||
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)
|
||||
compatible = ', '.join(parser.info.compatible)
|
||||
doc_text = f'''{parser.__doc__}
|
||||
Compatibility: {compatible}
|
||||
|
||||
Version {parser.info.version} by {parser.info.author} ({parser.info.author_email})
|
||||
'''
|
||||
|
||||
return doc_text
|
||||
|
||||
return helptext()
|
||||
|
||||
|
||||
def versiontext():
|
||||
"""Return the version text"""
|
||||
versiontext_string = f'''\
|
||||
jc version {info.version}
|
||||
{info.website}
|
||||
{info.copyright}'''
|
||||
return textwrap.dedent(versiontext_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:
|
||||
@@ -317,14 +381,16 @@ def json_out(data, pretty=False, env_colors=None, mono=False, piped_out=False):
|
||||
styles = set_env_colors(env_colors)
|
||||
|
||||
if pretty:
|
||||
return str(highlight(json.dumps(data, indent=2), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
|
||||
return str(highlight(json.dumps(data, indent=2, ensure_ascii=False),
|
||||
JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
|
||||
else:
|
||||
return str(highlight(json.dumps(data), JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
|
||||
return str(highlight(json.dumps(data, separators=(',', ':'), ensure_ascii=False),
|
||||
JsonLexer(), Terminal256Formatter(style=JcStyle))[0:-1])
|
||||
else:
|
||||
if pretty:
|
||||
return json.dumps(data, indent=2)
|
||||
return json.dumps(data, indent=2, ensure_ascii=False)
|
||||
else:
|
||||
return json.dumps(data)
|
||||
return json.dumps(data, separators=(',', ':'), ensure_ascii=False)
|
||||
|
||||
|
||||
def generate_magic_command(args):
|
||||
@@ -355,6 +421,10 @@ def generate_magic_command(args):
|
||||
else:
|
||||
break
|
||||
|
||||
# if -h, -a, or -v found in options, then bail out
|
||||
if 'h' in options or 'a' in options or 'v' in options:
|
||||
return False, None
|
||||
|
||||
# all options popped and no command found - for case like 'jc -a'
|
||||
if len(args_given) == 0:
|
||||
return False, None
|
||||
@@ -392,11 +462,13 @@ def magic():
|
||||
elif run_command is None:
|
||||
return
|
||||
else:
|
||||
print(helptext(f'parser not found for "{run_command}"'), file=sys.stderr)
|
||||
jc.utils.error_message(f'parser not found for "{run_command}". Use "jc -h" for help.')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
import jc.utils
|
||||
|
||||
# break on ctrl-c keyboard interrupt
|
||||
signal.signal(signal.SIGINT, ctrlc)
|
||||
|
||||
@@ -406,11 +478,11 @@ def main():
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
jc_colors = os.getenv('JC_COLORS')
|
||||
|
||||
# try magic syntax first: e.g. jc -p ls -al
|
||||
magic()
|
||||
|
||||
jc_colors = os.getenv('JC_COLORS')
|
||||
|
||||
options = []
|
||||
|
||||
# options
|
||||
@@ -418,23 +490,37 @@ def main():
|
||||
if opt.startswith('-') and not opt.startswith('--'):
|
||||
options.extend(opt[1:])
|
||||
|
||||
about = 'a' in options
|
||||
debug = 'd' in options
|
||||
verbose_debug = True if options.count('d') > 1 else False
|
||||
mono = 'm' in options
|
||||
help_me = 'h' in options
|
||||
pretty = 'p' in options
|
||||
quiet = 'q' in options
|
||||
raw = 'r' in options
|
||||
version_info = 'v' in options
|
||||
|
||||
if not pygments_installed:
|
||||
mono = True
|
||||
|
||||
if about:
|
||||
print(json_out(about_jc(), pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
|
||||
sys.exit(0)
|
||||
|
||||
if help_me:
|
||||
print(help_doc(sys.argv))
|
||||
sys.exit(0)
|
||||
|
||||
if version_info:
|
||||
print(versiontext())
|
||||
sys.exit(0)
|
||||
|
||||
if verbose_debug:
|
||||
import jc.tracebackplus
|
||||
jc.tracebackplus.enable(context=11)
|
||||
|
||||
if 'a' in options:
|
||||
print(json_out(about_jc(), pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
|
||||
sys.exit(0)
|
||||
|
||||
if sys.stdin.isatty():
|
||||
print(helptext('missing piped data'), file=sys.stderr)
|
||||
jc.utils.error_message('Missing piped data. Use "jc -h" for help.')
|
||||
sys.exit(1)
|
||||
|
||||
data = sys.stdin.read()
|
||||
@@ -459,11 +545,11 @@ def main():
|
||||
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 or -dd option.')
|
||||
' For details use the -d or -dd option. Use "jc -h" for help.')
|
||||
sys.exit(1)
|
||||
|
||||
if not found:
|
||||
print(helptext('missing or incorrect arguments'), file=sys.stderr)
|
||||
jc.utils.error_message('Missing or incorrect arguments. Use "jc -h" for help.')
|
||||
sys.exit(1)
|
||||
|
||||
print(json_out(result, pretty=pretty, env_colors=jc_colors, mono=mono, piped_out=piped_output()))
|
||||
|
||||
BIN
jc/man/jc.1.gz
Normal file
BIN
jc/man/jc.1.gz
Normal file
Binary file not shown.
389
jc/parsers/acpi.py
Normal file
389
jc/parsers/acpi.py
Normal file
@@ -0,0 +1,389 @@
|
||||
"""jc - JSON CLI output utility `acpi` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ acpi -V | jc --acpi
|
||||
|
||||
or
|
||||
|
||||
$ jc acpi -V
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.acpi
|
||||
result = jc.parsers.acpi.parse(acpi_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"type": string,
|
||||
"id": integer,
|
||||
"state": string,
|
||||
"charge_percent": integer,
|
||||
"until_charged": string,
|
||||
"until_charged_hours": integer,
|
||||
"until_charged_minuts": integer,
|
||||
"until_charged_seconds": integer,
|
||||
"until_charged_total_seconds": integer,
|
||||
"charge_remaining": string,
|
||||
"charge_remaining_hours": integer,
|
||||
"charge_remaining_minutes": integer,
|
||||
"charge_remaining_seconds": integer,
|
||||
"charge_remaining_total_seconds": integer,
|
||||
"design_capacity_mah": integer,
|
||||
"last_full_capacity": integer,
|
||||
"last_full_capacity_percent": integer,
|
||||
"on-line": boolean,
|
||||
"mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string,
|
||||
"trip_points": [
|
||||
{
|
||||
"id": integer,
|
||||
"switches_to_mode": string,
|
||||
"temperature": float,
|
||||
"temperature_unit": string
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
string
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ acpi -V | jc --acpi -p
|
||||
[
|
||||
{
|
||||
"type": "Battery",
|
||||
"id": 0,
|
||||
"state": "Charging",
|
||||
"charge_percent": 71,
|
||||
"until_charged": "00:29:20",
|
||||
"design_capacity_mah": 2110,
|
||||
"last_full_capacity": 2271,
|
||||
"last_full_capacity_percent": 100,
|
||||
"until_charged_hours": 0,
|
||||
"until_charged_minutes": 29,
|
||||
"until_charged_seconds": 20,
|
||||
"until_charged_total_seconds": 1760
|
||||
},
|
||||
{
|
||||
"type": "Adapter",
|
||||
"id": 0,
|
||||
"on-line": true
|
||||
},
|
||||
{
|
||||
"type": "Thermal",
|
||||
"id": 0,
|
||||
"mode": "ok",
|
||||
"temperature": 46.0,
|
||||
"temperature_unit": "C",
|
||||
"trip_points": [
|
||||
{
|
||||
"id": 0,
|
||||
"switches_to_mode": "critical",
|
||||
"temperature": 127.0,
|
||||
"temperature_unit": "C"
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"switches_to_mode": "hot",
|
||||
"temperature": 127.0,
|
||||
"temperature_unit": "C"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 0,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 1,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 2,
|
||||
"messages": [
|
||||
"x86_pkg_temp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 3,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 4,
|
||||
"messages": [
|
||||
"intel_powerclamp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": 5,
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
$ acpi -V | jc --acpi -p -r
|
||||
[
|
||||
{
|
||||
"type": "Battery",
|
||||
"id": "0",
|
||||
"state": "Charging",
|
||||
"charge_percent": "71",
|
||||
"until_charged": "00:29:20",
|
||||
"design_capacity_mah": "2110",
|
||||
"last_full_capacity": "2271",
|
||||
"last_full_capacity_percent": "100"
|
||||
},
|
||||
{
|
||||
"type": "Adapter",
|
||||
"id": "0",
|
||||
"on-line": true
|
||||
},
|
||||
{
|
||||
"type": "Thermal",
|
||||
"id": "0",
|
||||
"mode": "ok",
|
||||
"temperature": "46.0",
|
||||
"temperature_unit": "C",
|
||||
"trip_points": [
|
||||
{
|
||||
"id": "0",
|
||||
"switches_to_mode": "critical",
|
||||
"temperature": "127.0",
|
||||
"temperature_unit": "C"
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"switches_to_mode": "hot",
|
||||
"temperature": "127.0",
|
||||
"temperature_unit": "C"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "0",
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "1",
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "2",
|
||||
"messages": [
|
||||
"x86_pkg_temp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "3",
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "4",
|
||||
"messages": [
|
||||
"intel_powerclamp no state information available"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Cooling",
|
||||
"id": "5",
|
||||
"messages": [
|
||||
"Processor 0 of 10"
|
||||
]
|
||||
}
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.2'
|
||||
description = '`acpi` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux']
|
||||
magic_commands = ['acpi']
|
||||
|
||||
|
||||
__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 to conform to the schema.
|
||||
"""
|
||||
int_list = ['id', 'charge_percent', 'design_capacity_mah', 'last_full_capacity', 'last_full_capacity_percent']
|
||||
float_list = ['temperature']
|
||||
|
||||
for entry in proc_data:
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
if key in float_list:
|
||||
entry[key] = jc.utils.convert_to_float(entry[key])
|
||||
|
||||
if 'trip_points' in entry:
|
||||
for tp in entry['trip_points']:
|
||||
for key in tp:
|
||||
if key in int_list:
|
||||
tp[key] = jc.utils.convert_to_int(tp[key])
|
||||
if key in float_list:
|
||||
tp[key] = jc.utils.convert_to_float(tp[key])
|
||||
|
||||
for entry in proc_data:
|
||||
if 'until_charged' in entry:
|
||||
entry['until_charged_hours'] = int(entry['until_charged'].split(':')[0])
|
||||
entry['until_charged_minutes'] = int(entry['until_charged'].split(':')[1])
|
||||
entry['until_charged_seconds'] = int(entry['until_charged'].split(':')[2])
|
||||
entry['until_charged_total_seconds'] = (entry['until_charged_hours'] * 3600) + \
|
||||
(entry['until_charged_minutes'] * 60) + entry['until_charged_seconds']
|
||||
|
||||
if 'charge_remaining' in entry:
|
||||
entry['charge_remaining_hours'] = int(entry['charge_remaining'].split(':')[0])
|
||||
entry['charge_remaining_minutes'] = int(entry['charge_remaining'].split(':')[1])
|
||||
entry['charge_remaining_seconds'] = int(entry['charge_remaining'].split(':')[2])
|
||||
entry['charge_remaining_total_seconds'] = (entry['charge_remaining_hours'] * 3600) + \
|
||||
(entry['charge_remaining_minutes'] * 60) + entry['charge_remaining_seconds']
|
||||
|
||||
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 = []
|
||||
output_line = {}
|
||||
line_state = ''
|
||||
last_line_state = ''
|
||||
obj_type = ''
|
||||
obj_id = ''
|
||||
trip_points_list = []
|
||||
trip_points_dict = {}
|
||||
messages_list = []
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for line in filter(None, data.splitlines()):
|
||||
obj_type = line.split()[0]
|
||||
obj_id = line.split()[1][:-1]
|
||||
line_state = obj_type + obj_id
|
||||
|
||||
if line_state != last_line_state:
|
||||
if output_line:
|
||||
raw_output.append(output_line)
|
||||
|
||||
output_line = {}
|
||||
trip_points_list = []
|
||||
messages_list = []
|
||||
|
||||
if obj_type == 'Battery':
|
||||
output_line['type'] = obj_type
|
||||
output_line['id'] = obj_id
|
||||
if 'Charging' in line or 'Discharging' in line or 'Full' in line:
|
||||
output_line['state'] = line.split()[2][:-1]
|
||||
output_line['charge_percent'] = line.split()[3].rstrip('%,')
|
||||
if 'rate information unavailable' not in line:
|
||||
if 'Charging' in line:
|
||||
output_line['until_charged'] = line.split()[4]
|
||||
if 'Discharging' in line:
|
||||
output_line['charge_remaining'] = line.split()[4]
|
||||
|
||||
if 'design capacity' in line:
|
||||
output_line['design_capacity_mah'] = line.split()[4]
|
||||
output_line['last_full_capacity'] = line.split()[9]
|
||||
output_line['last_full_capacity_percent'] = line.split()[-1][:-1]
|
||||
|
||||
if obj_type == 'Adapter':
|
||||
output_line['type'] = obj_type
|
||||
output_line['id'] = obj_id
|
||||
if 'on-line' in line:
|
||||
output_line['on-line'] = True
|
||||
else:
|
||||
output_line['on-line'] = False
|
||||
|
||||
if obj_type == 'Thermal':
|
||||
output_line['type'] = obj_type
|
||||
output_line['id'] = obj_id
|
||||
if 'trip point' not in line:
|
||||
output_line['mode'] = line.split()[2][:-1]
|
||||
output_line['temperature'] = line.split()[3]
|
||||
output_line['temperature_unit'] = line.split()[-1]
|
||||
else:
|
||||
trip_points_dict = {
|
||||
"id": line.split()[4],
|
||||
"switches_to_mode": line.split()[8],
|
||||
"temperature": line.split()[11],
|
||||
"temperature_unit": line.split()[-1]
|
||||
}
|
||||
trip_points_list.append(trip_points_dict)
|
||||
output_line['trip_points'] = trip_points_list
|
||||
|
||||
if obj_type == 'Cooling':
|
||||
output_line['type'] = obj_type
|
||||
output_line['id'] = obj_id
|
||||
messages_list.append(line.split(maxsplit=2)[2])
|
||||
output_line['messages'] = messages_list
|
||||
|
||||
last_line_state = line_state
|
||||
|
||||
if output_line:
|
||||
raw_output.append(output_line)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return _process(raw_output)
|
||||
@@ -1,15 +1,39 @@
|
||||
"""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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'darwin'
|
||||
$ jc airport -I
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.airport
|
||||
result = jc.parsers.airport.parse(airport_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"agrctlrssi": integer,
|
||||
"agrextrssi": integer,
|
||||
"agrctlnoise": integer,
|
||||
"agrextnoise": integer,
|
||||
"state": string,
|
||||
"op_mode": string,
|
||||
"lasttxrate": integer,
|
||||
"maxrate": integer,
|
||||
"lastassocstatus": integer,
|
||||
"802_11_auth": string,
|
||||
"link_auth": string,
|
||||
"bssid": string,
|
||||
"ssid": string,
|
||||
"mcs": integer,
|
||||
"channel": string
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -55,8 +79,9 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'airport -I command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.3'
|
||||
description = '`airport -I` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
@@ -69,45 +94,24 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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. Structured data with the following schema:
|
||||
|
||||
{
|
||||
"agrctlrssi": integer,
|
||||
"agrextrssi": integer,
|
||||
"agrctlnoise": integer,
|
||||
"agrextnoise": integer,
|
||||
"state": string,
|
||||
"op_mode": string,
|
||||
"lasttxrate": integer,
|
||||
"maxrate": integer,
|
||||
"lastassocstatus": integer,
|
||||
"802_11_auth": string,
|
||||
"link_auth": string,
|
||||
"bssid": string,
|
||||
"ssid": string,
|
||||
"mcs": integer,
|
||||
"channel": string
|
||||
}
|
||||
Dictionary. Structured data to conform to the schema.
|
||||
"""
|
||||
# integer changes
|
||||
int_list = ['agrctlrssi', 'agrextrssi', 'agrctlnoise', 'agrextnoise',
|
||||
'lasttxrate', 'maxrate', 'lastassocstatus', 'mcs']
|
||||
for key in proc_data:
|
||||
if key in int_list:
|
||||
try:
|
||||
proc_data[key] = int(proc_data[key])
|
||||
except (ValueError):
|
||||
proc_data[key] = None
|
||||
proc_data[key] = jc.utils.convert_to_int(proc_data[key])
|
||||
|
||||
return proc_data
|
||||
|
||||
@@ -140,4 +144,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
@@ -1,15 +1,35 @@
|
||||
"""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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'darwin'
|
||||
$ jc airport -s
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.airport_s
|
||||
result = jc.parsers.airport_s.parse(airport_s_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"ssid": string,
|
||||
"bssid": string,
|
||||
"rssi": integer,
|
||||
"channel": string,
|
||||
"ht": boolean,
|
||||
"cc": string,
|
||||
"security": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -88,8 +108,9 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.2'
|
||||
description = 'airport -s command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.4'
|
||||
description = '`airport -s` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
@@ -102,50 +123,28 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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:
|
||||
[
|
||||
{
|
||||
"ssid": string,
|
||||
"bssid": string,
|
||||
"rssi": integer,
|
||||
"channel": string,
|
||||
"ht": boolean,
|
||||
"cc": string,
|
||||
"security": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
]
|
||||
List of Dictionaries. Structured data to conform to the schema.
|
||||
"""
|
||||
for entry in proc_data:
|
||||
|
||||
# integers
|
||||
# convert integers and booleans
|
||||
int_list = ['rssi']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
entry[key] = int(entry[key])
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
|
||||
# booleans
|
||||
bool_list = ['ht']
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
if key in bool_list:
|
||||
try:
|
||||
entry[key] = True if entry[key] == 'Y' else False
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
entry[key] = jc.utils.convert_to_bool(entry[key])
|
||||
|
||||
if 'security' in entry:
|
||||
entry['security'] = entry['security'].split()
|
||||
@@ -165,7 +164,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)
|
||||
@@ -185,4 +184,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
@@ -1,16 +1,34 @@
|
||||
"""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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'aix', 'freebsd', 'darwin'
|
||||
$ jc arp
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.arp
|
||||
result = jc.parsers.arp.parse(arp_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"address": string,
|
||||
"hwtype": string,
|
||||
"hwaddress": string,
|
||||
"flags_mask": string,
|
||||
"iface": string,
|
||||
"permanent": boolean,
|
||||
"expires": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -99,8 +117,9 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.6'
|
||||
description = 'arp command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.7'
|
||||
description = '`arp` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
@@ -112,30 +131,17 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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:
|
||||
|
||||
[
|
||||
{
|
||||
"name": string,
|
||||
"address": string,
|
||||
"hwtype": string,
|
||||
"hwaddress": string,
|
||||
"flags_mask": string,
|
||||
"iface": string,
|
||||
"permanent": boolean,
|
||||
"expires": integer
|
||||
}
|
||||
]
|
||||
List of Dictionaries. Structured data to conform to the schema:
|
||||
"""
|
||||
|
||||
# in BSD style, change name to null if it is a question mark
|
||||
@@ -144,12 +150,9 @@ def process(proc_data):
|
||||
entry['name'] = None
|
||||
|
||||
int_list = ['expires']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
entry[key] = int(entry[key])
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
return proc_data
|
||||
|
||||
@@ -166,7 +169,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)
|
||||
@@ -205,7 +208,7 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
# detect if linux style was used
|
||||
elif cleandata[0].startswith('Address'):
|
||||
@@ -232,4 +235,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
@@ -1,12 +1,53 @@
|
||||
"""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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc blkid
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.blkid
|
||||
result = jc.parsers.blkid.parse(blkid_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"device": string,
|
||||
"uuid": string,
|
||||
"type": string,
|
||||
"usage": string,
|
||||
"part_entry_scheme": string,
|
||||
"part_entry_type": string,
|
||||
"part_entry_flags": string,
|
||||
"part_entry_number": integer,
|
||||
"part_entry_offset": integer,
|
||||
"part_entry_size": integer,
|
||||
"part_entry_disk": string,
|
||||
"id_fs_uuid": string,
|
||||
"id_fs_uuid_enc": string,
|
||||
"id_fs_version": string,
|
||||
"id_fs_type": string,
|
||||
"id_fs_usage": string,
|
||||
"id_part_entry_scheme": string,
|
||||
"id_part_entry_type": string,
|
||||
"id_part_entry_flags": string,
|
||||
"id_part_entry_number": integer,
|
||||
"id_part_entry_offset": integer,
|
||||
"id_part_entry_size": integer,
|
||||
"id_iolimit_minimum_io_size": integer,
|
||||
"id_iolimit_physical_sector_size": integer,
|
||||
"id_iolimit_logical_sector_size": integer,
|
||||
"id_part_entry_disk": string,
|
||||
"minimum_io_size": integer,
|
||||
"physical_sector_size": integer,
|
||||
"logical_sector_size": integer
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -79,8 +120,9 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.2'
|
||||
description = 'blkid command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.4'
|
||||
description = '`blkid` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
@@ -93,51 +135,17 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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:
|
||||
|
||||
[
|
||||
{
|
||||
"device": string,
|
||||
"uuid": string,
|
||||
"type": string,
|
||||
"usage": string,
|
||||
"part_entry_scheme": string,
|
||||
"part_entry_type": string,
|
||||
"part_entry_flags": string,
|
||||
"part_entry_number": integer,
|
||||
"part_entry_offset": integer,
|
||||
"part_entry_size": integer,
|
||||
"part_entry_disk": string,
|
||||
"id_fs_uuid": string,
|
||||
"id_fs_uuid_enc": string,
|
||||
"id_fs_version": string,
|
||||
"id_fs_type": string,
|
||||
"id_fs_usage": string,
|
||||
"id_part_entry_scheme": string,
|
||||
"id_part_entry_type": string,
|
||||
"id_part_entry_flags": string,
|
||||
"id_part_entry_number": integer,
|
||||
"id_part_entry_offset": integer,
|
||||
"id_part_entry_size": integer,
|
||||
"id_iolimit_minimum_io_size": integer,
|
||||
"id_iolimit_physical_sector_size": integer,
|
||||
"id_iolimit_logical_sector_size": integer,
|
||||
"id_part_entry_disk": string,
|
||||
"minimum_io_size": integer,
|
||||
"physical_sector_size": integer,
|
||||
"logical_sector_size": integer
|
||||
}
|
||||
]
|
||||
List of Dictionaries. Structured data to conform to the schema.
|
||||
"""
|
||||
for entry in proc_data:
|
||||
if 'devname' in entry:
|
||||
@@ -147,12 +155,9 @@ def process(proc_data):
|
||||
'id_part_entry_offset', 'id_part_entry_size', 'minimum_io_size', 'physical_sector_size',
|
||||
'logical_sector_size', 'id_iolimit_minimum_io_size', 'id_iolimit_physical_sector_size',
|
||||
'id_iolimit_logical_sector_size']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
entry[key] = int(entry[key])
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
return proc_data
|
||||
|
||||
@@ -169,7 +174,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)
|
||||
@@ -216,4 +221,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
124
jc/parsers/cksum.py
Normal file
124
jc/parsers/cksum.py
Normal file
@@ -0,0 +1,124 @@
|
||||
"""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)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filename": string,
|
||||
"checksum": integer,
|
||||
"blocks": integer
|
||||
}
|
||||
]
|
||||
|
||||
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():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.2'
|
||||
description = '`cksum` and `sum` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
# 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 to conform to the schema.
|
||||
"""
|
||||
|
||||
for entry in proc_data:
|
||||
int_list = ['checksum', 'blocks']
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
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)
|
||||
@@ -1,12 +1,50 @@
|
||||
"""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):
|
||||
|
||||
Compatibility:
|
||||
$ crontab -l | jc --crontab
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
or
|
||||
|
||||
$ jc crontab -l
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.crontab
|
||||
result = jc.parsers.crontab.parse(crontab_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"variables": [
|
||||
"name": string,
|
||||
"value": string
|
||||
],
|
||||
"schedule": [
|
||||
{
|
||||
"occurrence" string,
|
||||
"minute": [
|
||||
string
|
||||
],
|
||||
"hour": [
|
||||
string
|
||||
],
|
||||
"day_of_month": [
|
||||
string
|
||||
],
|
||||
"month": [
|
||||
string
|
||||
],
|
||||
"day_of_week": [
|
||||
string
|
||||
],
|
||||
"occurrence": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -132,8 +170,9 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.4'
|
||||
description = 'crontab command and file parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.5'
|
||||
description = '`crontab` command and file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
@@ -146,47 +185,17 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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. Structured data with the following schema:
|
||||
|
||||
{
|
||||
"variables": [
|
||||
"name": string,
|
||||
"value": string
|
||||
],
|
||||
"schedule": [
|
||||
{
|
||||
"occurrence" string,
|
||||
"minute": [
|
||||
string
|
||||
],
|
||||
"hour": [
|
||||
string
|
||||
],
|
||||
"day_of_month": [
|
||||
string
|
||||
],
|
||||
"month": [
|
||||
string
|
||||
],
|
||||
"day_of_week": [
|
||||
string
|
||||
],
|
||||
"occurrence": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Dictionary. Structured data to conform to the schema.
|
||||
"""
|
||||
# put itmes in lists
|
||||
try:
|
||||
@@ -235,7 +244,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()
|
||||
@@ -269,4 +278,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
@@ -1,12 +1,47 @@
|
||||
"""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):
|
||||
|
||||
Compatibility:
|
||||
$ crontab -l | jc --crontab-u
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.crontab_u
|
||||
result = jc.parsers.crontab_u.parse(crontab_u_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"variables": [
|
||||
"name": string,
|
||||
"value": string
|
||||
],
|
||||
"schedule": [
|
||||
{
|
||||
"occurrence" string,
|
||||
"minute": [
|
||||
string
|
||||
],
|
||||
"hour": [
|
||||
string
|
||||
],
|
||||
"day_of_month": [
|
||||
string
|
||||
],
|
||||
"month": [
|
||||
string
|
||||
],
|
||||
"day_of_week": [
|
||||
string
|
||||
],
|
||||
"occurrence": string,
|
||||
"user": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -125,16 +160,15 @@ Examples:
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
import jc.utils
|
||||
import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.3'
|
||||
description = 'crontab file parser with user support'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.6'
|
||||
description = '`crontab` file parser with user support'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
@@ -146,48 +180,17 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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. Structured data with the following schema:
|
||||
|
||||
{
|
||||
"variables": [
|
||||
"name": string,
|
||||
"value": string
|
||||
],
|
||||
"schedule": [
|
||||
{
|
||||
"occurrence" string,
|
||||
"minute": [
|
||||
string
|
||||
],
|
||||
"hour": [
|
||||
string
|
||||
],
|
||||
"day_of_month": [
|
||||
string
|
||||
],
|
||||
"month": [
|
||||
string
|
||||
],
|
||||
"day_of_week": [
|
||||
string
|
||||
],
|
||||
"occurrence": string,
|
||||
"user": string,
|
||||
"command": string
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Dictionary. Structured data to conform to the schema.
|
||||
"""
|
||||
# put itmes in lists
|
||||
try:
|
||||
@@ -236,7 +239,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()
|
||||
@@ -272,4 +275,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
"""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):
|
||||
|
||||
Compatibility:
|
||||
$ cat file.csv | jc --csv
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.csv
|
||||
result = jc.parsers.csv.parse(csv_output)
|
||||
|
||||
Schema:
|
||||
|
||||
csv file converted to a Dictionary: https://docs.python.org/3/library/csv.html
|
||||
|
||||
[
|
||||
{
|
||||
"column_name1": string,
|
||||
"column_name2": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -63,7 +74,8 @@ import csv
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.2'
|
||||
description = 'CSV file parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
@@ -76,24 +88,17 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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:
|
||||
|
||||
[
|
||||
{
|
||||
csv file converted to a Dictionary
|
||||
https://docs.python.org/3/library/csv.html
|
||||
}
|
||||
]
|
||||
List of Dictionaries. Each Dictionary represents a row in the csv file.
|
||||
"""
|
||||
|
||||
# No further processing
|
||||
@@ -112,7 +117,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)
|
||||
@@ -139,4 +144,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
@@ -1,47 +1,79 @@
|
||||
"""jc - JSON CLI output utility date Parser
|
||||
"""jc - JSON CLI output utility `date` command output parser
|
||||
|
||||
Usage:
|
||||
The `epoch` calculated timestamp field is naive. (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
specify --date as the first argument if the piped input is coming from date
|
||||
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
|
||||
|
||||
Compatibility:
|
||||
Usage (cli):
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
$ date | jc --date
|
||||
|
||||
or
|
||||
|
||||
$ jc date
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.date
|
||||
result = jc.parsers.date.parse(date_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"year": integer,
|
||||
"month": string,
|
||||
"month_num": integer,
|
||||
"day": integer,
|
||||
"weekday": string,
|
||||
"weekday_num": integer,
|
||||
"hour": integer,
|
||||
"hour_24": integer,
|
||||
"minute": integer,
|
||||
"second": integer,
|
||||
"period": string,
|
||||
"timezone": string,
|
||||
"utc_offset": string, # null if timezone field is not UTC
|
||||
"day_of_year": integer,
|
||||
"week_of_year": integer,
|
||||
"iso": string,
|
||||
"epoch": integer, # naive timestamp
|
||||
"epoch_utc": integer, # timezone-aware timestamp. Only available if timezone field is UTC
|
||||
"timezone_aware": boolean # if true, all fields are correctly based on UTC
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
$ date | jc --date -p
|
||||
{
|
||||
"year": 2020,
|
||||
"month_num": 7,
|
||||
"day": 31,
|
||||
"hour": 16,
|
||||
"minute": 48,
|
||||
"second": 11,
|
||||
"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"
|
||||
"year": 2021,
|
||||
"month": "Mar",
|
||||
"month_num": 3,
|
||||
"day": 25,
|
||||
"weekday": "Thu",
|
||||
"weekday_num": 4,
|
||||
"hour": 2,
|
||||
"hour_24": 2,
|
||||
"minute": 2,
|
||||
"second": 26,
|
||||
"period": "AM",
|
||||
"timezone": "UTC",
|
||||
"utc_offset": "+0000",
|
||||
"day_of_year": 84,
|
||||
"week_of_year": 12,
|
||||
"iso": "2021-03-25T02:02:26+00:00",
|
||||
"epoch": 1616662946,
|
||||
"epoch_utc": 1616637746,
|
||||
"timezone_aware": true
|
||||
}
|
||||
"""
|
||||
from datetime import datetime, timezone
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.0'
|
||||
description = 'date command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '2.1'
|
||||
description = '`date` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
@@ -53,71 +85,20 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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. Structured data with the following schema:
|
||||
|
||||
{
|
||||
"year": integer,
|
||||
"month_num": integer,
|
||||
"day": integer,
|
||||
"hour": integer,
|
||||
"minute": integer,
|
||||
"second": integer,
|
||||
"month": string,
|
||||
"weekday": string,
|
||||
"weekday_num": integer,
|
||||
"timezone": string
|
||||
}
|
||||
Dictionary. Structured data to conform to the schema.
|
||||
"""
|
||||
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']),
|
||||
"month": proc_data['month'],
|
||||
"weekday": proc_data['weekday'],
|
||||
"weekday_num": weekday_map[proc_data['weekday']],
|
||||
"timezone": proc_data['timezone']
|
||||
}
|
||||
else:
|
||||
return {}
|
||||
# no further processing
|
||||
return proc_data
|
||||
|
||||
|
||||
def parse(data, raw=False, quiet=False):
|
||||
@@ -140,21 +121,71 @@ def parse(data, raw=False, quiet=False):
|
||||
raw_output = {}
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
data = data.replace(':', ' ')
|
||||
split_data = data.split()
|
||||
|
||||
# find the timezone no matter where it is in the string
|
||||
# from https://www.timeanddate.com/time/zones/
|
||||
tz_abbr = ['A', 'ACDT', 'ACST', 'ACT', 'ACWST', 'ADT', 'AEDT', 'AEST', 'AET', 'AFT', 'AKDT', 'AKST', 'ALMT',
|
||||
'AMST', 'AMT', 'ANAST', 'ANAT', 'AQTT', 'ART', 'AST', 'AT', 'AWDT', 'AWST', 'AZOST', 'AZOT',
|
||||
'AZST', 'AZT', 'AoE', 'B', 'BNT', 'BOT', 'BRST', 'BRT', 'BST', 'BTT', 'C', 'CAST', 'CAT', 'CCT',
|
||||
'CDT', 'CEST', 'CET', 'CHADT', 'CHAST', 'CHOST', 'CHOT', 'CHUT', 'CIDST', 'CIST', 'CKT', 'CLST',
|
||||
'CLT', 'COT', 'CST', 'CT', 'CVT', 'CXT', 'ChST', 'D', 'DAVT', 'DDUT', 'E', 'EASST', 'EAST',
|
||||
'EAT', 'ECT', 'EDT', 'EEST', 'EET', 'EGST', 'EGT', 'EST', 'ET', 'F', 'FET', 'FJST', 'FJT', 'FKST',
|
||||
'FKT', 'FNT', 'G', 'GALT', 'GAMT', 'GET', 'GFT', 'GILT', 'GMT', 'GST', 'GYT', 'H', 'HDT', 'HKT',
|
||||
'HOVST', 'HOVT', 'HST', 'I', 'ICT', 'IDT', 'IOT', 'IRDT', 'IRKST', 'IRKT', 'IRST', 'IST', 'JST',
|
||||
'K', 'KGT', 'KOST', 'KRAST', 'KRAT', 'KST', 'KUYT', 'L', 'LHDT', 'LHST', 'LINT', 'M', 'MAGST',
|
||||
'MAGT', 'MART', 'MAWT', 'MDT', 'MHT', 'MMT', 'MSD', 'MSK', 'MST', 'MT', 'MUT', 'MVT', 'MYT', 'N',
|
||||
'NCT', 'NDT', 'NFDT', 'NFT', 'NOVST', 'NOVT', 'NPT', 'NRT', 'NST', 'NUT', 'NZDT', 'NZST', 'O',
|
||||
'OMSST', 'OMST', 'ORAT', 'P', 'PDT', 'PET', 'PETST', 'PETT', 'PGT', 'PHOT', 'PHT', 'PKT', 'PMDT',
|
||||
'PMST', 'PONT', 'PST', 'PT', 'PWT', 'PYST', 'PYT', 'Q', 'QYZT', 'R', 'RET', 'ROTT', 'S', 'SAKT',
|
||||
'SAMT', 'SAST', 'SBT', 'SCT', 'SGT', 'SRET', 'SRT', 'SST', 'SYOT', 'T', 'TAHT', 'TFT', 'TJT', 'TKT',
|
||||
'TLT', 'TMT', 'TOST', 'TOT', 'TRT', 'TVT', 'U', 'ULAST', 'ULAT', 'UYST', 'UYT', 'UZT', 'V', 'VET',
|
||||
'VLAST', 'VLAT', 'VOST', 'VUT', 'W', 'WAKT', 'WARST', 'WAST', 'WAT', 'WEST', 'WET', 'WFT', 'WGST',
|
||||
'WGT', 'WIB', 'WIT', 'WITA', 'WST', 'WT', 'X', 'Y', 'YAKST', 'YAKT', 'YAPT', 'YEKST', 'YEKT', 'Z',
|
||||
'UTC', 'UTC-1200', 'UTC-1100', 'UTC-1000', 'UTC-0930', 'UTC-0900', 'UTC-0800', 'UTC-0700', 'UTC-0600',
|
||||
'UTC-0500', 'UTC-0400', 'UTC-0300', 'UTC-0230', 'UTC-0200', 'UTC-0100', 'UTC+0000', 'UTC-0000',
|
||||
'UTC+0100', 'UTC+0200', 'UTC+0300', 'UTC+0400', 'UTC+0430', 'UTC+0500', 'UTC+0530', 'UTC+0545',
|
||||
'UTC+0600', 'UTC+0630', 'UTC+0700', 'UTC+0800', 'UTC+0845', 'UTC+0900', 'UTC+1000', 'UTC+1030',
|
||||
'UTC+1100', 'UTC+1200', 'UTC+1300', 'UTC+1345', 'UTC+1400']
|
||||
tz = None
|
||||
for term in data.replace('(', '').replace(')', '').split():
|
||||
if term in tz_abbr:
|
||||
tz = term
|
||||
|
||||
dt = None
|
||||
dt_utc = None
|
||||
|
||||
timestamp = jc.utils.timestamp(data)
|
||||
if timestamp.naive:
|
||||
dt = datetime.fromtimestamp(timestamp.naive)
|
||||
if timestamp.utc:
|
||||
dt_utc = datetime.fromtimestamp(timestamp.utc, timezone.utc)
|
||||
|
||||
if dt_utc:
|
||||
dt = dt_utc
|
||||
|
||||
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]
|
||||
'year': dt.year,
|
||||
'month': dt.strftime('%b'),
|
||||
'month_num': dt.month,
|
||||
'day': dt.day,
|
||||
'weekday': dt.strftime('%a'),
|
||||
'weekday_num': dt.isoweekday(),
|
||||
'hour': int(dt.strftime('%I')),
|
||||
'hour_24': dt.hour,
|
||||
'minute': dt.minute,
|
||||
'second': dt.second,
|
||||
'period': dt.strftime('%p'),
|
||||
'timezone': tz,
|
||||
'utc_offset': dt.strftime('%z') or None,
|
||||
'day_of_year': int(dt.strftime('%j')),
|
||||
'week_of_year': int(dt.strftime('%W')),
|
||||
'iso': dt.isoformat(),
|
||||
'epoch': timestamp.naive,
|
||||
'epoch_utc': timestamp.utc,
|
||||
'timezone_aware': True if timestamp.utc else False
|
||||
}
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
@@ -1,12 +1,36 @@
|
||||
"""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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'freebsd'
|
||||
$ jc df
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.df
|
||||
result = jc.parsers.df.parse(df_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"filesystem": string,
|
||||
"size": string,
|
||||
"1k_blocks": integer,
|
||||
"512_blocks": integer,
|
||||
"used": integer,
|
||||
"available": integer,
|
||||
"capacity_percent": integer,
|
||||
"ifree": integer,
|
||||
"iused": integer,
|
||||
"use_percent": integer,
|
||||
"iused_percent": integer,
|
||||
"mounted_on": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -73,8 +97,9 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.5'
|
||||
description = 'df command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.7'
|
||||
description = '`df` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
@@ -86,34 +111,17 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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:
|
||||
|
||||
[
|
||||
{
|
||||
"filesystem": string,
|
||||
"size": string,
|
||||
"1k_blocks": integer,
|
||||
"512_blocks": integer,
|
||||
"used": integer,
|
||||
"available": integer,
|
||||
"capacity_percent": integer,
|
||||
"ifree": integer,
|
||||
"iused": integer,
|
||||
"use_percent": integer,
|
||||
"iused_percent": integer,
|
||||
"mounted_on": string
|
||||
}
|
||||
]
|
||||
List of Dictionaries. Structured data to conform to the schema:
|
||||
"""
|
||||
|
||||
for entry in proc_data:
|
||||
@@ -136,11 +144,7 @@ def process(proc_data):
|
||||
# change any entry for key with '_blocks' in the name to int
|
||||
for k in entry:
|
||||
if '_blocks' in str(k):
|
||||
try:
|
||||
blocks_int = int(entry[k])
|
||||
entry[k] = blocks_int
|
||||
except (ValueError):
|
||||
entry[k] = None
|
||||
entry[k] = jc.utils.convert_to_int(entry[k])
|
||||
|
||||
# remove percent sign from 'use_percent', 'capacity_percent', and 'iused_percent'
|
||||
if 'use_percent' in entry:
|
||||
@@ -154,13 +158,9 @@ def process(proc_data):
|
||||
|
||||
# change used, available, use_percent, capacity_percent, ifree, iused, iused_percent to int
|
||||
int_list = ['used', 'available', 'use_percent', 'capacity_percent', 'ifree', 'iused', 'iused_percent']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
key_int = int(entry[key])
|
||||
entry[key] = key_int
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
return proc_data
|
||||
|
||||
@@ -177,7 +177,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:
|
||||
@@ -199,4 +199,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
@@ -1,19 +1,104 @@
|
||||
"""jc - JSON CLI output utility dig Parser
|
||||
"""jc - JSON CLI output utility `dig` command output parser
|
||||
|
||||
Usage:
|
||||
The `when_epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
Specify --dig as the first argument if the piped input is coming from dig
|
||||
The `when_epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
|
||||
|
||||
Compatibility:
|
||||
Usage (cli):
|
||||
|
||||
'linux', 'darwin', 'cygwin', 'win32', 'aix', 'freebsd'
|
||||
$ dig example.com | jc --dig
|
||||
|
||||
or
|
||||
|
||||
$ jc dig example.com
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dig
|
||||
result = jc.parsers.dig.parse(dig_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"id": integer,
|
||||
"opcode": string,
|
||||
"status": string,
|
||||
"flags": [
|
||||
string
|
||||
],
|
||||
"query_num": integer,
|
||||
"answer_num": integer,
|
||||
"authority_num": integer,
|
||||
"additional_num": integer,
|
||||
"axfr": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": integer,
|
||||
"flags": [
|
||||
string
|
||||
],
|
||||
"udp": integer
|
||||
},
|
||||
"cookie": string
|
||||
},
|
||||
"question": {
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"additional": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"authority": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"query_size": integer,
|
||||
"query_time": integer, # in msec
|
||||
"server": string,
|
||||
"when": string,
|
||||
"when_epoch": integer, # naive timestamp if when field is parsable, else null
|
||||
"when_epoch_utc": integer, # timezone aware timestamp availabe for UTC, else null
|
||||
"rcvd": integer
|
||||
"size": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p
|
||||
$ dig example.com | jc --dig -p
|
||||
[
|
||||
{
|
||||
"id": 34128,
|
||||
"id": 2951,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
@@ -22,117 +107,43 @@ Examples:
|
||||
"ra"
|
||||
],
|
||||
"query_num": 1,
|
||||
"answer_num": 4,
|
||||
"answer_num": 1,
|
||||
"authority_num": 0,
|
||||
"additional_num": 1,
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": 0,
|
||||
"flags": [],
|
||||
"udp": 4096
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "cnn.com.",
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.65.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.193.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.1.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": 60,
|
||||
"data": "151.101.129.67"
|
||||
"ttl": 39302,
|
||||
"data": "93.184.216.34"
|
||||
}
|
||||
],
|
||||
"query_time": 37,
|
||||
"server": "2600",
|
||||
"when": "Tue Nov 12 07:14:42 PST 2019",
|
||||
"rcvd": 100
|
||||
},
|
||||
{
|
||||
"id": 15273,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
"qr",
|
||||
"aa",
|
||||
"rd"
|
||||
],
|
||||
"query_num": 1,
|
||||
"answer_num": 1,
|
||||
"authority_num": 4,
|
||||
"additional_num": 1,
|
||||
"question": {
|
||||
"name": "www.cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "www.cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "CNAME",
|
||||
"ttl": 300,
|
||||
"data": "turner-tls.map.fastly.net."
|
||||
}
|
||||
],
|
||||
"authority": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": 3600,
|
||||
"data": "ns-1086.awsdns-07.org."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": 3600,
|
||||
"data": "ns-1630.awsdns-11.co.uk."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": 3600,
|
||||
"data": "ns-47.awsdns-05.com."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": 3600,
|
||||
"data": "ns-576.awsdns-08.net."
|
||||
}
|
||||
],
|
||||
"query_time": 23,
|
||||
"server": "205.251.194.64#53(205.251.194.64)",
|
||||
"when": "Tue Nov 12 07:14:42 PST 2019",
|
||||
"rcvd": 212
|
||||
"query_time": 49,
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Fri Apr 16 16:05:10 PDT 2021",
|
||||
"rcvd": 56,
|
||||
"when_epoch": 1618614310,
|
||||
"when_epoch_utc": null
|
||||
}
|
||||
]
|
||||
|
||||
$ dig cnn.com www.cnn.com @205.251.194.64 | jc --dig -p -r
|
||||
[
|
||||
{
|
||||
"id": "23843",
|
||||
"id": "46052",
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
@@ -141,117 +152,41 @@ Examples:
|
||||
"ra"
|
||||
],
|
||||
"query_num": "1",
|
||||
"answer_num": "4",
|
||||
"answer_num": "1",
|
||||
"authority_num": "0",
|
||||
"additional_num": "1",
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": "0",
|
||||
"flags": [],
|
||||
"udp": "4096"
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "cnn.com.",
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"name": "example.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": "30",
|
||||
"data": "151.101.193.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": "30",
|
||||
"data": "151.101.1.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": "30",
|
||||
"data": "151.101.65.67"
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A",
|
||||
"ttl": "30",
|
||||
"data": "151.101.129.67"
|
||||
"ttl": "40426",
|
||||
"data": "93.184.216.34"
|
||||
}
|
||||
],
|
||||
"query_time": "24 msec",
|
||||
"server": "192.168.1.254#53(192.168.1.254)",
|
||||
"when": "Tue Nov 12 07:16:19 PST 2019",
|
||||
"rcvd": "100"
|
||||
},
|
||||
{
|
||||
"id": "8266",
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
"qr",
|
||||
"aa",
|
||||
"rd"
|
||||
],
|
||||
"query_num": "1",
|
||||
"answer_num": "1",
|
||||
"authority_num": "4",
|
||||
"additional_num": "1",
|
||||
"question": {
|
||||
"name": "www.cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "A"
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": "www.cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "CNAME",
|
||||
"ttl": "300",
|
||||
"data": "turner-tls.map.fastly.net."
|
||||
}
|
||||
],
|
||||
"authority": [
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": "3600",
|
||||
"data": "ns-1086.awsdns-07.org."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": "3600",
|
||||
"data": "ns-1630.awsdns-11.co.uk."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": "3600",
|
||||
"data": "ns-47.awsdns-05.com."
|
||||
},
|
||||
{
|
||||
"name": "cnn.com.",
|
||||
"class": "IN",
|
||||
"type": "NS",
|
||||
"ttl": "3600",
|
||||
"data": "ns-576.awsdns-08.net."
|
||||
}
|
||||
],
|
||||
"query_time": "26 msec",
|
||||
"server": "205.251.194.64#53(205.251.194.64)",
|
||||
"when": "Tue Nov 12 07:16:19 PST 2019",
|
||||
"rcvd": "212"
|
||||
"query_time": "48 msec",
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Fri Apr 16 16:06:12 PDT 2021",
|
||||
"rcvd": "56"
|
||||
}
|
||||
]
|
||||
|
||||
$ dig -x 1.1.1.1 | jc --dig -p
|
||||
[
|
||||
{
|
||||
"id": 34898,
|
||||
"id": 20785,
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
@@ -263,6 +198,13 @@ Examples:
|
||||
"answer_num": 1,
|
||||
"authority_num": 0,
|
||||
"additional_num": 1,
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": 0,
|
||||
"flags": [],
|
||||
"udp": 4096
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "1.1.1.1.in-addr.arpa.",
|
||||
"class": "IN",
|
||||
@@ -273,21 +215,23 @@ Examples:
|
||||
"name": "1.1.1.1.in-addr.arpa.",
|
||||
"class": "IN",
|
||||
"type": "PTR",
|
||||
"ttl": 952,
|
||||
"ttl": 1800,
|
||||
"data": "one.one.one.one."
|
||||
}
|
||||
],
|
||||
"query_time": 103,
|
||||
"server": "2600",
|
||||
"when": "Tue Nov 12 07:15:33 PST 2019",
|
||||
"rcvd": 78
|
||||
"query_time": 40,
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Sat Apr 17 14:50:50 PDT 2021",
|
||||
"rcvd": 78,
|
||||
"when_epoch": 1618696250,
|
||||
"when_epoch_utc": null
|
||||
}
|
||||
]
|
||||
|
||||
$ dig -x 1.1.1.1 | jc --dig -p -r
|
||||
[
|
||||
{
|
||||
"id": "50986",
|
||||
"id": "32644",
|
||||
"opcode": "QUERY",
|
||||
"status": "NOERROR",
|
||||
"flags": [
|
||||
@@ -299,6 +243,13 @@ Examples:
|
||||
"answer_num": "1",
|
||||
"authority_num": "0",
|
||||
"additional_num": "1",
|
||||
"opt_pseudosection": {
|
||||
"edns": {
|
||||
"version": "0",
|
||||
"flags": [],
|
||||
"udp": "4096"
|
||||
}
|
||||
},
|
||||
"question": {
|
||||
"name": "1.1.1.1.in-addr.arpa.",
|
||||
"class": "IN",
|
||||
@@ -313,9 +264,9 @@ Examples:
|
||||
"data": "one.one.one.one."
|
||||
}
|
||||
],
|
||||
"query_time": "38 msec",
|
||||
"server": "2600",
|
||||
"when": "Tue Nov 12 07:17:19 PST 2019",
|
||||
"query_time": "52 msec",
|
||||
"server": "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
|
||||
"when": "Sat Apr 17 14:51:46 PDT 2021",
|
||||
"rcvd": "78"
|
||||
}
|
||||
]
|
||||
@@ -324,8 +275,9 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.3'
|
||||
description = 'dig command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '2.0'
|
||||
description = '`dig` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
|
||||
@@ -337,116 +289,58 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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:
|
||||
|
||||
[
|
||||
{
|
||||
"id": integer,
|
||||
"opcode": string,
|
||||
"status": string,
|
||||
"flags": [
|
||||
string
|
||||
],
|
||||
"query_num": integer,
|
||||
"answer_num": integer,
|
||||
"authority_num": integer,
|
||||
"additional_num": integer,
|
||||
"axfr": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"question": {
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string
|
||||
},
|
||||
"answer": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"authority": [
|
||||
{
|
||||
"name": string,
|
||||
"class": string,
|
||||
"type": string,
|
||||
"ttl": integer,
|
||||
"data": string
|
||||
}
|
||||
],
|
||||
"query_time": integer, # in msec
|
||||
"server": string,
|
||||
"when": string,
|
||||
"rcvd": integer
|
||||
"size": string
|
||||
}
|
||||
]
|
||||
List of Dictionaries. Structured data to conform to the schema.
|
||||
"""
|
||||
|
||||
for entry in proc_data:
|
||||
int_list = ['id', 'query_num', 'answer_num', 'authority_num', 'additional_num', 'rcvd']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
key_int = int(entry[key])
|
||||
entry[key] = key_int
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
int_list = ['id', 'query_num', 'answer_num', 'authority_num', 'additional_num', 'rcvd',
|
||||
'query_size', 'query_time']
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
if 'axfr' in entry:
|
||||
for ax in entry['axfr']:
|
||||
try:
|
||||
ttl_int = int(ax['ttl'])
|
||||
ax['ttl'] = ttl_int
|
||||
except (ValueError):
|
||||
ax['ttl'] = None
|
||||
ax['ttl'] = jc.utils.convert_to_int(ax['ttl'])
|
||||
|
||||
if 'opt_pseudosection' in entry:
|
||||
if 'edns' in entry['opt_pseudosection']:
|
||||
if 'version' in entry['opt_pseudosection']['edns']:
|
||||
entry['opt_pseudosection']['edns']['version'] = jc.utils.convert_to_int(entry['opt_pseudosection']['edns']['version'])
|
||||
|
||||
if 'udp' in entry['opt_pseudosection']['edns']:
|
||||
entry['opt_pseudosection']['edns']['udp'] = jc.utils.convert_to_int(entry['opt_pseudosection']['edns']['udp'])
|
||||
|
||||
if 'answer' in entry:
|
||||
for ans in entry['answer']:
|
||||
try:
|
||||
ttl_int = int(ans['ttl'])
|
||||
ans['ttl'] = ttl_int
|
||||
except (ValueError):
|
||||
ans['ttl'] = None
|
||||
ans['ttl'] = jc.utils.convert_to_int(ans['ttl'])
|
||||
|
||||
if 'additional' in entry:
|
||||
for add in entry['additional']:
|
||||
add['ttl'] = jc.utils.convert_to_int(add['ttl'])
|
||||
|
||||
if 'authority' in entry:
|
||||
for auth in entry['authority']:
|
||||
try:
|
||||
ttl_int = int(auth['ttl'])
|
||||
auth['ttl'] = ttl_int
|
||||
except (ValueError):
|
||||
auth['ttl'] = None
|
||||
auth['ttl'] = jc.utils.convert_to_int(auth['ttl'])
|
||||
|
||||
if 'query_time' in entry:
|
||||
try:
|
||||
qt_int = int(entry['query_time'].split()[0])
|
||||
entry['query_time'] = qt_int
|
||||
except (ValueError):
|
||||
entry['query_time'] = None
|
||||
if 'when' in entry:
|
||||
ts = jc.utils.timestamp(entry['when'])
|
||||
entry['when_epoch'] = ts.naive
|
||||
entry['when_epoch_utc'] = ts.utc
|
||||
|
||||
return proc_data
|
||||
|
||||
|
||||
def parse_header(header):
|
||||
def _parse_header(header):
|
||||
# ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 6140
|
||||
header = header.split()
|
||||
opcode = header[3].rstrip(',')
|
||||
@@ -458,7 +352,7 @@ def parse_header(header):
|
||||
'status': status}
|
||||
|
||||
|
||||
def parse_flags_line(flagsline):
|
||||
def _parse_flags_line(flagsline):
|
||||
# ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
|
||||
flagsline = flagsline.split(';')
|
||||
flags = flagsline.pop(0)
|
||||
@@ -482,7 +376,32 @@ def parse_flags_line(flagsline):
|
||||
'additional_num': additional_num}
|
||||
|
||||
|
||||
def parse_question(question):
|
||||
def _parse_opt_pseudosection(optline):
|
||||
# ;; OPT PSEUDOSECTION:
|
||||
# ; EDNS: version: 0, flags:; udp: 4096
|
||||
# ; COOKIE: 1cbc06703eaef210
|
||||
if optline.startswith('; EDNS:'):
|
||||
optline_list = optline.replace(',', ' ').split(';')
|
||||
optline_first = optline_list[1]
|
||||
optline_rest = optline_list[2]
|
||||
_, _, ver, _, *flags = optline_first.split()
|
||||
udp = optline_rest.split()[-1]
|
||||
|
||||
return {
|
||||
'edns': {
|
||||
'version': ver,
|
||||
'flags': flags,
|
||||
'udp': udp
|
||||
}
|
||||
}
|
||||
|
||||
elif optline.startswith('; COOKIE:'):
|
||||
return {
|
||||
'cookie': optline.split()[2]
|
||||
}
|
||||
|
||||
|
||||
def _parse_question(question):
|
||||
# ;www.cnn.com. IN A
|
||||
question = question.split()
|
||||
dns_name = question[0].lstrip(';')
|
||||
@@ -494,31 +413,19 @@ def parse_question(question):
|
||||
'type': dns_type}
|
||||
|
||||
|
||||
def parse_authority(authority):
|
||||
# cnn.com. 3600 IN NS ns-1086.awsdns-07.org.
|
||||
authority = authority.split()
|
||||
authority_name = authority[0]
|
||||
authority_class = authority[2]
|
||||
authority_type = authority[3]
|
||||
authority_ttl = authority[1]
|
||||
authority_data = authority[4]
|
||||
|
||||
return {'name': authority_name,
|
||||
'class': authority_class,
|
||||
'type': authority_type,
|
||||
'ttl': authority_ttl,
|
||||
'data': authority_data}
|
||||
|
||||
|
||||
def parse_answer(answer):
|
||||
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,
|
||||
@@ -526,7 +433,7 @@ def parse_answer(answer):
|
||||
'data': answer_data}
|
||||
|
||||
|
||||
def parse_axfr(axfr):
|
||||
def _parse_axfr(axfr):
|
||||
# ; <<>> DiG 9.11.14-3-Debian <<>> @81.4.108.41 axfr zonetransfer.me +nocookie
|
||||
# ; (1 server found)
|
||||
# ;; global options: +cmd
|
||||
@@ -545,6 +452,28 @@ def parse_axfr(axfr):
|
||||
'data': axfr_data}
|
||||
|
||||
|
||||
def _parse_footer(footer):
|
||||
# footer consists of 4 lines
|
||||
# footer line 1
|
||||
if footer.startswith(';; Query time:'):
|
||||
return {'query_time': footer.split(':')[1].lstrip()}
|
||||
|
||||
# footer line 2
|
||||
if footer.startswith(';; SERVER:'):
|
||||
return {'server': footer.split(':', maxsplit=1)[1].lstrip()}
|
||||
|
||||
# footer line 3
|
||||
if footer.startswith(';; WHEN:'):
|
||||
return {'when': footer.split(':', maxsplit=1)[1].lstrip()}
|
||||
|
||||
# footer line 4 (last line)
|
||||
if footer.startswith(';; MSG SIZE rcvd:'):
|
||||
return {'rcvd': footer.split(':')[1].lstrip()}
|
||||
|
||||
elif footer.startswith(';; XFR size:'):
|
||||
return {'size': footer.split(':')[1].lstrip()}
|
||||
|
||||
|
||||
def parse(data, raw=False, quiet=False):
|
||||
"""
|
||||
Main text parsing function
|
||||
@@ -557,7 +486,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:
|
||||
@@ -568,110 +497,110 @@ def parse(data, raw=False, quiet=False):
|
||||
# remove blank lines
|
||||
cleandata = list(filter(None, cleandata))
|
||||
|
||||
question = False
|
||||
authority = False
|
||||
answer = False
|
||||
axfr = False
|
||||
|
||||
# section can be: header, flags, question, authority, answer, axfr, additional, opt_pseudosection, footer
|
||||
section = ''
|
||||
output_entry = {}
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
for line in cleandata:
|
||||
|
||||
# identify sections
|
||||
if line.startswith(';; Got answer:'):
|
||||
section = ''
|
||||
continue
|
||||
|
||||
if line.startswith('; <<>> ') and ' axfr ' in line.lower():
|
||||
question = False
|
||||
authority = False
|
||||
answer = False
|
||||
axfr = True
|
||||
section = 'axfr'
|
||||
axfr_list = []
|
||||
continue
|
||||
|
||||
if ';' not in line and axfr:
|
||||
axfr_list.append(parse_axfr(line))
|
||||
output_entry.update({'axfr': axfr_list})
|
||||
continue
|
||||
|
||||
if line.startswith(';; ->>HEADER<<-'):
|
||||
section = 'header'
|
||||
if output_entry:
|
||||
raw_output.append(output_entry)
|
||||
output_entry = {}
|
||||
output_entry.update(parse_header(line))
|
||||
output_entry.update(_parse_header(line))
|
||||
continue
|
||||
|
||||
if line.startswith(';; flags:'):
|
||||
output_entry.update(parse_flags_line(line))
|
||||
section = 'flags'
|
||||
output_entry.update(_parse_flags_line(line))
|
||||
continue
|
||||
|
||||
if line.startswith(';; OPT PSEUDOSECTION:'):
|
||||
section = 'opt_pseudosection'
|
||||
continue
|
||||
|
||||
if line.startswith(';; QUESTION SECTION:'):
|
||||
question = True
|
||||
authority = False
|
||||
answer = False
|
||||
axfr = False
|
||||
continue
|
||||
|
||||
if question:
|
||||
output_entry['question'] = parse_question(line)
|
||||
question = False
|
||||
authority = False
|
||||
answer = False
|
||||
axfr = False
|
||||
section = 'question'
|
||||
continue
|
||||
|
||||
if line.startswith(';; AUTHORITY SECTION:'):
|
||||
question = False
|
||||
authority = True
|
||||
answer = False
|
||||
axfr = False
|
||||
section = 'authority'
|
||||
authority_list = []
|
||||
continue
|
||||
|
||||
if ';' not in line and authority:
|
||||
authority_list.append(parse_authority(line))
|
||||
output_entry.update({'authority': authority_list})
|
||||
continue
|
||||
|
||||
if line.startswith(';; ANSWER SECTION:'):
|
||||
question = False
|
||||
authority = False
|
||||
answer = True
|
||||
axfr = False
|
||||
section = 'answer'
|
||||
answer_list = []
|
||||
continue
|
||||
|
||||
if ';' not in line and answer:
|
||||
answer_list.append(parse_answer(line))
|
||||
if line.startswith(';; ADDITIONAL SECTION:'):
|
||||
section = 'additional'
|
||||
additional_list = []
|
||||
continue
|
||||
|
||||
if line.startswith(';; Query time:'):
|
||||
section = 'footer'
|
||||
output_entry.update(_parse_footer(line))
|
||||
continue
|
||||
|
||||
# parse sections
|
||||
|
||||
if line.startswith(';; QUERY SIZE:'):
|
||||
output_entry.update({'query_size': line.split(': ', maxsplit=1)[1]})
|
||||
continue
|
||||
|
||||
if not line.startswith(';') and section == 'axfr':
|
||||
axfr_list.append(_parse_axfr(line))
|
||||
output_entry.update({'axfr': axfr_list})
|
||||
continue
|
||||
|
||||
if section == 'opt_pseudosection':
|
||||
if 'opt_pseudosection' not in output_entry:
|
||||
output_entry['opt_pseudosection'] = {}
|
||||
output_entry['opt_pseudosection'].update(_parse_opt_pseudosection(line))
|
||||
continue
|
||||
|
||||
if section == 'question':
|
||||
output_entry['question'] = _parse_question(line)
|
||||
continue
|
||||
|
||||
if not line.startswith(';') and section == 'authority':
|
||||
authority_list.append(_parse_answer(line))
|
||||
output_entry.update({'authority': authority_list})
|
||||
continue
|
||||
|
||||
if not line.startswith(';') and section == 'answer':
|
||||
answer_list.append(_parse_answer(line))
|
||||
output_entry.update({'answer': 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()})
|
||||
if not line.startswith(';') and section == 'additional':
|
||||
additional_list.append(_parse_answer(line))
|
||||
output_entry.update({'additional': additional_list})
|
||||
continue
|
||||
|
||||
# footer line 2
|
||||
if line.startswith(';; SERVER:'):
|
||||
output_entry.update({'server': line.split(':')[1].lstrip()})
|
||||
if section == 'footer':
|
||||
output_entry.update(_parse_footer(line))
|
||||
continue
|
||||
|
||||
# footer line 3
|
||||
if line.startswith(';; WHEN:'):
|
||||
output_entry.update({'when': line.split(':', maxsplit=1)[1].lstrip()})
|
||||
continue
|
||||
|
||||
# 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)
|
||||
elif line.startswith(';; XFR size:'):
|
||||
output_entry.update({'size': line.split(':')[1].lstrip()})
|
||||
|
||||
if output_entry:
|
||||
raw_output.append(output_entry)
|
||||
if output_entry:
|
||||
raw_output.append(output_entry)
|
||||
|
||||
raw_output = list(filter(None, raw_output))
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
213
jc/parsers/dir.py
Normal file
213
jc/parsers/dir.py
Normal file
@@ -0,0 +1,213 @@
|
||||
"""jc - JSON CLI output utility `dir` command output parser
|
||||
|
||||
Options supported:
|
||||
- `/T timefield`
|
||||
- `/O sortorder`
|
||||
- `/C, /-C`
|
||||
- `/S`
|
||||
|
||||
The `epoch` calculated timestamp field is naive (i.e. based on the local time of the system the parser is run on)
|
||||
|
||||
Usage (cli):
|
||||
|
||||
C:> dir | jc --dir
|
||||
|
||||
or
|
||||
|
||||
C:> jc dir
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dir
|
||||
result = jc.parsers.dir.parse(dir_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"date": string,
|
||||
"time": string,
|
||||
"epoch": integer, # naive timestamp
|
||||
"dir": boolean,
|
||||
"size": integer,
|
||||
"filename: string,
|
||||
"parent": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
C:> dir | jc --dir -p
|
||||
[
|
||||
{
|
||||
"date": "03/24/2021",
|
||||
"time": "03:15 PM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": ".",
|
||||
"parent": "C:\\Program Files\\Internet Explorer",
|
||||
"epoch": 1616624100
|
||||
},
|
||||
{
|
||||
"date": "03/24/2021",
|
||||
"time": "03:15 PM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": "..",
|
||||
"parent": "C:\\Program Files\\Internet Explorer",
|
||||
"epoch": 1616624100
|
||||
},
|
||||
{
|
||||
"date": "12/07/2019",
|
||||
"time": "02:49 AM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": "en-US",
|
||||
"parent": "C:\\Program Files\\Internet Explorer",
|
||||
"epoch": 1575715740
|
||||
},
|
||||
{
|
||||
"date": "12/07/2019",
|
||||
"time": "02:09 AM",
|
||||
"dir": false,
|
||||
"size": 54784,
|
||||
"filename": "ExtExport.exe",
|
||||
"parent": "C:\\Program Files\\Internet Explorer",
|
||||
"epoch": 1575713340
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
C:> dir | jc --dir -p -r
|
||||
[
|
||||
{
|
||||
"date": "03/24/2021",
|
||||
"time": "03:15 PM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": ".",
|
||||
"parent": "C:\\Program Files\\Internet Explorer"
|
||||
},
|
||||
{
|
||||
"date": "03/24/2021",
|
||||
"time": "03:15 PM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": "..",
|
||||
"parent": "C:\\Program Files\\Internet Explorer"
|
||||
},
|
||||
{
|
||||
"date": "12/07/2019",
|
||||
"time": "02:49 AM",
|
||||
"dir": true,
|
||||
"size": null,
|
||||
"filename": "en-US",
|
||||
"parent": "C:\\Program Files\\Internet Explorer"
|
||||
},
|
||||
{
|
||||
"date": "12/07/2019",
|
||||
"time": "02:09 AM",
|
||||
"dir": false,
|
||||
"size": "54,784",
|
||||
"filename": "ExtExport.exe",
|
||||
"parent": "C:\\Program Files\\Internet Explorer"
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import re
|
||||
import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.2'
|
||||
description = '`dir` command parser'
|
||||
author = 'Rasheed Elsaleh'
|
||||
author_email = 'rasheed@rebelliondefense.com'
|
||||
|
||||
# compatible options: win32
|
||||
compatible = ['win32']
|
||||
magic_commands = ['dir']
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def _process(proc_data):
|
||||
"""
|
||||
Final processing to conform to the schema.
|
||||
|
||||
Parameters:
|
||||
|
||||
proc_data: (Dictionary of Lists) raw structured data to process
|
||||
|
||||
Returns:
|
||||
|
||||
List of Dictionaries. Structured data to conform to the schema.
|
||||
"""
|
||||
for entry in proc_data:
|
||||
# add timestamps
|
||||
if 'date' in entry and 'time' in entry:
|
||||
dt = entry['date'] + ' ' + entry['time']
|
||||
timestamp = jc.utils.timestamp(dt)
|
||||
entry['epoch'] = timestamp.naive
|
||||
|
||||
# add ints
|
||||
int_list = ["size"]
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
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 data.splitlines():
|
||||
if line.startswith(" Directory of"):
|
||||
parent_dir = line.lstrip(" Directory of ")
|
||||
continue
|
||||
# skip lines that don't start with a date
|
||||
if not re.match(r'^\d{2}/\d{2}/\d{4}', line):
|
||||
continue
|
||||
|
||||
output_line = {}
|
||||
parsed_line = line.split()
|
||||
output_line["date"] = parsed_line[0]
|
||||
output_line["time"] = " ".join(parsed_line[1:3])
|
||||
output_line.setdefault("dir", False)
|
||||
output_line.setdefault("size", None)
|
||||
if parsed_line[3] == "<DIR>":
|
||||
output_line["dir"] = True
|
||||
else:
|
||||
output_line["size"] = parsed_line[3]
|
||||
|
||||
output_line["filename"] = " ".join(parsed_line[4:])
|
||||
output_line["parent"] = parent_dir
|
||||
|
||||
raw_output.append(output_line)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return _process(raw_output)
|
||||
@@ -1,12 +1,34 @@
|
||||
"""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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux'
|
||||
$ jc dmidecode
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dmidecode
|
||||
result = jc.parsers.dmidecode.parse(dmidecode_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"handle": string,
|
||||
"type": integer,
|
||||
"bytes": integer,
|
||||
"description": string,
|
||||
"values": { (null if empty)
|
||||
"lowercase_no_spaces_keys": string,
|
||||
"multiline_key_values": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -102,8 +124,9 @@ import jc.utils
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.1'
|
||||
description = 'dmidecode command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.3'
|
||||
description = '`dmidecode` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
@@ -116,42 +139,23 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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:
|
||||
|
||||
[
|
||||
{
|
||||
"handle": string,
|
||||
"type": integer,
|
||||
"bytes": integer,
|
||||
"description": string,
|
||||
"values": { (null if empty)
|
||||
"lowercase_no_spaces_keys": string,
|
||||
"multiline_key_values": [
|
||||
string,
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
List of Dictionaries. Structured data to conform to the schema.
|
||||
"""
|
||||
for entry in proc_data:
|
||||
int_list = ['type', 'bytes']
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
key_int = int(entry[key])
|
||||
entry[key] = key_int
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
if not entry['values']:
|
||||
entry['values'] = None
|
||||
@@ -171,7 +175,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)
|
||||
@@ -338,4 +342,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
247
jc/parsers/dpkg_l.py
Normal file
247
jc/parsers/dpkg_l.py
Normal file
@@ -0,0 +1,247 @@
|
||||
"""jc - JSON CLI output utility `dpkg -l` command output parser
|
||||
|
||||
Set the `COLUMNS` environment variable to a large value to avoid field truncation. For example:
|
||||
|
||||
$ COLUMNS=500 dpkg -l | jc --dpkg-l
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ dpkg -l | jc --dpkg-l
|
||||
|
||||
or
|
||||
|
||||
$ jc dpkg -l
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.dpkg_l
|
||||
result = jc.parsers.dpkg_l.parse(dpkg_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"codes": string,
|
||||
"name": string,
|
||||
"version": string,
|
||||
"architecture": string,
|
||||
"description": string,
|
||||
"desired": string,
|
||||
"status": string,
|
||||
"error": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
$ dpkg -l | jc --dpkg-l -p
|
||||
[
|
||||
{
|
||||
"codes": "ii",
|
||||
"name": "accountsservice",
|
||||
"version": "0.6.45-1ubuntu1.3",
|
||||
"architecture": "amd64",
|
||||
"description": "query and manipulate user account information",
|
||||
"desired": "install",
|
||||
"status": "installed"
|
||||
},
|
||||
{
|
||||
"codes": "rc",
|
||||
"name": "acl",
|
||||
"version": "2.2.52-3build1",
|
||||
"architecture": "amd64",
|
||||
"description": "Access control list utilities",
|
||||
"desired": "remove",
|
||||
"status": "config-files"
|
||||
},
|
||||
{
|
||||
"codes": "uWR",
|
||||
"name": "acpi",
|
||||
"version": "1.7-1.1",
|
||||
"architecture": "amd64",
|
||||
"description": "displays information on ACPI devices",
|
||||
"desired": "unknown",
|
||||
"status": "trigger await",
|
||||
"error": "reinstall required"
|
||||
},
|
||||
{
|
||||
"codes": "rh",
|
||||
"name": "acpid",
|
||||
"version": "1:2.0.28-1ubuntu1",
|
||||
"architecture": "amd64",
|
||||
"description": "Advanced Configuration and Power Interface event daemon",
|
||||
"desired": "remove",
|
||||
"status": "half installed"
|
||||
},
|
||||
{
|
||||
"codes": "pn",
|
||||
"name": "adduser",
|
||||
"version": "3.116ubuntu1",
|
||||
"architecture": "all",
|
||||
"description": "add and remove users and groups",
|
||||
"desired": "purge",
|
||||
"status": "not installed"
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
$ dpkg -l | jc --dpkg-l -p -r
|
||||
[
|
||||
{
|
||||
"codes": "ii",
|
||||
"name": "accountsservice",
|
||||
"version": "0.6.45-1ubuntu1.3",
|
||||
"architecture": "amd64",
|
||||
"description": "query and manipulate user account information"
|
||||
},
|
||||
{
|
||||
"codes": "rc",
|
||||
"name": "acl",
|
||||
"version": "2.2.52-3build1",
|
||||
"architecture": "amd64",
|
||||
"description": "Access control list utilities"
|
||||
},
|
||||
{
|
||||
"codes": "uWR",
|
||||
"name": "acpi",
|
||||
"version": "1.7-1.1",
|
||||
"architecture": "amd64",
|
||||
"description": "displays information on ACPI devices"
|
||||
},
|
||||
{
|
||||
"codes": "rh",
|
||||
"name": "acpid",
|
||||
"version": "1:2.0.28-1ubuntu1",
|
||||
"architecture": "amd64",
|
||||
"description": "Advanced Configuration and Power Interface event daemon"
|
||||
},
|
||||
{
|
||||
"codes": "pn",
|
||||
"name": "adduser",
|
||||
"version": "3.116ubuntu1",
|
||||
"architecture": "all",
|
||||
"description": "add and remove users and groups"
|
||||
},
|
||||
...
|
||||
]
|
||||
"""
|
||||
import jc.utils
|
||||
import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.1'
|
||||
description = '`dpkg -l` 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 = ['dpkg -l']
|
||||
|
||||
|
||||
__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 to conform to the schema:
|
||||
"""
|
||||
for entry in proc_data:
|
||||
if 'codes' in entry:
|
||||
desired, status, *err = list(entry['codes'])
|
||||
|
||||
desired_map = {
|
||||
'u': 'unknown',
|
||||
'i': 'install',
|
||||
'r': 'remove',
|
||||
'p': 'purge',
|
||||
'h': 'hold'
|
||||
}
|
||||
|
||||
for key, value in desired_map.items():
|
||||
if desired.lower() == key:
|
||||
entry['desired'] = value
|
||||
break
|
||||
|
||||
status_map = {
|
||||
'n': 'not installed',
|
||||
'i': 'installed',
|
||||
'c': 'config-files',
|
||||
'u': 'unpacked',
|
||||
'f': 'failed config',
|
||||
'h': 'half installed',
|
||||
'w': 'trigger await',
|
||||
't': 'trigger pending'
|
||||
}
|
||||
|
||||
for key, value in status_map.items():
|
||||
if status.lower() == key:
|
||||
entry['status'] = value
|
||||
break
|
||||
|
||||
if err:
|
||||
err_map = {
|
||||
'r': 'reinstall required'
|
||||
}
|
||||
|
||||
for key, value in err_map.items():
|
||||
if err[0].lower() == key:
|
||||
entry['error'] = value
|
||||
break
|
||||
|
||||
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)
|
||||
|
||||
working_list = []
|
||||
raw_output = []
|
||||
header_found = False
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
# clean up headers
|
||||
for line in filter(None, data.splitlines()):
|
||||
if 'Architecture' in line:
|
||||
header_found = True
|
||||
working_list.append(line.lower().replace('||/', 'codes'))
|
||||
continue
|
||||
|
||||
if '=========' in line:
|
||||
continue
|
||||
|
||||
if header_found:
|
||||
working_list.append(line)
|
||||
|
||||
raw_output = jc.parsers.universal.simple_table_parse(working_list)
|
||||
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return _process(raw_output)
|
||||
@@ -1,12 +1,26 @@
|
||||
"""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
|
||||
|
||||
Compatibility:
|
||||
or
|
||||
|
||||
'linux', 'darwin', 'aix', 'freebsd'
|
||||
$ jc du
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc.parsers.du
|
||||
result = jc.parsers.du.parse(du_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
[
|
||||
{
|
||||
"size": integer,
|
||||
"name": string
|
||||
}
|
||||
]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -73,8 +87,9 @@ import jc.parsers.universal
|
||||
|
||||
|
||||
class info():
|
||||
version = '1.2'
|
||||
description = 'du command parser'
|
||||
"""Provides parser metadata (version, author, etc.)"""
|
||||
version = '1.4'
|
||||
description = '`du` command parser'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
# details = 'enter any other details here'
|
||||
@@ -87,34 +102,23 @@ class info():
|
||||
__version__ = info.version
|
||||
|
||||
|
||||
def process(proc_data):
|
||||
def _process(proc_data):
|
||||
"""
|
||||
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:
|
||||
|
||||
[
|
||||
{
|
||||
"size": integer,
|
||||
"name": string
|
||||
}
|
||||
]
|
||||
List of Dictionaries. Structured data to conform to the schema.
|
||||
"""
|
||||
int_list = ['size']
|
||||
for entry in proc_data:
|
||||
for key in int_list:
|
||||
if key in entry:
|
||||
try:
|
||||
key_int = int(entry[key])
|
||||
entry[key] = key_int
|
||||
except (ValueError):
|
||||
entry[key] = None
|
||||
for key in entry:
|
||||
if key in int_list:
|
||||
entry[key] = jc.utils.convert_to_int(entry[key])
|
||||
|
||||
return proc_data
|
||||
|
||||
@@ -131,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)
|
||||
@@ -149,4 +153,4 @@ def parse(data, raw=False, quiet=False):
|
||||
if raw:
|
||||
return raw_output
|
||||
else:
|
||||
return process(raw_output)
|
||||
return _process(raw_output)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user