-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
channel/email: Enhance ConfigOptions
- Loading branch information
1 parent
45cb07b
commit 15a9e8a
Showing
1 changed file
with
29 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ const ( | |
type Email struct { | ||
Host string `json:"host"` | ||
Port string `json:"port"` | ||
From string `json:"from"` | ||
SenderName string `json:"sender_name"` | ||
SenderMail string `json:"sender_mail"` | ||
User string `json:"user"` | ||
Password string `json:"password"` | ||
Encryption string `json:"encryption"` | ||
|
@@ -53,7 +54,7 @@ func (ch *Email) SendNotification(req *plugin.NotificationRequest) error { | |
|
||
return enmime.Builder(). | ||
ToAddrs(to). | ||
From("", ch.From). | ||
From(ch.SenderName, ch.SenderMail). | ||
Subject(fmt.Sprintf("[#%d] %s %s is %s", req.Incident.Id, req.Event.Type, req.Object.Name, req.Incident.Severity)). | ||
Text(msg.Bytes()). | ||
Send(ch) | ||
|
@@ -75,10 +76,6 @@ func (ch *Email) Send(reversePath string, recipients []string, msg []byte) error | |
} | ||
defer client.Close() | ||
|
||
if err = client.Hello("localhost"); err != nil { | ||
return err | ||
} | ||
|
||
if ch.Encryption == TypeStartTls { | ||
if err = client.StartTLS(nil); err != nil { | ||
return err | ||
|
@@ -112,7 +109,7 @@ func (ch *Email) SetConfig(jsonStr json.RawMessage) error { | |
ch.Port = "25" | ||
} | ||
|
||
if ch.From == "" { | ||
if ch.SenderMail == "" { | ||
hostname, err := os.Hostname() | ||
if err != nil { | ||
return fmt.Errorf("failed to get the os's hostname: %w", err) | ||
|
@@ -123,18 +120,35 @@ func (ch *Email) SetConfig(jsonStr json.RawMessage) error { | |
return fmt.Errorf("failed to get the os's current user: %w", err) | ||
} | ||
|
||
ch.From = usr.Username + "@" + hostname | ||
ch.SenderMail = usr.Username + "@" + hostname | ||
} | ||
|
||
if ch.User == "" { | ||
ch.User = ch.From | ||
ch.User = ch.SenderMail | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (ch *Email) GetInfo() *plugin.Info { | ||
elements := []*plugin.ConfigOption{ | ||
{ | ||
Name: "sender_name", | ||
Type: "string", | ||
Label: map[string]string{ | ||
"en_US": "Sender Name", | ||
"de_DE": "Absendername", | ||
}, | ||
}, | ||
{ | ||
Name: "sender_mail", | ||
Type: "string", | ||
Label: map[string]string{ | ||
"en_US": "Sender Address", | ||
"de_DE": "Absenderadresse", | ||
}, | ||
Default: "[email protected]", | ||
}, | ||
{ | ||
Name: "host", | ||
Type: "string", | ||
|
@@ -153,39 +167,30 @@ func (ch *Email) GetInfo() *plugin.Info { | |
Min: types.Int{NullInt64: sql.NullInt64{Int64: 1, Valid: true}}, | ||
Max: types.Int{NullInt64: sql.NullInt64{Int64: 65535, Valid: true}}, | ||
}, | ||
{ | ||
Name: "from", | ||
Type: "string", | ||
Label: map[string]string{ | ||
"en_US": "From", | ||
"de_DE": "Von", | ||
}, | ||
Default: "[email protected]", | ||
}, | ||
{ | ||
Name: "user", | ||
Type: "string", | ||
Label: map[string]string{ | ||
"en_US": "User", | ||
"de_DE": "Benutzer", | ||
"en_US": "SMTP User", | ||
"de_DE": "SMTP Benutzer", | ||
}, | ||
Default: "[email protected]", | ||
}, | ||
{ | ||
Name: "password", | ||
Type: "secret", | ||
Label: map[string]string{ | ||
"en_US": "Password", | ||
"de_DE": "Passwort", | ||
"en_US": "SMTP Password", | ||
"de_DE": "SMTP Passwort", | ||
}, | ||
}, | ||
{ | ||
Name: "encryption", | ||
Type: "option", | ||
Required: true, | ||
Label: map[string]string{ | ||
"en_US": "TLS / SSL", | ||
"de_DE": "TLS / SSL", | ||
"en_US": "Transport Encryption", | ||
"de_DE": "Transportverschlüsselung", | ||
}, | ||
Options: map[string]string{ | ||
TypeNone: "None", | ||
|