alerting

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: AGPL-3.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotifyByEmailTask    = taskq.NewTask("notify-by-email")
	NotifyBySlackTask    = taskq.NewTask("notify-by-slack")
	NotifyByWebhookTask  = taskq.NewTask("notify-by-webhook")
	NotifyByTelegramTask = taskq.NewTask("notify-by-telegram")
)

Functions

func DecodeAlertFilter

func DecodeAlertFilter(req bunrouter.Request, f *AlertFilter) error

func Init

func Init(ctx context.Context, app *bunapp.App)

func InsertNotifChannel

func InsertNotifChannel(ctx context.Context, app *bunapp.App, channel NotifChannel) error

func NewAlertmanagerMessage

func NewAlertmanagerMessage(
	app *bunapp.App, project *org.Project, alert org.Alert,
) (models.PostableAlerts, error)

func SelectAlert

func SelectAlert(ctx context.Context, app *bunapp.App, id uint64) (org.Alert, error)

func SelectBaseAlert

func SelectBaseAlert(ctx context.Context, app *bunapp.App, alertID uint64) (*org.BaseAlert, error)

func UpdateNotifChannel

func UpdateNotifChannel(ctx context.Context, app *bunapp.App, channel NotifChannel) error

func UpdateNotifChannelState

func UpdateNotifChannelState(
	ctx context.Context, app *bunapp.App, channel *BaseNotifChannel, state NotifChannelState,
) error

Types

type AlertFilter

type AlertFilter struct {
	ProjectID uint32 `urlstruct:"-"`

	org.FacetFilter
	org.OrderByMixin

	Status []string
	Type   []string

	MonitorID uint64
}

func (*AlertFilter) Clone

func (f *AlertFilter) Clone() *AlertFilter

func (*AlertFilter) PGOrder

func (f *AlertFilter) PGOrder(q *bun.SelectQuery) *bun.SelectQuery

func (*AlertFilter) UnmarshalValues

func (f *AlertFilter) UnmarshalValues(ctx context.Context, values url.Values) error

func (*AlertFilter) WhereClause

func (f *AlertFilter) WhereClause(q *bun.SelectQuery) *bun.SelectQuery

type AlertFormatter

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

func NewAlertFormatter

func NewAlertFormatter(breakLine string, opts ...AlertFormatterOption) *AlertFormatter

func (*AlertFormatter) Format

func (f *AlertFormatter) Format(project *org.Project, alert org.Alert) string

type AlertFormatterOption

type AlertFormatterOption func(*AlertFormatter)

func WithClosedByTemplate

func WithClosedByTemplate(tpl ...string) AlertFormatterOption

func WithClosedTemplate

func WithClosedTemplate(tpl ...string) AlertFormatterOption

func WithCreatedTemplate

func WithCreatedTemplate(tpl ...string) AlertFormatterOption

func WithRecurringTemplate

func WithRecurringTemplate(tpl ...string) AlertFormatterOption

func WithReopenedByTemplate

func WithReopenedByTemplate(tpl ...string) AlertFormatterOption

func WithReopenedTemplate

func WithReopenedTemplate(tpl ...string) AlertFormatterOption

type AlertHandler

type AlertHandler struct {
	*bunapp.App
}

func NewAlertHandler

func NewAlertHandler(app *bunapp.App) *AlertHandler

func (*AlertHandler) Close

func (*AlertHandler) Delete

func (*AlertHandler) List

func (*AlertHandler) Open

func (*AlertHandler) Show

type BaseNotifChannel

type BaseNotifChannel struct {
	bun.BaseModel `bun:"notif_channels,alias:c"`

	ID        uint64 `json:"id" bun:",pk,autoincrement"`
	ProjectID uint32 `json:"projectId"`

	Name  string            `json:"name" bun:",nullzero"`
	Type  NotifChannelType  `json:"type"`
	State NotifChannelState `json:"state" bun:",nullzero"`

	ParamsData []byte         `json:"-" bun:"params,nullzero,type:jsonb"`
	ParamsMap  map[string]any `json:"params" bun:"-"`
}

func (*BaseNotifChannel) AfterScanRow

func (c *BaseNotifChannel) AfterScanRow(ctx context.Context) error

func (*BaseNotifChannel) Base

type EmailNotifier

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

func NewEmailNotifier

func NewEmailNotifier(app *bunapp.App) *EmailNotifier

func (*EmailNotifier) NotifyHandler

func (n *EmailNotifier) NotifyHandler(
	ctx context.Context, eventID uint64, recipients []string,
) error

type ErrorAlert

type ErrorAlert struct {
	org.BaseAlert `bun:",inherit"`

	Event *ErrorAlertEvent `json:"-" bun:"rel:belongs-to,join:event_id=id"`
}

