Ai
1 Star 0 Fork 0

ryancartoon/sensu-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
set_proxy_request.go 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
package subcommands
import (
"encoding/json"
"errors"
"fmt"
"os"
"github.com/sensu/sensu-go/cli"
"github.com/sensu/sensu-go/types"
"github.com/spf13/cobra"
)
// SetProxyRequestsCommand adds a command that allows a user to set the proxy
// requests for a check
func SetProxyRequestsCommand(cli *cli.SensuCli) *cobra.Command {
cmd := &cobra.Command{
Use: "set-proxy-requests [NAME]",
Short: "set proxy requests for a check from file or stdin",
SilenceUsage: false,
RunE: func(cmd *cobra.Command, args []string) error {
// Print usage if we do not receive one argument
if len(args) != 1 {
_ = cmd.Help()
return errors.New("invalid argument(s) received")
}
check, err := cli.Client.FetchCheck(args[0])
if err != nil {
return err
}
filePath, _ := cmd.Flags().GetString("file")
var in *os.File
if len(filePath) > 0 {
in, err = os.Open(filePath)
if err != nil {
return err
}
defer func() { _ = in.Close() }()
} else {
in = os.Stdin
}
var proxyRequest types.ProxyRequests
if err := json.NewDecoder(in).Decode(&proxyRequest); err != nil {
return err
}
// Set the default splay_coverage value if not configured
if proxyRequest.SplayCoverage == 0 {
proxyRequest.SplayCoverage = types.DefaultSplayCoverage
}
check.ProxyRequests = &proxyRequest
if err := check.Validate(); err != nil {
return err
}
if err := cli.Client.UpdateCheck(check); err != nil {
return err
}
fmt.Fprintln(cmd.OutOrStdout(), "Updated")
return nil
},
}
cmd.Flags().StringP("file", "f", "", "Proxy request definition file")
return cmd
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ryancartoon/sensu-go.git
git@gitee.com:ryancartoon/sensu-go.git
ryancartoon
sensu-go
sensu-go
v5.10.1

搜索帮助