-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfa7619
commit 3edb9c3
Showing
13 changed files
with
392 additions
and
412 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
general: | ||
outputFile: support-collector_icinga-dev_20241010-1037.zip | ||
enabledModules: | ||
- all | ||
disabledModules: [ ] | ||
extraObfuscators: [ ] | ||
detailedCollection: true | ||
commandTimeout: 1m0s | ||
icinga2: | ||
endpoints: | ||
- address: localhost | ||
port: 5665 | ||
username: poweruser | ||
password: poweruser | ||
- address: 127.0.0.1 | ||
port: 5665 | ||
username: poweruser | ||
password: poweruser |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"gopkg.in/yaml.v3" | ||
"io" | ||
"os" | ||
) | ||
|
||
const defaultAnswerFileName = "answer-file.yml" | ||
|
||
// GenerateDefaultAnswerFile creates a new answer-file with default values in current dir | ||
func GenerateDefaultAnswerFile() error { | ||
file, err := os.Create(defaultAnswerFileName) | ||
if err != nil { | ||
return fmt.Errorf("could not create answer file: %w", err) | ||
} | ||
|
||
defer file.Close() | ||
|
||
defaults := GetControlDefaultObject() | ||
|
||
yamlData, err := yaml.Marshal(defaults) | ||
if err != nil { | ||
return fmt.Errorf("could not marshal yamldata for answer-file: %w", err) | ||
} | ||
|
||
_, err = io.WriteString(file, string(yamlData)) | ||
if err != nil { | ||
return fmt.Errorf("could not write to answer file: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// ReadAnswerFile reads given values from answerFile and returns new Config | ||
func ReadAnswerFile(answerFile string, conf *Config) error { | ||
data, err := os.ReadFile(answerFile) | ||
if err != nil { | ||
return fmt.Errorf("could not read answer file: %w", err) | ||
} | ||
|
||
err = yaml.Unmarshal(data, &conf) | ||
if err != nil { | ||
return fmt.Errorf("could not unmarshal answer file: %w", err) | ||
} | ||
|
||
return nil | ||
} |
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,80 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"github.com/NETWAYS/support-collector/internal/util" | ||
"github.com/NETWAYS/support-collector/modules/icinga2/icingaApi" | ||
"slices" | ||
"time" | ||
) | ||
|
||
var ( | ||
ModulesOrder = []string{ | ||
"ansible", | ||
"base", | ||
"corosync", | ||
"elastic", | ||
"foreman", | ||
"grafana", | ||
"graphite", | ||
"graylog", | ||
"icinga-director", | ||
"icinga2", | ||
"icingadb", | ||
"icingaweb2", | ||
"influxdb", | ||
"keepalived", | ||
"mongodb", | ||
"mysql", | ||
"postgresql", | ||
"prometheus", | ||
"puppet", | ||
"redis", | ||
"webservers", | ||
} | ||
) | ||
|
||
type Config struct { | ||
General General `yaml:"general" json:"general"` | ||
Icinga2 Icinga2 `yaml:"icinga2" json:"icinga2"` | ||
} | ||
|
||
type General struct { | ||
OutputFile string `yaml:"outputFile" json:"outputFile"` | ||
AnswerFile string `yaml:"answerFile,omitempty" json:"answerFile,omitempty"` | ||
EnabledModules []string `yaml:"enabledModules" json:"enabledModules"` | ||
DisabledModules []string `yaml:"disabledModules" json:"disabledModules"` | ||
ExtraObfuscators []string `yaml:"extraObfuscators" json:"extraObfuscators"` | ||
DetailedCollection bool `yaml:"detailedCollection" json:"detailedCollection"` | ||
CommandTimeout time.Duration `yaml:"commandTimeout" json:"commandTimeout"` | ||
} | ||
|
||
type Icinga2 struct { | ||
Endpoints []icingaApi.Endpoint `yaml:"endpoints" json:"endpoints"` | ||
} | ||
|
||
// GetControlDefaultObject returns a new Config object with some pre-defined default values | ||
func GetControlDefaultObject() Config { | ||
return Config{ | ||
General: General{ | ||
OutputFile: util.BuildFileName(), | ||
AnswerFile: "", | ||
EnabledModules: []string{"all"}, | ||
DisabledModules: nil, | ||
ExtraObfuscators: nil, | ||
DetailedCollection: true, | ||
CommandTimeout: 60 * time.Second, | ||
}, | ||
Icinga2: Icinga2{}, | ||
} | ||
} | ||
|
||
// ValidateConfig validates the given config.Config for errors. Returns []error | ||
func ValidateConfig(conf Config) (errors []error) { | ||
for _, name := range conf.General.EnabledModules { | ||
if !slices.Contains(ModulesOrder, name) { | ||
errors = append(errors, fmt.Errorf("invalid module '%s' provided. Cant be enabled", name)) | ||
} | ||
} | ||
return errors | ||
} |
Oops, something went wrong.