forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
workload_list.go
88 lines (70 loc) · 2.38 KB
/
workload_list.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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-present Datadog, Inc.
package app
import (
"encoding/json"
"fmt"
"github.com/StackVista/stackstate-agent/cmd/agent/common"
"github.com/StackVista/stackstate-agent/pkg/api/util"
"github.com/StackVista/stackstate-agent/pkg/config"
"github.com/StackVista/stackstate-agent/pkg/workloadmeta"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
var verboseList bool
func init() {
AgentCmd.AddCommand(workloadListCommand)
workloadListCommand.Flags().BoolVarP(&verboseList, "verbose", "v", false, "print out a full dump of the workload store")
}
var workloadListCommand = &cobra.Command{
Use: "workload-list",
Short: "Print the workload content of a running agent",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
if flagNoColor {
color.NoColor = true
}
err := common.SetupConfigWithoutSecrets(confFilePath, "")
if err != nil {
return fmt.Errorf("unable to set up global agent configuration: %v", err)
}
err = config.SetupLogger(loggerName, config.GetEnvDefault("DD_LOG_LEVEL", "off"), "", "", false, true, false)
if err != nil {
fmt.Printf("Cannot setup logger, exiting: %v\n", err)
return err
}
c := util.GetClient(false) // FIX: get certificates right then make this true
// Set session token
err = util.SetAuthToken()
if err != nil {
return err
}
ipcAddress, err := config.GetIPCAddress()
if err != nil {
return err
}
r, err := util.DoGet(c, workloadURL(verboseList, ipcAddress, config.Datadog.GetInt("cmd_port")))
if err != nil {
if r != nil && string(r) != "" {
fmt.Fprintf(color.Output, "The agent ran into an error while getting the workload store information: %s\n", string(r))
} else {
fmt.Fprintf(color.Output, "Failed to query the agent (running?): %s\n", err)
}
}
workload := workloadmeta.WorkloadDumpResponse{}
err = json.Unmarshal(r, &workload)
if err != nil {
return err
}
workload.Write(color.Output)
return nil
},
}
func workloadURL(verbose bool, address string, port int) string {
if verbose {
return fmt.Sprintf("https://%v:%v/agent/workload-list/verbose", address, port)
}
return fmt.Sprintf("https://%v:%v/agent/workload-list/short", address, port)
}