notifier

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2017 License: GPL-3.0 Imports: 12 Imported by: 8

README

Notifier

Documentation Status Build Status Coverage Status Gitter(https://badges.gitter.im/Join Chat.svg)

Code in this repository is a part of Moira monitoring application. Other parts are Worker, Cache and Web.

Notifier is responsible for delivering notifications via email, Slack, Pushover, Telegram and other channels.

Documentation for the entire Moira project is available on Read the Docs site.

If you have any questions, you can ask us on Gitter.

Thanks

SKB Kontur

Moira was originally developed and is supported by SKB Kontur, a B2G company based in Ekaterinburg, Russia. We express gratitude to our company for encouraging us to opensource Moira and for giving back to the community that created Graphite and many other useful DevOps tools.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// GetNow allows you to travel in time while testing
	GetNow = func() time.Time {
		return time.Now()
	}
)
View Source
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

func FetchEvents(shutdown chan bool, wg *sync.WaitGroup)

FetchEvents is a cycle that fetches events from database

func FetchScheduledNotifications

func FetchScheduledNotifications(shutdown chan bool, wg *sync.WaitGroup)

FetchScheduledNotifications is a cycle that fetches scheduled notifications from database

func GetWaitGroup

func GetWaitGroup() *sync.WaitGroup

GetWaitGroup return senders wait group

func InitMetrics

func InitMetrics()

InitMetrics inits graphite metrics and starts graphite flush cycle

func NewRedisPool

func NewRedisPool(redisURI string, dbID ...int) *redis.Pool

NewRedisPool creates Redis pool

func ProcessEvent

func ProcessEvent(event EventData) error

ProcessEvent generate notifications from EventData

func ProcessScheduledNotifications

func ProcessScheduledNotifications() error

ProcessScheduledNotifications gets all notifications by now and send it

func RegisterSender

func RegisterSender(senderSettings map[string]string, sender Sender) error

RegisterSender adds sender for notification type and registers metrics

func SelfStateMonitor added in v1.0.7

func SelfStateMonitor(shutdown chan bool, wg *sync.WaitGroup)

SelfStateMonitor - send message when moira don't work

func SetDb

func SetDb(connector Database)

SetDb allows you to use mock database in tests

func SetLogger

func SetLogger(logger Logger)

SetLogger allows you to redefine logging in tests

func SetSettings

func SetSettings(c *Config)

SetSettings allows you to redefine config in tests

func StopSenders

func StopSenders()

StopSenders close all sending channels

func ToBool added in v1.0.7

func ToBool(str string) bool

ToBool - parse bool from config

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

type DbConnector struct {
	Pool *redis.Pool
}

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

func (event *EventData) GetPseudoTags() []string

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 GraphiteConfig struct {
	URI      string `yaml:"uri"`
	Prefix   string `yaml:"prefix"`
	Interval int64  `yaml:"interval"`
}

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 RedisConfig struct {
	Host string `yaml:"host"`
	Port string `yaml:"port"`
	DBID int    `yaml:"dbid"`
}

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

func (schedule *ScheduleData) CalculateNextDelivery(nextTime time.Time) (time.Time, error)

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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