Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: 1.24
go-version: 1.25

- name: Test
run: go test -v ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.1.6
version: v2.11.2
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/NETWAYS/support-collector

go 1.24.0

toolchain go1.24.9
go 1.25.0

require (
github.com/Showmax/go-fqdn v1.0.0
Expand All @@ -16,7 +14,7 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-isatty v0.0.22 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/sys v0.43.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHP
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -19,6 +21,8 @@ github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
4 changes: 2 additions & 2 deletions internal/collection/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
)

type File struct {
io.Writer

Name string
Source string
Modified time.Time
Data []byte

io.Writer
}

var reIgnoreFiles = regexp.MustCompile(`(^\.|~$|\.key$|\.csr$|\.crt$|\.pem$)`)
Expand Down
11 changes: 9 additions & 2 deletions internal/collection/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ func LoadGitRepoInfo(path string) (*GitRepoInfo, error) {
}

func ExecGitCommand(dir string, command ...string) ([]byte, error) {
arguments := []string{"--git-dir", filepath.Join(dir, ".git"), "--work-tree", dir}
arguments = append(arguments, command...)
arguments := make([]string, 4+len(command))
arguments[0] = "--git-dir"
arguments[1] = filepath.Join(dir, ".git")
arguments[2] = "--work-tree"
arguments[3] = dir

for i := range command {
arguments[i+4] = command[i]
}

return LoadCommandOutput("git", arguments...)
}
23 changes: 18 additions & 5 deletions internal/collection/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func DetectPackageManager() string {
priority := []string{PackageManagerDebian, PackageManagerRPM}

for _, name := range priority {
if _, err := exec.LookPath(name); err == nil {
_, err := exec.LookPath(name)
if err == nil {
FoundPackageManager = name
return name
}
Expand All @@ -40,13 +41,25 @@ func DetectPackageManager() string {
func ListInstalledPackagesRaw(pattern ...string) ([]byte, error) {
switch DetectPackageManager() {
case PackageManagerRPM:
arguments := []string{"-qa", "--queryformat", rpmQueryFormat}
arguments = append(arguments, pattern...)
arguments := make([]string, 3+len(pattern))
arguments[0] = "-qa"
arguments[1] = "--queryformat"
arguments[2] = rpmQueryFormat

for i := range pattern {
arguments[i+3] = pattern[i]
}

return LoadCommandOutput("rpm", arguments...)
case PackageManagerDebian:
arguments := []string{"-W", "-f", dpkgQueryFormat}
arguments = append(arguments, pattern...)
arguments := make([]string, 3+len(pattern))
arguments[0] = "-W"
arguments[1] = "-f"
arguments[2] = dpkgQueryFormat

for i := range pattern {
arguments[i+3] = pattern[i]
}

return LoadCommandOutput("dpkg-query", arguments...)
default:
Expand Down
6 changes: 4 additions & 2 deletions internal/collection/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func DetectServiceManager() string {
}

for command, manager := range priority {
if _, err := exec.LookPath(command); err == nil {
_, err := exec.LookPath(command)
if err == nil {
FoundServiceManager = manager
return manager
}
Expand Down Expand Up @@ -84,7 +85,8 @@ func FindServicesSystemd(pattern string) (map[string]string, error) {

for _, file := range files {
// Skip the file if it is a symlink
if stat, err := os.Lstat(file); err != nil || IsSymlink(stat) {
stat, err := os.Lstat(file)
if err != nil || IsSymlink(stat) {
continue
}

Expand Down
9 changes: 6 additions & 3 deletions internal/config/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ func (w *Wizard) newStringPrompt(callback *string, usage string, required bool)
return
}
} else {
if err := w.Scanner.Err(); err != nil {
err := w.Scanner.Err()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, "reading standard input:", err)
return
}
Expand All @@ -252,7 +253,8 @@ func (w *Wizard) newStringPromptWithDefault(callback *string, defaultValue, usag
return
}
} else {
if err := w.Scanner.Err(); err != nil {
err := w.Scanner.Err()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, "reading standard input:", err)
return
}
Expand Down Expand Up @@ -283,7 +285,8 @@ func (w *Wizard) newIntPromptWithDefault(callback *int, defaultValue int, usage
return
}
} else {
if err := w.Scanner.Err(); err != nil {
err := w.Scanner.Err()
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, "reading standard input:", err)
return
}
Expand Down
1 change: 1 addition & 0 deletions internal/obfuscate/obfuscate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
// Replacement will be iterated, so all matches or matched groups will be replaced.
type Obfuscator struct {
Kind

ShouldAffect []*regexp.Regexp
ReplacePattern *regexp.Regexp
ObfuscatedFiles []string
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ func main() {
conf := config.GetControlDefaultObject()

// Add and parse flags
if err := parseFlags(); err != nil {
err := parseFlags()
if err != nil {
logrus.Fatal(err)
}

// Read input from answer-file if provided
// Needs to done after parsing flags to have the value for answerFile
if answerFile != "" {
if err := config.ReadAnswerFile(answerFile, &conf); err != nil {
err := config.ReadAnswerFile(answerFile, &conf)
if err != nil {
logrus.Fatal(err)
}

Expand Down Expand Up @@ -139,6 +141,7 @@ func main() {

// Initialize new metrics and defer function to save it to json
c.Metric = metrics.New(getVersion())

defer func() {
// Save metrics to file
body, err := json.Marshal(c.Metric)
Expand Down
6 changes: 4 additions & 2 deletions modules/base/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ func Collect(c *collection.Collection) {
CollectKernelInfo(c)

// Check if apparmor is installed and get status
if _, err := exec.LookPath("apparmor_status"); err == nil {
_, err := exec.LookPath("apparmor_status")
if err == nil {
c.AddCommandOutput(filepath.Join(ModuleName, "apparmor-status.txt"), "apparmor_status")
}

// Check if we can detect SELinux enforcing
for _, cmd := range []string{"sestatus", "getenforce"} {
if _, err := exec.LookPath(cmd); err == nil {
_, err := exec.LookPath(cmd)
if err == nil {
c.AddCommandOutput(filepath.Join(ModuleName, "selinux-status.txt"), cmd)
break
}
Expand Down
2 changes: 1 addition & 1 deletion modules/base/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func CharsToString(chars []int8) string {
break
}

s[i] = byte(chars[i])
s[i] = byte(chars[i]) //nolint: gosec
}

return string(s[0:i])
Expand Down
3 changes: 2 additions & 1 deletion modules/graphite/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func Collect(c *collection.Collection) {
}

for name, element := range journalctlLogs {
if service, err := collection.FindServices(element.Service); err == nil && len(service) > 0 {
service, err := collection.FindServices(element.Service)
if err == nil && len(service) > 0 {
c.AddJournalLog(filepath.Join(ModuleName, name), element.Service)
}
}
Expand Down
6 changes: 4 additions & 2 deletions modules/icinga2/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func Collect(c *collection.Collection) {
c.AddFilesIfFound(ModuleName, pluginFiles...)

for _, file := range optionalFiles {
if _, err := os.Stat(file); err != nil {
_, err := os.Stat(file)
if err != nil {
continue
}

Expand Down Expand Up @@ -162,7 +163,8 @@ func Collect(c *collection.Collection) {
c.Log.Debugf("New API endpoint found: '%s'. Trying...", e.Address)

// Check if endpoint is reachable
if err := e.IsReachable(5 * time.Second); err != nil { //nolint:mnd
err := e.IsReachable(5 * time.Second)
if err != nil { //nolint:mnd
c.Log.Warn(err)
continue
}
Expand Down
7 changes: 6 additions & 1 deletion modules/icinga2/icingaapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ func newClient() *http.Client {
// IsReachable checks if the endpoint is reachable within 5 sec
func (endpoint *Endpoint) IsReachable(timeout time.Duration) error {
// try to dial tcp connection within 5 seconds
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", endpoint.Address, endpoint.Port), timeout)
context, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

var dialer net.Dialer

conn, err := dialer.DialContext(context, "tcp", fmt.Sprintf("%s:%d", endpoint.Address, endpoint.Port))
if err != nil {
return fmt.Errorf("cant connect to endpoint '%s' within 5 seconds: %w", endpoint.Address, err)
}
Expand Down
6 changes: 4 additions & 2 deletions modules/icingadb/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func Collect(c *collection.Collection) {
}

for _, file := range optionalFiles {
if _, err := os.Stat(file); err != nil {
_, err := os.Stat(file)
if err != nil {
continue
}

Expand All @@ -87,7 +88,8 @@ func Collect(c *collection.Collection) {
}

for name, element := range journalctlLogs {
if service, err := collection.FindServices(element.Service); err == nil && len(service) > 0 {
service, err := collection.FindServices(element.Service)
if err == nil && len(service) > 0 {
c.AddJournalLog(filepath.Join(ModuleName, name), element.Service)
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/icingadirector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func Collect(c *collection.Collection) {

if c.Detailed {
for name, element := range journalctlLogs {
if service, err := collection.FindServices(element.Service); err == nil && len(service) > 0 {
service, err := collection.FindServices(element.Service)
if err == nil && len(service) > 0 {
c.AddJournalLog(filepath.Join(ModuleName, name), element.Service)
}
}
Expand Down
6 changes: 4 additions & 2 deletions modules/icingaweb2/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func Collect(c *collection.Collection) {
// Detect PHP related packages and services
c.AddInstalledPackagesRaw(filepath.Join(ModuleName, "packages-php.txt"), "*php*")

if services, err := collection.FindServices("*php*-fpm"); err == nil && len(services) > 0 {
services, err := collection.FindServices("*php*-fpm")
if err == nil && len(services) > 0 {
for _, name := range services {
c.AddServiceStatusRaw(filepath.Join(ModuleName, "service-"+name+".txt"), name)
}
Expand All @@ -112,7 +113,8 @@ func Collect(c *collection.Collection) {
}

for name, element := range journalctlLogs {
if service, err := collection.FindServices(element.Service); err == nil && len(service) > 0 {
service, err := collection.FindServices(element.Service)
if err == nil && len(service) > 0 {
c.AddJournalLog(filepath.Join(ModuleName, name), element.Service)
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/mysql/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func Collect(c *collection.Collection) {
}

for _, file := range optionalFiles {
if _, err := os.Stat(file); err != nil {
_, err := os.Stat(file)
if err != nil {
continue
}

Expand Down
6 changes: 4 additions & 2 deletions modules/webservers/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func Collect(c *collection.Collection) {
)

for _, file := range optionalFiles {
if _, err := os.Stat(file); err != nil {
_, err := os.Stat(file)
if err != nil {
continue
}

Expand All @@ -71,7 +72,8 @@ func Collect(c *collection.Collection) {
}

for _, file := range possibleDaemons {
if _, err := os.Stat(file); err != nil {
_, err := os.Stat(file)
if err != nil {
continue
}

Expand Down