notifier

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 4, 2016 License: GPL-3.0 Imports: 13 Imported by: 0

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()
	}
)

Functions

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 InitRedisDatabase

func InitRedisDatabase()

InitRedisDatabase creates Redis pool based on config

func NewRedisPool

func NewRedisPool(redisURI string) *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 SetDb

func SetDb(connector *DbConnector)

SetDb allows you to use mock database in tests

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

func StopSenders

func StopSenders()

StopSenders close all sending channels

Types

type ContactData

type ContactData struct {
	Type  string `json:"type"`
	Value string `json:"value"`
	ID    string `json:"id"`
}

ContactData represents contact object

type DbConnector

type DbConnector struct {
	Pool *redis.Pool
}

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

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 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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