diff --git a/main.go b/main.go index 140c59e..52ff1a6 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/NETWAYS/support-collector/modules/icingadb" "github.com/NETWAYS/support-collector/modules/icingadirector" "github.com/NETWAYS/support-collector/modules/icingaweb2" + "github.com/NETWAYS/support-collector/modules/keepalived" "github.com/NETWAYS/support-collector/modules/influxdb" "github.com/NETWAYS/support-collector/modules/mysql" "github.com/NETWAYS/support-collector/modules/postgresql" @@ -50,6 +51,7 @@ var modules = map[string]func(*collection.Collection){ "icinga2": icinga2.Collect, "icingaweb2": icingaweb2.Collect, "icinga-director": icingadirector.Collect, + "keepalived": keepalived.Collect, "mysql": mysql.Collect, "influxdb": influxdb.Collect, "postgresql": postgresql.Collect, @@ -67,6 +69,7 @@ var ( "icingaweb2", "icinga-director", "icingadb", + "keepalived", "mysql", "influxdb", "postgresql", diff --git a/modules/keepalived/collector.go b/modules/keepalived/collector.go new file mode 100644 index 0000000..1a28e88 --- /dev/null +++ b/modules/keepalived/collector.go @@ -0,0 +1,56 @@ +package keepalived + +import ( + "github.com/NETWAYS/support-collector/pkg/collection" + "github.com/NETWAYS/support-collector/pkg/obfuscate" + "os" +) + +const ModuleName = "keepalived" + +var relevantPaths = []string{ + "/etc/keepalived", +} + +var files = []string{ + "/etc/keepalived/keepalived.conf", +} + +var commands = map[string][]string{ + "version.txt": {"keepalived", "--version"}, +} + +var obfuscators = []*obfuscate.Obfuscator{ + // auth_pass in keepalived.conf + obfuscate.NewFile(`(?i)(auth_pass) (.*)`, `conf`), +} + +func Detect() bool { + for _, path := range relevantPaths { + _, err := os.Stat(path) + if err == nil { + return true + } + } + + return false +} + +func Collect(c *collection.Collection) { + if !Detect() { + c.Log.Info("Could not find keepalived") + return + } + + c.Log.Info("Collecting keepalived information") + + c.RegisterObfuscators(obfuscators...) + + for _, file := range files { + c.AddFiles(ModuleName, file) + } + + for name, cmd := range commands { + c.AddCommandOutput(ModuleName+"/"+name, cmd[0], cmd[1:]...) + } +} diff --git a/modules/keepalived/collector_test.go b/modules/keepalived/collector_test.go new file mode 100644 index 0000000..d9daf29 --- /dev/null +++ b/modules/keepalived/collector_test.go @@ -0,0 +1,21 @@ +package keepalived + +import ( + "bytes" + "github.com/NETWAYS/support-collector/pkg/collection" + "github.com/NETWAYS/support-collector/pkg/obfuscate" + "github.com/NETWAYS/support-collector/pkg/util" + "testing" +) + +func TestCollect(t *testing.T) { + c := collection.New(&bytes.Buffer{}) + + Collect(c) +} + +func TestObfuscators(t *testing.T) { + util.AssertObfuscationExample(t, obfuscators, obfuscate.KindFile, "/etc/keepalived/keepalived.conf") + + util.AssertAllObfuscatorsTested(t, obfuscators) +} diff --git a/modules/keepalived/testdata/etc/keepalived/keepalived.conf b/modules/keepalived/testdata/etc/keepalived/keepalived.conf new file mode 100644 index 0000000..eaa7026 --- /dev/null +++ b/modules/keepalived/testdata/etc/keepalived/keepalived.conf @@ -0,0 +1,14 @@ +vrrp_instance VI_1 { + state MASTER + interface eth0 + virtual_router_id 51 + priority 255 + advert_int 1 + authentication { + auth_type PASS + auth_pass pwd123! + } + virtual_ipaddress { + 192.168.122.200/24 + } +} diff --git a/modules/keepalived/testdata/etc/keepalived/keepalived.conf.obfuscated b/modules/keepalived/testdata/etc/keepalived/keepalived.conf.obfuscated new file mode 100644 index 0000000..684c564 --- /dev/null +++ b/modules/keepalived/testdata/etc/keepalived/keepalived.conf.obfuscated @@ -0,0 +1,14 @@ +vrrp_instance VI_1 { + state MASTER + interface eth0 + virtual_router_id 51 + priority 255 + advert_int 1 + authentication { + auth_type PASS + + } + virtual_ipaddress { + 192.168.122.200/24 + } +}