newrelic

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2022 License: Apache-2.0 Imports: 29 Imported by: 17

Documentation

Overview

Package newrelic is a convenience package that provides a programmatic API surface area for interacting with all the New Relic One products encompassed by this project. Refer to each package's documentation to learn more about its capabilities.

Authentication

You will need a valid Personal API to communicate with the backend New Relic APIs that this client communicates with. See the API key documentation below for more information on how to locate this key:

https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

Example (Basic)
// Initialize the client.
client, err := New(
	ConfigPersonalAPIKey(os.Getenv("NEW_RELIC_API_KEY")),
	ConfigRegion("US"),
	ConfigLogLevel("DEBUG"),
)
if err != nil {
	log.Fatal("error initializing client:", err)
}

// Interact with the New Relic Alerts product.
policies, err := client.Alerts.ListPolicies(&alerts.ListPoliciesParams{
	Name: "Example policy",
})
if err != nil {
	log.Fatal("error listing alert policies:", err)
}

fmt.Printf("Policies: %v+\n", policies)

// Interact with the New Relic APM product.
apps, err := client.APM.ListApplications(&apm.ListApplicationsParams{
	Name: "Example application",
})
if err != nil {
	log.Fatal("error listing APM applications:", err)
}

fmt.Printf("Applications: %v+\n", apps)

// Interact with New Relic One entities.
entities, err := client.Entities.GetEntitySearch(
	entities.EntitySearchOptions{},
	"",
	entities.EntitySearchQueryBuilder{
		Name: "Example entity",
	},
	[]entities.EntitySearchSortCriteria{},
)
if err != nil {
	log.Fatal("error listing entities:", err)
}

fmt.Printf("Entities: %v+\n", entities)

// Interact with the New Relic One NerdGraph API.
query := "{ actor { user { email } } }"

resp, err := client.NerdGraph.Query(query, nil)
if err != nil {
	log.Fatal("error executing query:", err)
}

fmt.Printf("Query response: %v+\n", resp)

// Interact with the New Relic Plugins product.
plugins, err := client.Plugins.ListPlugins(&plugins.ListPluginsParams{
	IDs: []int{1234, 5678},
})
if err != nil {
	log.Fatal("error listing plugins:", err)
}

fmt.Printf("Plugins: %v+\n", plugins)

// Interact with the New Relic Synthetics product.
monitors, err := client.Synthetics.ListMonitors()
if err != nil {
	log.Fatal("error listing monitors:", err)
}

fmt.Printf("Synthetics monitors: %v+\n", monitors)

// Interact with the New Relic One Workloads product.
workload, err := client.Workloads.WorkloadCreate(12345678, workloads.WorkloadCreateInput{Name: "test-workload"})
if err != nil {
	log.Fatal("error creating workload:", err)
}

fmt.Printf("Workload created: %v+\n", workload)
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigOption added in v0.3.0

type ConfigOption func(*config.Config) error

ConfigOption configures the Config when provided to NewApplication. https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

func ConfigAdminAPIKey added in v0.12.0

func ConfigAdminAPIKey(adminAPIKey string) ConfigOption

ConfigAdminAPIKey sets the New Relic Admin API key this client will use. Deprecated. Use a personal API key for authentication. https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

func ConfigBaseURL added in v0.3.0

func ConfigBaseURL(url string) ConfigOption

ConfigBaseURL sets the base URL used to make requests to the REST API V2.

func ConfigHTTPTimeout added in v0.3.0

func ConfigHTTPTimeout(t time.Duration) ConfigOption

ConfigHTTPTimeout sets the timeout for HTTP requests.

func ConfigHTTPTransport added in v0.3.0

func ConfigHTTPTransport(transport http.RoundTripper) ConfigOption

ConfigHTTPTransport sets the HTTP Transporter.

func ConfigInfrastructureBaseURL added in v0.7.0

func ConfigInfrastructureBaseURL(url string) ConfigOption

ConfigInfrastructureBaseURL sets the base URL used to make requests to the Infrastructure API.

func ConfigInsightsInsertKey added in v0.33.0

func ConfigInsightsInsertKey(insightsInsertKey string) ConfigOption

ConfigInsightsInsertKey sets the New Relic Insights insert key this client will use. https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

func ConfigLogJSON added in v0.7.0

func ConfigLogJSON(logJSON bool) ConfigOption

ConfigLogJSON toggles JSON formatting on for the logger if set to true.

func ConfigLogLevel added in v0.7.0

func ConfigLogLevel(logLevel string) ConfigOption

ConfigLogLevel sets the log level for the client.

func ConfigLogger added in v0.7.0

func ConfigLogger(logger logging.Logger) ConfigOption

ConfigLogger can be used to customize the client's logger. Custom loggers must conform to the logging.Logger interface.

func ConfigNerdGraphBaseURL added in v0.7.0

func ConfigNerdGraphBaseURL(url string) ConfigOption

ConfigNerdGraphBaseURL sets the base URL used to make requests to the NerdGraph API.

func ConfigPersonalAPIKey added in v0.5.0

func ConfigPersonalAPIKey(apiKey string) ConfigOption

ConfigPersonalAPIKey sets the New Relic Admin API key this client will use. This key should be used to create a client instance. https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys

func ConfigRegion added in v0.3.0

func ConfigRegion(r string) ConfigOption

ConfigRegion sets the New Relic Region this client will use.

func ConfigServiceName added in v0.10.1

func ConfigServiceName(name string) ConfigOption

ConfigServiceName sets the service name logged

func ConfigSyntheticsBaseURL added in v0.7.0

func ConfigSyntheticsBaseURL(url string) ConfigOption

ConfigSyntheticsBaseURL sets the base URL used to make requests to the Synthetics API.

func ConfigUserAgent added in v0.3.0

func ConfigUserAgent(ua string) ConfigOption

ConfigUserAgent sets the HTTP UserAgent for API requests.

type NewRelic

type NewRelic struct {
	Accounts        accounts.Accounts
	Alerts          alerts.Alerts
	APIAccess       apiaccess.APIAccess
	APM             apm.APM
	Cloud           cloud.Cloud
	Dashboards      dashboards.Dashboards
	Edge            edge.Edge
	Entities        entities.Entities
	Events          events.Events
	EventsToMetrics eventstometrics.EventsToMetrics
	InstallEvents   installevents.Installevents
	Logs            logs.Logs
	NerdGraph       nerdgraph.NerdGraph
	NerdStorage     nerdstorage.NerdStorage
	Notifications   notifications.Notifications
	Nrdb            nrdb.Nrdb
	Nrqldroprules   nrqldroprules.Nrqldroprules
	Plugins         plugins.Plugins
	ServiceLevel    servicelevel.Servicelevel
	Synthetics      synthetics.Synthetics
	Workflows       workflows.Workflows
	Workloads       workloads.Workloads
	// contains filtered or unexported fields
}

NewRelic is a collection of New Relic APIs.

func New

func New(opts ...ConfigOption) (*NewRelic, error)

New returns a collection of New Relic APIs.

func (*NewRelic) SetLogLevel added in v0.55.4

func (nr *NewRelic) SetLogLevel(levelName string)

func (*NewRelic) TestEndpoints added in v0.59.3

func (nr *NewRelic) TestEndpoints() error

TestEndpoints makes a few calls to determine if the NewRelic enpoints are reachable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL