forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reloadcheck.go
63 lines (51 loc) · 1.69 KB
/
reloadcheck.go
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
60
61
62
63
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2019 Datadog, Inc.
package app
import (
"fmt"
"strings"
"github.com/ninnemana/datadog-agent/cmd/agent/common"
"github.com/ninnemana/datadog-agent/pkg/api/util"
"github.com/ninnemana/datadog-agent/pkg/config"
"github.com/spf13/cobra"
)
func init() {
// TODO: re-enable when the API endpoint is implemented
// AgentCmd.AddCommand(reloadCheckCommand)
checkCmd.SetArgs([]string{"checkName"})
}
var reloadCheckCommand = &cobra.Command{
Use: "reload-check <check_name>",
Short: "Reload a running check",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
var checkName string
if len(args) != 0 {
checkName = args[0]
} else {
return fmt.Errorf("missing arguments")
}
err := common.SetupConfigWithoutSecrets(confFilePath)
if err != nil {
return fmt.Errorf("unable to set up global agent configuration: %v", err)
}
return doReloadCheck(checkName)
},
}
// reload check
func doReloadCheck(checkName string) error {
if checkName == "" {
return fmt.Errorf("Must supply a check name to query")
}
c := util.GetClient(false) // FIX: get certificates right then make this true
urlstr := fmt.Sprintf("https://localhost:%v/check/%s/reload", config.Datadog.GetInt("cmd_port"), checkName)
postbody := ""
body, e := util.DoPost(c, urlstr, "application/json", strings.NewReader(postbody))
if e != nil {
return fmt.Errorf("error getting check status for check %s: %v", checkName, e)
}
fmt.Printf("Reload check %s: %s\n", checkName, body)
return nil
}