-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
status.go
78 lines (70 loc) · 2.31 KB
/
status.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
// 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 daemon
import (
_ "embed"
"fmt"
"os"
"text/template"
"github.com/DataDog/datadog-agent/cmd/installer/command"
"github.com/DataDog/datadog-agent/comp/core"
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/log/logimpl"
"github.com/DataDog/datadog-agent/comp/core/secrets"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
"github.com/DataDog/datadog-agent/comp/updater/localapiclient"
"github.com/DataDog/datadog-agent/comp/updater/localapiclient/localapiclientimpl"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/fatih/color"
"github.com/spf13/cobra"
"go.uber.org/fx"
)
func statusCommand(global *command.GlobalParams) *cobra.Command {
statusCmd := &cobra.Command{
Use: "status",
Short: "Print the installer status",
GroupID: "daemon",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
return statusFxWrapper(global)
},
}
return statusCmd
}
func statusFxWrapper(global *command.GlobalParams) error {
return fxutil.OneShot(status,
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(global.ConfFilePath),
SecretParams: secrets.NewEnabledParams(),
SysprobeConfigParams: sysprobeconfigimpl.NewParams(),
LogParams: logimpl.ForOneShot("INSTALLER", "off", true),
}),
core.Bundle(),
localapiclientimpl.Module(),
)
}
//go:embed status.tmpl
var statusTmpl []byte
var functions = template.FuncMap{
"greenText": color.GreenString,
"yellowText": color.YellowString,
"redText": color.RedString,
"boldText": color.New(color.Bold).Sprint,
}
func status(client localapiclient.Component) error {
tmpl, err := template.New("status").Funcs(functions).Parse(string(statusTmpl))
if err != nil {
return fmt.Errorf("error parsing status template: %w", err)
}
status, err := client.Status()
if err != nil {
return fmt.Errorf("error getting status: %w", err)
}
err = tmpl.Execute(os.Stdout, status)
if err != nil {
return fmt.Errorf("error executing status template: %w", err)
}
return nil
}