synthetics

package module
v0.0.1-pre Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 14 Imported by: 0

README

new-relic-synthetics-go

GoDoc CircleCI

A New Relic Synthetics API client for Go. This package provides CRUD functionality for both Synthetics monitors, backed by the New Relic Synthetics API, and Synthetics alert conditions, backed by the New Relic V2 API.

Detailed API docs for this client can be found on the GoDoc link above.

Example

conf := func(s *synthetics.Client) {
	s.APIKey = os.Getenv("NEWRELIC_API_KEY")

	// SyntheticsBaseURL is optional.
	// Default is https://synthetics.newrelic.com/synthetics/api/v3
	s.SyntheticsBaseURL = os.Getenv("NEWRELIC_SYNTHETICS_API_URL")

	// V2BaseURL is optional.
	// Default is https://api.newrelic.com/v2
	s.V2BaseURL = os.Getenv("NEWRELIC_V2_API_URL")
}
client, _ := synthetics.NewClient(conf)

// Get specific monitor
client.GetMonitor("monitor-id")

// Create a monitor
client.CreateMonitor(&synthetics.CreateMonitorArgs{
	Name:         "sample-monitor",
	Type:         "SIMPLE",
	Frequency:    60,
	URI:          "https://www.dollarshaveclub.com",
	Locations:    []string{"AWS_US_WEST_1"},
	Status:       "ENABLED",
	SLAThreshold: 7,
})

// Update monitor
client.UpdateMonitor("monitor-id", &synthetics.UpdateMonitorArgs{
	Name: "new-monitor-name",
})

// Create an alert condition
client.CreateAlertCondition("policy-id"), &synthetics.CreateAlertConditionArgs{
	Name: "alert-condition-name",
	MonitorID: "monitor-id",
	Enabled: true,
})

Documentation

Index

Constants

View Source
const (

	// The different monitor types.
	TypeSimple        = "SIMPLE"
	TypeBrowser       = "BROWSER"
	TypeScriptAPI     = "SCRIPT_API"
	TypeScriptBrowser = "SCRIPT_BROWSER"

	// SyntheticsBaseURL sets the base URL for the synthetics API.
	// Default is https://synthetics.newrelic.com/synthetics/api/v3
	SyntheticsBaseURL = "https://synthetics.newrelic.com/synthetics/api/v3"

	// V2BaseURL sets the base URL for the V2 API.
	// Default is https://api.newrelic.com/v2
	V2BaseURL = "https://api.newrelic.com/v2"
)

Variables

View Source
var (

	// ErrMonitorNotFound is returned when a monitor can't be
	// found.
	ErrMonitorNotFound = errors.New("error: monitor not found")

	// ErrMonitorScriptNotFound is returned when a monitor script can't
	// be found.
	ErrMonitorScriptNotFound = errors.New("error: monitor script not found")

	// ErrAlertConditionNotFound is returned when an alert
	// condition can't be found.
	ErrAlertConditionNotFound = errors.New("error: alert condition not found")
)

Functions

This section is empty.

Types

type AlertCondition

type AlertCondition struct {
	ID         uint   `json:"id"`
	Name       string `json:"name"`
	MonitorID  string `json:"monitor_id"`
	RunbookURL string `json:"runbook_url,omitempty"`
	Enabled    bool   `json:"enabled"`
}

AlertCondition is the response to CreateAlertCondition.

type Client

type Client struct {
	APIKey            string
	SyntheticsBaseURL string
	V2BaseURL         string
	HTTPClient        HTTPClient
	// contains filtered or unexported fields
}

Client is a client to New Relic's Synthetics API and V2 API.

func NewClient

func NewClient(configs ...func(*Client)) (*Client, error)

NewClient instantiates a new Client.

func (*Client) CreateAlertCondition

func (c *Client) CreateAlertCondition(policyID uint, args *CreateAlertConditionArgs) (*AlertCondition, error)

CreateAlertCondition creates a Synthetics alert condition for an existing policy.

func (*Client) CreateMonitor

func (c *Client) CreateMonitor(m *CreateMonitorArgs) (*Monitor, error)

CreateMonitor creates a new Monitor.

func (*Client) DeleteAlertCondition

func (c *Client) DeleteAlertCondition(alertConditionID uint) error

DeleteAlertCondition deletes a Synthetics alert condition.

func (*Client) DeleteMonitor

func (c *Client) DeleteMonitor(id string) error

DeleteMonitor deletes a Monitor.

func (*Client) GetAlertCondition

func (c *Client) GetAlertCondition(policyID, alertConditionID uint) (*AlertCondition, error)

GetAlertCondition finds a Synthetics alert condition.

func (*Client) GetAllMonitors

func (c *Client) GetAllMonitors(offset, limit uint) (*GetAllMonitorsResponse, error)

GetAllMonitors returns all monitors within a New Relic Synthetics account. Values of -1 indicate to use the defaults.

func (*Client) GetMonitor

func (c *Client) GetMonitor(id string) (*Monitor, error)

GetMonitor returns a specific Monitor.

func (*Client) GetMonitorScript

func (c *Client) GetMonitorScript(id string) (string, error)

GetMonitorScript returns the script that backs a monitor.

func (*Client) UpdateAlertCondition

func (c *Client) UpdateAlertCondition(alertConditionID uint, args *UpdateAlertConditionArgs) (*AlertCondition, error)

