watcher

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: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodWorst = "worst"
)
View Source
const (
	WatcherCollectionName = "default_entities"
)

WatcherCollectionName is where we store watchers

Variables

This section is empty.

Functions

func DefaultCollection

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

Types

type Adapter

type Adapter interface {
	// Insert a watcher
	Insert(watcher Watcher) error

	// GetAll gets all watchers from database
	GetAll(watchers *[]Watcher) error

	// GetAllValidWatchers gets all valid and enabled watchers from database
	GetAllValidWatchers(watchers *[]Watcher) error

	// GetAllValidWatchersID gets all valid and enabled watchers ids from database
	GetAllValidWatchersID() ([]string, error)

	// GetByID finds the watcher by its entity id
	GetByID(id string, watchers *Watcher) error

	// GetEntities gets the entities watched by the watcher
	GetEntities(watcher Watcher, entities *[]types.Entity) error

	// Get gets the watchers accordingly to the filter
	Get(filter map[string]interface{}, watchers *[]Watcher) error

	// GetWatchersWithDependencies gets all the watchers and their respective active dependencies entities
	GetWatchersWithDependencies(idList []string) ([]WatcherWithDependencies, error)
}

func NewAdapter

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

NewAdapter gives the correct mongo watcher adapter.

type AmqpChannelPublisher

type AmqpChannelPublisher interface {
	// Publish sends an amqp.Publishing from the client to an exchange on the server.
	Publish(exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error
}

AmqpChannelPublisher is an interface that represents a non-consumable AMQP channel. This interface is implemented by amqp.Channel. It should be used in services that only publish to amqp, in order to be able to test them easily by mocking this interface.

type Service

type Service interface {
	// Insert a watcher
	Insert(watcher Watcher) error

	// GetAll gets all watchers from database
	GetAll(watchers *[]Watcher) error

	// GetAllValidWatchers gets all valid and enabled watchers from database
	GetAllValidWatchers(watchers *[]Watcher) error

	// GetWatcherByID finds the watcher by its entity id.
	GetByID(id string, watcher *Watcher) error

	// GetWatcherEntities gets the entities watched by the watcher
	GetEntities(watcher Watcher, entities *[]types.Entity) error

	// Process updates the watchers impacted by provided event and alarmChange
	Process(ctx context.Context, event *types.Event, alarmChange types.AlarmChange) error

	// ProcessResolvedAlarms updates the watchers impacted by the resolution of provided alarms
	ProcessResolvedAlarms(ctx context.Context, alarms []types.AlarmWithEntity)

	// ProcessUpdateWatcherEvent updates the watchers impacted by provided updatewatcher event
	ProcessUpdateWatcherEvent(ctx context.Context, event *types.Event) error

	// ComputeAllWatchers recompute all valid watchers
	ComputeAllWatchers(ctx context.Context) error
}

Service allows you to manipulate watchers in database.

func NewService

func NewService(pubChannel AmqpChannelPublisher, pubExchangeName, pubQueueName string, jsonEncoder encoding.Encoder, watcherAdapter Adapter, alarmAdapter alarm.Adapter, pbehaviorService pbehavior.Service) Service

NewService gives the correct watcher adapter.

type StateCounts

type StateCounts struct {
	Critical int
	Major    int
	Minor    int
	Info     int
}

StateCounts is a struct containing the number of alarms in each state that impact a watcher.

type TemplateData

type TemplateData struct {
	Alarms          int
	State           StateCounts
	Acknowledged    int
	NotAcknowledged int
}

TemplateData is a struct containing various values that can be used in the watchers output templates.

type Watcher

type Watcher struct {
	types.Entity   `bson:",inline"`          // inherits from entity
	Entities       pattern.EntityPatternList `bson:"entities"`
	State          map[string]interface{}    `bson:"state"`
	OutputTemplate string                    `bson:"output_template"`
}

Watcher is a structure representing a watcher type entity document.

func NewWatcher

func NewWatcher(id string, name string, infos map[string]types.Info, impacts, depends *types.DedupList, entities pattern.EntityPatternList, state map[string]interface{}, outTpl string) Watcher

NewWatcher instanciate a new watcher struct

func (*Watcher) CheckEntityInWatcher

func (w *Watcher) CheckEntityInWatcher(entity types.Entity) bool

CheckEntityInWatcher checks if the entity is watched by the watcher, returns true when the entity is matched by a pattern in the watcher, false else

type WatcherWithDependencies

type WatcherWithDependencies struct {
	Watcher      Watcher  `bson:"watcher"`
	Dependencies []string `bson:"enabled_dependencies"`
}

Jump to

Keyboard shortcuts

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