service

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID        string            `json:"id"`         // Unique alert identifier
	Source    string            `json:"source"`     // Source of the alert
	Summary   string            `json:"summary"`    // Brief description of the alert
	Labels    map[string]string `json:"labels"`     // Labels of the alert
	CreatedAt time.Time         `json:"created_at"` // Time when the alert was created
}

Alert represents the data structure for an alert.

type AlertParser

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

AlertParser handles the parsing and aggregation of alerts.

func NewAlertParser

func NewAlertParser(cfg *AlertParserConfig) *AlertParser

NewAlertParser initializes a new AlertParser instance.

func (*AlertParser) Run

func (ap *AlertParser) Run(ctx context.Context, dataCh <-chan CollectorData, alertsCh chan<- []Alert)

Run starts the process of parsing and aggregating alerts.

type AlertParserConfig

type AlertParserConfig struct {
	AggregationInterval         time.Duration `validate:"required,min=5s"`                    // Interval for aggregating alerts (min 5s).
	GrafanaAMParseField         string        `validate:"required,oneof=summary description"` // Field to parse from Grafana Alertmanager alerts ("summary" or "description").
	GrafanaPrometheusParseField string        `validate:"required,oneof=summary description"` // Field to parse from Grafana Prometheus alerts ("summary" or "description").
}

AlertParserConfig defines the configuration for parsing alerts from different sources.

func (*AlertParserConfig) Validate

func (apc *AlertParserConfig) Validate() error

Validate checks if the AlertParserConfig struct is valid according to the rules defined in struct tags. It ensures that all required fields are present and that the values for certain fields conform to the specified constraints (e.g., minimum aggregation interval, allowed Grafana field values).

type Collector

type Collector interface {
	// Run is a method that implementations of Collector should define.
	// It should asynchronously collect data and send it to the provided channel.
	// The method accepts a context for handling cancellations and timeouts,
	// and a channel for sending collected data.
	//
	// ctx: a context.Context used for cancellation signals and deadlines.
	// dataCh: a channel for sending collected data, where each data item is
	// a CollectorData struct containing the collector type and associated JSON data.
	Run(ctx context.Context, dataCh chan<- CollectorData)
}

Collector represents an interface for data collectors.

type CollectorData

type CollectorData struct {
	Type     CollectorType
	JsonData []byte
}

CollectorData holds the data collected from different collectors. It includes the type of collector (e.g., Grafana, Zabbix) and the associated JSON data.

type CollectorType

type CollectorType string

CollectorType is a custom type defined as a string. It's used to represent the type of collector.

const (
	// GrafanaAMCollector represents a Grafana Alert Manager collector.
	GrafanaAMCollector CollectorType = "grafana_alertmanager"
	// GrafanaPrometheusCollector represents a Grafana Prometheus collector.
	GrafanaPrometheusCollector CollectorType = "grafana_prometheus"
	// ZabbixCollector represents a Zabbix collector.
	ZabbixCollector CollectorType = "zabbix"
)

Below are constants of type CollectorType, each representing a different type of collector.

type GrafanaParseField

type GrafanaParseField string

GrafanaParseField represents a specific field in Grafana alerts, such as summary or description.

const (
	GrafanaSummaryField     GrafanaParseField = "summary"
	GrafanaDescriptionField GrafanaParseField = "description"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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