Skip to content

Commit

Permalink
Add option for moved filebeat modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Dec 6, 2018
1 parent 6442d5f commit 9af3f75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions filebeat/fileset/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"

"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/kibana"
Expand Down Expand Up @@ -57,6 +58,12 @@ func newModuleRegistry(modulesPath string,
continue
}

// Look for moved modules
if module, moved := getCurrentModuleName(modulesPath, mcfg.Module); moved {
logp.Warn("Using old name '%s' for module '%s', please update your configuration", mcfg.Module, module)
mcfg.Module = module
}

reg.registry[mcfg.Module] = map[string]*Fileset{}
moduleFilesets, err := getModuleFilesets(modulesPath, mcfg.Module)
if err != nil {
Expand Down Expand Up @@ -180,7 +187,27 @@ func mcfgFromConfig(cfg *common.Config) (*ModuleConfig, error) {
return &mcfg, nil
}

func getCurrentModuleName(modulePath, module string) (string, bool) {
moduleConfigPath := filepath.Join(modulePath, module, "module.yml")
logp.Info("path: %s, module: %s, path: %s", modulePath, module, moduleConfigPath)
d, err := ioutil.ReadFile(moduleConfigPath)
if err != nil {
return module, false
}

var moduleConfig struct {
MovedTo string `yaml:"movedTo"`
}
err = yaml.Unmarshal(d, &moduleConfig)
if err == nil && moduleConfig.MovedTo != "" {
return moduleConfig.MovedTo, true
}

return module, false
}

func getModuleFilesets(modulePath, module string) ([]string, error) {
module, _ = getCurrentModuleName(modulePath, module)
fileInfos, err := ioutil.ReadDir(filepath.Join(modulePath, module))
if err != nil {
return []string{}, err
Expand Down
1 change: 1 addition & 0 deletions filebeat/module/apache2/module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
movedTo: apache

0 comments on commit 9af3f75

Please sign in to comment.