Documentation
¶
Index ¶
- Variables
- func CheckSelfStateMonitorSettings() error
- func FetchEvents(shutdown chan bool, wg *sync.WaitGroup)
- func FetchScheduledNotifications(shutdown chan bool, wg *sync.WaitGroup)
- func GetWaitGroup() *sync.WaitGroup
- func InitMetrics()
- func NewRedisPool(redisURI string, dbID ...int) *redis.Pool
- func ProcessEvent(event EventData) error
- func ProcessScheduledNotifications() error
- func RegisterSender(senderSettings map[string]string, sender Sender) error
- func SelfStateMonitor(shutdown chan bool, wg *sync.WaitGroup)
- func SetDb(connector Database)
- func SetLogger(logger Logger)
- func SetSettings(c *Config)
- func StopSenders()
- func ToBool(str string) bool
- type Config
- type ContactData
- type Database
- type DbConnector
- func (connector *DbConnector) AddNotification(notification *ScheduledNotification) error
- func (connector *DbConnector) DeregisterBot(messenger string) error
- func (connector *DbConnector) DeregisterBots()
- func (connector *DbConnector) FetchEvent() (*EventData, error)
- func (connector *DbConnector) GetChecksCount() (int64, error)
- func (connector *DbConnector) GetContact(id string) (ContactData, error)
- func (connector *DbConnector) GetContacts() ([]ContactData, error)
- func (connector *DbConnector) GetIDByUsername(messenger, username string) (string, error)
- func (connector *DbConnector) GetMetricsCount() (int64, 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) RegisterBotIfAlreadyNot(messenger string) bool
- func (connector *DbConnector) SetContact(contact *ContactData) error
- func (connector *DbConnector) SetTriggerThrottlingTimestamp(triggerID string, next time.Time) error
- func (connector *DbConnector) SetUsernameID(messenger, username, id string) error
- type EventData
- type EventsData
- type FrontConfig
- type GraphiteConfig
- type Logger
- type NotifierConfig
- type RedisConfig
- type ScheduleData
- type ScheduleDataDay
- type ScheduledNotification
- type SelfStateConfig
- type Sender
- 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() } )
var SelfCheckInterval = time.Second * 10
SelfCheckInterval defines the period for self check
Functions ¶
func CheckSelfStateMonitorSettings ¶ added in v1.0.7
func CheckSelfStateMonitorSettings() error
CheckSelfStateMonitorSettings - validate contact types
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 NewRedisPool ¶
NewRedisPool creates Redis pool
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 SelfStateMonitor ¶ added in v1.0.7
SelfStateMonitor - send message when moira don't work
Types ¶
type Config ¶ added in v1.0.7
type Config struct { Redis RedisConfig `yaml:"redis"` Front FrontConfig `yaml:"front"` Graphite GraphiteConfig `yaml:"graphite"` Notifier NotifierConfig `yaml:"notifier"` }
type ContactData ¶
type ContactData struct { Type string `json:"type"` Value string `json:"value"` ID string `json:"id"` User string `json:"user"` }
ContactData represents contact object
type Database ¶ added in v1.0.8
type Database interface { FetchEvent() (*EventData, error) GetTrigger(id string) (TriggerData, error) GetTriggerTags(id string) ([]string, error) GetTagsSubscriptions(tags []string) ([]SubscriptionData, error) GetSubscription(id string) (SubscriptionData, error) GetContact(id string) (ContactData, error) GetContacts() ([]ContactData, error) SetContact(contact *ContactData) error AddNotification(notification *ScheduledNotification) error GetTriggerThrottlingTimestamps(id string) (time.Time, time.Time) GetTriggerEventsCount(id string, from int64) int64 SetTriggerThrottlingTimestamp(id string, next time.Time) error GetNotifications(to int64) ([]*ScheduledNotification, error) GetMetricsCount() (int64, error) GetChecksCount() (int64, error) }
Database implements DB functionality
type DbConnector ¶
DbConnector contains redis pool
func InitRedisDatabase ¶
func InitRedisDatabase(config RedisConfig) *DbConnector
InitRedisDatabase creates Redis pool based on config
func (*DbConnector) AddNotification ¶
func (connector *DbConnector) AddNotification(notification *ScheduledNotification) error
AddNotification store notification at given timestamp
func (*DbConnector) DeregisterBot ¶ added in v1.0.8
func (connector *DbConnector) DeregisterBot(messenger string) error
DeregisterBot removes registration of bot instance in redis
func (*DbConnector) DeregisterBots ¶ added in v1.0.8
func (connector *DbConnector) DeregisterBots()
DeregisterBots cancels registration for all registered messengers
func (*DbConnector) FetchEvent ¶
func (connector *DbConnector) FetchEvent() (*EventData, error)
FetchEvent waiting for event from Db
func (*DbConnector) GetChecksCount ¶ added in v1.0.7
func (connector *DbConnector) GetChecksCount() (int64, error)
GetChecksCount - return checks count by Moira-Checker
func (*DbConnector) GetContact ¶
func (connector *DbConnector) GetContact(id string) (ContactData, error)
GetContact returns contact data by given id
func (*DbConnector) GetContacts ¶ added in v1.0.8
func (connector *DbConnector) GetContacts() ([]ContactData, error)
GetContacts returns full contact list
func (*DbConnector) GetIDByUsername ¶ added in v1.0.8
func (connector *DbConnector) GetIDByUsername(messenger, username string) (string, error)
GetIDByUsername read ID of user by messenger username
func (*DbConnector) GetMetricsCount ¶ added in v1.0.7
func (connector *DbConnector) GetMetricsCount() (int64, error)
GetMetricsCount - return metrics count received by Moira-Cache
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) RegisterBotIfAlreadyNot ¶ added in v1.0.8
func (connector *DbConnector) RegisterBotIfAlreadyNot(messenger string) bool
RegisterBotIfAlreadyNot creates registration of bot instance in redis
func (*DbConnector) SetContact ¶ added in v1.0.8
func (connector *DbConnector) SetContact(contact *ContactData) error
SetContact store contact information
func (*DbConnector) SetTriggerThrottlingTimestamp ¶
func (connector *DbConnector) SetTriggerThrottlingTimestamp(triggerID string, next time.Time) error
SetTriggerThrottlingTimestamp store throttling or scheduled notifications delay for given triggerID
func (*DbConnector) SetUsernameID ¶ added in v1.0.8
func (connector *DbConnector) SetUsernameID(messenger, username, id string) error
SetUsernameID store id of username
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
func (*EventData) GetPseudoTags ¶ added in v1.0.7
GetPseudoTags returns additional subscription tags based on trigger state
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 FrontConfig ¶ added in v1.0.7
type FrontConfig struct {
URI string `yaml:"uri"`
}
type GraphiteConfig ¶ added in v1.0.7
type Logger ¶ added in v1.0.8
type Logger interface { Debug(args ...interface{}) Debugf(format string, args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Warning(args ...interface{}) Warningf(format string, args ...interface{}) }
Logger implements logger abstraction
type NotifierConfig ¶ added in v1.0.7
type NotifierConfig struct { LogFile string `yaml:"log_file"` LogLevel string `yaml:"log_level"` LogColor string `yaml:"log_color"` SenderTimeout string `yaml:"sender_timeout"` ResendingTimeout string `yaml:"resending_timeout"` Senders []map[string]string `yaml:"senders"` SelfState SelfStateConfig `yaml:"moira_selfstate"` }
type RedisConfig ¶ added in v1.0.7
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 SelfStateConfig ¶ added in v1.0.7
type SelfStateConfig struct { Enabled string `yaml:"enabled"` RedisDisconectDelay int64 `yaml:"redis_disconect_delay"` LastMetricReceivedDelay int64 `yaml:"last_metric_received_delay"` LastCheckDelay int64 `yaml:"last_check_delay"` Contacts []map[string]string `yaml:"contacts"` NoticeInterval int64 `yaml:"notice_interval"` }
type Sender ¶
type Sender interface { SendEvents(events EventsData, contact ContactData, trigger TriggerData, throttled bool) error Init(senderSettings map[string]string, logger Logger) error }
Sender interface for implementing specified contact type sender
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"` Desc string `json:"desc"` 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