notify

package
v0.0.0-...-900fa13 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2015 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TemplatePath = "notify/templates"
	BaseTemplate = "layout.html"
)
View Source
const (
	// number of times to try sending a notification
	NumSmtpRetries = 3

	// period to sleep between tries
	SmtpSleepTime = time.Duration(1) * time.Second

	// smtp port to connect to
	SmtpPort = 25

	// smtp relay host to connect to
	SmtpServer = "localhost"

	// Thus on each run of the notifier, we check if the last notification time
	// (LNT) is within this window. If it is, then we use the retrieved LNT.
	// If not, we use the current time
	LNRWindow = 60 * time.Minute

	// MCI ops notification prefaces
	ProvisionFailurePreface = "[PROVISION-FAILURE]"
	ProvisionTimeoutPreface = "[PROVISION-TIMEOUT]"
	ProvisionLatePreface    = "[PROVISION-LATE]"

	// repotracker notification prefaces
	RepotrackerFailurePreface = "[REPOTRACKER-FAILURE %v] on %v"

	// branch name to use if the project reference is not found
	UnknownProjectBranch = ""
)
View Source
const (
	RunnerName  = "notify"
	Description = "send notifications for failed tasks and system issues"
)
View Source
const (
	TimeOutMessage      = "timeout"
	UnresponsiveMessage = "unresponsive"
)

Variables

View Source
var (
	Handlers = map[string]NotificationHandler{
		// contains filtered or unexported fields
	}
)

Functions

func NotifyAdmins

func NotifyAdmins(subject, message string, settings *evergreen.Settings) error

NotifyAdmins is a helper method to send a notification to the MCI admin team

func ProcessNotifications

func ProcessNotifications(ae *web.App, configName string, mciNotification *MCINotification, updateTimes bool) (map[NotificationKey][]Email, error)

This function is responsible for all notifications processing

func Run

func Run(settings *evergreen.Settings) error

This function is responsible for running the notifications pipeline

ParseNotifications

↓↓

ValidateNotifications

↓↓

ProcessNotifications

↓↓

SendNotifications

↓↓

UpdateNotificationTimes

func SendNotifications

func SendNotifications(settings *evergreen.Settings, mciNotification *MCINotification,
	emails map[NotificationKey][]Email, mailer Mailer) (err error)

This function is responsible for managing the sending triggered email notifications

func TemplateEmailBody

func TemplateEmailBody(ae *web.App, name string, data interface{}) (string, error)

func TrySendNotification

func TrySendNotification(recipients []string, subject, body string, mailer Mailer) (err error)

Helper function to send notifications

func TrySendNotificationToUser

func TrySendNotificationToUser(userId string, subject, body string, mailer Mailer) (err error)

Helper function to send notification to a given user

func UpdateNotificationTimes

func UpdateNotificationTimes() (err error)

This stores the last time threshold after which we search for possible new notification events

func ValidateNotifications

func ValidateNotifications(configName string, mciNotification *MCINotification) error

This function is responsible for validating the notifications file

Types

type BuildCompletionHandler

type BuildCompletionHandler struct {
	BuildNotificationHandler
	Name string
}

Handler for build completion notifications, i.e. send notifications whenever a build finishes. Implements NotificationHandler from notification_handler.go.

func (*BuildCompletionHandler) GetChangeInfo

func (self *BuildCompletionHandler) GetChangeInfo(
	notification *TriggeredBuildNotification) ([]ChangeInfo, error)

func (*BuildCompletionHandler) GetNotifications

func (self *BuildCompletionHandler) GetNotifications(ae *web.App, configName string,
	key *NotificationKey) ([]Email, error)

func (*BuildCompletionHandler) TemplateNotification

func (self *BuildCompletionHandler) TemplateNotification(ae *web.App, _ string,
	notification *TriggeredBuildNotification) (Email, error)

type BuildEmail

type BuildEmail struct {
	EmailBase
	Trigger TriggeredBuildNotification
}

