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{}, []entities.SortCriterionWithDirection{}, ) 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 ¶
- type ConfigOption
- func ConfigAdminAPIKey(adminAPIKey string) ConfigOption
- func ConfigBaseURL(url string) ConfigOption
- func ConfigHTTPTimeout(t time.Duration) ConfigOption
- func ConfigHTTPTransport(transport http.RoundTripper) ConfigOption
- func ConfigInfrastructureBaseURL(url string) ConfigOption
- func ConfigInsightsInsertKey(insightsInsertKey string) ConfigOption
- func ConfigLogJSON(logJSON bool) ConfigOption
- func ConfigLogLevel(logLevel string) ConfigOption
- func ConfigLogger(logger logging.Logger) ConfigOption
- func ConfigNerdGraphBaseURL(url string) ConfigOption
- func ConfigPersonalAPIKey(apiKey string) ConfigOption
- func ConfigRegion(r string) ConfigOption
- func ConfigServiceName(name string) ConfigOption
- func ConfigSyntheticsBaseURL(url string) ConfigOption
- func ConfigUserAgent(ua string) ConfigOption
- type NewRelic
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigOption ¶
type ConfigOption = config.ConfigOption
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 ¶
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 ¶
func ConfigBaseURL(url string) ConfigOption
ConfigBaseURL sets the base URL used to make requests to the REST API V2.
func ConfigHTTPTimeout ¶
func ConfigHTTPTimeout(t time.Duration) ConfigOption
ConfigHTTPTimeout sets the timeout for HTTP requests.
func ConfigHTTPTransport ¶
func ConfigHTTPTransport(transport http.RoundTripper) ConfigOption
ConfigHTTPTransport sets the HTTP Transporter.
func ConfigInfrastructureBaseURL ¶
func ConfigInfrastructureBaseURL(url string) ConfigOption
ConfigInfrastructureBaseURL sets the base URL used to make requests to the Infrastructure API.
func ConfigInsightsInsertKey ¶
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 ¶
func ConfigLogJSON(logJSON bool) ConfigOption
ConfigLogJSON toggles JSON formatting on for the logger if set to true.
func ConfigLogLevel ¶
func ConfigLogLevel(logLevel string) ConfigOption
ConfigLogLevel sets the log level for the client.
func ConfigLogger ¶
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 ¶
func ConfigNerdGraphBaseURL(url string) ConfigOption
ConfigNerdGraphBaseURL sets the base URL used to make requests to the NerdGraph API.
func ConfigPersonalAPIKey ¶
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 ¶
func ConfigRegion(r string) ConfigOption
ConfigRegion sets the New Relic Region this client will use.
func ConfigServiceName ¶
func ConfigServiceName(name string) ConfigOption
ConfigServiceName sets the service name logged
func ConfigSyntheticsBaseURL ¶
func ConfigSyntheticsBaseURL(url string) ConfigOption
ConfigSyntheticsBaseURL sets the base URL used to make requests to the Synthetics API.
func ConfigUserAgent ¶
func ConfigUserAgent(ua string) ConfigOption
ConfigUserAgent sets the HTTP UserAgent for API requests.
type NewRelic ¶
type NewRelic struct { AccountManagement accountmanagement.Accountmanagement Accounts accounts.Accounts Agent agent.Agent AgentApplications agentapplications.AgentApplications Alerts alerts.Alerts APIAccess apiaccess.APIAccess APM apm.APM AuthorizationManagement authorizationmanagement.Authorizationmanagement ChangeTracking changetracking.Changetracking Cloud cloud.Cloud CustomerAdministration customeradministration.Customeradministration Dashboards dashboards.Dashboards Edge edge.Edge Entities entities.Entities Events events.Events EventsToMetrics eventstometrics.EventsToMetrics InstallEvents installevents.Installevents Logs logs.Logs Logconfigurations logconfigurations.Logconfigurations NerdGraph nerdgraph.NerdGraph NerdStorage nerdstorage.NerdStorage Notifications notifications.Notifications Nrdb nrdb.Nrdb Nrqldroprules nrqldroprules.Nrqldroprules Organization organization.Organization Plugins plugins.Plugins ServiceLevel servicelevel.Servicelevel Synthetics synthetics.Synthetics UserManagement usermanagement.Usermanagement Workflows workflows.Workflows Workloads workloads.Workloads KeyTransaction keytransaction.Keytransaction // 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 ¶
func (*NewRelic) TestEndpoints ¶
TestEndpoints makes a few calls to determine if the NewRelic enpoints are reachable.