Documentation ¶
Index ¶
- Variables
- func FetchEvents(shutdown chan bool, wg *sync.WaitGroup)
- func FetchScheduledNotifications(shutdown chan bool, wg *sync.WaitGroup)
- func GetWaitGroup() *sync.WaitGroup
- func InitMetrics()
- func InitRedisDatabase()
- func NewRedisPool(redisURI string) *redis.Pool
- func ProcessEvent(event EventData) error
- func ProcessScheduledNotifications() error
- func RegisterSender(senderSettings map[string]string, sender Sender) error
- func SetDb(connector *DbConnector)
- func SetLogger(logger *logging.Logger)
- func SetSettings(settings Settings)
- func StopSenders()
- type ContactData
- type DbConnector
- func (connector *DbConnector) AddNotification(notification *ScheduledNotification) error
- func (connector *DbConnector) FetchEvent() (*EventData, error)
- func (connector *DbConnector) GetContact(id string) (ContactData, error)
- func (connector *DbConnector) GetNotifications(to int64) ([]*ScheduledNotification, error)
- func (connector *DbConnector) GetSubscription(id string) (SubscriptionData, error)
- func (connector *DbConnector) GetTagsSubscriptions(tags []string) ([]SubscriptionData, error)
- func (connector *DbConnector) GetTrigger(id string) (TriggerData, error)
- func (connector *DbConnector) GetTriggerEventsCount(triggerID string, from int64) int64
- func (connector *DbConnector) GetTriggerTags(triggerID string) ([]string, error)
- func (connector *DbConnector) GetTriggerThrottlingTimestamps(triggerID string) (time.Time, time.Time)
- func (connector *DbConnector) SetTriggerThrottlingTimestamp(triggerID string, next time.Time) error
- type EventData
- type EventsData
- type ScheduleData
- type ScheduleDataDay
- type ScheduledNotification
- type Sender
- type Settings
- type SubscriptionData
- type TriggerData
Constants ¶
This section is empty.
Variables ¶
var ( // GetNow allows you to travel in time while testing GetNow = func() time.Time { return time.Now() } )
Functions ¶
func FetchEvents ¶
FetchEvents is a cycle that fetches events from database
func FetchScheduledNotifications ¶
FetchScheduledNotifications is a cycle that fetches scheduled notifications from database
func InitMetrics ¶
func InitMetrics()
InitMetrics inits graphite metrics and starts graphite flush cycle
func InitRedisDatabase ¶
func InitRedisDatabase()
InitRedisDatabase creates Redis pool based on config
func ProcessEvent ¶
ProcessEvent generate notifications from EventData
func ProcessScheduledNotifications ¶
func ProcessScheduledNotifications() error
ProcessScheduledNotifications gets all notifications by now and send it
func RegisterSender ¶
RegisterSender adds sender for notification type and registers metrics
func SetLogger ¶
func SetLogger(logger *logging.Logger)
SetLogger allows you to redefine logging in tests
func SetSettings ¶
func SetSettings(settings Settings)
SetSettings allows you to redefine config in tests
Types ¶
type ContactData ¶
type ContactData struct { Type string `json:"type"` Value string `json:"value"` ID string `json:"id"` }
ContactData represents contact object
type DbConnector ¶
DbConnector contains redis pool
func (*DbConnector) AddNotification ¶
func (connector *DbConnector) AddNotification(notification *ScheduledNotification) error
AddNotification store notification at given timestamp
func (*DbConnector) FetchEvent ¶
func (connector *DbConnector) FetchEvent() (*EventData, error)
FetchEvent waiting for event from Db
func (*DbConnector) GetContact ¶
func (connector *DbConnector) GetContact(id string) (ContactData, error)
GetContact returns contact data by given id
func (*DbConnector) GetNotifications ¶
func (connector *DbConnector) GetNotifications(to int64) ([]*ScheduledNotification, error)
GetNotifications fetch notifications by given timestamp
func (*DbConnector) GetSubscription ¶
func (connector *DbConnector) GetSubscription(id string) (SubscriptionData, error)
GetSubscription returns subscription data by given id
func (*DbConnector) GetTagsSubscriptions ¶
func (connector *DbConnector) GetTagsSubscriptions(tags []string) ([]SubscriptionData, error)
GetTagsSubscriptions returns all subscriptions for given tags list
func (*DbConnector) GetTrigger ¶
func (connector *DbConnector) GetTrigger(id string) (TriggerData, error)
GetTrigger returns trigger data
func (*DbConnector) GetTriggerEventsCount ¶ added in v1.0.4
func (connector *DbConnector) GetTriggerEventsCount(triggerID string, from int64) int64
GetTriggerEventsCount retuns planned notifications count from given timestamp
func (*DbConnector) GetTriggerTags ¶
func (connector *DbConnector) GetTriggerTags(triggerID string) ([]string, error)
GetTriggerTags returns trigger tags
func (*DbConnector) GetTriggerThrottlingTimestamps ¶
func (connector *DbConnector) GetTriggerThrottlingTimestamps(triggerID string) (time.Time, time.Time)
GetTriggerThrottlingTimestamps get throttling or scheduled notifications delay for given triggerID
func (*DbConnector) SetTriggerThrottlingTimestamp ¶
func (connector *DbConnector) SetTriggerThrottlingTimestamp(triggerID string, next time.Time) error
SetTriggerThrottlingTimestamp store throttling or scheduled notifications delay for given triggerID
type EventData ¶
type EventData struct { Timestamp int64 `json:"timestamp"` Metric string `json:"metric"` Value float64 `json:"value"` State string `json:"state"` TriggerID string `json:"trigger_id"` SubscriptionID string `json:"sub_id"` OldState string `json:"old_state"` Message string `json:"msg"` }
EventData represents trigger state changes event
type EventsData ¶ added in v1.0.2
type EventsData []EventData
EventsData represents slice of EventData
func (EventsData) GetSubjectState ¶ added in v1.0.2
func (events EventsData) GetSubjectState() string
GetSubjectState returns the most critial state of events
type ScheduleData ¶
type ScheduleData struct { Days []ScheduleDataDay `json:"days"` TimezoneOffset int64 `json:"tzOffset"` StartOffset int64 `json:"startOffset"` EndOffset int64 `json:"endOffset"` }
ScheduleData respresent subscription schedule
func (*ScheduleData) CalculateNextDelivery ¶
CalculateNextDelivery return first avaiable timestamp according to schedule
type ScheduleDataDay ¶
type ScheduleDataDay struct {
Enabled bool `json:"enabled"`
}
ScheduleDataDay respresent week day of schedule
type ScheduledNotification ¶
type ScheduledNotification struct { Event EventData `json:"event"` Trigger TriggerData `json:"trigger"` Contact ContactData `json:"contact"` Throttled bool `json:"throttled"` SendFail int `json:"send_fail"` Timestamp int64 `json:"timestamp"` }
ScheduledNotification respresent notification object
func ConvertNotifications ¶
func ConvertNotifications(redisResponse interface{}) ([]*ScheduledNotification, error)
ConvertNotifications extracts ScheduledNotification from redis response
func (*ScheduledNotification) GetKey ¶ added in v1.0.3
func (notification *ScheduledNotification) GetKey() string
GetKey return notification key to prevent duplication to the same contact
type Sender ¶
type Sender interface { SendEvents(events EventsData, contact ContactData, trigger TriggerData, throttled bool) error Init(senderSettings map[string]string, logger *logging.Logger) error }
Sender interface for implementing specified contact type sender
type Settings ¶
type Settings interface { Get(section, key string) string GetInterface(section, key string) interface{} }
Settings is a collection of configuration options
type SubscriptionData ¶
type SubscriptionData struct { Contacts []string `json:"contacts"` Enabled bool `json:"enabled"` Tags []string `json:"tags"` Schedule ScheduleData `json:"sched"` ID string `json:"id"` ThrottlingEnabled bool `json:"throttling"` }
SubscriptionData respresent user subscription
type TriggerData ¶
type TriggerData struct { ID string `json:"id"` Name string `json:"name"` Targets []string `json:"targets"` WarnValue float64 `json:"warn_value"` ErrorValue float64 `json:"error_value"` Tags []string `json:"__notifier_trigger_tags"` }
TriggerData represents trigger object
func (*TriggerData) GetTags ¶ added in v1.0.2
func (trigger *TriggerData) GetTags() string
GetTags returns "[tag1][tag2]...[tagN]" string