From 32bf26e3217a64697faab1ce9f8497a00e0a9517 Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Thu, 27 Jun 2024 15:14:44 +0200 Subject: [PATCH] Rename cmd/channel to cmd/channels There are multiple channel plugins under cmd/channel. Especially later in the installation, the channels directory will contain multiple channels, not just one. For consistency, the YAML configuration channel-plugin-dir was renamed to channels-dir. The "plugin" part was dropped as it is redundant here. Closes #224 --- Makefile | 8 ++++---- cmd/{channel => channels}/email/main.go | 0 cmd/{channel => channels}/rocketchat/main.go | 0 cmd/{channel => channels}/webhook/main.go | 0 cmd/icinga-notifications/main.go | 2 +- config.example.yml | 2 +- internal/channel/plugin.go | 2 +- internal/daemon/config.go | 18 +++++++++--------- 8 files changed, 16 insertions(+), 16 deletions(-) rename cmd/{channel => channels}/email/main.go (100%) rename cmd/{channel => channels}/rocketchat/main.go (100%) rename cmd/{channel => channels}/webhook/main.go (100%) diff --git a/Makefile b/Makefile index e41bbe51..a0bf79dc 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ all: -o build/ \ -ldflags "-X '$(pkg).LibExecDir=$(libexecdir)' -X '$(pkg).SysConfDir=$(sysconfdir)'" \ ./cmd/icinga-notifications - go build -o build/channel/ ./cmd/channel/... + go build -o build/channels/ ./cmd/channels/... test: go test ./... @@ -28,9 +28,9 @@ install: install -m644 config.example.yml $(DESTDIR)$(sysconfdir)/icinga-notifications/config.yml @# dameon install -D build/icinga-notifications $(DESTDIR)$(sbindir)/icinga-notifications - @# channel plugins - install -d $(DESTDIR)$(libexecdir)/icinga-notifications/channel - install build/channel/* $(DESTDIR)$(libexecdir)/icinga-notifications/channel/ + @# channels + install -d $(DESTDIR)$(libexecdir)/icinga-notifications/channels + install build/channels/* $(DESTDIR)$(libexecdir)/icinga-notifications/channels/ @# database schema install -d $(DESTDIR)$(datadir)/icinga-notifications cp -rv --no-dereference schema $(DESTDIR)$(datadir)/icinga-notifications diff --git a/cmd/channel/email/main.go b/cmd/channels/email/main.go similarity index 100% rename from cmd/channel/email/main.go rename to cmd/channels/email/main.go diff --git a/cmd/channel/rocketchat/main.go b/cmd/channels/rocketchat/main.go similarity index 100% rename from cmd/channel/rocketchat/main.go rename to cmd/channels/rocketchat/main.go diff --git a/cmd/channel/webhook/main.go b/cmd/channels/webhook/main.go similarity index 100% rename from cmd/channel/webhook/main.go rename to cmd/channels/webhook/main.go diff --git a/cmd/icinga-notifications/main.go b/cmd/icinga-notifications/main.go index 19e86443..680f0b79 100644 --- a/cmd/icinga-notifications/main.go +++ b/cmd/icinga-notifications/main.go @@ -75,7 +75,7 @@ func main() { logger.Fatalf("Cannot connect to the database: %+v", err) } - channel.UpsertPlugins(ctx, conf.ChannelPluginDir, logs.GetChildLogger("channel"), db) + channel.UpsertPlugins(ctx, conf.ChannelsDir, logs.GetChildLogger("channel"), db) icinga2Launcher := &icinga2.Launcher{ Ctx: ctx, diff --git a/config.example.yml b/config.example.yml index 3d126a63..43f728af 100644 --- a/config.example.yml +++ b/config.example.yml @@ -7,7 +7,7 @@ #debug-password: "put-something-secret-here" icingaweb2-url: http://localhost/icingaweb2/ -#channel-plugin-dir: /usr/libexec/icinga-notifications/channel +#channels-dir: /usr/libexec/icinga-notifications/channels api-timeout: 1m database: diff --git a/internal/channel/plugin.go b/internal/channel/plugin.go index e1d50a91..9b0d8caf 100644 --- a/internal/channel/plugin.go +++ b/internal/channel/plugin.go @@ -31,7 +31,7 @@ type Plugin struct { // NewPlugin starts and returns a new plugin instance. If the start of the plugin fails, an error is returned func NewPlugin(pluginType string, logger *zap.SugaredLogger) (*Plugin, error) { - file := filepath.Join(daemon.Config().ChannelPluginDir, pluginType) + file := filepath.Join(daemon.Config().ChannelsDir, pluginType) logger.Debugw("Starting new channel plugin process", zap.String("path", file)) diff --git a/internal/daemon/config.go b/internal/daemon/config.go index e612cc6a..e930ec84 100644 --- a/internal/daemon/config.go +++ b/internal/daemon/config.go @@ -12,19 +12,19 @@ import ( ) type ConfigFile struct { - Listen string `yaml:"listen" default:"localhost:5680"` - DebugPassword string `yaml:"debug-password"` - ChannelPluginDir string `yaml:"channel-plugin-dir"` - ApiTimeout time.Duration `yaml:"api-timeout" default:"1m"` - Icingaweb2URL string `yaml:"icingaweb2-url"` - Database database.Config `yaml:"database"` - Logging logging.Config `yaml:"logging"` + Listen string `yaml:"listen" default:"localhost:5680"` + DebugPassword string `yaml:"debug-password"` + ChannelsDir string `yaml:"channels-dir"` + ApiTimeout time.Duration `yaml:"api-timeout" default:"1m"` + Icingaweb2URL string `yaml:"icingaweb2-url"` + Database database.Config `yaml:"database"` + Logging logging.Config `yaml:"logging"` } // SetDefaults implements the defaults.Setter interface. func (c *ConfigFile) SetDefaults() { - if defaults.CanUpdate(c.ChannelPluginDir) { - c.ChannelPluginDir = internal.LibExecDir + "/icinga-notifications/channel" + if defaults.CanUpdate(c.ChannelsDir) { + c.ChannelsDir = internal.LibExecDir + "/icinga-notifications/channels" } }