Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Oct 19, 2023
1 parent 51a8064 commit 770caaa
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 157 deletions.
77 changes: 76 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" {
return errors.New("dummy fail")
}

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

func (ch *Email) GetInfo() *plugin.Info {
return &plugin.Info{Name: "Email"}
var elements []*plugin.FormElement
elements = append(elements,
&plugin.FormElement{
Name: "host",
Type: "text",
Options: map[string]string{
"label": "SMTP Host",
"placeholder": "localhost",
},
},
&plugin.FormElement{
Name: "port",
Type: "select",
Options: map[string]string{
"label": "SMTP Port",
"options": `{"25":25, "465":465, "587":587, "2525":2525}`,
},
},
&plugin.FormElement{
Name: "from",
Type: "text",
Options: map[string]string{
"auto-complete": "off",
"label": "From",
},
},
&plugin.FormElement{
Name: "password",
Type: "password",
Options: map[string]string{
"auto-complete": "off",
"label": "Password",
},
},
&plugin.FormElement{
Name: "tls",
Type: "checkbox",
Options: map[string]string{
"label": "TLS / SSL",
"class": "autosubmit",
"checkedValue": "1",
"uncheckedValue": "0",
"value": "1",
},
},
&plugin.FormElement{
Name: "tls_certcheck",
Type: "checkbox",
Options: map[string]string{
"label": "Certificate Check",
"class": "autosubmit",
"checkedValue": "1",
"uncheckedValue": "0",
"value": "0",
},
},
)

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

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

func (ch *Email) GetServer() string {
Expand Down
44 changes: 43 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,46 @@ func (ch *RocketChat) SetConfig(jsonStr json.RawMessage) error {
}

func (ch *RocketChat) GetInfo() *plugin.Info {
return &plugin.Info{Name: "Rocket.Chat"}
var elements []*plugin.FormElement
elements = append(elements,
&plugin.FormElement{
Name: "url",
Type: "text",
Options: map[string]string{
"required": "true",
"label": "Rocket.Chat URL",
},
},
&plugin.FormElement{
Name: "user_id",
Type: "text",
Options: map[string]string{
"required": "true",
"auto-complete": "off",
"label": "User ID",
},
},
&plugin.FormElement{
Name: "token",
Type: "password",
Options: map[string]string{
"required": "true",
"auto-complete": "off",
"label": "Personal Access Token",
},
},
)

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

return &plugin.Info{
FileName: "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 770caaa

Please sign in to comment.