alarm

package
v0.0.0-...-4ecf446 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlarmCollectionName = "periodical_alarm"
)

AlarmCollectionName is where we store alarms

Variables

This section is empty.

Functions

func DefaultCollection

func DefaultCollection(session *mgo.Session) mongo.Collection

func NewBackend

func NewBackend() (*redis.Client, error)

NewBackend handle cache connection

func NewCache

func NewCache(redis *redis.Client) cache.Cache

NewCache creates the local cache and remote cache access for alarms. You may want to wrap with CacheThreadSafe.

Types

type Adapter

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

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

	// RemoveAll remove all alarms
	RemoveAll() error

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

	Get(filter bson.M, alarms *[]types.Alarm) error

	// GetAlarmsByID finds all alarms with an entity id. This function does not
	// use cache.
	GetAlarmsByID(id string) ([]types.Alarm, error)

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

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

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

	// GetAlarmsWithFlappingStatus returns all alarms whose status is flapping
	GetAlarmsWithFlappingStatus() ([]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)

	// 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)

	// 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.This function does not use cache.
	GetUnresolved() ([]types.AlarmWithEntity, error)

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

	// MassUpdate updates alarms with a mgo.Bulk object, by slices of max 1000 alarms.
	MassUpdate(alarms []types.Alarm) error

	// MassUpdateWithEntity updates alarms with a mgo.Bulk object, by slices of max 1000 alarms.
	MassUpdateWithEntity(alarms []types.AlarmWithEntity) error
}

func NewAdapter

func NewAdapter(collection mongo.Collection, entityCollectionName string, safeBulk bulk.Bulk) Adapter

NewAdapter gives the correct mongo alarm adapter.

type Cache

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

Cache uses Redis and a local map for alarms.

func (*Cache) Drop

func (c *Cache) Drop(alarmids ...string) error

Drop alarms in local and remote cache. Use Alarm.AlarmID() for ids.

func (*Cache) Flush

func (c *Cache) Flush() error

Flush resets local and remote caches

func (*Cache) Get

func (c *Cache) Get(alarmid string, alarm interface{}) bool

Get an Alarm from cache if available, returns nil, false if not. Example:

val, err := cache.Get(id) alarm := val.(Alarm)

func (*Cache) Set

func (c *Cache) Set(alarm cache.Cacheable) error

Set the local and remote cache with this alarm.

func (*Cache) SetRaw

func (c *Cache) SetRaw(id string, alarm interface{}) error

SetRaw is not implemented, will panic.

type Service

type Service interface {
	Insert(alarm types.Alarm) error

	Update(alarm types.Alarm) error

	Remove(alarm types.Alarm) error

	RemoveAll() error

	FlushCache() error

	GetAlarmsByID(id string) ([]types.Alarm, error)

	GetAlarmsWithCancelMark() ([]types.AlarmWithEntity, error)

	GetAlarmsWithDoneMark() ([]types.AlarmWithEntity, error)

	GetAlarmsWithSnoozeMark() ([]types.AlarmWithEntity, error)

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

	Get(filter bson.M, alarms *[]types.Alarm) error

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

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

	GetUnresolved() ([]types.AlarmWithEntity, error)

	// ProcessAlarmEvent 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.
	ProcessAlarmEvent(ctx context.Context, event *types.Event) (types.AlarmChange, error)

	// ProcessCheckOrWatcher processes an event of type check or watcher, and
	// returns an AlarmChangeType representing the change that occured on this
	// alarm.
	ProcessCheckOrWatcher(event *types.Event) (types.AlarmChangeType, error)

	// ProcessAckResources processes an event with ack_resources.
	// It adds an ack step to all the alarms whose component is the same as the
	// event's.
	ProcessAckResources(event *types.Event, step types.AlarmStep) error

	// SetTicketWithAckResources sets a ticket corresponding to an event with
	// ack_resource.
	// It adds a ticket to all the alarms whose component is the same as the
	// event's.
	SetTicketWithAckResources(stepType string, event types.Event, ticketNumber string, data map[string]string) error

	// ResolveAlarms that have v.resolved to null
	ResolveAlarms(ctx context.Context, baggotTime time.Duration) ([]types.AlarmWithEntity, error)

	// ResolveCancels close canceld alarms when time has expired
	ResolveCancels(ctx context.Context) ([]types.AlarmWithEntity, error)

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

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

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

Service allows you to manipulate alarms in database. It glue Adapter and Cache together

func NewService

func NewService(alarmAdapter Adapter, c cache.Cache, LastEventDate bool) 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