entities

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Overview

Package entities provides a programmatic API for interacting with New Relic One entities. It can be used for a variety of operations, including:

- Searching and reading New Relic One entities

- Creating, reading, updating, and deleting New Relic One entity tags

Authentication

You will need a valid Personal API key to communicate with the backend New Relic API that provides this functionality. 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

Package entities provides a programmatic API for interacting with New Relic One entities.

Example (Entity)
// Initialize the client configuration.  A Personal API key is required to
// communicate with the backend API.
cfg := config.New()
cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")

// Initialize the client.
client := New(cfg)

// Search the current account for entities by name and type.
searchParams := SearchEntitiesParams{
	Name: "Example entity",
	Type: EntityTypes.Application,
}

entities, err := client.SearchEntities(searchParams)
if err != nil {
	log.Fatal("error searching entities:", err)
}

// Get several entities by GUID.
var entityGuids []string
for _, e := range entities {
	entityGuids = append(entityGuids, e.GUID)
}

entities, err = client.GetEntities(entityGuids)
if err != nil {
	log.Fatal("error getting entities:", err)
}

// Get an entity by GUID.
entity, err := client.GetEntity(entities[0].GUID)
if err != nil {
	log.Fatal("error getting entity:", err)
}

// Output the entity's URL.
fmt.Printf("Entity name: %s, URL: %s\n", entity.Name, entity.Permalink)
Output:

Example (Tags)
// Initialize the client configuration.  A Personal API key is required to
// communicate with the backend API.
cfg := config.New()
cfg.PersonalAPIKey = os.Getenv("NEW_RELIC_API_KEY")

// Initialize the client.
client := New(cfg)

// Search the current account for entities by tag.
searchParams := SearchEntitiesParams{
	Tags: &TagValue{
		Key:   "exampleKey",
		Value: "exampleValue",
	},
}

entities, err := client.SearchEntities(searchParams)
if err != nil {
	log.Fatal("error searching entities:", err)
}

// List the tags associated with a given entity.  This example assumes that
// at least one entity has been returned by the search endpoint, but in
// practice it is possible that an empty slice is returned.
entityGUID := entities[0].GUID
tags, err := client.ListTags(entityGUID)
if err != nil {
	log.Fatal("error listing tags:", err)
}

// Output all tags and their values.
for _, t := range tags {
	fmt.Printf("Key: %s, Values: %v\n", t.Key, t.Values)
}

// Add tags to a given entity.
addTags := []Tag{
	{
		Key: "environment",
		Values: []string{
			"production",
		},
	},
	{
		Key: "teams",
		Values: []string{
			"ops",
			"product-development",
		},
	},
}

err = client.AddTags(entityGUID, addTags)
if err != nil {
	log.Fatal("error adding tags to entity:", err)
}

// Delete tag values from a given entity.
// This example deletes the "ops" value from the "teams" tag.
tagValuesToDelete := []TagValue{
	{
		Key:   "teams",
		Value: "ops",
	},
}

err = client.DeleteTagValues(entityGUID, tagValuesToDelete)
if err != nil {
	log.Fatal("error deleting tag values from entity:", err)
}

// Delete tags from a given entity.
// This example delete the "teams" tag and all its values from the entity.
err = client.DeleteTags(entityGUID, []string{"teams"})
if err != nil {
	log.Fatal("error deleting tags from entity:", err)
}

// Replace all existing tags for a given entity with the given set.
datacenterTag := Tag{
	Key: "datacenter",
	Values: []string{
		"east",
	},
}

replaceTags := []Tag{datacenterTag}

