sensu / sensu-go

Simple. Scalable. Multi-cloud monitoring.
https://sensu.io
MIT License
1.02k stars 176 forks source link

Token substitution should support lists #894

Closed cwjohnston closed 4 years ago

cwjohnston commented 6 years ago

In sensu-ruby we currently do not support list (array) values in the various contexts where token substitution is supported. If token substitution is used to insert a list value, the result is a textual (string) representation of the list.

It would be nice if sensu-go could improve on this by supporting list values in a way that passes along the original list instead of a textual representation of the same.

Example:

Client definition:

{
  "client": {
    "foo": {
      "tags": [
        "bar",
        "baz"
      ]
    }
  }
}

Check definition:

{
  "checks": {
    "tag_test": {
      "command": "echo OK",
      "tags": ":::foo.tags:::",
      "interval": 10,
      "standalone": true
    }
  }
}

Check result:

{
  "client": "sensu",
  "check": {
    "command": "echo OK",
    "tags": "[\"bar\", \"baz\"]",
    "interval": 10,
    "standalone": true,
    "name": "tag_test",
    "issued": 1516147101,
    "executed": 1516147101,
    "duration": 0.003,
    "output": "OK\n",
    "status": 0,
    "type": "standard"
  }
}

Ideally the check result would look more like

Check result:

{
  "client": "sensu",
  "check": {
    "command": "echo OK",
    "tags": ["bar", "baz"],
    ...
  }
}
rgeniesse commented 5 years ago

I am going to mention the newly opened #2729 here as well, as in Sensu 1.x we would get questions regarding token substitution fully supporting integers and lists frequently.

echlebek commented 4 years ago

Given that we don't have a way of encoding lists for tokens, I don't know if this feature is still valid.

Can we close this?

calebhailey commented 4 years ago

I think we can close this for now.We're pretty committed to keeping the data model as simple as possible (labels and annotations are always strings). Perhaps we can offer some utilities for dealing with string escaped JSON in the plugin SDK instead? Feel free to open an issue there as needed: https://github.com/sensu-community/sensu-plugin-sdk/issues

Thanks!