diff --git a/cmd/auto-complete.go b/cmd/auto-complete.go
index 650f010d..3f1f461c 100644
--- a/cmd/auto-complete.go
+++ b/cmd/auto-complete.go
@@ -448,22 +448,19 @@ var completeCmds = map[string]complete.Predictor{
"/alias/remove": aliasCompleter,
"/alias/import": nil,
- "/support/callhome": aliasCompleter,
- "/support/logs/enable": aliasCompleter,
- "/support/logs/disable": aliasCompleter,
- "/support/logs/status": aliasCompleter,
- "/support/logs/show": aliasCompleter,
- "/support/register": aliasCompleter,
- "/support/diag": aliasCompleter,
- "/support/profile": aliasCompleter,
- "/support/inspect": aliasCompleter,
- "/support/perf": aliasCompleter,
- "/support/metrics": aliasCompleter,
- "/support/status": aliasCompleter,
- "/support/top/locks": aliasCompleter,
- "/support/top/api": aliasCompleter,
- "/support/top/drive": aliasCompleter,
- "/support/top/disk": aliasCompleter,
+ "/support/callhome": aliasCompleter,
+ "/support/logs": aliasCompleter,
+ "/support/register": aliasCompleter,
+ "/support/diag": aliasCompleter,
+ "/support/profile": aliasCompleter,
+ "/support/inspect": aliasCompleter,
+ "/support/perf": aliasCompleter,
+ "/support/metrics": aliasCompleter,
+ "/support/status": aliasCompleter,
+ "/support/top/locks": aliasCompleter,
+ "/support/top/api": aliasCompleter,
+ "/support/top/drive": aliasCompleter,
+ "/support/top/disk": aliasCompleter,
"/license/register": aliasCompleter,
"/license/info": aliasCompleter,
diff --git a/cmd/support-callhome.go b/cmd/support-callhome.go
index 4fc34514..52234eec 100644
--- a/cmd/support-callhome.go
+++ b/cmd/support-callhome.go
@@ -18,6 +18,8 @@
package cmd
import (
+ "strings"
+
"github.com/minio/cli"
json "github.com/minio/colorjson"
"github.com/minio/madmin-go"
@@ -25,13 +27,24 @@ import (
"github.com/minio/pkg/console"
)
+var supportCallhomeFlags = append([]cli.Flag{
+ cli.BoolFlag{
+ Name: "logs",
+ Usage: "push logs to SUBNET in real-time",
+ },
+ cli.BoolFlag{
+ Name: "diag",
+ Usage: "push diagnostics info to SUBNET every 24hrs",
+ },
+}, supportGlobalFlags...)
+
var supportCallhomeCmd = cli.Command{
Name: "callhome",
Usage: "configure callhome settings",
OnUsageError: onUsageError,
Action: mainCallhome,
Before: setGlobalsFromContext,
- Flags: supportGlobalFlags,
+ Flags: supportCallhomeFlags,
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
@@ -39,8 +52,8 @@ USAGE:
{{.HelpName}} enable|disable|status ALIAS
OPTIONS:
- enable - Enable pushing callhome info to SUBNET every 24hrs
- disable - Disable pushing callhome info to SUBNET
+ enable - Enable callhome
+ disable - Disable callhome
status - Display callhome settings
FLAGS:
@@ -55,21 +68,45 @@ EXAMPLES:
3. Check callhome status for cluster with alias 'myminio'
{{.Prompt}} {{.HelpName}} status myminio
+
+ 4. Enable diagnostics callhome for cluster with alias 'myminio'
+ {{.Prompt}} {{.HelpName}} enable myminio --diag
+
+ 5. Disable logs callhome for cluster with alias 'myminio'
+ {{.Prompt}} {{.HelpName}} disable myminio --logs
+
+ 6. Check logs callhome status for cluster with alias 'myminio'
+ {{.Prompt}} {{.HelpName}} status myminio --logs
`,
}
type supportCallhomeMessage struct {
- Status string `json:"status"`
- Callhome string `json:"callhome"`
- MsgPfx string `json:"-"`
+ Status string `json:"status"`
+ Diag string `json:"diag,omitempty"`
+ Logs string `json:"logs,omitempty"`
+ Feature string `json:"-"`
+ Action string `json:"-"`
}
-// String colorized service status message.
+// String colorized callhome command output message.
func (s supportCallhomeMessage) String() string {
- return console.Colorize(featureToggleMessageTag, s.MsgPfx+s.Callhome)
+ var msg string
+ if s.Action == "status" {
+ msgs := []string{}
+ if len(s.Diag) > 0 {
+ msgs = append(msgs, "Diagnostics is "+s.Diag)
+ }
+ if len(s.Logs) > 0 {
+ msgs = append(msgs, "Logs is "+s.Logs)
+ }
+ msg = strings.Join(msgs, "\n")
+ } else {
+ msg = s.Feature + " is now " + s.Action
+ }
+ return console.Colorize(featureToggleMessageTag, msg)
}
-// JSON jsonified service status message.
+// JSON jsonified callhome command output message.
func (s supportCallhomeMessage) JSON() string {
s.Status = "success"
jsonBytes, e := json.MarshalIndent(s, "", " ")
@@ -78,7 +115,7 @@ func (s supportCallhomeMessage) JSON() string {
return string(jsonBytes)
}
-func isSupportCallhomeEnabled(alias string) bool {
+func isDiagCallhomeEnabled(alias string) bool {
return isFeatureEnabled(alias, "callhome", madmin.Default)
}
@@ -86,20 +123,77 @@ func mainCallhome(ctx *cli.Context) error {
setToggleMessageColor()
alias, arg := checkToggleCmdSyntax(ctx, "callhome")
+ diag, logs := parseCallhomeFlags(ctx)
+
if arg == "status" {
- printMsg(supportCallhomeMessage{
- Callhome: featureStatusStr(isSupportCallhomeEnabled(alias)),
- })
+ printCallhomeStatus(alias, diag, logs)
return nil
}
- enable := arg == "enable"
+ toggleCallhome(alias, arg == "enable", diag, logs)
+
+ return nil
+}
+
+func parseCallhomeFlags(ctx *cli.Context) (diag bool, logs bool) {
+ diag = ctx.Bool("diag")
+ logs = ctx.Bool("logs")
+
+ if !diag && !logs {
+ // When both flags are not passed, apply the action to both
+ diag = true
+ logs = true
+ }
+
+ return diag, logs
+}
+
+func printCallhomeStatus(alias string, diag bool, logs bool) {
+ resultMsg := supportCallhomeMessage{Action: "status"}
+ if diag {
+ resultMsg.Diag = featureStatusStr(isDiagCallhomeEnabled(alias))
+ }
+
+ if logs {
+ resultMsg.Logs = featureStatusStr(isLogsCallhomeEnabled(alias))
+ }
+ printMsg(resultMsg)
+}
+
+func toggleCallhome(alias string, enable bool, diag bool, logs bool) {
+ newStatus := featureStatusStr(enable)
+ resultMsg := supportCallhomeMessage{
+ Action: newStatus,
+ Feature: getFeature(diag, logs),
+ }
+
if enable {
validateClusterRegistered(alias, true)
}
- setCallhomeConfig(alias, enable)
- return nil
+ if diag {
+ setCallhomeConfig(alias, enable)
+ resultMsg.Diag = newStatus
+ }
+
+ if logs {
+ configureSubnetWebhook(alias, enable)
+ resultMsg.Logs = newStatus
+ }
+
+ printMsg(resultMsg)
+}
+
+func getFeature(diag bool, logs bool) string {
+ if diag && logs {
+ return "Diagnostics and logs callhome"
+ }
+
+ if diag {
+ return "Diagnostics"
+ }
+
+ return "Logs"
}
func setCallhomeConfig(alias string, enableCallhome bool) {
@@ -118,9 +212,4 @@ func setCallhomeConfig(alias string, enableCallhome bool) {
configStr := "callhome enable=" + enableStr
_, e := client.SetConfigKV(globalContext, configStr)
fatalIf(probe.NewError(e), "Unable to set callhome config on minio")
-
- printMsg(supportCallhomeMessage{
- Callhome: featureStatusStr(enableCallhome),
- MsgPfx: "Callhome is now ",
- })
}
diff --git a/cmd/support-logs-disable.go b/cmd/support-logs-disable.go
deleted file mode 100644
index 11e98b10..00000000
--- a/cmd/support-logs-disable.go
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright (c) 2015-2022 MinIO, Inc.
-//
-// This file is part of MinIO Object Storage stack
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-package cmd
-
-import (
- "github.com/minio/cli"
-)
-
-var supportLogsDisableCmd = cli.Command{
- Name: "disable",
- Usage: "disable uploading MinIO logs to SUBNET",
- OnUsageError: onUsageError,
- Action: mainDisableLogs,
- Before: setGlobalsFromContext,
- Flags: supportGlobalFlags,
- CustomHelpTemplate: `NAME:
- {{.HelpName}} - {{.Usage}}
-USAGE:
- {{.HelpName}} ALIAS
-FLAGS:
- {{range .VisibleFlags}}{{.}}
- {{end}}
-EXAMPLES:
- 1. Disable uploading logs for cluster with alias 'play' to SUBNET
- {{.Prompt}} {{.HelpName}} play
-`,
-}
-
-func mainDisableLogs(ctx *cli.Context) error {
- setToggleMessageColor()
- alias := validateLogsToggleCmd(ctx, "disable")
- configureSubnetWebhook(alias, false)
- return nil
-}
diff --git a/cmd/support-logs-enable.go b/cmd/support-logs-enable.go
deleted file mode 100644
index 1b9791a3..00000000
--- a/cmd/support-logs-enable.go
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 2015-2022 MinIO, Inc.
-//
-// This file is part of MinIO Object Storage stack
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-package cmd
-
-import (
- "github.com/minio/cli"
-)
-
-var supportLogsEnableCmd = cli.Command{
- Name: "enable",
- Usage: "enable uploading real-time MinIO logs to SUBNET",
- Action: mainEnableLogs,
- OnUsageError: onUsageError,
- Before: setGlobalsFromContext,
- Flags: supportGlobalFlags,
- HideHelpCommand: true,
- CustomHelpTemplate: `NAME:
- {{.HelpName}} - {{.Usage}}
-USAGE:
- {{.HelpName}} ALIAS
-FLAGS:
- {{range .VisibleFlags}}{{.}}
- {{end}}
-EXAMPLES:
- 1. Enable uploading real-time logs for cluster with alias 'play' to SUBNET.
- {{.Prompt}} {{.HelpName}} play
-`,
-}
-
-func mainEnableLogs(ctx *cli.Context) error {
- setToggleMessageColor()
- alias := validateLogsToggleCmd(ctx, "enable")
- configureSubnetWebhook(alias, true)
- return nil
-}
diff --git a/cmd/support-logs-show.go b/cmd/support-logs-show.go
index f0467a98..1c62205b 100644
--- a/cmd/support-logs-show.go
+++ b/cmd/support-logs-show.go
@@ -46,31 +46,6 @@ var logsShowFlags = []cli.Flag{
},
}
-var supportLogsShowCmd = cli.Command{
- Name: "show",
- Usage: "show MinIO logs",
- Action: mainLogsShowConsole,
- OnUsageError: onUsageError,
- Before: setGlobalsFromContext,
- Flags: append(logsShowFlags, globalFlags...),
- HideHelpCommand: true,
- CustomHelpTemplate: `NAME:
- {{.HelpName}} - {{.Usage}}
-USAGE:
- {{.HelpName}} [FLAGS] TARGET [NODENAME]
-FLAGS:
- {{range .VisibleFlags}}{{.}}
- {{end}}
-EXAMPLES:
- 1. Show logs for a MinIO server with alias 'myminio'
- {{.Prompt}} {{.HelpName}} myminio
- 2. Show last 5 log entries for node 'node1' for a MinIO server with alias 'myminio'
- {{.Prompt}} {{.HelpName}} --last 5 myminio node1
- 3. Show application errors in logs for a MinIO server with alias 'myminio'
- {{.Prompt}} {{.HelpName}} --type application myminio
-`,
-}
-
func checkLogsShowSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 3 {
showCommandHelpAndExit(ctx, 1) // last argument is exit code
diff --git a/cmd/support-logs-status.go b/cmd/support-logs-status.go
deleted file mode 100644
index 35cdcfb1..00000000
--- a/cmd/support-logs-status.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2015-2022 MinIO, Inc.
-//
-// This file is part of MinIO Object Storage stack
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-package cmd
-
-import (
- "github.com/minio/cli"
-)
-
-var supportLogsStatusCmd = cli.Command{
- Name: "status",
- Usage: "show current status of MinIO logs",
- OnUsageError: onUsageError,
- Action: mainStatusLogs,
- Before: setGlobalsFromContext,
- Flags: supportGlobalFlags,
- CustomHelpTemplate: `NAME:
- {{.HelpName}} - {{.Usage}}
-USAGE:
- {{.HelpName}} ALIAS
-FLAGS:
- {{range .VisibleFlags}}{{.}}
- {{end}}
-EXAMPLES:
- 1. Show current status of MinIO logs for cluster with alias 'myminio', whether it is uploading to SUBNET or not
- {{.Prompt}} {{.HelpName}} myminio
-`,
-}
-
-func isSupportLogsEnabled(alias string) bool {
- return isFeatureEnabled(alias, "logger_webhook", "subnet")
-}
-
-func mainStatusLogs(ctx *cli.Context) error {
- setToggleMessageColor()
- alias := validateLogsToggleCmd(ctx, "status")
- printMsg(supportLogsMessage{
- Logs: featureStatusStr(isSupportLogsEnabled(alias)),
- })
-
- return nil
-}
diff --git a/cmd/support-logs.go b/cmd/support-logs.go
index 43d7ef60..03bfcb25 100644
--- a/cmd/support-logs.go
+++ b/cmd/support-logs.go
@@ -21,47 +21,32 @@ import (
"fmt"
"github.com/minio/cli"
- json "github.com/minio/colorjson"
"github.com/minio/mc/pkg/probe"
- "github.com/minio/pkg/console"
)
-var supportLogsSubcommands = []cli.Command{
- supportLogsEnableCmd,
- supportLogsDisableCmd,
- supportLogsStatusCmd,
- supportLogsShowCmd,
-}
-
var supportLogsCmd = cli.Command{
Name: "logs",
- Usage: "configure/display MinIO console logs",
+ Usage: "show MinIO logs",
OnUsageError: onUsageError,
- Action: mainLogs,
+ Action: mainLogsShowConsole,
Before: setGlobalsFromContext,
- Flags: globalFlags,
+ Flags: append(logsShowFlags, globalFlags...),
HideHelpCommand: true,
- Subcommands: supportLogsSubcommands,
-}
-
-type supportLogsMessage struct {
- Status string `json:"status"`
- Logs string `json:"logs"`
- MsgPfx string `json:"-"`
-}
-
-// String colorized service status message.
-func (s supportLogsMessage) String() string {
- return console.Colorize(featureToggleMessageTag, s.MsgPfx+s.Logs)
-}
-
-// JSON jsonified service status message.
-func (s supportLogsMessage) JSON() string {
- s.Status = "success"
- jsonBytes, e := json.MarshalIndent(s, "", " ")
- fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
-
- return string(jsonBytes)
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+USAGE:
+ {{.HelpName}} [FLAGS] TARGET [NODENAME]
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Show logs for a MinIO server with alias 'myminio'
+ {{.Prompt}} {{.HelpName}} myminio
+ 2. Show last 5 log entries for node 'node1' for a MinIO server with alias 'myminio'
+ {{.Prompt}} {{.HelpName}} --last 5 myminio node1
+ 3. Show application errors in logs for a MinIO server with alias 'myminio'
+ {{.Prompt}} {{.HelpName}} --type application myminio
+`,
}
func configureSubnetWebhook(alias string, enable bool) {
@@ -81,24 +66,8 @@ func configureSubnetWebhook(alias string, enable bool) {
// Call set config API
_, e := client.SetConfigKV(globalContext, input)
fatalIf(probe.NewError(e), "Unable to set '%s' to server", input)
-
- printMsg(supportLogsMessage{
- Logs: featureStatusStr(enable),
- MsgPfx: "Logging to support is now ",
- })
}
-func validateLogsToggleCmd(ctx *cli.Context, cmdName string) string {
- if len(ctx.Args()) != 1 {
- showCommandHelpAndExit(ctx, 1) // last argument is exit code
- }
- alias, _ := url2Alias(ctx.Args().Get(0))
- return alias
-}
-
-// mainLogs is the handle for "mc support logs" command.
-func mainLogs(ctx *cli.Context) error {
- commandNotFound(ctx, supportLogsSubcommands)
- return nil
- // Sub-commands like "enable", "disable", "status", "print" have their own main.
+func isLogsCallhomeEnabled(alias string) bool {
+ return isFeatureEnabled(alias, "logger_webhook", "subnet")
}