Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Oct 24, 2023
1 parent 51a8064 commit 0260388
Show file tree
Hide file tree
Showing 11 changed files with 458 additions and 160 deletions.
78 changes: 77 additions & 1 deletion cmd/channel/email/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/icinga/icinga-notifications/internal"
"github.com/icinga/icinga-notifications/pkg/plugin"
"net"
"net/smtp"
Expand Down Expand Up @@ -54,6 +56,10 @@ func (ch *Email) SetConfig(jsonStr json.RawMessage) error {
return fmt.Errorf("failed to load config: %s %w", jsonStr, err)
}

if ch.From == "fail" { //TODO: remove it
return errors.New("dummy fail")
}

if ch.Host == "" {
ch.Host = "localhost"
}
Expand All @@ -80,7 +86,77 @@ func (ch *Email) SetConfig(jsonStr json.RawMessage) error {
}

func (ch *Email) GetInfo() *plugin.Info {
return &plugin.Info{Name: "Email"}
elements := []*plugin.FormElement{
{
Name: "host",
Type: "string",
Label: map[string]string{
"en_US": "SMTP Host",
"de_DE": "SMTP Host",
},
Default: "localhost",
},
{
Name: "port",
Type: "option",
Label: map[string]string{
"en_US": "SMTP Port",
"de_DE": "SMTP Port",
},
Options: map[string]string{
"25": "25",
"465": "465",
"587": "587",
"2525": "2525",
},
},
{
Name: "from",
Type: "string",
Label: map[string]string{
"en_US": "From",
"de_DE": "From",
},
Default: "notifications@icinga",
},
{
Name: "password",
Type: "secret",
Label: map[string]string{
"en_US": "Password",
"de_DE": "Password",
},
},
{
Name: "tls",
Type: "bool",
Label: map[string]string{
"en_US": "TLS / SSL",
"de_DE": "TLS / SSL",
},
},
{
Name: "tls_certcheck",
Type: "bool",
Label: map[string]string{
"en_US": "Certificate Check",
"de_DE": "Certificate Check",
},
},
}

configAttrs, err := json.Marshal(elements)
if err != nil {
panic(err)
}

return &plugin.Info{
Type: "email",
Name: "Email",
Version: internal.Version.Version,
AuthorName: "Icinga GmbH",
ConfigAttributes: configAttrs,
}
}

func (ch *Email) GetServer() string {
Expand Down
45 changes: 44 additions & 1 deletion cmd/channel/rocketchat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/icinga/icinga-notifications/internal"
"github.com/icinga/icinga-notifications/pkg/plugin"
"net/http"
"time"
Expand Down Expand Up @@ -80,5 +81,47 @@ func (ch *RocketChat) SetConfig(jsonStr json.RawMessage) error {
}

func (ch *RocketChat) GetInfo() *plugin.Info {
return &plugin.Info{Name: "Rocket.Chat"}

elements := []*plugin.FormElement{
{
Name: "url",
Type: "string",
Label: map[string]string{
"en_US": "Rocket.Chat URL",
"de_DE": "Rocket.Chat URL",
},
Required: true,
},
{
Name: "user_id",
Type: "string",
Label: map[string]string{
"en_US": "User ID",
"de_DE": "User ID",
},
Required: true,
},
{
Name: "token",
Type: "secret",
Label: map[string]string{
"en_US": "Personal Access Token",
"de_DE": "Personal Access Token",
},
Required: true,
},
}

configAttrs, err := json.Marshal(elements)
if err != nil {
panic(err)
}

return &plugin.Info{
Type: "rocketchat",
Name: "Rocket.Chat",
Version: internal.Version.Version,
AuthorName: "Icinga GmbH",
ConfigAttributes: configAttrs,
}
}
3 changes: 3 additions & 0 deletions cmd/icinga-notifications-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"github.com/icinga/icinga-notifications/internal"
"github.com/icinga/icinga-notifications/internal/channel"
"github.com/icinga/icinga-notifications/internal/config"
"github.com/icinga/icinga-notifications/internal/daemonConfig"
"github.com/icinga/icinga-notifications/internal/listener"
Expand Down Expand Up @@ -76,6 +77,8 @@ func main() {
}
}

channel.SyncPlugins(conf.ChannelPluginDir, logs, db)

runtimeConfig := config.NewRuntimeConfig(db, logs)
if err := runtimeConfig.UpdateFromDatabase(context.TODO()); err != nil {
logger.Fatalw("failed to load config from database", zap.Error(err))
Expand Down
Loading

0 comments on commit 0260388

Please sign in to comment.