func NewErrorAlert

func NewErrorAlert() *ErrorAlert

func (*ErrorAlert) Base

func (a *ErrorAlert) Base() *org.BaseAlert

func (*ErrorAlert) GetEvent added in v1.7.0

func (a *ErrorAlert) GetEvent() org.AlertEvent

func (*ErrorAlert) SetEvent added in v1.7.0

func (a *ErrorAlert) SetEvent(event org.AlertEvent)

type ErrorAlertEvent added in v1.7.0

type ErrorAlertEvent struct {
	org.BaseAlertEvent `bun:",inherit"`

	Params org.ErrorAlertParams `json:"params" bun:"type:jsonb,nullzero"`
}

func (*ErrorAlertEvent) Base added in v1.7.0

func (e *ErrorAlertEvent) Base() *org.BaseAlertEvent

func (*ErrorAlertEvent) Clone added in v1.7.0

func (e *ErrorAlertEvent) Clone() org.AlertEvent

type ErrorMonitorIn

type ErrorMonitorIn struct {
	Name string `json:"name"`

	NotifyEveryoneByEmail bool                   `json:"notifyEveryoneByEmail"`
	Params                org.ErrorMonitorParams `json:"params"`

	ChannelIDs []uint64 `json:"channelIds"`
}

func (*ErrorMonitorIn) Validate

func (in *ErrorMonitorIn) Validate(
	ctx context.Context, app *bunapp.App, monitor *org.ErrorMonitor,
) error

type Manager

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

func NewManager

func NewManager(app *bunapp.App, conf *ManagerConfig) *Manager

func (*Manager) Run

func (m *Manager) Run()

func (*Manager) Stop

func (m *Manager) Stop()

type ManagerConfig

type ManagerConfig struct {
	Monitors []*org.MetricMonitor
	Logger   *zap.Logger
}

type MetricAlert

type MetricAlert struct {
	org.BaseAlert `bun:",inherit"`

	Event *MetricAlertEvent `json:"-" bun:"rel:belongs-to,join:event_id=id"`
}

func NewMetricAlert

func NewMetricAlert() *MetricAlert

func (*MetricAlert) Base

func (a *MetricAlert) Base() *org.BaseAlert

func (*MetricAlert) GetEvent added in v1.7.0

func (a *MetricAlert) GetEvent() org.AlertEvent

func (*MetricAlert) LongSummary

func (a *MetricAlert) LongSummary(sep string) string

func (*MetricAlert) SetEvent added in v1.7.0

func (a *MetricAlert) SetEvent(event org.AlertEvent)

func (*MetricAlert) ShortSummary

func (a *MetricAlert) ShortSummary() string

type MetricAlertEvent added in v1.7.0

type MetricAlertEvent struct {
	org.BaseAlertEvent `bun:",inherit"`

	Params MetricAlertParams `json:"params" bun:"type:jsonb,nullzero"`
}

func (*MetricAlertEvent) Base added in v1.7.0

func (e *MetricAlertEvent) Base() *org.BaseAlertEvent

func (*MetricAlertEvent) Clone added in v1.7.0

func (e *MetricAlertEvent) Clone() org.AlertEvent

type MetricAlertParams

type MetricAlertParams struct {
	Firing       int     `json:"firing"`
	InitialValue float64 `json:"initialValue"`
	CurrentValue float64 `json:"currentValue"`
	NormalValue  float64 `json:"normalValue"`

	NumPointFiring int    `json:"numPointFiring"`
	WhereQuery     string `json:"whereQuery"`

	Bounds madalarm.Bounds `json:"bounds"`

	Monitor struct {
		Metrics          []mql.MetricAlias `json:"metrics"`
		Query            string            `json:"query"`
		Column           string            `json:"column"`
		ColumnUnit       string            `json:"columnUnit"`
		GroupingInterval unixtime.Millis   `json:"groupingInterval"`
	} `json:"monitor"`
}

func (*MetricAlertParams) Update

func (params *MetricAlertParams) Update(
	monitor *org.MetricMonitor, checkRes *madalarm.CheckResult,
)

func (*MetricAlertParams) UpdateCheckResult added in v1.7.0

func (params *MetricAlertParams) UpdateCheckResult(checkRes *madalarm.CheckResult)

func (*MetricAlertParams) UpdateMonitor added in v1.7.0

func (params *MetricAlertParams) UpdateMonitor(monitor *org.MetricMonitor)

type MetricMonitorIn

type MetricMonitorIn struct {
	Name string `json:"name"`

	NotifyEveryoneByEmail bool                    `json:"notifyEveryoneByEmail"`
	Params                org.MetricMonitorParams `json:"params"`

	ChannelIDs []uint64 `json:"channelIds"`
}

func (*MetricMonitorIn) Validate

func (in *MetricMonitorIn) Validate(
	ctx context.Context, app *bunapp.App, monitor *org.MetricMonitor,
) error

type Middleware

type Middleware struct {
	App *bunapp.App
	*org.Middleware
}

func NewMiddleware

func NewMiddleware(app *bunapp.App) Middleware

func (*Middleware) Monitor

func (*Middleware) NotifChannel

func (m *Middleware) NotifChannel(next bunrouter.HandlerFunc) bunrouter.HandlerFunc

type MonitorFilter

type MonitorFilter struct {
	*bunapp.App
	urlstruct.Pager
	org.OrderByMixin

	Q string

	ProjectID uint32
	MonitorID uint64
	State     string
}

func (*MonitorFilter) PGOrder added in v1.7.0

func (f *MonitorFilter) PGOrder(q *bun.SelectQuery) *bun.SelectQuery

func (*MonitorFilter) UnmarshalValues

func (f *MonitorFilter) UnmarshalValues(ctx context.Context, values url.Values) (err error)

type MonitorHandler

type MonitorHandler struct {
	*bunapp.App
}

func NewMonitorHandler

func NewMonitorHandler(app *bunapp.App) *MonitorHandler

func (*MonitorHandler) Activate

func (*MonitorHandler) CreateErrorMonitor

func (h *MonitorHandler) CreateErrorMonitor(w http.ResponseWriter, req bunrouter.Request) error

func (*MonitorHandler) CreateMetricMonitor

func (h *MonitorHandler) CreateMetricMonitor(w http.ResponseWriter, req bunrouter.Request) error

func (*MonitorHandler) CreateMonitorFromYAML added in v1.6.2

func (h *MonitorHandler) CreateMonitorFromYAML(
	w http.ResponseWriter, req bunrouter.Request,
) error

func (*MonitorHandler) Delete

func (*MonitorHandler) List

func (*MonitorHandler) Pause

func (*MonitorHandler) Show

func (*MonitorHandler) ShowYAML added in v1.6.2

func (*MonitorHandler) UpdateErrorMonitor

func (h *MonitorHandler) UpdateErrorMonitor(w http.ResponseWriter, req bunrouter.Request) error

func (*MonitorHandler) UpdateMetricMonitor

func (h *MonitorHandler) UpdateMetricMonitor(w http.ResponseWriter, req bunrouter.Request) error

type MonitorOut

type MonitorOut struct {
	org.BaseMonitor  `bun:",extend"`
	AlertOpenCount   int `json:"alertOpenCount" bun:",scanonly"`
	AlertClosedCount int `json:"alertClosedCount" bun:",scanonly"`
}

type NotifChannel

type NotifChannel interface {
	Base() *BaseNotifChannel
}

func NotifChannelFromContext

func NotifChannelFromContext(ctx context.Context) NotifChannel

func SelectNotifChannel

func SelectNotifChannel(
	ctx context.Context, app *bunapp.App, channelID uint64,
) (NotifChannel, error)

type NotifChannelHandler

type NotifChannelHandler struct {
	*bunapp.App
	// contains filtered or unexported fields
}

func NewNotifChannelHandler

func NewNotifChannelHandler(app *bunapp.App) *NotifChannelHandler

func (*NotifChannelHandler) Delete

func (*NotifChannelHandler) EmailShow

func (*NotifChannelHandler) EmailUpdate

func (*NotifChannelHandler) List

func (*NotifChannelHandler) Pause

func (*NotifChannelHandler) SlackCreate

func (*NotifChannelHandler) SlackShow

func (*NotifChannelHandler) SlackUpdate

func (*NotifChannelHandler) TelegramCreate

func (h *NotifChannelHandler) TelegramCreate(w http.ResponseWriter, req bunrouter.Request) error

func (*NotifChannelHandler) TelegramShow

func (*NotifChannelHandler) TelegramUpdate

func (h *NotifChannelHandler) TelegramUpdate(w http.ResponseWriter, req bunrouter.Request) error

func (*NotifChannelHandler) Unpause

func (*NotifChannelHandler) UpdateNotifChannelState

func (h *NotifChannelHandler) UpdateNotifChannelState(
	w http.ResponseWriter, req bunrouter.Request, state NotifChannelState,
) error

func (*NotifChannelHandler) WebhookCreate

func (h *NotifChannelHandler) WebhookCreate(w http.ResponseWriter, req bunrouter.Request) error

func (*NotifChannelHandler) WebhookShow

func (*NotifChannelHandler) WebhookUpdate

func (h *NotifChannelHandler) WebhookUpdate(w http.ResponseWriter, req bunrouter.Request) error

type NotifChannelState

