consul icon indicating copy to clipboard operation
consul copied to clipboard

Option for json output for CLI

Open rgarrigue opened this issue 6 years ago • 5 comments

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

rgarrigue avatar May 28 '19 07:05 rgarrigue

I will take care of it.

jewertow avatar Oct 07 '19 08:10 jewertow

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

wenerme avatar Dec 16 '19 09:12 wenerme

Is there any progress on this feature?

ghost avatar Jun 16 '20 00:06 ghost

#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.

dnephin avatar Jun 16 '20 16:06 dnephin

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.

josegonzalez avatar Jul 10 '24 21:07 josegonzalez