@@ -172,6 +172,50 @@ func convertTabsToSpaces(input []byte, tabWidth int) []byte {
172
172
return output
173
173
}
174
174
175
+ func (c * HostAgent ) updateConfigWithRestrictions (config map [string ]interface {}) (map [string ]interface {}, error ) {
176
+
177
+ receiversData , ok := config [Receivers ].(map [string ]interface {})
178
+ if ! ok {
179
+ return nil , ErrParseReceivers
180
+ }
181
+
182
+ serviceData , ok := config [Service ].(map [string ]interface {})
183
+ if ! ok {
184
+ return nil , ErrParseService
185
+ }
186
+
187
+ pipelinesData , ok := serviceData [Pipelines ].(map [string ]interface {})
188
+ if ! ok {
189
+ return nil , ErrParsePipelines
190
+ }
191
+
192
+ for key , _ := range pipelinesData {
193
+ if ! c .HostConfig .AgentFeatures .LogCollection && strings .HasPrefix (key , "logs" ) {
194
+ delete (pipelinesData , key )
195
+ }
196
+
197
+ if ! c .HostConfig .AgentFeatures .MetricCollection && strings .HasPrefix (key , "metrics" ) {
198
+ delete (pipelinesData , key )
199
+ }
200
+ }
201
+
202
+ if ! c .HostConfig .AgentFeatures .LogCollection {
203
+ delete (receiversData , "filelog" )
204
+ delete (receiversData , "windowseventlog" )
205
+ }
206
+
207
+ if ! c .HostConfig .AgentFeatures .MetricCollection {
208
+ delete (receiversData , "hostmetrics" )
209
+ delete (receiversData , "windowsperfcounters" )
210
+ delete (receiversData , "docker_stats" )
211
+ delete (receiversData , "prometheus" )
212
+ delete (receiversData , "kubeletstats" )
213
+ delete (receiversData , "k8s_cluster" )
214
+ }
215
+
216
+ return config , nil
217
+ }
218
+
175
219
func (c * HostAgent ) updateConfig (config map [string ]interface {}, cnf integrationConfiguration ) (map [string ]interface {}, error ) {
176
220
177
221
if c .isIPPortFormat (cnf .Endpoint ) {
@@ -318,6 +362,13 @@ func (c *HostAgent) updateConfigFile(configType string) error {
318
362
319
363
}
320
364
365
+ if ! c .AgentFeatures .LogCollection || ! c .AgentFeatures .MetricCollection {
366
+ apiYAMLConfig , err = c .updateConfigWithRestrictions (apiYAMLConfig )
367
+ if err != nil {
368
+ return err
369
+ }
370
+ }
371
+
321
372
apiYAMLBytes , err := yaml .Marshal (apiYAMLConfig )
322
373
if err != nil {
323
374
c .logger .Error ("failed to marshal api data" , zap .Error (err ))
0 commit comments