alarm

package
Version: v0.0.0-...-d841f61 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlarmCollectionName = libmongo.AlarmMongoCollection
)
View Source
const MaxRedisLockRetries = 10

Variables

This section is empty.

Functions

func UpdateToWorstState

func UpdateToWorstState(metaAlarm *types.Alarm, updateChildren []*types.Alarm,
	a Adapter, alarmConfig config.AlarmConfig) bool

UpdateToWorstState updates meta-alarm's state from its worst children, return true when meta-alarm has updated

Types

type ActivationService

type ActivationService interface {
	Process(*types.Alarm) (bool, error)
}

AlarmActivationService checks alarm and sends activation event if alarm doesn't have active snooze and pbehavior

func NewActivationService

func NewActivationService(
	encoder encoding.Encoder,
	publisher amqplib.Publisher,
	queueName string,
	logger zerolog.Logger,
) ActivationService

type Adapter

type Adapter interface {
	// Insert insert an alarm
	Insert(alarm types.Alarm) error

	// Update update an alarm
	Update(alarm types.Alarm) error

	PartialUpdateOpen(ctx context.Context, alarm *types.Alarm) error

	// RemoveAll remove all alarms
	RemoveAll() error

	// RemoveId remove an alarm from its id
	RemoveId(id string) error

	Get(filter map[string]interface{}, alarms *[]types.Alarm) error

	// GetAlarmsByID finds all alarms with an entity id.
	GetAlarmsByID(id string) ([]types.Alarm, error)

	// GetAlarmsWithCancelMark returns all alarms where v.cancel is not null
	GetAlarmsWithCancelMark() ([]types.Alarm, error)

	// GetAlarmsWithDoneMark returns all alarms where v.done is not null
	GetAlarmsWithDoneMark() ([]types.Alarm, error)

	// GetAlarmsWithSnoozeMark returns all alarms where v.snooze is not null
	GetAlarmsWithSnoozeMark() ([]types.Alarm, error)

	// GetAlarmsWithFlappingStatus returns all alarms whose status is flapping
	GetAlarmsWithFlappingStatus() ([]types.Alarm, error)

	// GetAllOpenedResourceAlarmsByComponent returns all ongoing alarms for component
	GetAllOpenedResourceAlarmsByComponent(component string) ([]types.AlarmWithEntity, error)

	// GetUnacknowledgedAlarmsByComponent returns all ongoing alarms which have
	// not been acknowledged, given a component's name.
	GetUnacknowledgedAlarmsByComponent(component string) ([]types.Alarm, error)

	// GetAlarmsWithoutTicketByComponent returns all ongoing alarms which do
	// not have a ticket, given a component's name.
	GetAlarmsWithoutTicketByComponent(component string) ([]types.Alarm, error)

	GetOpenedAlarmByAlarmId(id string) (types.Alarm, error)

	// GetOpenedAlarm find one opened alarm with his entity id.
	// Note : a control is added to prevent fetching future alarms.
	GetOpenedAlarm(connector, connectorName, id string) (types.Alarm, error)

	GetOpenedMetaAlarm(ruleId string, valuePath string) (types.Alarm, error)

	// GetLastAlarm find the last alarm with an id
	GetLastAlarm(connector, connectorName, id string) (types.Alarm, error)

	// GetUnresolved returns all alarms that have v.resolved to null or absent field.
	GetUnresolved() ([]types.Alarm, error)

	// GetOpenedAlarmsByIDs gets ongoing alarms related the provided entity ids
	GetOpenedAlarmsByIDs(ids []string, alarms *[]types.Alarm) error
	GetOpenedAlarmsWithEntityByIDs(ids []string, alarms *[]types.AlarmWithEntity) error
	GetCountOpenedAlarmsByIDs(ids []string) (int, error)

	// GetOpenedAlarmsByAlarmIDs gets ongoing alarms related the provided alarm ids
	GetOpenedAlarmsByAlarmIDs(ids []string, alarms *[]types.Alarm) error
	GetOpenedAlarmsWithEntityByAlarmIDs(ids []string, alarms *[]types.AlarmWithEntity) error

	MassUpdate(alarms []types.Alarm, notUpdateResolved bool) error

	MassUpdateWithEntity(alarms []types.AlarmWithEntity) error

	// MassPartialUpdateOpen updates opened alarms matching by list of IDs, applying partial update from alarm
	MassPartialUpdateOpen(context.Context, *types.Alarm, []string) error

	GetOpenedAlarmsWithLastDatesBefore(ctx context.Context, time types.CpsTime) (mongo.Cursor, error)

	GetOpenedAlarmsByConnectorIdleRules(ctx context.Context) ([]types.Alarm, error)

	CountResolvedAlarm(alarmList []string) (int, error)

	GetLastAlarmByEntityID(ctx context.Context, entityID string) (*types.Alarm, error)
}

func NewAdapter

func NewAdapter(dbClient libmongo.DbClient) Adapter

type EventProcessor

type EventProcessor interface {
	// Process processes an event and updates the corresponding
	// alarm. It enriches the event with this alarm, and returns an AlarmChange
	// representing the change that occured on this alarm and its previous
	// state.
	Process(ctx context.Context, event *types.Event) (types.AlarmChange, error)
}

func NewEventProcessor

func NewEventProcessor(
	adapter Adapter,
	entityAdapter entity.Adapter,
	ruleAdapter metaalarm.RulesAdapter,
	alarmConfigProvider config.AlarmConfigProvider,
	executor liboperation.Executor,
	redisLockClient redis.LockClient,
	logger zerolog.Logger,
) EventProcessor

type Service

type Service interface {
	// ResolveAlarms that have v.resolved to null
	ResolveAlarms(ctx context.Context, alarmConfig config.AlarmConfig) ([]types.Alarm, error)

	// ResolveCancels close canceled alarms when time has expired
	ResolveCancels(ctx context.Context, alarmConfig config.AlarmConfig) ([]types.Alarm, error)

	// ResolveDone close one alarms when time has expired
	ResolveDone(ctx context.Context) ([]types.Alarm, error)

	// ResolveSnoozes remove snooze state when snooze time has expired
	ResolveSnoozes(ctx context.Context, alarmConfig config.AlarmConfig) ([]types.Alarm, error)

	// UpdateFlappingAlarms updates the status of the flapping alarms, removing
	// the flapping status if needed.
	UpdateFlappingAlarms(ctx context.Context, alarmConfig config.AlarmConfig) ([]types.Alarm, error)
}

func NewService

func NewService(alarmAdapter Adapter, logger zerolog.Logger) Service

NewService gives the correct alarm adapter. Give nil to the redis client and it will create a new redis.Client with the dedicated redis database for alarms.

Jump to

Keyboard shortcuts

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