err = client.ReplaceTags(entityGUID, replaceTags)
if err != nil {
	log.Fatal("error replacing tags for entity:", err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// EntityAlertSeverities specifies the possible alert severities for a New Relic One entity.
	EntityAlertSeverities = struct {
		Critical      EntityAlertSeverityType
		NotAlerting   EntityAlertSeverityType
		NotConfigured EntityAlertSeverityType
		Warning       EntityAlertSeverityType
	}{
		Critical:      "CRITICAL",
		NotAlerting:   "NOT_ALERTING",
		NotConfigured: "NOT_CONFIGURED",
		Warning:       "WARNING",
	}
)
View Source
var (
	// EntityDomains specifies the possible domains for a New Relic One entity.
	EntityDomains = struct {
		APM            EntityDomainType
		Browser        EntityDomainType
		Infrastructure EntityDomainType
		Mobile         EntityDomainType
		Nr1            EntityDomainType
		Synthetics     EntityDomainType
		Visualization  EntityDomainType
	}{
		APM:            "APM",
		Browser:        "BROWSER",
		Infrastructure: "INFRA",
		Mobile:         "MOBILE",
		Nr1:            "NR1",
		Synthetics:     "SYNTH",
		Visualization:  "VIZ",
	}
)
View Source
var (
	// EntityTypes specifies the possible types for a New Relic One entity.
	EntityTypes = struct {
		Application EntityType
		Browser     EntityType
		Dashboard   EntityType
		Host        EntityType
		Mobile      EntityType
		Monitor     EntityType
		Workload    EntityType
	}{
		Application: "APM_APPLICATION_ENTITY",
		Browser:     "BROWSER_APPLICATION_ENTITY",
		Dashboard:   "DASHBOARD_ENTITY",
		Host:        "INFRASTRUCTURE_HOST_ENTITY",
		Mobile:      "MOBILE_APPLICATION_ENTITY",
		Monitor:     "SYNTHETIC_MONITOR_ENTITY",
		Workload:    "WORKLOAD_ENTITY",
	}
)
View Source
var (
	// Types specifies the possible types for a New Relic One entity.
	Types = struct {
		Application Type
		Dashboard   Type
		Host        Type
		Monitor     Type
		Workload    Type
	}{
		Application: "APPLICATION",
		Dashboard:   "DASHBOARD",
		Host:        "HOST",
		Monitor:     "MONITOR",
		Workload:    "WORKLOAD",
	}
)

Functions

This section is empty.

Types

type ApmApplicationEntity added in v0.16.0

type ApmApplicationEntity struct {
	Language             *string                                          `json:"language,omitempty"`
	RunningAgentVersions *ApmApplicationEntityOutlineRunningAgentVersions `json:"runningAgentVersions,omitempty"`
	Settings             *ApmApplicationEntityOutlineSettings             `json:"settings,omitempty"`
}

ApmApplicationEntity represents the unique fields returned on the ApmApplicationEntity interface

type ApmApplicationEntityOutlineRunningAgentVersions added in v0.16.0

type ApmApplicationEntityOutlineRunningAgentVersions struct {
	MaxVersion *string `json:"maxVersion,omitempty"`
	MinVersion *string `json:"minVersion,omitempty"`
}

type ApmApplicationEntityOutlineSettings added in v0.16.0

type ApmApplicationEntityOutlineSettings struct {
	ApdexTarget      *float64 `json:"apdexTarget,omitempty"`
	ServerSideConfig *bool    `json:"serverSideConfig"`
}

type BrowserApplicationEntity added in v0.16.0

type BrowserApplicationEntity struct {
	ServingApmApplicationID *int `json:"servingApmApplicationId,omitempty"`
}

BrowserApplicationEntity represents the unique fields returned on the BrowserApplicationEntity interface

type Entities

type Entities struct {
	// contains filtered or unexported fields
}

Entities is used to communicate with the New Relic Entities product.

func New

func New(config config.Config) Entities

New returns a new client for interacting with New Relic One entities.

func (*Entities) AddTags

func (e *Entities) AddTags(guid string, tags []Tag) error

AddTags writes tags to the entity specified by the provided entity GUID.

func (*Entities) DeleteTagValues

func (e *Entities) DeleteTagValues(guid string, tagValues []TagValue) error

DeleteTagValues deletes specific tag key and value pairs from the entity.

func (*Entities) DeleteTags

func (e *Entities) DeleteTags(guid string, tagKeys []string) error

DeleteTags deletes specific tag keys from the entity.

func (*Entities) GetEntities

func (e *Entities) GetEntities(guids []string) ([]*Entity, error)

GetEntities retrieves a set of New Relic One entities by their entity guids.

func (*Entities) GetEntity

func (e *Entities) GetEntity(guid string) (*Entity, error)

GetEntity retrieve a set of New Relic One entities by their entity guids.

func (*Entities) ListTags

func (e *Entities) ListTags(guid string) ([]*Tag, error)

ListTags returns a collection of tags for a given entity by entity GUID.

func (*Entities) ReplaceTags

func (e *Entities) ReplaceTags(guid string, tags []Tag) error

ReplaceTags replaces the entity's entire set of tags with the provided tag set.

func (*Entities) SearchEntities

func (e *Entities) SearchEntities(params SearchEntitiesParams) ([]*Entity, error)

SearchEntities searches New Relic One entities based on the provided search parameters.

type Entity

type Entity struct {
	AccountID  int              `json:"accountId,omitempty"`
	Domain     EntityDomainType `json:"domain,omitempty"`
	EntityType EntityType       `json:"entityType,omitempty"` // Full Type (ie APM_APPLICATION_ENTITY)
	GUID       string           `json:"guid,omitempty"`
	Name       string           `json:"name,omitempty"`
	Permalink  string           `json:"permalink,omitempty"`
	Reporting  bool             `json:"reporting,omitempty"`
	Type       Type             `json:"type,omitempty"`

	// ApmApplicationEntity, BrowserApplicationEntity
	AlertSeverity *EntityAlertSeverityType `json:"alertSeverity,omitempty"`
	ApplicationID *int                     `json:"applicationId,omitempty"`

	// Stitch in other structs
	ApmApplicationEntity
	BrowserApplicationEntity
}

Entity represents a New Relic One entity.

type EntityAlertSeverityType

type EntityAlertSeverityType string

EntityAlertSeverityType represents a New Relic One entity alert severity.

type EntityDomainType

type EntityDomainType string

EntityDomainType represents a New Relic One entity domain.

type EntityType

type EntityType string

EntityType represents a New Relic One entity type (full)

type SearchEntitiesParams added in v0.7.1

type SearchEntitiesParams struct {
	AlertSeverity                 EntityAlertSeverityType `json:"alertSeverity,omitempty"`
	Domain                        EntityDomainType        `json:"domain,omitempty"`
	InfrastructureIntegrationType string                  `json:"infrastructureIntegrationType,omitempty"`
	Name                          string                  `json:"name,omitempty"`
	Reporting                     *bool                   `json:"reporting,omitempty"`
	Tags                          *TagValue               `json:"tags,omitempty"`
	Type                          EntityType              `json:"type,omitempty"`
}

SearchEntitiesParams represents a set of search parameters for retrieving New Relic One entities.

type Tag

type Tag struct {
	Key    string
	Values []string
}

Tag represents a New Relic One entity tag.

type TagValue

type TagValue struct {
	Key   string
	Value string
}

TagValue represents a New Relic One entity tag and value pair.

type Type added in v0.16.0

type Type string

Type represents a New Relic One entity type (short)

Jump to

Keyboard shortcuts

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