mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
add redact type, and begin wiring global redactors use per-collector redactors add a test of the 'data' collector and redaction handle literal string replacements remove redundant types and redact calls add proper redactor type, foundations of global redactors accept global redactors from the CLI, include sample redaction spec
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package collect
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/go-redis/redis/v7"
|
|
"github.com/pkg/errors"
|
|
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
|
|
)
|
|
|
|
func Redis(ctx *Context, databaseCollector *troubleshootv1beta1.Database) (map[string][]byte, error) {
|
|
databaseConnection := DatabaseConnection{}
|
|
|
|
opt, err := redis.ParseURL(databaseCollector.URI)
|
|
if err != nil {
|
|
databaseConnection.Error = err.Error()
|
|
} else {
|
|
client := redis.NewClient(opt)
|
|
stringResult := client.Info("server")
|
|
|
|
if stringResult.Err() != nil {
|
|
databaseConnection.Error = stringResult.Err().Error()
|
|
}
|
|
|
|
databaseConnection.IsConnected = stringResult.Err() == nil
|
|
|
|
if databaseConnection.Error == "" {
|
|
lines := strings.Split(stringResult.Val(), "\n")
|
|
for _, line := range lines {
|
|
lineParts := strings.Split(line, ":")
|
|
if len(lineParts) == 2 {
|
|
if lineParts[0] == "redis_version" {
|
|
databaseConnection.Version = strings.TrimSpace(lineParts[1])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
b, err := json.Marshal(databaseConnection)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to marshal database connection")
|
|
}
|
|
|
|
collectorName := databaseCollector.CollectorName
|
|
if collectorName == "" {
|
|
collectorName = "redis"
|
|
}
|
|
|
|
redisOutput := map[string][]byte{
|
|
fmt.Sprintf("redis/%s.json", collectorName): b,
|
|
}
|
|
|
|
return redisOutput, nil
|
|
}
|