alerts

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 1 Imported by: 0

README

Alerting

Alerting allows you to use custom alerting providers such as sentry, etc. The only thing the developers need to do is to implement the alert interface

Example usage of alerting with sentry

package main

import (
	"errors"
	"fmt"
	"github.com/flannel-dev-lab/cyclops/alerts"
	"github.com/flannel-dev-lab/cyclops/alerts/sentry"
	"net/http"
)

type Sentry struct {
	// URL for sentry
	DSN         string
	// Specifies if alert belongs to dev, stage, production environment
	Environment string
	// Trigger to see if alert is enabled or disabled
	Enabled     bool
}

func main() {
	sentryAlerts := sentry.Sentry{
		DSN: "https://sentry.io/app1",
		Environment: "dev",
		Enabled: true,
	}

	sentryAlerts.Bootstrap()
	
	var alert alerts.Alert

	alert = sentryAlerts
	alert.CaptureError(errors.New("test"), "test")
}

As Alert is an interface{}, you can implement it to use your own custom alerting

Documentation

Overview

Package alerts handles the alerting systems such as Sentry, etc

Package sentry implements the Alert interface for Sentry alerting systems

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert interface {
	// CaptureError captures error and a message and sends an alert
	CaptureError(err error, message string)
	// Bootstrap acts like a constructor to setup alerting parameters such as environment, alerting endpoint, etc.
	Bootstrap() error
}

Alert is an interface to configure alerting system. Cyclops provides sentry alerting by default and implements the following methods

type Sentry

type Sentry struct {
	// DSN is the URL for sentry
	DSN string
	// Environment specifies if alert belongs to dev, stage, production environment
	Environment string
	// Enabled is a trigger for an alert to be enabled or disabled
	Enabled bool
}

Sentry struct to hold sentry variables

func (Sentry) Bootstrap added in v1.3.0

func (sentry Sentry) Bootstrap() error

Bootstrap initializes the raven DSN by setting the environment

func (Sentry) CaptureError

func (sentry Sentry) CaptureError(err error, message string)

CaptureError implements the alert interface to capture error and send a message if alerting is enabled

Jump to

Keyboard shortcuts

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