-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmonitor_enable.go
More file actions
58 lines (48 loc) · 1.7 KB
/
monitor_enable.go
File metadata and controls
58 lines (48 loc) · 1.7 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
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 MonitorEnableCommand(cli *di.Deps) *cobra.Command {
args := &IdArgs{}
cmd := &cobra.Command{
Use: "enable",
Short: "Enable a disabled monitor to resume scheduled execution",
Long: "Enable a disabled monitor to resume running on its configured schedule. The monitor will start producing health states again.",
Example: `# enable a monitor by ID
sts monitor enable --id 123456789
# enable a monitor by identifier
sts monitor enable --identifier urn:stackpack:my-monitor`,
RunE: cli.CmdRunEWithApi(RunMonitorEnableCommand(args)),
}
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 RunMonitorEnableCommand(args *IdArgs) 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, sts.MONITORSTATUSVALUE_ENABLED.Ptr(), 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 enabled", identifier))
}
return nil
}
}