type NotifChannelState string
const (
	NotifChannelDraft      NotifChannelState = "draft"
	NotifChannelDelivering NotifChannelState = "delivering"
	NotifChannelPaused     NotifChannelState = "paused"
	NotifChannelDisabled   NotifChannelState = "disabled"
)

type NotifChannelType

type NotifChannelType string
const (
	NotifChannelSlack        NotifChannelType = "slack"
	NotifChannelWebhook      NotifChannelType = "webhook"
	NotifChannelAlertmanager NotifChannelType = "alertmanager"
	NotifChannelTelegram     NotifChannelType = "telegram"
)

type SlackNotifChannel

type SlackNotifChannel struct {
	*BaseNotifChannel `bun:",inherit"`

	Params SlackParams `json:"params"`
}

func SelectSlackNotifChannel

func SelectSlackNotifChannel(
	ctx context.Context, app *bunapp.App, channelID uint64,
) (*SlackNotifChannel, error)

func SlackNotifChannelFromContext

func SlackNotifChannelFromContext(ctx context.Context) (*SlackNotifChannel, error)

func (*SlackNotifChannel) Base

type SlackNotifChannelIn

type SlackNotifChannelIn struct {
	Name   string      `json:"name"`
	Params SlackParams `json:"params"`
}

func (*SlackNotifChannelIn) Validate

func (in *SlackNotifChannelIn) Validate(channel *SlackNotifChannel) error

type SlackParams

type SlackParams struct {
	WebhookURL string `json:"webhookUrl"`
}

type StateCount

type StateCount struct {
	State string `json:"state"`
	Count int    `json:"count"`
}

func SelectMonitorStatesCount

func SelectMonitorStatesCount(ctx context.Context, f *MonitorFilter) ([]StateCount, error)

type TelegramNotifChannel

type TelegramNotifChannel struct {
	*BaseNotifChannel `bun:",inherit"`

	Params TelegramParams `json:"params"`
}

func SelectTelegramNotifChannel

func SelectTelegramNotifChannel(
	ctx context.Context, app *bunapp.App, channelID uint64,
) (*TelegramNotifChannel, error)

func TelegramNotifChannelFromContext

func TelegramNotifChannelFromContext(ctx context.Context) (*TelegramNotifChannel, error)

func (*TelegramNotifChannel) Base

func (*TelegramNotifChannel) TelegramBot

func (c *TelegramNotifChannel) TelegramBot(app *bunapp.App) (*tgbotapi.BotAPI, error)

type TelegramNotifChannelIn

type TelegramNotifChannelIn struct {
	Name   string `json:"name"`
	Params struct {
		ChatID int64 `json:"chatId"`
	} `json:"params"`
}

func (*TelegramNotifChannelIn) Validate

func (in *TelegramNotifChannelIn) Validate(channel *TelegramNotifChannel) error

type TelegramParams

type TelegramParams struct {
	ChatID int64 `json:"chatId"`
}

type WebhookMessage

type WebhookMessage struct {
	ID        uint64             `json:"id,string"`
	EventName org.AlertEventName `json:"eventName"`
	Payload   any                `json:"payload"`
	CreatedAt time.Time          `json:"createdAt"`

	Alert struct {
		ID        uint64          `json:"id,string"`
		URL       string          `json:"url"`
		Name      string          `json:"name"`
		Type      org.AlertType   `json:"type"`
		Status    org.AlertStatus `json:"status"`
		CreatedAt time.Time       `json:"createdAt"`
	} `json:"alert"`
}

func NewWebhookMessage

func NewWebhookMessage(app *bunapp.App, alert org.Alert, payload any) *WebhookMessage

type WebhookNotifChannel

type WebhookNotifChannel struct {
	*BaseNotifChannel `bun:",inherit"`

	Params WebhookParams `json:"params"`
}

func SelectWebhookNotifChannel

func SelectWebhookNotifChannel(
	ctx context.Context, app *bunapp.App, channelID uint64,
) (*WebhookNotifChannel, error)

func WebhookNotifChannelFromContext

func WebhookNotifChannelFromContext(ctx context.Context) (*WebhookNotifChannel, error)

func (*WebhookNotifChannel) Base

type WebhookNotifChannelIn

type WebhookNotifChannelIn struct {
	Type   NotifChannelType `json:"type"`
	Name   string           `json:"name"`
	Params struct {
		WebhookParams
		Payload string `json:"payload"`
	} `json:"params"`
}

func (*WebhookNotifChannelIn) Validate

func (in *WebhookNotifChannelIn) Validate(channel *WebhookNotifChannel) error

type WebhookParams

type WebhookParams struct {
	URL     string `json:"url"`
	Payload any    `json:"payload"`
}

Jump to

Keyboard shortcuts

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