diff --git a/main.go b/main.go index 52ff1a6..b545fe1 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/NETWAYS/support-collector/modules/ansible" "github.com/NETWAYS/support-collector/modules/base" + "github.com/NETWAYS/support-collector/modules/corosync" "github.com/NETWAYS/support-collector/modules/grafana" "github.com/NETWAYS/support-collector/modules/graphite" "github.com/NETWAYS/support-collector/modules/icinga2" @@ -51,6 +52,7 @@ var modules = map[string]func(*collection.Collection){ "icinga2": icinga2.Collect, "icingaweb2": icingaweb2.Collect, "icinga-director": icingadirector.Collect, + "corosync": corosync.Collect, "keepalived": keepalived.Collect, "mysql": mysql.Collect, "influxdb": influxdb.Collect, @@ -69,6 +71,7 @@ var ( "icingaweb2", "icinga-director", "icingadb", + "corosync", "keepalived", "mysql", "influxdb", diff --git a/modules/corosync/collector.go b/modules/corosync/collector.go new file mode 100644 index 0000000..e7b39e5 --- /dev/null +++ b/modules/corosync/collector.go @@ -0,0 +1,58 @@ +package corosync + +import ( + "github.com/NETWAYS/support-collector/pkg/collection" + "os" +) + +const ModuleName = "corosync" + +var relevantPaths = []string{ + "/etc/corosync/service.d", +} + +var possibleDaemons = []string{ + "/lib/systemd/system/corosync.service", + "/usr/lib/systemd/system/corosync.service", +} + +var files = []string{ + "/etc/corosync/corosync.conf", + "/var/lib/pacemaker/cib/cib.xml", +} + +var commands = map[string][]string{ + "version.txt": {"corosync", "-v"}, +} + +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 corosync") + return + } + + c.Log.Info("Collecting corosync information") + + for _, file := range files { + c.AddFiles(ModuleName, file) + } + + for _, file := range possibleDaemons { + c.AddFilesIfFound(ModuleName, file) + } + + for name, cmd := range commands { + c.AddCommandOutput(ModuleName+"/"+name, cmd[0], cmd[1:]...) + } +} diff --git a/modules/corosync/collector_test.go b/modules/corosync/collector_test.go new file mode 100644 index 0000000..541d3a4 --- /dev/null +++ b/modules/corosync/collector_test.go @@ -0,0 +1,13 @@ +package corosync + +import ( + "bytes" + "github.com/NETWAYS/support-collector/pkg/collection" + "testing" +) + +func TestCollect(t *testing.T) { + c := collection.New(&bytes.Buffer{}) + + Collect(c) +} diff --git a/modules/corosync/testdata/etc/corosync/corosync.conf b/modules/corosync/testdata/etc/corosync/corosync.conf new file mode 100644 index 0000000..c993647 --- /dev/null +++ b/modules/corosync/testdata/etc/corosync/corosync.conf @@ -0,0 +1,31 @@ +totem { + version: 2 + cluster_name: lbcluster + transport: udpu + interface { + ringnumber: 0 + bindnetaddr: 127.0.0.1 + broadcast: yes + mcastport: 5405 + } +} + +quorum { + provider: corosync_votequorum + two_node: 1 +} + +nodelist { + node { + ring0_addr: 127.0.0.1 + name: primary + nodeid: 1 + } +} + +logging { + to_logfile: yes + logfile: /var/log/corosync/corosync.log + to_syslog: yes + timestamp: on +} diff --git a/modules/corosync/testdata/etc/corosync/service.d/pcmk b/modules/corosync/testdata/etc/corosync/service.d/pcmk new file mode 100644 index 0000000..a990a02 --- /dev/null +++ b/modules/corosync/testdata/etc/corosync/service.d/pcmk @@ -0,0 +1,4 @@ +service { + name: pacemaker + ver: 1 +} diff --git a/modules/corosync/testdata/var/lib/pacemaker/cib/cib.xml b/modules/corosync/testdata/var/lib/pacemaker/cib/cib.xml new file mode 100644 index 0000000..a9c8ab2 --- /dev/null +++ b/modules/corosync/testdata/var/lib/pacemaker/cib/cib.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +