-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
146 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |