18
18
config_path string
19
19
token string
20
20
observe_url string
21
+ cloud_resource_detectors []string
21
22
self_monitoring_enabled bool
22
23
host_monitoring_enabled bool
23
24
host_monitoring_logs_enabled bool
@@ -33,6 +34,7 @@ const configTemplate = "observe-agent.tmpl"
33
34
type FlatAgentConfig struct {
34
35
Token string
35
36
ObserveURL string
37
+ CloudResourceDetectors []string
36
38
SelfMonitoring_Enabled bool
37
39
HostMonitoring_Enabled bool
38
40
HostMonitoring_LogsEnabled bool
@@ -41,67 +43,79 @@ type FlatAgentConfig struct {
41
43
HostMonitoring_Metrics_ProcessEnabled bool
42
44
}
43
45
44
- func NewConfigureCmd () * cobra.Command {
46
+ func NewConfigureCmd (v * viper. Viper ) * cobra.Command {
45
47
return & cobra.Command {
46
48
Use : "init-config" ,
47
49
Short : "Initialize agent configuration" ,
48
50
Long : `This command takes in parameters and creates an initialized observe agent configuration file. Will overwrite existing config file and should only be used to initialize.` ,
49
51
RunE : func (cmd * cobra.Command , args []string ) error {
50
52
configValues := FlatAgentConfig {
51
- Token : viper .GetString ("token" ),
52
- ObserveURL : viper .GetString ("observe_url" ),
53
- SelfMonitoring_Enabled : viper .GetBool ("self_monitoring::enabled" ),
54
- HostMonitoring_Enabled : viper .GetBool ("host_monitoring::enabled" ),
55
- HostMonitoring_LogsEnabled : viper .GetBool ("host_monitoring::logs::enabled" ),
56
- HostMonitoring_Metrics_HostEnabled : viper .GetBool ("host_monitoring::metrics::host::enabled" ),
57
- HostMonitoring_Metrics_ProcessEnabled : viper .GetBool ("host_monitoring::metrics::process::enabled" ),
53
+ Token : v .GetString ("token" ),
54
+ ObserveURL : v .GetString ("observe_url" ),
55
+ CloudResourceDetectors : v .GetStringSlice ("cloud_resource_detectors" ),
56
+ SelfMonitoring_Enabled : v .GetBool ("self_monitoring::enabled" ),
57
+ HostMonitoring_Enabled : v .GetBool ("host_monitoring::enabled" ),
58
+ HostMonitoring_LogsEnabled : v .GetBool ("host_monitoring::logs::enabled" ),
59
+ HostMonitoring_Metrics_HostEnabled : v .GetBool ("host_monitoring::metrics::host::enabled" ),
60
+ HostMonitoring_Metrics_ProcessEnabled : v .GetBool ("host_monitoring::metrics::process::enabled" ),
58
61
}
59
62
if configValues .HostMonitoring_LogsEnabled {
60
- configValues .HostMonitoring_LogsInclude = viper .GetStringSlice ("host_monitoring::logs::include" )
63
+ configValues .HostMonitoring_LogsInclude = v .GetStringSlice ("host_monitoring::logs::include" )
61
64
}
62
- var outputPath string
63
- if config_path != "" {
64
- outputPath = config_path
65
+ var f * os. File
66
+ if v . GetBool ( "print" ) {
67
+ f = os . Stdout
65
68
} else {
66
- outputPath = viper .ConfigFileUsed ()
69
+ var outputPath string
70
+ if config_path != "" {
71
+ outputPath = config_path
72
+ } else {
73
+ outputPath = v .ConfigFileUsed ()
74
+ }
75
+ var err error
76
+ f , err = os .Create (outputPath )
77
+ if err != nil {
78
+ return err
79
+ }
80
+ defer f .Close ()
81
+ fmt .Printf ("Writing configuration values to %s...\n \n " , outputPath )
67
82
}
68
- f , err := os .Create (outputPath )
69
- if err != nil {
70
- return err
71
- }
72
- defer f .Close ()
73
83
t := template .Must (template .New (configTemplate ).ParseFS (configTemplateFS , configTemplate ))
74
84
if err := t .ExecuteTemplate (f , configTemplate , configValues ); err != nil {
75
85
return err
76
86
}
77
- fmt .Printf ("Writing configuration values to %s...\n \n " , outputPath )
78
87
return nil
79
88
},
80
89
}
81
90
}
82
91
83
92
func init () {
84
- configureCmd := NewConfigureCmd ()
85
- RegisterConfigFlags (configureCmd )
93
+ v := viper .GetViper ()
94
+ configureCmd := NewConfigureCmd (v )
95
+ RegisterConfigFlags (configureCmd , v )
86
96
root .RootCmd .AddCommand (configureCmd )
87
97
}
88
98
89
- func RegisterConfigFlags (cmd * cobra.Command ) {
99
+ func RegisterConfigFlags (cmd * cobra.Command , v * viper. Viper ) {
90
100
cmd .Flags ().StringVarP (& config_path , "config_path" , "" , "" , "Path to write config output file to" )
101
+ cmd .PersistentFlags ().Bool ("print" , false , "Print the configuration to stdout instead of writing to a file" )
91
102
cmd .PersistentFlags ().StringVar (& token , "token" , "" , "Observe token" )
92
103
cmd .PersistentFlags ().StringVar (& observe_url , "observe_url" , "" , "Observe data collection url" )
104
+ cmd .PersistentFlags ().StringSliceVar (& cloud_resource_detectors , "cloud_resource_detectors" , []string {}, "The cloud environments from which to detect resources" )
93
105
cmd .PersistentFlags ().BoolVar (& self_monitoring_enabled , "self_monitoring::enabled" , true , "Enable self monitoring" )
94
106
cmd .PersistentFlags ().BoolVar (& host_monitoring_enabled , "host_monitoring::enabled" , true , "Enable host monitoring" )
95
107
cmd .PersistentFlags ().BoolVar (& host_monitoring_logs_enabled , "host_monitoring::logs::enabled" , true , "Enable host monitoring logs" )
96
108
cmd .PersistentFlags ().StringSliceVar (& host_monitoring_logs_include , "host_monitoring::logs::include" , nil , "Set host monitoring log include paths" )
97
109
cmd .PersistentFlags ().BoolVar (& host_monitoring_metrics_host_enabled , "host_monitoring::metrics::host::enabled" , true , "Enable host monitoring host metrics" )
98
110
cmd .PersistentFlags ().BoolVar (& host_monitoring_metrics_process_enabled , "host_monitoring::metrics::process::enabled" , false , "Enable host monitoring process metrics" )
99
- viper .BindPFlag ("token" , cmd .PersistentFlags ().Lookup ("token" ))
100
- viper .BindPFlag ("observe_url" , cmd .PersistentFlags ().Lookup ("observe_url" ))
101
- viper .BindPFlag ("self_monitoring::enabled" , cmd .PersistentFlags ().Lookup ("self_monitoring::enabled" ))
102
- viper .BindPFlag ("host_monitoring::enabled" , cmd .PersistentFlags ().Lookup ("host_monitoring::enabled" ))
103
- viper .BindPFlag ("host_monitoring::logs::enabled" , cmd .PersistentFlags ().Lookup ("host_monitoring::logs::enabled" ))
104
- viper .BindPFlag ("host_monitoring::logs::include" , cmd .PersistentFlags ().Lookup ("host_monitoring::logs::include" ))
105
- viper .BindPFlag ("host_monitoring::metrics::host::enabled" , cmd .PersistentFlags ().Lookup ("host_monitoring::metrics::host::enabled" ))
106
- viper .BindPFlag ("host_monitoring::metrics::process::enabled" , cmd .PersistentFlags ().Lookup ("host_monitoring::metrics::process::enabled" ))
111
+ v .BindPFlag ("print" , cmd .PersistentFlags ().Lookup ("print" ))
112
+ v .BindPFlag ("token" , cmd .PersistentFlags ().Lookup ("token" ))
113
+ v .BindPFlag ("observe_url" , cmd .PersistentFlags ().Lookup ("observe_url" ))
114
+ v .BindPFlag ("cloud_resource_detectors" , cmd .PersistentFlags ().Lookup ("cloud_resource_detectors" ))
115
+ v .BindPFlag ("self_monitoring::enabled" , cmd .PersistentFlags ().Lookup ("self_monitoring::enabled" ))
116
+ v .BindPFlag ("host_monitoring::enabled" , cmd .PersistentFlags ().Lookup ("host_monitoring::enabled" ))
117
+ v .BindPFlag ("host_monitoring::logs::enabled" , cmd .PersistentFlags ().Lookup ("host_monitoring::logs::enabled" ))
118
+ v .BindPFlag ("host_monitoring::logs::include" , cmd .PersistentFlags ().Lookup ("host_monitoring::logs::include" ))
119
+ v .BindPFlag ("host_monitoring::metrics::host::enabled" , cmd .PersistentFlags ().Lookup ("host_monitoring::metrics::host::enabled" ))
120
+ v .BindPFlag ("host_monitoring::metrics::process::enabled" , cmd .PersistentFlags ().Lookup ("host_monitoring::metrics::process::enabled" ))
107
121
}
0 commit comments