-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmonitor_disable.go
More file actions
59 lines (48 loc) · 1.74 KB
/
monitor_disable.go
File metadata and controls
59 lines (48 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package monitor
import (
"fmt"
"github.com/spf13/cobra"
sts "github.com/stackvista/stackstate-cli/generated/stackstate_api"
stscobra "github.com/stackvista/stackstate-cli/internal/cobra"
"github.com/stackvista/stackstate-cli/internal/common"
"github.com/stackvista/stackstate-cli/internal/di"
)
func MonitorDisableCommand(cli *di.Deps) *cobra.Command {
args := &IdArgs{}
cmd := &cobra.Command{
Use: "disable",
Short: "Disable a monitor to stop it from running",
Long: "Disable a monitor to prevent it from running on its scheduled interval. A disabled monitor will not produce new health states.",
Example: `# disable a monitor by ID
sts monitor disable --id 123456789
# disable a monitor by identifier
sts monitor disable --identifier urn:stackpack:my-monitor`,
RunE: cli.CmdRunEWithApi(RunMonitorDisableCommand(args, sts.MONITORSTATUSVALUE_DISABLED.Ptr())),
}
common.AddIDFlagVar(cmd, &args.ID, IDFlagUsage)
common.AddIdentifierFlagVar(cmd, &args.Identifier, IdentifierFlagUsage)
stscobra.MarkMutexFlags(cmd, []string{common.IDFlag, common.IdentifierFlag}, "identifier", true)
return cmd
}
func RunMonitorDisableCommand(args *IdArgs, status *sts.MonitorStatusValue) di.CmdWithApiFn {
return func(
cmd *cobra.Command,
cli *di.Deps,
api *sts.APIClient,
serverInfo *sts.ServerInfo,
) common.CLIError {
identifier := IdOrIdentifier(args.ID, args.Identifier)
monitorPatchResult, resp, err := RunMonitorStatusPatch(cli, api, status, identifier)
if err != nil {
return common.NewResponseError(err, resp)
}
if cli.IsJson() {
cli.Printer.PrintJson(map[string]interface{}{
"monitor": monitorPatchResult,
})
} else {
cli.Printer.Success(fmt.Sprintf("Monitor %s has been disabled", identifier))
}
return nil
}
}