notification levels
parent
d837d7cda9
commit
773850b876
|
@ -15,3 +15,6 @@ const (
|
|||
EnvSlackBotName = "SLACK_BOT_NAME"
|
||||
EnvSlackChannels = "SLACK_CHANNELS"
|
||||
)
|
||||
|
||||
// EnvNotificationLevel - minimum level for notifications, defaults to info
|
||||
const EnvNotificationLevel = "NOTIFICATION_LEVEL"
|
||||
|
|
|
@ -32,6 +32,7 @@ var (
|
|||
// notifiers.
|
||||
type Config struct {
|
||||
Attempts int
|
||||
Level types.Level
|
||||
Params map[string]interface{} `yaml:",inline"`
|
||||
}
|
||||
|
||||
|
@ -76,6 +77,7 @@ func RegisterSender(name string, s Sender) {
|
|||
type DefaultNotificationSender struct {
|
||||
config *Config
|
||||
stopper *stopper.Stopper
|
||||
level types.Level
|
||||
}
|
||||
|
||||
// New - create new sender
|
||||
|
@ -118,6 +120,10 @@ func (m *DefaultNotificationSender) Senders() map[string]Sender {
|
|||
|
||||
// Send - send notifications through all configured senders
|
||||
func (m *DefaultNotificationSender) Send(event types.EventNotification) error {
|
||||
if event.Level < m.config.Level {
|
||||
return nil
|
||||
}
|
||||
|
||||
sendersM.RLock()
|
||||
defer sendersM.RUnlock()
|
||||
|
||||
|
|
13
main.go
13
main.go
|
@ -74,8 +74,21 @@ func main() {
|
|||
ctx, cancel := netContext.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
notificationLevel := types.LevelInfo
|
||||
if os.Getenv(constants.EnvNotificationLevel) != "" {
|
||||
parsedLevel, err := types.ParseLevel(os.Getenv(constants.EnvNotificationLevel))
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"error": err,
|
||||
}).Errorf("main: got error while parsing notification level, defaulting to: %s", notificationLevel)
|
||||
} else {
|
||||
notificationLevel = parsedLevel
|
||||
}
|
||||
}
|
||||
|
||||
notifCfg := ¬ification.Config{
|
||||
Attempts: 10,
|
||||
Level: notificationLevel,
|
||||
}
|
||||
sender := notification.New(ctx)
|
||||
|
||||
|
|
Loading…
Reference in New Issue