summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 3968268..2753ac9 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -35,6 +35,7 @@ type Config struct {
EmailTo string `json:"EmailTo,omitempty"`
EmailFrom string `json:"EmailFrom,omitempty"`
SMTPServer string `json:"SMTPServer,omitempty"`
+ MailThrottle int `json:"MailThrottle,omitempty"`
}
func NewFromConfigFile(configFile string) (Config, error) {
@@ -69,6 +70,21 @@ func NewFromConfigFile(configFile string) (Config, error) {
}
conf.Nodes = newNodes
+ if conf.SMTPServer == "" {
+ hostname, err := os.Hostname()
+ if err != nil {
+ log.Fatal(err)
+ }
+ conf.SMTPServer = fmt.Sprintf("%s:25", hostname)
+ log.Println("Set SMTPServer to " + conf.SMTPServer)
+ }
+
+ if conf.MailThrottle == 0 {
+ // By default, send out an E-Mail once every minute max. This
+ // is to avoid E-Mail bursts.
+ conf.MailThrottle = 60
+ }
+
return conf.setDefaults()
}
@@ -188,3 +204,7 @@ func (conf Config) findNode(hostname string) (Node, error) {
return Node{}, fmt.Errorf("node %s not found in %v", hostname, conf.Nodes)
}
+
+func (conf Config) EmailNotifycationEnabled() bool {
+ return conf.EmailFrom != "" && conf.EmailTo != "" && conf.SMTPServer != ""
+}