alert

package
v3.0.0-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Name of this alert client implementation.
	Name = "alert_kvdb"
	// NameTest of this alert instance used only for unit tests.
	NameTest = "alert_kvdb_test"
)

Variables

View Source
var (
	// ErrNotSupported implemenation of a specific function is not supported.
	ErrNotSupported = errors.New("Implementation not supported")
	// ErrNotFound raised if Key is not found.
	ErrNotFound = errors.New("Key not found")
	// ErrExist raised if key already exists.
	ErrExist = errors.New("Key already exists")
	// ErrUnmarshal raised if Get fails to unmarshal value.
	ErrUnmarshal = errors.New("Failed to unmarshal value")
	// ErrIllegal raised if object is not valid.
	ErrIllegal = errors.New("Illegal operation")
	// ErrNotInitialized raised if alert not initialized.
	ErrNotInitialized = errors.New("Alert not initialized")
	// ErrAlertClientNotFound raised if no client implementation found.
	ErrAlertClientNotFound = errors.New("Alert client not found")
	// ErrResourceNotFound raised if ResourceType is not found>
	ErrResourceNotFound = errors.New("Resource not found in Alert")
	// ErrSubscribedRaise raised if unable to raise a subscribed alert
	ErrSubscribedRaise = errors.New("Could not raise alert and its subscribed alerts")
)

Functions

func Register

func Register(name string, initFunc InitFunc) error

Register an alert interface.

func Shutdown

func Shutdown()

Shutdown the alert instance.

Types

type Alert

type Alert interface {
	fmt.Stringer

	// Shutdown.
	Shutdown()

	// GetKvdbInstance.
	GetKvdbInstance() kvdb.Kvdb

	// Raise raises an Alert.
	Raise(alert *api.Alert) error

	// Raise raises an Alert only if another alert with given resource type,
	// resource id, and unqiue_tage doesnt exists already.
	RaiseIfNotExist(alert *api.Alert) error

	// Subscribe allows a child (dependent) alert to subscribe to a parent alert
	Subscribe(parentAlertType int64, childAlert *api.Alert) error

	// Retrieve retrieves specific Alert.
	Retrieve(resourceType api.ResourceType, id int64) (*api.Alert, error)

	// Enumerate enumerates Alert.
	Enumerate(filter *api.Alert) ([]*api.Alert, error)

	// EnumerateWithinTimeRange enumerates Alert between timeStart and timeEnd.
	EnumerateWithinTimeRange(
		timeStart time.Time,
		timeEnd time.Time,
		resourceType api.ResourceType,
	) ([]*api.Alert, error)

	// Erase erases an Alert.
	Erase(resourceType api.ResourceType, alertID int64) error

	// Clear an Alert.
	Clear(resourceType api.ResourceType, alertID int64, ttl uint64) error

	// Clear an Alert for a resource with unique tag.
	ClearByUniqueTag(
		resourceType api.ResourceType,
		resourceId string,
		uniqueTag string,
		ttl uint64,
	) error

	// Watch on all Alerts for the given clusterID. It uses the global kvdb
	// options provided while creating the alertClient object to access this
	// cluster
	Watch(clusterID string, alertWatcher AlertWatcherFunc) error
}

Alert interface for Alert API.

func Init

func Init(kv kvdb.Kvdb, clusterID string) (Alert, error)

Init initializes a AlertClient interface implementation.

func New

func New(name string, clusterID string, kv kvdb.Kvdb) (Alert, error)

New returns a new alert instance tied with a clusterID and kvdb.

type AlertWatcherFunc

type AlertWatcherFunc func(*api.Alert, api.AlertActionType, string, string) error

AlertWatcherFunc is a function type used as a callback for KV WatchTree.

type InitFunc

type InitFunc func(kv kvdb.Kvdb, clusterID string) (Alert, error)

InitFunc initialization function for alert.

type KvAlert

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

KvAlert is used for managing the alerts and its kvdb instance

func (*KvAlert) Clear

func (kva *KvAlert) Clear(resourceType api.ResourceType, alertID int64, ttl uint64) error

Clear clears an alert.

func (*KvAlert) ClearByUniqueTag

func (kva *KvAlert) ClearByUniqueTag(
	resourceType api.ResourceType,
	resourceId string,
	uniqueTag string,
	ttl uint64,
) error

func (*KvAlert) Enumerate

func (kva *KvAlert) Enumerate(filter *api.Alert) ([]*api.Alert, error)

Enumerate enumerates alert

func (*KvAlert) EnumerateWithinTimeRange

func (kva *KvAlert) EnumerateWithinTimeRange(
	timeStart time.Time,
	timeEnd time.Time,
	resourceType api.ResourceType,
) ([]*api.Alert, error)

EnumerateWithinTimeRange enumerates alert between timeStart and timeEnd.

func (*KvAlert) Erase

func (kva *KvAlert) Erase(resourceType api.ResourceType, alertID int64) error

Erase erases an alert.

func (*KvAlert) GetKvdbInstance

func (kva *KvAlert) GetKvdbInstance() kvdb.Kvdb

GetKvdbInstance returns a kvdb instance associated with this alert client and clusterID combination.

func (*KvAlert) Raise

func (kva *KvAlert) Raise(a *api.Alert) error

Raise raises an Alert.

func (*KvAlert) RaiseIfNotExist

func (kva *KvAlert) RaiseIfNotExist(a *api.Alert) error

Raise raises an Alert if does not exists yet.

func (*KvAlert) Retrieve

func (kva *KvAlert) Retrieve(resourceType api.ResourceType, alertID int64) (*api.Alert, error)

Retrieve retrieves a specific alert.

func (*KvAlert) Shutdown

func (kva *KvAlert) Shutdown()

Shutdown shutdown

func (*KvAlert) String

func (kva *KvAlert) String() string

String

func (*KvAlert) Subscribe

func (kva *KvAlert) Subscribe(parentAlertType int64, childAlert *api.Alert) error

Subscribe allows a child (dependent) alert to subscribe to a parent alert

func (*KvAlert) Watch

func (kva *KvAlert) Watch(clusterID string, alertWatcherFunc AlertWatcherFunc) error

Watch on all Alerts for the given clusterID. It uses the global kvdb options provided while creating the alertClient object to access this cluster This way we ensure that the caller of the api is able to watch alerts on clusters that it is authorized for.

Jump to

Keyboard shortcuts

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