-
Notifications
You must be signed in to change notification settings - Fork 127
/
agent_config.go
61 lines (48 loc) · 1.68 KB
/
agent_config.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
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package plugins
import (
"github.com/newrelic/infrastructure-agent/pkg/entity"
"github.com/newrelic/infrastructure-agent/pkg/log"
"github.com/sirupsen/logrus"
"github.com/newrelic/infrastructure-agent/internal/agent"
"github.com/newrelic/infrastructure-agent/pkg/config"
"github.com/newrelic/infrastructure-agent/pkg/helpers"
"github.com/newrelic/infrastructure-agent/pkg/plugins/ids"
)
var aclog = log.WithPlugin("AgentConfig")
type AgentConfigPlugin struct {
agent.PluginCommon
config config.Config
}
type ConfigAttrs map[string]interface{}
func (ac ConfigAttrs) SortKey() string {
return "infrastructure"
}
func NewAgentConfigPlugin(id ids.PluginID, ctx agent.AgentContext) agent.Plugin {
return &AgentConfigPlugin{
PluginCommon: agent.PluginCommon{ID: id, Context: ctx},
config: *ctx.Config(),
}
}
// This plugin is pretty simple - it simply returns once with the object containing the agent's config settings
func (ac *AgentConfigPlugin) Run() {
ac.Context.AddReconnecting(ac)
ac.config.License = ""
if ac.config.Proxy != "" {
ac.config.Proxy = "<proxy set>"
}
fields, err := ac.config.PublicFields()
if err != nil {
aclog.WithError(err).Error("cannot retrieve public config fields")
return
}
inventoryItems := map[string]interface{}{}
for name, value := range fields {
inventoryItems[name] = map[string]interface{}{
"value": value,
}
}
helpers.LogStructureDetails(aclog, inventoryItems, "config", "raw", logrus.Fields{})
ac.EmitInventory(agent.PluginInventoryDataset{ConfigAttrs(inventoryItems)}, entity.NewFromNameWithoutID(ac.Context.EntityKey()))
}