UpdateAlertCondition updates a Synthetics alert condition. All fields must be specified.

func (*Client) UpdateMonitor

func (c *Client) UpdateMonitor(id string, args *UpdateMonitorArgs) (*Monitor, error)

UpdateMonitor creates a new Monitor.

func (*Client) UpdateMonitorScript

func (c *Client) UpdateMonitorScript(id string, args *UpdateMonitorScriptArgs) error

UpdateMonitorScript updates the script that backs a monitor.

type CreateAlertConditionArgs

type CreateAlertConditionArgs struct {
	Name       string `json:"name"`
	MonitorID  string `json:"monitor_id"`
	RunbookURL string `json:"runbook_url,omitempty"`
	Enabled    bool   `json:"enabled"`
}

CreateAlertConditionArgs are the arguments to CreateAlertCondition.

type CreateMonitorArgs

type CreateMonitorArgs struct {
	Name                   string   `json:"name"`
	Type                   string   `json:"type"`
	Frequency              uint     `json:"frequency"`
	URI                    string   `json:"uri,omitempty"`
	Locations              []string `json:"locations"`
	Status                 string   `json:"status"`
	SLAThreshold           float64  `json:"slaThreshold,omitempty"`
	ValidationString       *string  `json:"-"`
	VerifySSL              *bool    `json:"-"`
	BypassHEADRequest      *bool    `json:"-"`
	TreatRedirectAsFailure *bool    `json:"-"`
}

CreateMonitorArgs are the arguments to CreateMonitor.

type ExtendedMonitor

type ExtendedMonitor struct {
	ID           string                 `json:"id"`
	Name         string                 `json:"name"`
	Type         string                 `json:"type"`
	Frequency    uint                   `json:"frequency"`
	URI          string                 `json:"uri"`
	Locations    []string               `json:"locations"`
	Status       string                 `json:"status"`
	SLAThreshold float64                `json:"slaThreshold"`
	Options      map[string]interface{} `json:"options"`
	ModifiedAt   time.Time
	CreatedAt    time.Time
	UserID       uint   `json:"userId"`
	APIVersion   string `json:"apiVersion"`

	// These are only used for parsing.
	ModifiedAtRaw string `json:"modifiedAt"`
	CreatedAtRaw  string `json:"createdAt"`
}

ExtendedMonitor is the monitor format provided by GetAllMonitors.

type GetAllMonitorsResponse

type GetAllMonitorsResponse struct {
	Monitors []*ExtendedMonitor `json:"monitors"`
	Count    uint               `json:"count"`
}

GetAllMonitorsResponse is the response by GetAllMonitors.

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient is the interface to an HTTP client.

type Monitor

type Monitor struct {
	ID                     string                 `json:"id,omitempty"`
	Name                   string                 `json:"name"`
	Type                   string                 `json:"type"`
	Frequency              uint                   `json:"frequency"`
	URI                    string                 `json:"uri"`
	Locations              []string               `json:"locations"`
	Status                 string                 `json:"status"`
	SLAThreshold           float64                `json:"slaThreshold"`
	UserID                 uint                   `json:"userId,omitempty"`
	APIVersion             string                 `json:"apiVersion,omitempty"`
	Options                map[string]interface{} `json:"options,omitempty"`
	ValidationString       *string                `json:"-"`
	VerifySSL              *bool                  `json:"-"`
	BypassHEADRequest      *bool                  `json:"-"`
	TreatRedirectAsFailure *bool                  `json:"-"`
}

Monitor describes a specific Synthetics monitor.

type RetryableHTTPClient

type RetryableHTTPClient interface {
	Do(func() (*http.Request, error)) (*http.Response, error)
}

RetryableHTTPClient is the interface to an HTTP client that supports retries.

type ScriptLocation

type ScriptLocation struct {
	Name string `json:"name"`
	HMAC string `json:"hmac"`
}

ScriptLocation corresponds to the different locations a script can be executed from.

type UpdateAlertConditionArgs

type UpdateAlertConditionArgs struct {
	Name       string `json:"name"`
	MonitorID  string `json:"monitor_id"`
	RunbookURL string `json:"runbook_url,omitempty"`
	Enabled    bool   `json:"enabled"`
}

UpdateAlertConditionArgs are the arguments to UpdateAlertCondition.

type UpdateMonitorArgs

type UpdateMonitorArgs struct {
	Name                   string   `json:"name,omitempty"`
	Frequency              uint     `json:"frequency,omitempty"`
	URI                    string   `json:"uri,omitempty"`
	Locations              []string `json:"locations,omitempty"`
	Status                 string   `json:"status,omitempty"`
	SLAThreshold           float64  `json:"slaThreshold,omitempty"`
	ValidationString       *string  `json:"-"`
	VerifySSL              *bool    `json:"-"`
	BypassHEADRequest      *bool    `json:"-"`
	TreatRedirectAsFailure *bool    `json:"-"`
}

UpdateMonitorArgs are the arguments to UpdateMonitor.

type UpdateMonitorScriptArgs

type UpdateMonitorScriptArgs struct {
	ScriptText      string            `json:"scriptText"`
	ScriptLocations []*ScriptLocation `json:"scriptLocations,omitempty"`
}

UpdateMonitorScriptArgs are the arguments to UpdateMonitorScript.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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