Implements Email interface for build-specific emails. Defines skip logic for emails specific to build

func (*BuildEmail) GetRecipients

func (self *BuildEmail) GetRecipients(defaultRecipient string) []string

func (*BuildEmail) IsLikelySystemFailure

func (self *BuildEmail) IsLikelySystemFailure() bool

func (*BuildEmail) ShouldSkip

func (self *BuildEmail) ShouldSkip(skipVariants []string) bool

type BuildFailureHandler

type BuildFailureHandler struct {
	BuildNotificationHandler
	Name string
}

Handler for build failure notifications. Implements NotificationHandler from notification_handler.go.

func (*BuildFailureHandler) GetChangeInfo

func (self *BuildFailureHandler) GetChangeInfo(
	notification *TriggeredBuildNotification) ([]ChangeInfo, error)

func (*BuildFailureHandler) GetNotifications

func (self *BuildFailureHandler) GetNotifications(ae *web.App, configName string,
	key *NotificationKey) ([]Email, error)

func (*BuildFailureHandler) TemplateNotification

func (self *BuildFailureHandler) TemplateNotification(ae *web.App, _ string,
	notification *TriggeredBuildNotification) (Email, error)

type BuildNotificationForTemplate

type BuildNotificationForTemplate struct {
	Notification *TriggeredBuildNotification
	FailedTasks  []build.TaskCache
	Subject      string
}

type BuildNotificationHandler

type BuildNotificationHandler struct {
	Type string
}

"Base class" for all build_*_handler.go structs. Contains code that's common to all the build_*_handlers. Note that this struct does NOT implement NotificationHandler

type BuildSuccessHandler

type BuildSuccessHandler struct {
	BuildNotificationHandler
	Name string
}

Handler for build success notifications. Implements NotificationHandler from notification_handler.go.

func (*BuildSuccessHandler) GetChangeInfo

func (self *BuildSuccessHandler) GetChangeInfo(
	notification *TriggeredBuildNotification) ([]ChangeInfo, error)

func (*BuildSuccessHandler) GetNotifications

func (self *BuildSuccessHandler) GetNotifications(ae *web.App, configName string,
	key *NotificationKey) ([]Email, error)

func (*BuildSuccessHandler) TemplateNotification

func (self *BuildSuccessHandler) TemplateNotification(ae *web.App, _ string,
	notification *TriggeredBuildNotification) (Email, error)

type BuildSuccessToFailureHandler

type BuildSuccessToFailureHandler struct {
	BuildNotificationHandler
	Name string
}

Handler for notifications generated specifically when a build fails and the previous finished build succeeded. Implements NotificationHandler from notification_handler.go.

func (*BuildSuccessToFailureHandler) GetChangeInfo

func (self *BuildSuccessToFailureHandler) GetChangeInfo(
	notification *TriggeredBuildNotification) ([]ChangeInfo, error)

func (*BuildSuccessToFailureHandler) GetNotifications

func (self *BuildSuccessToFailureHandler) GetNotifications(ae *web.App, configName string,
	key *NotificationKey) ([]Email, error)

func (*BuildSuccessToFailureHandler) TemplateNotification

func (self *BuildSuccessToFailureHandler) TemplateNotification(ae *web.App, _ string,
	notification *TriggeredBuildNotification) (Email, error)

type ChangeInfo

type ChangeInfo struct {
	Revision string
	Author   string
	Email    string
	Pushtime string
	Project  string
	Message  string
}

stores information pertaining to a repository's changes

type Email

type Email interface {
	GetBody() string
	GetSubject() string
	// for system-related failures, we only want to notify the admins
	// regardless of who the default recipient is
	IsLikelySystemFailure() bool
	GetRecipients(defaultRecipient string) []string
	GetChangeInfo() []ChangeInfo
	// Should you skip sending this email given the provided variants to skip
	ShouldSkip(skipVariants []string) bool
}

Interface around an email that may be sent as a notification. Provides getters for body, subject, and change info, and functions to determine if this email should be skipped.

