Skip to content

Commit

Permalink
Add module redis (#133)
Browse files Browse the repository at this point in the history
fixes #128
  • Loading branch information
tbauriedel authored Sep 3, 2024
1 parent e942ea8 commit 2f2a912
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 33 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

# NETWAYS support collector

The support collector allows to collect relevant information from servers. The resulting ZIP file can be given to second
to get an insight into the system.
The support collector allows to collect relevant information from servers. The resulting ZIP file can be given to second to get an insight into the system.

> **WARNING:** DO NOT transfer the generated file over insecure connections, it contains potential sensitive
> information!
Expand Down Expand Up @@ -40,10 +39,8 @@ By default, we collect all we can find. You can control this by only enabling ce

If you want to see what is collected, add `--verbose`

To collect advanced data for module `Icinga 2`, you can use the Icinga 2 API to collect data from all endpoints
provided.
The API requests are performed with a global API user you have to create yourself. Just create that user in a global
zone like 'director-global' to sync it to all endpoints
To collect advanced data for module `Icinga 2`, you can use the Icinga 2 API to collect data from all endpoints provided.
The API requests are performed with a global API user you have to create yourself. Just create that user in a global zone like 'director-global' to sync it to all endpoints

| Short | Long | Description |
|:-----:|:------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand All @@ -62,18 +59,17 @@ zone like 'director-global' to sync it to all endpoints

## Modules

A brief overview about the modules, you can check the source code under [modules](modules) for what exactly is
collected.
A brief overview about the modules, you can check the source code under [modules](modules) for what exactly is collected.

Most modules check if the component is installed before trying to collect data. If the module is not detected, it will
not be collected.
Most modules check if the component is installed before trying to collect data. If the module is not detected, it will not be collected.

| Module name | Description |
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| ansible | Configuration and packages |
| base | Basic information about the system (operating system, kernel, memory, cpu, processes, repositories, firewalls, etc.) |
| corosync | Includes corosync and pacemaker. Collects configuration, logs, packages and service status |
| elastic | Includes elasticsearch, logstash and kibana. Collects configuration, packages and service status |
| foreman | Configuration, logs, packages and service status |
| grafana | Configuration, logs, plugins, packages and service status |
| graphite | Includes graphite and carbon. Collects configuration, logs, python / pip version and list, packages and service status |
| graylog | Configuration, packages and service status |
Expand All @@ -88,8 +84,8 @@ not be collected.
| postgresql | Configuration, logs, packages and service status |
| prometheus | Configuration, packages and service status |
| puppet | Configuration, logs, module list, packages and service status |
| redis | Configuration, logs, packages and service status |
| webservers | Includes apache2, httpd and nginx. Collects configuration, logs, packages and service status |
| foreman | Configuration, logs, packages and service status |

## Supported systems

Expand Down
47 changes: 25 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/NETWAYS/support-collector/internal/arguments"
"github.com/NETWAYS/support-collector/internal/metrics"
"github.com/NETWAYS/support-collector/modules/redis"
flag "github.com/spf13/pflag"
"os"
"path/filepath"
Expand Down Expand Up @@ -60,50 +61,52 @@ email, it contains potential sensitive information!
`

var modules = map[string]func(*collection.Collection){
"ansible": ansible.Collect,
"base": base.Collect,
"webservers": webservers.Collect,
"corosync": corosync.Collect,
"elastic": elastic.Collect,
"foreman": foreman.Collect,
"grafana": grafana.Collect,
"graphite": graphite.Collect,
"graylog": graylog.Collect,
"icinga-director": icingadirector.Collect,
"icinga2": icinga2.Collect,
"icingadb": icingadb.Collect,
"icingaweb2": icingaweb2.Collect,
"icinga-director": icingadirector.Collect,
"elastic": elastic.Collect,
"corosync": corosync.Collect,
"influxdb": influxdb.Collect,
"keepalived": keepalived.Collect,
"mongodb": mongodb.Collect,
"mysql": mysql.Collect,
"influxdb": influxdb.Collect,
"postgresql": postgresql.Collect,
"prometheus": prometheus.Collect,
"ansible": ansible.Collect,
"puppet": puppet.Collect,
"grafana": grafana.Collect,
"graphite": graphite.Collect,
"graylog": graylog.Collect,
"icingadb": icingadb.Collect,
"foreman": foreman.Collect,
"redis": redis.Collect,
"webservers": webservers.Collect,
}

var (
moduleOrder = []string{
"ansible",
"base",
"webservers",
"icinga2",
"icingaweb2",
"corosync",
"elastic",
"foreman",
"grafana",
"graphite",
"graylog",
"icinga-director",
"icinga2",
"icingadb",
"elastic",
"corosync",
"icingaweb2",
"influxdb",
"keepalived",
"mongodb",
"mysql",
"influxdb",
"postgresql",
"prometheus",
"ansible",
"puppet",
"grafana",
"graphite",
"graylog",
"foreman",
"redis",
"webservers",
}
)

Expand Down
76 changes: 76 additions & 0 deletions modules/redis/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package redis

import (
"github.com/NETWAYS/support-collector/internal/collection"
"github.com/NETWAYS/support-collector/internal/obfuscate"
"github.com/NETWAYS/support-collector/internal/util"
"path/filepath"
)

const ModuleName = "redis"

var relevantPaths = []string{
"/etc/redis",
"/etc/redis.conf",
}

var files = []string{
"/etc/redis*",
}

var optionalFiles = []string{
"/etc/logrotate.d/redis*",
}

var detailedFiles = []string{
"/var/log/redis/redis-server.log",
"/var/log/redis/redis.log",
}

var possibleDaemons = []string{
"/lib/systemd/system/redis-server.service",
"/lib/systemd/system/[email protected]",
"/etc/systemd/system/redis*",
"/usr/lib/systemd/system/redis*",
}

var services = []string{
"redis-server",
}

var obfuscators = []*obfuscate.Obfuscator{
obfuscate.NewFile(`(?i)(?:requirepass)\s*(.*)`, `conf`),
}

func Collect(c *collection.Collection) {
if !util.ModuleExists(relevantPaths) {
c.Log.Info("Could not find redis")
return
}

c.Log.Info("Collecting redis information")

c.RegisterObfuscators(obfuscators...)

for _, file := range files {
c.AddFiles(ModuleName, file)
}

for _, file := range optionalFiles {
c.AddFilesIfFound(ModuleName, file)
}

for _, file := range possibleDaemons {
c.AddFilesIfFound(ModuleName, file)
}

for _, service := range services {
c.AddServiceStatusRaw(filepath.Join(ModuleName, "service-"+service+".txt"), service)
}

if c.Detailed {
for _, file := range detailedFiles {
c.AddFilesIfFound(ModuleName, file)
}
}
}
30 changes: 30 additions & 0 deletions modules/redis/collector_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package redis

import (
"bytes"
"github.com/NETWAYS/support-collector/internal/collection"
"github.com/NETWAYS/support-collector/internal/obfuscate"
"github.com/NETWAYS/support-collector/internal/util"
"github.com/stretchr/testify/assert"
"testing"
)

func TestCollect(t *testing.T) {
if !util.ModuleExists(relevantPaths) {
t.Skip("could not find redis in the test environment")
return
}

c := collection.New(&bytes.Buffer{})

Collect(c)

err := c.Close()
assert.NoError(t, err)
}

func TestObfuscator(t *testing.T) {
util.AssertObfuscationExample(t, obfuscators, obfuscate.KindFile, "/etc/redis.conf")

util.AssertAllObfuscatorsTested(t, obfuscators)
}
4 changes: 4 additions & 0 deletions modules/redis/testdata/etc/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
daemonize yes
port 6379
bind 127.0.0.1
requirepass 18fgJ2hfjJahgsfh8j0jfhS
4 changes: 4 additions & 0 deletions modules/redis/testdata/etc/redis.conf.obfuscated
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
daemonize yes
port 6379
bind 127.0.0.1
requirepass <HIDDEN>

0 comments on commit 2f2a912

Please sign in to comment.