notifier

package
v0.0.0-...-05ee0c8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package notifier contains implementations for writing notifications to arbitrary sources based on inbound events.

Index

Constants

View Source
const (
	// NotificationColourRed is used to set a notification's colour to red.
	NotificationColourRed = NotificationColour("red")
)

Variables

View Source
var ErrDiscordAPI = errors.New("error from discord API")

ErrDiscordAPI is a general error returned when a non 200 response has been returned from the discord API.

View Source
var ErrSlackAPI = errors.New("error from slack API")

ErrSlackAPI is a general error returned when a non 200 response has been returned from the slack API.

Functions

This section is empty.

Types

type DiscordNotifier

type DiscordNotifier struct {
	// contains filtered or unexported fields
}

The DiscordNotifier type is a Notifier implementation that writes notifications to a discord channel via a webhook URL.

func NewDiscordNotifier

func NewDiscordNotifier(webhookURL string) *DiscordNotifier

NewDiscordNotifier returns a new instance of the DiscordNotifier type that will send notifications to the specified webhook.

func (*DiscordNotifier) Notify

func (dn *DiscordNotifier) Notify(ctx context.Context, opts NotifyOptions) error

Notify a discord channel based on the NotifyOptions.

type EventHandler

type EventHandler struct {
	// contains filtered or unexported fields
}

The EventHandler type is responsible for handling inbound events and producing notifications when applicable.

func NewEventHandler

func NewEventHandler(reader EventReader, notifier Notifier) *EventHandler

NewEventHandler returns a new instance of the EventHandler type that will read events from the given EventHandler information and produce notifications via the Notifier implementation where applicable. Currently, this is used to produce policy failure notifications.

func (*EventHandler) Handle

func (eh *EventHandler) Handle(ctx context.Context) error

Handle inbound events. This method blocks until an error occurs or the provided context.Context is cancelled.

type EventReader

type EventReader interface {
	Read(ctx context.Context, fn event.Handler) error
}

The EventReader interface describes types that can read events from an arbitrary event stream.

type NotificationColour

type NotificationColour string

The NotificationColour type is an enum used to pass a desired colour to Notifier implementations so they can set their provider specific colours.

type Notifier

type Notifier interface {
	Notify(ctx context.Context, opts NotifyOptions) error
}

The Notifier interface describes types that send notifications to an arbitrary receiver based on the NotifyOptions.

type NotifyOptions

type NotifyOptions struct {
	Title   string
	Message string
	Data    map[string]interface{}
	Colour  NotificationColour
}

The NotifyOptions type contains all options passed to a Notifier that can be used to construct notifications.

type SlackNotifier

type SlackNotifier struct {
	// contains filtered or unexported fields
}

The SlackNotifier type is a Notifier implementation that writes notifications to a slack channel via a webhook URL.

func NewSlackNotifier

func NewSlackNotifier(webhookURL string) *SlackNotifier

NewSlackNotifier returns a new instance of the SlackNotifier type that will send notifications to the specified webhook.

func (*SlackNotifier) Notify

func (sn *SlackNotifier) Notify(ctx context.Context, opts NotifyOptions) error

Notify a slack channel based on the NotifyOptions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL