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
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) Get ¶
Get an Alarm from cache if available, returns nil, false if not. Example:
val, err := cache.Get(id) alarm := val.(Alarm)
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
Click to show internal directories.
Click to hide internal directories.