sensu-plugins-slack icon indicating copy to clipboard operation
sensu-plugins-slack copied to clipboard

Omit field if missing from event

Open warmfusion opened this issue 7 years ago • 3 comments

  • Given fields are configured
  • When an event is submitted which does not include an entry for that field
  • Then the slack message sent should not include the field element

Scenario

Using fields for tips or url links in alert configurations. Sometimes our alerts include them, sometimes they dont. In all cases currently the message includes blank sections which isn't very attractive.

There may be an argument for showing the field name and not including a value at all to demonstrate that the user hasn't included this information, but that seems to be implict based on its absence on a message?

warmfusion avatar Jan 22 '18 10:01 warmfusion

I definitely see the value although I think there should be an option for it but the default should be off.

Reasons why it should default off:

  • remaining backwards compatible
  • I think that is an excellent way to prompt people to start writing those tips/links/runbooks when they resolve the incident they should think about adding it.

majormoses avatar Jan 26 '18 06:01 majormoses

So would you be thinking of an ignore_field_if_missing: true flag?

Or perhaps a more structural change to fields themselves, eg

fields:
 {
      "list": nil,
      "clientkeys": "A default value",
      "to_render": 123
}

Such that the assigned value is used as a default, and if set to nil is simply omitted from display if no client value has set it.

Note; I have an extended use case/pull request to develop which will include event field custom values in this listing, such that events themselves can include metadata to submit on alerts

warmfusion avatar Jan 31 '18 12:01 warmfusion

How about include_missing_fields with a default of true. I generally dislike having "negative" variable/option names in code when dealing with booleans. The reason is that it is much clearer and avoids needing to eval true as false when I am quickly reviewing code/documentation I am unfamiliar with.

I suppose we could make a more structural change and have a render flag and if evals nil||true we would include it. If it evals as false we would not render.

majormoses avatar Jan 31 '18 22:01 majormoses