add email channel
This commit is contained in:
parent
0f4bb211d5
commit
63cacee1a7
13
main.go
13
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
_ "expvar"
|
_ "expvar"
|
||||||
|
"infini.sh/console/plugin/api/email"
|
||||||
_ "time/tzdata"
|
_ "time/tzdata"
|
||||||
|
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
@ -65,7 +66,9 @@ func main() {
|
||||||
modules = append(modules, &elastic2.ElasticModule{})
|
modules = append(modules, &elastic2.ElasticModule{})
|
||||||
modules = append(modules, &queue2.DiskQueue{})
|
modules = append(modules, &queue2.DiskQueue{})
|
||||||
modules = append(modules, &redis.RedisModule{})
|
modules = append(modules, &redis.RedisModule{})
|
||||||
modules = append(modules, &pipeline.PipeModule{})
|
pipeM := &pipeline.PipeModule{}
|
||||||
|
global.Register("pipeline_module", pipeM)
|
||||||
|
modules = append(modules, pipeM)
|
||||||
modules = append(modules, &task.TaskModule{})
|
modules = append(modules, &task.TaskModule{})
|
||||||
modules = append(modules, &metrics.MetricsModule{})
|
modules = append(modules, &metrics.MetricsModule{})
|
||||||
modules = append(modules, &security.Module{})
|
modules = append(modules, &security.Module{})
|
||||||
|
@ -135,6 +138,7 @@ func main() {
|
||||||
orm.RegisterSchemaWithIndexName(task1.Task{}, "task")
|
orm.RegisterSchemaWithIndexName(task1.Task{}, "task")
|
||||||
orm.RegisterSchemaWithIndexName(model.Layout{}, "layout")
|
orm.RegisterSchemaWithIndexName(model.Layout{}, "layout")
|
||||||
orm.RegisterSchemaWithIndexName(model.Notification{}, "notification")
|
orm.RegisterSchemaWithIndexName(model.Notification{}, "notification")
|
||||||
|
orm.RegisterSchemaWithIndexName(model.EmailServer{}, "email-server")
|
||||||
api.RegisterSchema()
|
api.RegisterSchema()
|
||||||
|
|
||||||
if global.Env().SetupRequired() {
|
if global.Env().SetupRequired() {
|
||||||
|
@ -150,6 +154,13 @@ func main() {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
task1.RunWithinGroup("initialize_email_server", func(ctx context.Context) error {
|
||||||
|
err := email.InitEmailServer()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("init email server error: %v", err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !global.Env().SetupRequired() {
|
if !global.Env().SetupRequired() {
|
||||||
|
|
|
@ -12,11 +12,11 @@ type CustomWebhook struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Email struct {
|
type Email struct {
|
||||||
ServerID string `json:"server_id"`
|
ServerID string `json:"server_id" elastic_mapping:"server_id:{type:keyword}"`
|
||||||
Recipients struct {
|
Recipients struct {
|
||||||
To []string `json:"to" elastic_mapping:"to:{type:keyword}"`
|
To []string `json:"to,omitempty" elastic_mapping:"to:{type:keyword}"`
|
||||||
CC []string `json:"cc" elastic_mapping:"cc:{type:keyword}"`
|
CC []string `json:"cc,omitempty" elastic_mapping:"cc:{type:keyword}"`
|
||||||
BCC []string `json:"bcc" elastic_mapping:"bcc:{type:keyword}"`
|
BCC []string `json:"bcc,omitempty" elastic_mapping:"bcc:{type:keyword}"`
|
||||||
} `json:"recipients" elastic_mapping:"recipients:{type:object}"`
|
} `json:"recipients" elastic_mapping:"recipients:{type:object}"`
|
||||||
Subject string `json:"subject" elastic_mapping:"subject:{type:text}"`
|
Subject string `json:"subject" elastic_mapping:"subject:{type:text}"`
|
||||||
Body string `json:"body" elastic_mapping:"body:{type:text}"`
|
Body string `json:"body" elastic_mapping:"body:{type:text}"`
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"infini.sh/console/plugin/api/email"
|
||||||
"infini.sh/console/plugin/api/license"
|
"infini.sh/console/plugin/api/license"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
@ -75,4 +76,5 @@ func Init(cfg *config.AppConfig) {
|
||||||
notification.InitAPI()
|
notification.InitAPI()
|
||||||
|
|
||||||
license.InitAPI()
|
license.InitAPI()
|
||||||
|
email.InitAPI()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,10 @@ type EmailAction struct {
|
||||||
Body string
|
Body string
|
||||||
}
|
}
|
||||||
|
|
||||||
const EmailQueueName = "alert_email_messages"
|
//const EmailQueueName = "alert_email_messages"
|
||||||
|
|
||||||
func (act *EmailAction) Execute()([]byte, error){
|
func (act *EmailAction) Execute()([]byte, error){
|
||||||
queueCfg := queue.GetOrInitConfig(EmailQueueName)
|
queueCfg := queue.GetOrInitConfig(act.Data.ServerID)
|
||||||
emailMsg := util.MapStr{
|
emailMsg := util.MapStr{
|
||||||
"email": act.Data.Recipients.To,
|
"email": act.Data.Recipients.To,
|
||||||
"template": "raw",
|
"template": "raw",
|
||||||
|
|
Loading…
Reference in New Issue