forked from newrelic/nri-flex
/
infra.go
52 lines (42 loc) · 1.38 KB
/
infra.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
/*
* Copyright 2019 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package outputs
import (
"os"
"github.com/newrelic/nri-flex/internal/load"
"github.com/sirupsen/logrus"
Integration "github.com/newrelic/infra-integrations-sdk/integration"
)
// InfraIntegration Creates Infrastructure SDK Integration
func InfraIntegration() {
load.Hostname, _ = os.Hostname() // set hostname
var err error
load.Integration, err = Integration.New(load.IntegrationName, load.IntegrationVersion, Integration.Args(&load.Args))
// Accepts ConfigPath as alias for ConfigFile. This will allow the Infrastructure Agent
// passing an embedded config via the default CONFIG_PATH environment variable
if load.Args.ConfigPath != "" {
load.Args.ConfigFile = load.Args.ConfigPath
}
if err != nil {
load.Logrus.WithFields(logrus.Fields{"err": err}).Fatal("flex: create integration")
}
if load.Args.Local {
load.Entity = load.Integration.LocalEntity()
} else {
InfraRemoteEntity()
}
}
// InfraRemoteEntity Creates Infrastructure Remote Entity
func InfraRemoteEntity() {
var err error
setEntity := load.Hostname // default hostname
if load.Args.Entity != "" {
setEntity = load.Args.Entity
}
load.Entity, err = load.Integration.Entity(setEntity, "nri-flex")
if err != nil {
load.Logrus.WithFields(logrus.Fields{"err": err}).Fatal("flex: create remote entity")
}
}