Documentation ¶
Overview ¶
Package notifications contains functions needed to send notifications to the relevant stakeholders for the FIFE Managed Tokens Utilities
The two EmailManager funcs here, NewServiceEmailManager, and NewAdminEmailManager, are the primary interfaces by which calling code should send notifications that need to eventually be send via email. Either of these will sort error notifications properly.const
We expect callers to call NewServiceEmailManager if they are running any of the utilities for a service, and want to abstract away the notification sorting and sending.
NewAdminEmailManager can be called if the notifications will only be sent to admins. In this case, the calling code is expected to separately run SendAdminNotifications to actually send the accumulated data.
Both of these EmailManagers require a configured *email object to be passed in. The implication, then, is that using this package to collect and send notifications pre-supposes that one of these notifications will be of the email type.
Index ¶
- func NewEmail(from string, to []string, subject, smtpHost string, smtpPort int) *email
- func NewPushError(message, service, node string) *pushError
- func NewSetupError(message, service string) *setupError
- func NewSlackMessage(url string) *slackMessage
- func PrepareTableStringFromMap(m map[string]string, helpMessage string, header []string) string
- func SendAdminNotifications(ctx context.Context, operation string, adminTemplatePath string, isTest bool, ...) error
- func SendMessage(ctx context.Context, s SendMessager, msg string) error
- type AdminDataFinal
- type AdminNotificationManager
- type AdminNotificationManagerOption
- type Notification
- type SendMessageError
- type SendMessager
- type ServiceEmailManager
- type ServiceEmailManagerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPushError ¶
func NewPushError(message, service, node string) *pushError
NewPushError returns a *pushError that can be populated and then sent through an EmailManager
func NewSetupError ¶
func NewSetupError(message, service string) *setupError
NewSetupError returns a *setupError that can be populated and then sent through an EmailManager
func NewSlackMessage ¶
func NewSlackMessage(url string) *slackMessage
NewSlackMessage returns a configured *slackMessage that can be used to send a message using SendMessage()
func PrepareTableStringFromMap ¶
PrepareTableStringFromMap formats a map[string]string and appends a message onto the beginning
func SendAdminNotifications ¶
func SendAdminNotifications(ctx context.Context, operation string, adminTemplatePath string, isTest bool, sendMessagers ...SendMessager) error
SendAdminNotifications sends admin messages via email and Slack that have been collected in adminErrors. It expects a valid template file configured at adminTemplatePath
func SendMessage ¶
func SendMessage(ctx context.Context, s SendMessager, msg string) error
SendMessage sends a message (msg). The kind of message and how that message is sent is determined by the SendMessager, which should be configured before passing into SendMessage
Types ¶
type AdminDataFinal ¶
AdminDataFinal stores the same information as adminData, but with the PushErrors converted to string form, as a table. The PushErrorsTable field is meant to be read as is and used directly in an admin message
type AdminNotificationManager ¶ added in v0.9.1
type AdminNotificationManager struct { ReceiveChan chan Notification // ReceiveChan is the channel on which callers should send Notifications to be forwarded to administrators // Database is the underlying *db.ManagedTokensDatabase that will be queried by the AdminNotificationManager to determine whether // or not to send a particular Notification received on the ReceiveChan to administrators Database *db.ManagedTokensDatabase // NotificationMinimum is the minimum number of prior similar Notifications required for an AdminNotificationManager to determine that it should // send a Notification to administrators NotificationMinimum int // TrackErrorCounts determines whether or not the AdminNotificationManager should consult the Database or not. If set to false, all received // Notifications will be sent to administrators TrackErrorCounts bool // DatabaseReadOnly determines whether the AdminNotificationManager should write its error counts to the db.ManagedTokensDatabase after finishing // all processing. This should only be set to false if there are no other possible database writers (like ServiceEmailManager), to avoid double-counting // of errors DatabaseReadOnly bool }
AdminNotificationManager holds information needed to receive and handle notifications meant to be sent to the administrators of the managed tokens utilities.
func NewAdminNotificationManager ¶
func NewAdminNotificationManager(ctx context.Context, opts ...AdminNotificationManagerOption) *AdminNotificationManager
NewAdminNotificationManager returns an EmailManager channel for callers to send Notifications on. It will collect messages and sort them according to the underlying type of the Notification. Calling code is expected to run SendAdminNotifications separately to send the accumulated data via email (or otherwise). Functional options should be specified to set the fields (see AdminNotificationManagerOption documentation)
type AdminNotificationManagerOption ¶ added in v0.9.1
type AdminNotificationManagerOption func(*AdminNotificationManager) error
AdminNotificationManagerOption is a functional option that should be used as an argument to NewAdminNotificationManager to set various fields of the AdminNotificationManager For example:
f := func(a *AdminNotificationManager) error { a.NotificationMinimum = 42 return nil } g := func(a *AdminNotificationManager) error { a.DatabaseReadOnly = false return nil } manager := NewAdminNotificationManager(context.Background, f, g)
type Notification ¶
Notification is an interface to various types of notifications sent by a caller to
type SendMessageError ¶
type SendMessageError struct {
// contains filtered or unexported fields
}
SendMessageError indicates that an error occurred sending a message
func (*SendMessageError) Error ¶
func (s *SendMessageError) Error() string
type SendMessager ¶
type SendMessager interface {
// contains filtered or unexported methods
}
SendMessager wraps the SendMessage method
type ServiceEmailManager ¶ added in v0.9.1
type ServiceEmailManager struct { ReceiveChan chan Notification Service string Email *email Database *db.ManagedTokensDatabase NotificationMinimum int // contains filtered or unexported fields }
ServiceEmailManager contains all the information needed to receive Notifications for services and ensure they get sent in the correct email
func NewServiceEmailManager ¶
func NewServiceEmailManager(ctx context.Context, wg *sync.WaitGroup, service string, e *email, opts ...ServiceEmailManagerOption) *ServiceEmailManager
NewServiceEmailManager returns an EmailManager channel for callers to send Notifications on. It will collect messages and sort them according to the underlying type of the Notification, and when EmailManager is closed, will send emails. Set up the ManagedTokensDatabase and the NotificationMinimum via EmailManagerOptions passed in. If a ManagedTokensDatabase is not passed in via an EmailManagerOption, then the EmailManager will send all notifications
type ServiceEmailManagerOption ¶ added in v0.9.1
type ServiceEmailManagerOption func(*ServiceEmailManager) error