type EmailBase

type EmailBase struct {
	Body       string
	Subject    string
	ChangeInfo []ChangeInfo
}

"Base class" for structs that implement the Email interface. Stores the basics that any email should have.

func (*EmailBase) GetBody

func (self *EmailBase) GetBody() string

func (*EmailBase) GetChangeInfo

func (self *EmailBase) GetChangeInfo() []ChangeInfo

func (*EmailBase) GetSubject

func (self *EmailBase) GetSubject() string

type MCINotification

type MCINotification struct {
	Notifications      []Notification `yaml:"notifications"`
	Teams              []Team         `yaml:"teams"`
	PatchNotifications []Subscription `yaml:"patch_notifications"`
}

store notifications file

func ParseNotifications

func ParseNotifications(configName string) (*MCINotification, error)

This function is responsible for reading the notifications file

type Mailer

type Mailer interface {
	SendMail([]string, string, string) error
}

func ConstructMailer

func ConstructMailer(notifyConfig evergreen.NotifyConfig) Mailer

type Notification

type Notification struct {
	Name         string   `yaml:"name"`
	Project      string   `yaml:"project"`
	Recipients   []string `yaml:"recipients"`
	SkipVariants []string `yaml:"skip_variants"`
}

stores supported notifications

type NotificationHandler

type NotificationHandler interface {
	// Given a key, scan through database and generate the notifications that
	// have been triggered since the last time this function ran. Returns the
	// emails generated for this particular key.
	GetNotifications(ae *web.App, configName string, key *NotificationKey) ([]Email, error)
}

General interface for how notify.go deals with a given type of notification. At a high level, structs that implement this interface are responsible for scanning the database to find which notifications to generate and returning an object matching the Email interface for each notification.

type NotificationKey

type NotificationKey struct {
	Project               string
	NotificationName      string
	NotificationType      string
	NotificationRequester string
}

stores high level notifications key

func (NotificationKey) String

func (nk NotificationKey) String() string

String method for notification key

type Runner

type Runner struct{}

func (*Runner) Description

func (r *Runner) Description() string

func (*Runner) Name

func (r *Runner) Name() string

func (*Runner) Run

func (r *Runner) Run(config *evergreen.Settings) error

type SmtpMailer

type SmtpMailer struct {
	From     string
	Server   string
	Port     int
	UseSSL   bool
	Username string
	Password string
}

func (SmtpMailer) SendMail

func (self SmtpMailer) SendMail(recipients []string, subject, body string) error

Connects an SMTP server (usually localhost:25 in prod) and uses that to

send an email with the body encoded in base64.

type Subscription

type Subscription struct {
	Project      string   `yaml:"project"`
	SkipVariants []string `yaml:"skip_variants"`
	NotifyOn     []string `yaml:"notify_on"`
}

stores notifications subscription for a team

type TaskCompletionHandler

type TaskCompletionHandler struct {
	TaskNotificationHandler
	Name string
}

Handler for task completion notifications, i.e. send notifications whenever a task finishes. Implements NotificationHandler from notification_handler.go.

func (*TaskCompletionHandler) GetChangeInfo

func (self *TaskCompletionHandler) GetChangeInfo(
	notification *TriggeredTaskNotification) ([]ChangeInfo, error)

func (*TaskCompletionHandler) GetNotifications

func (self *TaskCompletionHandler) GetNotifications(ae *web.App, configName string,
	key *NotificationKey) ([]Email, error)

func (*TaskCompletionHandler) TemplateNotification

func (self *TaskCompletionHandler) TemplateNotification(ae *web.App, configName string,
	notification *TriggeredTaskNotification) (Email, error)

type TaskEmail

type TaskEmail struct {
	EmailBase
	Trigger TriggeredTaskNotification
}

Implements Email interface for task-specific emails. Defines skip logic for emails specific to tasks

func (*TaskEmail) GetRecipients

func (self *TaskEmail) GetRecipients(defaultRecipient string) []string

func (*TaskEmail) IsLikelySystemFailure

func (self *TaskEmail) IsLikelySystemFailure() bool

func (*TaskEmail) ShouldSkip

func (self *TaskEmail) ShouldSkip(skipVariants []string) bool

type TaskFailureHandler

type TaskFailureHandler struct {
	TaskNotificationHandler
	Name string
}

Handler for task failure notifications. Implements NotificationHandler from notification_handler.go.

func (*TaskFailureHandler) GetChangeInfo

func (self *TaskFailureHandler) GetChangeInfo(
	notification *TriggeredTaskNotification) ([]ChangeInfo, error)

func (*TaskFailureHandler) GetNotifications

func (self *TaskFailureHandler) GetNotifications(ae *web.App, configName string,
	key *NotificationKey) ([]Email, error)

func (*TaskFailureHandler) TemplateNotification

func (self *TaskFailureHandler) TemplateNotification(ae *web.App, configName string,
	notification *TriggeredTaskNotification) (Email, error)

type TaskNotificationForTemplate

type TaskNotificationForTemplate struct {
	Notification *TriggeredTaskNotification
	LogsUrl      string
	Details      apimodels.TaskEndDetail
	FailedTests  []model.TestResult
	Subject      string
}

type TaskNotificationHandler

type TaskNotificationHandler struct {
	Type string
}

"Base class" for all task_*_handler.go structs. Contains code that's common to all the task_*_handlers. Note that this struct does NOT implement NotificationHandler

type TaskSuccessHandler

type TaskSuccessHandler struct {
	TaskNotificationHandler
	Name string
}

Handler for notifying users that a task succeeded. Implements NotificationHandler from notification_handler.go.

func (*TaskSuccessHandler) GetChangeInfo

func (self *TaskSuccessHandler) GetChangeInfo(
	notification *TriggeredTaskNotification) ([]ChangeInfo, error)

func (*TaskSuccessHandler) GetNotifications

func (self *TaskSuccessHandler) GetNotifications(ae *web.App, configName string,
	key *NotificationKey) ([]Email, error)

func (*TaskSuccessHandler) TemplateNotification

func (self *TaskSuccessHandler) TemplateNotification(ae *web.App, configName string,
	notification *TriggeredTaskNotification) (Email, error)

type TaskSuccessToFailureHandler

type TaskSuccessToFailureHandler struct {
	TaskNotificationHandler
	Name string
}

Handler for notifications generated specifically when a task fails and the previous finished task succeeded. Implements NotificationHandler from notification_handler.go.

func (*TaskSuccessToFailureHandler) GetChangeInfo

func (self *TaskSuccessToFailureHandler) GetChangeInfo(
	notification *TriggeredTaskNotification) ([]ChangeInfo, error)

func (*TaskSuccessToFailureHandler) GetNotifications

func (self *TaskSuccessToFailureHandler) GetNotifications(ae *web.App, configName string,
	key *NotificationKey) ([]Email, error)

func (*TaskSuccessToFailureHandler) TemplateNotification

func (self *TaskSuccessToFailureHandler) TemplateNotification(ae *web.App,
	configName string, notification *TriggeredTaskNotification) (Email, error)

type Team

type Team struct {
	Name          string         `yaml:"name"`
	Address       string         `yaml:"address"`
	Subscriptions []Subscription `yaml:"subscriptions"`
}

stores 10gen team information

type TriggeredBuildNotification

type TriggeredBuildNotification struct {
	Current    *build.Build
	Previous   *build.Build
	Info       []ChangeInfo
	Key        NotificationKey
	Preface    string
	Transition string
}

convenience wrapper about everything we want to know about a build notification before it goes off for templating.

type TriggeredTaskNotification

type TriggeredTaskNotification struct {
	Current    *model.Task
	Previous   *model.Task
	Info       []ChangeInfo
	Key        NotificationKey
	Preface    string
	Transition string
}

convenience wrapper about everything we want to know about a task notification before it goes off for templating.

Jump to

Keyboard shortcuts

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