Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add BigPanda handler options #2643

Merged
merged 8 commits into from
Nov 19, 2021

Conversation

alespour
Copy link
Contributor

@alespour alespour commented Oct 15, 2021

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated

This PR solves #2304.

  1. adds the following options to the handler (per BigPanda Alert specification):
  • host - corresponds to host alert payload parameter, ie. identifies "main object that caused the alert"
  • attribute - option to add additional attribute(s) to the alert payload

The following template data are available in host and attribute value expressions: ID, Message, Level, Time, Duration, Details, Name, TaskName, Group, Tags, Fields.

  1. tags and fields are added to the payload as additional attributes. A new handler configuration option auto-attributes has been added to control this behavior. The value can be either "tags", "fields" or both these keywords (comma-separated). For backward compatibility with previous version, default value is "tags,fields".

Example:

stream
  |from()
    .database('telegraf')
    .measurement('cpu')
    .groupBy('host')
    .where(lambda: "cpu" == 'cpu-total')
  |eval(lambda: 100.0 - "usage_idle").as('total_used')
  |window().period(10s).every(10s)
  |mean('total_used').as('total_used')
  |alert()
    .id('cpu_usage_check')
    .message('Hey {{ index .Tags "host"}} / {{ .ID }}: is high!')
    .details('https://example.com/dashboard/{{ index .Tags "host"}}')
    .info(lambda: "total_used" > 70)
    .warn(lambda: "total_used" > 80)
    .crit(lambda: "total_used" > 90)
    .bigPanda()
      .host('{{ .Tags.host }}')
      .attribute('monitor_link', 'http://example.com/monitor?node={{ .Tags.host }}')
      .attribute('x_total_used', '{{ .Fields.total_used }}')

Payload:

{
  "app_key": "8f5795cada387b9f310f41fc369c88e4",
  "check": "cpu_usage_check",
  "description": "Hey localhost / cpu_usage_check: is high!",
  "details": "https://example.com/dashboard/server-1",
  "host": "server-1",
  "monitor_link": "http://example.com/monitor?node=server-1",
  "status": "critical",
  "task": "cpu_usage_check:cpu",
  "timestamp": 1633010510,
  "x_total_used": "92.53376688320374",
}

@alespour alespour marked this pull request as ready for review October 15, 2021 12:53
@ivankudibal ivankudibal requested a review from rhajek October 18, 2021 12:39
services/bigpanda/config.go Show resolved Hide resolved
@alespour alespour force-pushed the feat/bigpanda-attributes branch from 6bdfe2f to eac8587 Compare November 1, 2021 12:28
@docmerlin
Copy link
Contributor

@alespour is this ready?

@alespour
Copy link
Contributor Author

alespour commented Nov 2, 2021

@docmerlin Yes. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants