Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependency for disabled modules #130

Merged
merged 1 commit into from
Aug 28, 2024
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
6 changes: 2 additions & 4 deletions internal/arguments/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ var (
)

const interactiveHelpText = `Welcome to the support-collector argument wizard!
We will guide you through all required details.

Available modules are: %s`
We will guide you through all required details.`

type Argument struct {
Name string
Expand All @@ -44,7 +42,7 @@ func New() Handler {
}

func (args *Handler) CollectArgsFromStdin(availableModules string) []error {
fmt.Printf(interactiveHelpText+"\n\n", availableModules)
fmt.Printf("%s\n\nAvailable modules are: %s\n\n", interactiveHelpText, availableModules)

errors := make([]error, 0, len(args.arguments))

Expand Down
22 changes: 14 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,19 @@ func init() {
// Run specific arguments
args.NewPromptStringVar(&outputFile, "output", buildFileName(), "Filename for resulting zip", true, nil)
args.NewPromptStringSliceVar(&enabledModules, "enable", moduleOrder, "Enabled modules for collection (comma separated)", false, nil)
args.NewPromptStringSliceVar(&disabledModules, "disable", []string{}, "Explicit disabled modules for collection (comma separated)", false, nil)
args.NewPromptStringSliceVar(&disabledModules, "disable", []string{}, "Explicit disabled modules for collection (comma separated)", false, func() bool {
if len(enabledModules) == 0 || len(enabledModules) == len(moduleOrder) {
return true
}

return false
})
args.NewPromptBoolVar(&noDetailedCollection, "no-details", false, "Disable detailed collection including logs and more", nil)

// Icinga 2 specific arguments
args.NewPromptStringVar(&icinga2.APICred.Username, "icinga2-api-user", "", "Icinga 2: Username of global API user to collect data about Icinga 2 Infrastructure", false, icinga2Enabled)
args.NewPromptStringVar(&icinga2.APICred.Password, "icinga2-api-pass", "", "Icinga 2: Password for global API user to collect data about Icinga 2 Infrastructure", false, icinga2Enabled)
args.NewPromptStringSliceVar(&icinga2.APIEndpoints, "icinga2-api-endpoints", []string{}, "Icinga 2: Comma separated list of API Endpoints (including port) to collect data from. FQDN or IP address must be reachable. (Example: i2-master01.local:5665)", false, icinga2Enabled)
args.NewPromptStringVar(&icinga2.APICred.Username, "icinga2-api-user", "", "Icinga 2: Username of global API user to collect data about Icinga 2 Infrastructure", false, isIcingaEnabled)
args.NewPromptStringVar(&icinga2.APICred.Password, "icinga2-api-pass", "", "Icinga 2: Password for global API user to collect data about Icinga 2 Infrastructure", false, isIcingaEnabled)
args.NewPromptStringSliceVar(&icinga2.APIEndpoints, "icinga2-api-endpoints", []string{}, "Icinga 2: Comma separated list of API Endpoints (including port) to collect data from. FQDN or IP address must be reachable. (Example: i2-master01.local:5665)", false, isIcingaEnabled)

flag.CommandLine.SortFlags = false

Expand Down Expand Up @@ -178,7 +184,7 @@ func buildFileName() string {
return FilePrefix + "_" + util.GetHostnameWithoutDomain() + "_" + time.Now().Format("20060102-1504") + ".zip"
}

func icinga2Enabled() bool {
func isIcingaEnabled() bool {
for _, name := range enabledModules {
if name == "icinga2" {
return true
Expand Down Expand Up @@ -268,17 +274,17 @@ func NewCollection(outputFile string) (*collection.Collection, func()) {
}

c := collection.New(file)
c.Log.SetLevel(logrus.DebugLevel)

consoleLevel := logrus.InfoLevel
if verbose {
// logrus.StandardLogger().SetLevel(logrus.DebugLevel)
consoleLevel = logrus.DebugLevel
}

c.Log.SetLevel(consoleLevel)

// Add console log output via logrus.Hook
c.Log.AddHook(&util.ExtraLogHook{
Formatter: &logrus.TextFormatter{ForceColors: true},
Formatter: &logrus.TextFormatter{ForceColors: true, FullTimestamp: true, TimestampFormat: "15:04:05"},
Writer: colorable.NewColorableStdout(),
Level: consoleLevel,
})
Expand Down