consul
consul copied to clipboard
Option for json output for CLI
Feature Description
A global -out [table|json] option to modify the commands output from the current "table" to json
consul info -out json
{ "agent": {
"check_monitors": 0,
"check_ttls": 0,
"checks": 5,
...
or
consul acl token list
[
{
"AccessorID": "49f6bd35-0cc6-8acc-ee71-2ccfe8c57161",
"Description": "client service token",
"Local": "false",
"Create Time": "2019-05-27 11:28:40.321670815 +0000 UTC",
"Legacy": "false",
"Policies": {
{
"AccessorID": "c4a6823e-62b0-1740-ea4a-1eef83988669",
"Description": "client-service-policy"
}
}
},
...
]
Use Case(s)
consul CLI is very convenient for a bit of bash scripting, when one doesn't wan't to curl everything. One annoying bit is the "human readable" output, which need to be parsed to be exploitable. The good ol' | grep | awk and so on. But it's unreliable on the long term. Adding a "machine readable" output like json would allow using jq for a more sustainable result
I will take care of it.
Vault has these options
Output Options:
-field=<string>
Print only the field with the given name. Specifying this option will
take precedence over other formatting directives. The result will not
have a trailing newline making it ideal for piping to other processes.
-format=<string>
Print the output in the given format. Valid formats are "table", "json",
or "yaml". The default is table. This can also be specified via the
VAULT_FORMAT environment variable.
Really hop consul can get these, e.g. consul acl token read -id $ACCESSOR_ID -format json
Is there any progress on this feature?
#7198 added -format=json to a bunch of the acl commands. It is available in 1.8.0. The first RC for 1.8.0 was just released.
More work will need to be done to add the json format to all the other commands.
Just bumping this. It would be useful to get the info as json so that I could parse the output in systemd hooks to ensure the cluster is working as expected.