From c6baf42e72b4f41ed511e7db943297d03a39c0d5 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 9 Jul 2020 16:18:33 -0700 Subject: [PATCH] doc updates --- docgen.sh | 1 + docs/parsers/sysctl.md | 86 ++++++++++++++++++++++++++++++++++++++++++ jc/parsers/sysctl.py | 14 +++---- 3 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 docs/parsers/sysctl.md diff --git a/docgen.sh b/docgen.sh index 4c58b0c5..f7ab0bab 100755 --- a/docgen.sh +++ b/docgen.sh @@ -44,6 +44,7 @@ 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 diff --git a/docs/parsers/sysctl.md b/docs/parsers/sysctl.md new file mode 100644 index 00000000..d7d00b15 --- /dev/null +++ b/docs/parsers/sysctl.md @@ -0,0 +1,86 @@ +# jc.parsers.sysctl +jc - JSON CLI output utility sysctl -a Parser + +Usage: + + specify --sysctl as the first argument if the piped input is coming from sysctl -a + + Note: since sysctl output is not easily parsable only a very simple key/value object + will be output. An attempt is made to covert obvious integers and floats. If no + conversion is desired, use the -r (raw) option. + +Compatibility: + + 'linux', 'darwin', 'freebsd' + +Examples: + + $ sysctl | jc --sysctl -p + { + "user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin", + "user.bc_base_max": 99, + "user.bc_dim_max": 2048, + "user.bc_scale_max": 99, + "user.bc_string_max": 1000, + "user.coll_weights_max": 2, + "user.expr_nest_max": 32 + ... + } + + $ sysctl | jc --sysctl -p -r + { + "user.cs_path": "/usr/bin:/bin:/usr/sbin:/sbin", + "user.bc_base_max": "99", + "user.bc_dim_max": "2048", + "user.bc_scale_max": "99", + "user.bc_string_max": "1000", + "user.coll_weights_max": "2", + "user.expr_nest_max": "32", + ... + } + +## info +```python +info(self, /, *args, **kwargs) +``` + +## 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, + "bar": string/integer/float, + "baz": string/integer/float + } + ] + +## parse +```python +parse(data, raw=False, quiet=False) +``` + +Main text parsing function + +Parameters: + + data: (string) text data to parse + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + +Returns: + + Dictionary. Raw or processed structured data. + diff --git a/jc/parsers/sysctl.py b/jc/parsers/sysctl.py index e71a2e65..f3b613df 100644 --- a/jc/parsers/sysctl.py +++ b/jc/parsers/sysctl.py @@ -5,12 +5,12 @@ Usage: specify --sysctl as the first argument if the piped input is coming from sysctl -a Note: since sysctl output is not easily parsable only a very simple key/value object - will be output. An attempt is made to covert obvious integers. If no conversion - is desired, use the -r (raw) option in jc. + will be output. An attempt is made to covert obvious integers and floats. If no + conversion is desired, use the -r (raw) option. Compatibility: - 'linux', 'darwin', 'aix', 'freebsd' + 'linux', 'darwin', 'freebsd' Examples: @@ -49,7 +49,7 @@ class info(): # details = 'enter any other details here' # compatible options: linux, darwin, cygwin, win32, aix, freebsd - compatible = ['linux', 'darwin', 'aix', 'freebsd'] + compatible = ['linux', 'darwin', 'freebsd'] magic_commands = ['sysctl'] @@ -70,9 +70,9 @@ def process(proc_data): [ { - "foo": string/integer, - "bar": string/integer, - "baz": string/integer + "foo": string/integer/float, + "bar": string/integer/float, + "baz": string/integer/float } ] """