Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce plugin table #108

Merged
merged 14 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion cmd/channel/email/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package main

import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"github.com/icinga/icinga-notifications/internal"
"github.com/icinga/icinga-notifications/pkg/plugin"
"github.com/icinga/icingadb/pkg/types"
"net"
"net/smtp"
"os"
Expand Down Expand Up @@ -80,7 +83,47 @@ func (ch *Email) SetConfig(jsonStr json.RawMessage) error {
}

func (ch *Email) GetInfo() *plugin.Info {
return &plugin.Info{Name: "Email"}
elements := []*plugin.ConfigOption{
{
Name: "host",
Type: "string",
Label: map[string]string{
"en_US": "SMTP Host",
"de_DE": "SMTP Host",
},
},
{
Name: "port",
Type: "number",
Label: map[string]string{
"en_US": "SMTP Port",
"de_DE": "SMTP Port",
},
Min: types.Int{NullInt64: sql.NullInt64{Int64: 0, 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",
},
Placeholder: "[email protected]",
},
}

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

return &plugin.Info{
Name: "Email",
Version: internal.Version.Version,
sukhwinder33445 marked this conversation as resolved.
Show resolved Hide resolved
Author: "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"}

elements := []*plugin.ConfigOption{
{
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": "Benutzer ID",
},
Required: true,
},
{
Name: "token",
Type: "secret",
Label: map[string]string{
"en_US": "Personal Access Token",
"de_DE": "Persönliches Zugangstoken",
},
Required: true,
},
}

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

return &plugin.Info{
Name: "Rocket.Chat",
Version: internal.Version.Version,
Author: "Icinga GmbH",
ConfigAttributes: configAttrs,
}
}
10 changes: 8 additions & 2 deletions cmd/icinga-notifications-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ 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/daemon"
"github.com/icinga/icinga-notifications/internal/listener"
"github.com/icinga/icingadb/pkg/logging"
"github.com/icinga/icingadb/pkg/utils"
Expand Down Expand Up @@ -43,12 +45,14 @@ func main() {
os.Exit(1)
}

conf, err := config.FromFile(configPath)
err := daemon.LoadConfig(configPath)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, "cannot load config:", err)
os.Exit(1)
}

conf := daemon.Config()

logs, err := logging.NewLogging(
"icinga-notifications",
conf.Logging.Level,
Expand All @@ -75,6 +79,8 @@ func main() {
}
}

channel.UpsertPlugins(conf.ChannelPluginDir, logs.GetChildLogger("channel"), db)

ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer cancel()

Expand All @@ -85,7 +91,7 @@ func main() {

go runtimeConfig.PeriodicUpdates(ctx, 1*time.Second)

if err := listener.NewListener(db, conf, runtimeConfig, logs).Run(ctx); err != nil {
if err := listener.NewListener(db, runtimeConfig, logs).Run(ctx); err != nil {
logger.Errorw("Listener has finished with an error", zap.Error(err))
} else {
logger.Info("Listener has finished")
Expand Down
Loading