alertlog

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func NewDB

func NewDB(ctx context.Context, db *sql.DB) (*DB, error)

func (*DB) FindAll

func (db *DB) FindAll(ctx context.Context, alertID int) ([]Entry, error)

func (*DB) FindLatestByType

func (db *DB) FindLatestByType(ctx context.Context, alertID int, status Type) (Entry, error)

FindLatestByType returns the latest Log Entry given alertID and status type

func (*DB) FindOne

func (db *DB) FindOne(ctx context.Context, logID int) (Entry, error)

func (*DB) Log

func (db *DB) Log(ctx context.Context, alertID int, _type Type, meta interface{}) error

func (*DB) LogEPTx

func (db *DB) LogEPTx(ctx context.Context, tx *sql.Tx, epID string, _type Type, meta *EscalationMetaData) error

func (*DB) LogManyTx

func (db *DB) LogManyTx(ctx context.Context, tx *sql.Tx, alertIDs []int, _type Type, meta interface{}) error

func (*DB) LogServiceTx

func (db *DB) LogServiceTx(ctx context.Context, tx *sql.Tx, serviceID string, _type Type, meta interface{}) error

func (*DB) LogTx

func (db *DB) LogTx(ctx context.Context, tx *sql.Tx, alertID int, _type Type, meta interface{}) error

func (*DB) MustLog

func (db *DB) MustLog(ctx context.Context, alertID int, _type Type, meta interface{})

func (*DB) MustLogTx

func (db *DB) MustLogTx(ctx context.Context, tx *sql.Tx, alertID int, _type Type, meta interface{})

func (*DB) Search

func (db *DB) Search(ctx context.Context, opts *SearchOptions) ([]Entry, int, error)

Search will return a list of matching log entries

type Entry

type Entry interface {
	// AlertID returns the ID of the alert the Entry belongs to.
	AlertID() int

	// ID returns the ID of the log entry.
	ID() int
	// Timestamp returns the time the Entry was created.
	Timestamp() time.Time

	// Type returns type type of log entry.
	Type() Type

	// Subject will return the subject, if available of the Entry.
	Subject() *Subject

	// String returns the string representation of a log Event.
	String() string

	Meta() interface{}
}

An Entry is an alert log entry.

type EscalationMetaData

type EscalationMetaData struct {
	NewStepIndex    int
	Repeat          bool
	Forced          bool
	Deleted         bool
	OldDelayMinutes int
}

type NotificationMetaData

type NotificationMetaData struct {
	UserID string
	CMType string
}

type SearchOptions

type SearchOptions struct {
	/// AlertID, if specified, will restrict alert logs to those with a matching AlertID.
	AlertID int

	// ServiceID, if specified, will restrict alert logs to those alerts which map to this particular ServiceID.
	ServiceID string

	// UserID, if specified, will restrict alert logs to those with events performed by the specified user.
	UserID string

	// IntegrationKeyID, if specified, will restrict alert logs to those with events authorized via the specified integration key.
	IntegrationKeyID string

	// Start will restrict alert logs to those which were created on or after this time.
	Start time.Time

	// End will restrict alert logs to those which were created before this time.
	End time.Time

	// Event, if specified, will restrict alert logs to those of the specified event type.
	Event Type

	// SortBy can be used to alter the primary sorting criteria. By default, results are ordered by timestamp as newest first.
	// Results will always have a secondary sort criteria of newest-events-first, unless SortByTimestamp is set and SortDesc is false.
	SortBy SortBy

	// SortDesc controls ascending or descending results of the primary sort (SortBy field).
	SortDesc bool

	// Offset indicates the starting row of the returned results.
	Offset int

	// Limit restricts the maximum number of rows returned. Default is 25. Maximum is 50.
	// Note: Limit is applied AFTER Offset is taken into account.
	Limit int
}

SearchOptions contains criteria for filtering alert logs. At a minimum, at least one of AlertID or ServiceID must be specified.

type SortBy

type SortBy int

SortBy describes the possible primary sort options for alert logs.

const (
	SortByTimestamp SortBy = iota
	SortByAlertID
	SortByEventType
	SortByUserName
)

Configurable sort columns.

type Store

type Store interface {
	FindOne(ctx context.Context, logID int) (Entry, error)
	FindAll(ctx context.Context, alertID int) ([]Entry, error)
	Log(ctx context.Context, alertID int, _type Type, meta interface{}) error
	LogTx(ctx context.Context, tx *sql.Tx, alertID int, _type Type, meta interface{}) error
	LogEPTx(ctx context.Context, tx *sql.Tx, epID string, _type Type, meta *EscalationMetaData) error
	LogServiceTx(ctx context.Context, tx *sql.Tx, serviceID string, _type Type, meta interface{}) error
	LogManyTx(ctx context.Context, tx *sql.Tx, alertIDs []int, _type Type, meta interface{}) error
	FindLatestByType(ctx context.Context, alertID int, status Type) (Entry, error)
	Search(ctx context.Context, opt *SearchOptions) ([]Entry, int, error)

	MustLog(ctx context.Context, alertID int, _type Type, meta interface{})
	MustLogTx(ctx context.Context, tx *sql.Tx, alertID int, _type Type, meta interface{})
}

type Subject

type Subject struct {
	ID         string      `json:"id"`
	Name       string      `json:"name"`
	Type       SubjectType `json:"type"`
	Classifier string      `json:"classifier"`
}

A Subject is generally the causer of an event. If a user closes an alert, the entry would have a Subject set to the user.

type SubjectType

type SubjectType string

SubjectType represents the type of subject or causer of an alert event.

const (
	SubjectTypeUser             SubjectType = "user"
	SubjectTypeIntegrationKey   SubjectType = "integration_key"
	SubjectTypeHeartbeatMonitor SubjectType = "heartbeat_monitor"
	SubjectTypeChannel          SubjectType = "channel"
	SubjectTypeNone             SubjectType = ""
)

Possible subject types

func (*SubjectType) Scan

func (s *SubjectType) Scan(value interface{}) error

Scan handles reading a Type from the DB enum

func (SubjectType) Value

func (s SubjectType) Value() (driver.Value, error)

type Type

type Type string

A Type represents a log entry type for an alert.

const (
	TypeCreated            Type = "created"
	TypeClosed             Type = "closed"
	TypeNotificationSent   Type = "notification_sent"
	TypeEscalated          Type = "escalated"
	TypeAcknowledged       Type = "acknowledged"
	TypePolicyUpdated      Type = "policy_updated"
	TypeDuplicateSupressed Type = "duplicate_suppressed"
	TypeEscalationRequest  Type = "escalation_request"
)

Types of Log Entries

func (*Type) Scan

func (ty *Type) Scan(value interface{}) error

Scan handles reading a Type from the DB enum

Jump to

Keyboard shortcuts

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