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

Templatize receiver details in receiver in Subscription of Notification Service #132

Open
mabdh opened this issue Sep 26, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@mabdh
Copy link
Member

mabdh commented Sep 26, 2022

Is your feature request related to a problem? Please describe.
Based on this PRD and this RFC. We plan to move responsibility of sending notification to siren from provider. There is a need to flexibly send custom notification messages to each receiver type.

Describe the solution you'd like

The Flow
Custom notification message could be implemented with a pre-defined template assigned to each receiver in the subscription flow. When subscribing a notification, one should pass this struct.

type Subscription struct {
	ID        uint64            `json:"id"`
	URN       string            `json:"urn"`
	Namespace uint64            `json:"namespace"`
	Receivers []Receiver        `json:"receivers"`
	Match     map[string]string `json:"match"`
	CreatedAt time.Time         `json:"created_at"`
	UpdatedAt time.Time         `json:"updated_at"`
}

Each receiver needs to be like this

type Receiver struct {
	ID            uint64            `json:"id"`
	Type          string            `json:"type"`
	Configuration map[string]string `json:"configuration"`
}

Depending on the receiver type, receiver configuration could have various field. A new template field could be added to define that this receiver of the subscription would use the template for the notification message.

The Template
The template could be created with the same way as user create template for the rules. Instead of having a type rule, template would have type notification. The content of the template should be compatible with the contract of receiver type payload. For example, this is how the slack notification template is.

apiVersion: v2
type: template
name: alert-slack-details
body:
  receiver_type: slack
  attachments:
    - text: '[[.text]]'
      icon_emoji: ':eagle:'
      link_names: false
      color: '[[.color]]'
      title: '[[.title]]'
      pretext: '[[.pretext]]'
      text: '[[.text]]'
      actions:
        - type: button
          text: 'Runbook :books:'
          url: '[[.runbook"]]'
        - type: button
          text: 'Dashboard :bar_chart:'
          url: '[[.dashboard"]]'
variables:
  - name: color
    type: string
    description: slack color
    default: #2eb886
  - name: text
    type: string
    default: This is an alert
  - name: title
    type: string
    default: Alert
  - name: pretext
    type: string
    description: Pre-text of slack alert
    default: Siren
  - name: runbook
    type: string
    description: url to runbook
    default: http://url
  - name: dashboard
    type: string
    description: url to dashboard
    default: http://url
tags:
  - slack

Template will be rendered when notification is being dispatched and before a notification message is generated. Therefore, notification message would contain the rendered version of the notification message. Other than that, variables are being populated based on labels that the notification has.

@mabdh mabdh added the enhancement New feature or request label Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant