-
Notifications
You must be signed in to change notification settings - Fork 122
/
custom_attrs.go
45 lines (36 loc) · 1.29 KB
/
custom_attrs.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
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package plugins
import (
"github.com/newrelic/infrastructure-agent/internal/agent"
"github.com/newrelic/infrastructure-agent/pkg/config"
"github.com/newrelic/infrastructure-agent/pkg/entity"
"github.com/newrelic/infrastructure-agent/pkg/plugins/ids"
)
type CustomAttrsPlugin struct {
agent.PluginCommon
customAttributes map[string]interface{}
}
type CustomAttrs map[string]interface{}
func (self CustomAttrs) SortKey() string {
return "customAttributes"
}
func NewCustomAttrsPlugin(ctx agent.AgentContext) agent.Plugin {
return &CustomAttrsPlugin{
PluginCommon: agent.PluginCommon{
ID: ids.CustomAttrsID,
Context: ctx,
},
customAttributes: ctx.Config().CustomAttributes,
}
}
// This plugin is pretty simple - it simply returns once with the object containing current custom attributes.
func (self *CustomAttrsPlugin) Run() {
self.Context.AddReconnecting(self)
data := agent.PluginInventoryDataset{CustomAttrs(self.customAttributes)}
entityKey := self.Context.EntityKey()
aclog.
WithField(config.TracesFieldName, config.FeatureTrace).
Tracef("run, entity: %s, data: %+v", entityKey, self.customAttributes)
self.EmitInventory(data, entity.NewFromNameWithoutID(entityKey))
}