pingdom

package
v1.0.31 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package pingdom provides a client interface to the Pingdom API. This currently only supports working with basic HTTP and ping checks.

Construct a new Pingdom client:

client, err := pingdom.NewClientWithConfig(pingdom.ClientConfig{
	Username: "pingdom_username",
	Password: "pingdom_password",
	APIKey: "pingdom_api_key",
})

Using a Pingdom client, you can access supported services.

CheckService

This service manages pingdom Checks which are represented by the `Check` struct. When creating or updating Checks you must specify at a minimum the `Name`, `Hostname` and `Resolution`. Other fields are optional but if not set will be given the zero values for the underlying type.

More information on Checks from Pingdom: https://www.pingdom.com/features/api/documentation/#ResourceChecks

Get a list of all checks:

checks, err := client.Checks.List()
fmt.Println("Checks:", checks) // [{ID Name} ...]

Create a new HTTP check:

newCheck := pingdom.Check{Name: "Test Check", Hostname: "example.com", Resolution: 5}
check, err := client.Checks.Create(&newCheck)
fmt.Println("Created check:", check) // {ID, Name}

Create a new HTTP check with alerts for specified users:

newCheck := pingdom.Check{Name: "Test Check", Hostname: "example.com", Resolution: 5, UserIds: []int{12345}}
check, err := client.Checks.Create(&newCheck)
fmt.Println("Created check:", check) // {ID, Name}

Create a new Ping check:

newCheck := pingdom.PingCheck{Name: "Test Check", Hostname: "example.com", Resolution: 5}
check, err := client.Checks.Create(&newCheck)
fmt.Println("Created check:", check) // {ID, Name}

Get details for a specific check:

checkDetails, err := client.Checks.Read(12345)

Update a check:

updatedCheck := pingdom.Check{Name: "Updated Check", Hostname: "example2.com", Resolution: 5}
msg, err := client.Checks.Update(12345, &updatedCheck)

Delete a check:

msg, err := client.Checks.Delete(12345)

Index

Constants

This section is empty.

Variables

View Source
var ErrBadResolution = errors.New("resolution must be either 'hour', 'day' or 'week'")

ErrBadResolution is an error for when an invalid resolution is specified.

View Source
var ErrMissingId = errors.New("required field 'Id' missing")

ErrMissingId is an error for when a required Id field is missing.

Functions

This section is empty.

Types

type Check

type Check interface {
	PutParams() map[string]string
	PostParams() map[string]string
	Valid() error
}

Check is an interface representing a Pingdom check. Specific check types should implement the methods of this interface.

type CheckResponse

type CheckResponse struct {
	ID                       int                 `json:"id"`
	Name                     string              `json:"name"`
	Resolution               int                 `json:"resolution,omitempty"`
	SendNotificationWhenDown int                 `json:"sendnotificationwhendown,omitempty"`
	NotifyAgainEvery         int                 `json:"notifyagainevery,omitempty"`
	NotifyWhenBackup         bool                `json:"notifywhenbackup,omitempty"`
	Created                  int64               `json:"created,omitempty"`
	Hostname                 string              `json:"hostname,omitempty"`
	Status                   string              `json:"status,omitempty"`
	LastErrorTime            int64               `json:"lasterrortime,omitempty"`
	LastTestTime             int64               `json:"lasttesttime,omitempty"`
	LastResponseTime         int64               `json:"lastresponsetime,omitempty"`
	Paused                   bool                `json:"paused,omitempty"`
	IntegrationIds           []int               `json:"integrationids,omitempty"`
	SeverityLevel            string              `json:"severity_level,omitempty"`
	Type                     CheckResponseType   `json:"type,omitempty"`
	Tags                     []CheckResponseTag  `json:"tags,omitempty"`
	UserIds                  []int               `json:"userids,omitempty"`
	Teams                    []CheckTeamResponse `json:"teams,omitempty"`
	ResponseTimeThreshold    int                 `json:"responsetime_threshold,omitempty"`
	ProbeFilters             []string            `json:"probe_filters,omitempty"`
	IP6                      bool                `json:"ip6,omitempty"`

	// Legacy; this is not returned by the API, we backfill the value from the
	// Teams field.
	TeamIds []int
}

CheckResponse represents the JSON response for a check from the Pingdom API.

type CheckResponseHTTPDetails

type CheckResponseHTTPDetails struct {
	Url              string            `json:"url,omitempty"`
	Encryption       bool              `json:"encryption,omitempty"`
	Port             int               `json:"port,omitempty"`
	Username         string            `json:"username,omitempty"`
	Password         string            `json:"password,omitempty"`
	ShouldContain    string            `json:"shouldcontain,omitempty"`
	ShouldNotContain string            `json:"shouldnotcontain,omitempty"`
	PostData         string            `json:"postdata,omitempty"`
	RequestHeaders   map[string]string `json:"requestheaders,omitempty"`
}

CheckResponseHTTPDetails represents the details specific to HTTP checks.

type CheckResponseTCPDetails

type CheckResponseTCPDetails struct {
	Port           int    `json:"port,omitempty"`
	StringToSend   string `json:"stringtosend,omitempty"`
	StringToExpect string `json:"stringtoexpect,omitempty"`
}

CheckResponseTCPDetails represents the details specific to TCP checks.

type CheckResponseTag

type CheckResponseTag struct {
	Name  string      `json:"name"`
	Type  string      `json:"type"`
	Count interface{} `json:"count"`
}

CheckResponseTag is an optional tag that can be added to checks.

type CheckResponseType

type CheckResponseType struct {
	Name string                    `json:"-"`
	HTTP *CheckResponseHTTPDetails `json:"http,omitempty"`
	TCP  *CheckResponseTCPDetails  `json:"tcp,omitempty"`
}

CheckResponseType is the type of the Pingdom check.

func (*CheckResponseType) UnmarshalJSON

func (c *CheckResponseType) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a byte array into a CheckResponseType.

type CheckService

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

CheckService provides an interface to Pingdom checks.

func (*CheckService) Create

func (cs *CheckService) Create(check Check) (*CheckResponse, error)

Create a new check. This function will validate the given check param to ensure that it contains correct values before submitting the request Returns a CheckResponse object representing the response from Pingdom. Note that Pingdom does not return a full check object so in the returned object you should only use the ID field.

func (*CheckService) Delete

func (cs *CheckService) Delete(id int) (*PingdomResponse, error)

Delete will delete the check for the given ID.

func (*CheckService) List

func (cs *CheckService) List(params ...map[string]string) ([]CheckResponse, error)

List returns a list of checks from Pingdom. This returns type CheckResponse rather than Check since the Pingdom API does not return a complete representation of a check.

func (*CheckService) Read

func (cs *CheckService) Read(id int) (*CheckResponse, error)

ReadCheck returns detailed information about a pingdom check given its ID. This returns type CheckResponse rather than Check since the pingdom API does not return a complete representation of a check.

func (*CheckService) Results

func (cs *CheckService) Results(id int, params ...map[string]string) (*ResultsResponse, error)

Results returns raw check results and the list of associated probe IDs used from Pingdom.

func (*CheckService) SummaryPerformance

func (cs *CheckService) SummaryPerformance(request SummaryPerformanceRequest) (*SummaryPerformanceResponse, error)

SummaryPerformance returns a performance summary from Pingdom.

func (*CheckService) Update

func (cs *CheckService) Update(id int, check Check) (*PingdomResponse, error)

Update will update the check represented by the given ID with the values in the given check. You should submit the complete list of values in the given check parameter, not just those that have changed.

type CheckTeamResponse

type CheckTeamResponse struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

CheckTeamResponse is a Team returned inside of a Check instance. (We can't use TeamResponse because the ID returned here is an int, not a string).

type Client

type Client struct {
	APIToken string
	BaseURL  *url.URL

	Checks       *CheckService
	Maintenances *MaintenanceService
	Probes       *ProbeService
	// contains filtered or unexported fields
}

Client represents a client to the Pingdom API. This package also provides a NewClient function for convenience to initialize a client with default parameters.

func NewClientWithConfig

func NewClientWithConfig(config ClientConfig) (*Client, error)

NewClientWithConfig returns a Pingdom client.

func (*Client) Do

func (pc *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do makes an HTTP request and will unmarshal the JSON response in to the passed in interface. If the HTTP response is outside of the 2xx range the response will be returned along with the error.

func (*Client) NewRequest

func (pc *Client) NewRequest(method string, rsc string, params map[string]string) (*http.Request, error)

NewRequest makes a new HTTP Request. The method param should be an HTTP method in all caps such as GET, POST, PUT, DELETE. The rsc param should correspond with a restful resource. Params can be passed in as a map of strings Usually users of the client can use one of the convenience methods such as ListChecks, etc but this method is provided to allow for making other API calls that might not be built in.

type ClientConfig

type ClientConfig struct {
	APIToken   string
	BaseURL    string
	HTTPClient *http.Client
}

ClientConfig represents a configuration for a pingdom client.

type CreateUserContactResponse

type CreateUserContactResponse struct {
	Id int `json:"id"`
}

CreateUserContactResponse represents the JSON response for a user contact.

type HttpCheck

type HttpCheck struct {
	Name                     string            `json:"name"`
	Hostname                 string            `json:"hostname,omitempty"`
	Resolution               int               `json:"resolution,omitempty"`
	Paused                   bool              `json:"paused,omitempty"`
	SendNotificationWhenDown int               `json:"sendnotificationwhendown,omitempty"`
	NotifyAgainEvery         int               `json:"notifyagainevery,omitempty"`
	NotifyWhenBackup         bool              `json:"notifywhenbackup,omitempty"`
	Url                      string            `json:"url,omitempty"`
	Encryption               bool              `json:"encryption,omitempty"`
	Port                     int               `json:"port,omitempty"`
	Username                 string            `json:"username,omitempty"`
	Password                 string            `json:"password,omitempty"`
	ShouldContain            string            `json:"shouldcontain,omitempty"`
	ShouldNotContain         string            `json:"shouldnotcontain,omitempty"`
	PostData                 string            `json:"postdata,omitempty"`
	RequestHeaders           map[string]string `json:"requestheaders,omitempty"`
	IntegrationIds           []int             `json:"integrationids,omitempty"`
	ResponseTimeThreshold    int               `json:"responsetime_threshold,omitempty"`
	Tags                     string            `json:"tags,omitempty"`
	ProbeFilters             string            `json:"probe_filters,omitempty"`
	UserIds                  []int             `json:"userids,omitempty"`
	TeamIds                  []int             `json:"teamids,omitempty"`
}

HttpCheck represents a Pingdom HTTP check.

func (*HttpCheck) PostParams

func (ck *HttpCheck) PostParams() map[string]string

PostParams returns a map of parameters for an HttpCheck that can be sent along with an HTTP POST request. They are the same than the Put params, but empty strings cleared out, to avoid Pingdom API reject the request.

func (*HttpCheck) PutParams

func (ck *HttpCheck) PutParams() map[string]string

PutParams returns a map of parameters for an HttpCheck that can be sent along with an HTTP PUT request.

func (*HttpCheck) Valid

func (ck *HttpCheck) Valid() error

Valid determines whether the HttpCheck contains valid fields. This can be used to guard against sending illegal values to the Pingdom API.

type Maintenance

type Maintenance interface {
	PutParams() map[string]string
	PostParams() map[string]string
	Valid() error
}

Maintenance is a Pingdom maintenance window.

type MaintenanceCheckResponse

type MaintenanceCheckResponse struct {
	Uptime []int `json:"uptime"`
	Tms    []int `json:"tms"`
}

MaintenanceCheckResponse represents Check reply in json MaintenanceResponse.

type MaintenanceDelete

type MaintenanceDelete interface {
	DeleteParams() map[string]string
	ValidDelete() error
}

MaintenanceDelete is the set of parameters to a Pingdom maintenance delete request.

type MaintenanceResponse

type MaintenanceResponse struct {
	ID             int                      `json:"id"`
	Description    string                   `json:"description"`
	From           int64                    `json:"from"`
	To             int64                    `json:"to"`
	RecurrenceType string                   `json:"recurrencetype"`
	RepeatEvery    int                      `json:"repeatevery"`
	EffectiveTo    int64                    `json:"effectiveto"`
	Checks         MaintenanceCheckResponse `json:"checks"`
}

MaintenanceResponse represents the JSON response for a maintenance from the Pingdom API.

type MaintenanceService

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

MaintenanceService provides an interface to Pingdom maintenance windows.

func (*MaintenanceService) Create

func (cs *MaintenanceService) Create(maintenance Maintenance) (*MaintenanceResponse, error)

Create creates a new Maintenance.

func (*MaintenanceService) Delete

func (cs *MaintenanceService) Delete(id int) (*PingdomResponse, error)

Delete will delete the Maintenance for the given ID.

func (*MaintenanceService) List

func (cs *MaintenanceService) List(params ...map[string]string) ([]MaintenanceResponse, error)

List returns the response holding a list of Maintenance windows.

func (*MaintenanceService) MultiDelete

func (cs *MaintenanceService) MultiDelete(maintenance MaintenanceDelete) (*PingdomResponse, error)

MultiDelete will delete the Maintenance for the given ID.

func (*MaintenanceService) Read

Read returns a Maintenance for a given ID.

func (*MaintenanceService) Update

func (cs *MaintenanceService) Update(id int, maintenance Maintenance) (*PingdomResponse, error)

Update is used to update an existing Maintenance. Only the 'Description', and 'To' fields can be updated.

type MaintenanceWindow

type MaintenanceWindow struct {
	Description    string `json:"description"`
	From           int64  `json:"from"`
	To             int64  `json:"to"`
	RecurrenceType string `json:"recurrencetype,omitempty"`
	RepeatEvery    int    `json:"repeatevery,omitempty"`
	EffectiveTo    int    `json:"effectiveto,omitempty"`
	UptimeIDs      string `json:"uptimeids,omitempty"`
	TmsIDs         string `json:"tmsids,omitempty"`
}

MaintenanceWindow represents a Pingdom Maintenance Window.

func (*MaintenanceWindow) PostParams

func (ck *MaintenanceWindow) PostParams() map[string]string

PostParams returns a map of parameters for an Maintenance Window that can be sent along with an HTTP POST request. They are the same than the Put params, but empty strings cleared out, to avoid Pingdom API reject the request.

func (*MaintenanceWindow) PutParams

func (ck *MaintenanceWindow) PutParams() map[string]string

PutParams returns a map of parameters for an MaintenanceWindow that can be sent along.

func (*MaintenanceWindow) Valid

func (ck *MaintenanceWindow) Valid() error

Valid determines whether the MaintenanceWindow contains valid fields. This can be used to guard against sending illegal values to the Pingdom API.

type MaintenanceWindowDelete

type MaintenanceWindowDelete struct {
	MaintenanceIDs string `json:"maintenanceids"`
}

MaintenanceWindowDelete represents delete request parameters.

func (*MaintenanceWindowDelete) DeleteParams

func (ck *MaintenanceWindowDelete) DeleteParams() map[string]string

DeleteParams returns a map of parameters for an MaintenanceWindow that can be sent along.

func (*MaintenanceWindowDelete) ValidDelete

func (ck *MaintenanceWindowDelete) ValidDelete() error

ValidDelete determines whether a delete request contains valid parameters.

type PingCheck

type PingCheck struct {
	Name                     string `json:"name"`
	Hostname                 string `json:"hostname,omitempty"`
	Resolution               int    `json:"resolution,omitempty"`
	Paused                   bool   `json:"paused,omitempty"`
	SendNotificationWhenDown int    `json:"sendnotificationwhendown,omitempty"`
	NotifyAgainEvery         int    `json:"notifyagainevery,omitempty"`
	NotifyWhenBackup         bool   `json:"notifywhenbackup,omitempty"`
	IntegrationIds           []int  `json:"integrationids,omitempty"`
	Tags                     string `json:"tags,omitempty"`
	ResponseTimeThreshold    int    `json:"responsetime_threshold,omitempty"`
	ProbeFilters             string `json:"probe_filters,omitempty"`
	UserIds                  []int  `json:"userids,omitempty"`
	TeamIds                  []int  `json:"teamids,omitempty"`
}

PingCheck represents a Pingdom ping check.

func (*PingCheck) PostParams

func (ck *PingCheck) PostParams() map[string]string

PostParams returns a map of parameters for a PingCheck that can be sent along with an HTTP POST request. Same as PUT.

func (*PingCheck) PutParams

func (ck *PingCheck) PutParams() map[string]string

PutParams returns a map of parameters for a PingCheck that can be sent along with an HTTP PUT request.

func (*PingCheck) Valid

func (ck *PingCheck) Valid() error

Valid determines whether the PingCheck contains valid fields. This can be used to guard against sending illegal values to the Pingdom API.

type PingdomError

type PingdomError struct {
	StatusCode int    `json:"statuscode"`
	StatusDesc string `json:"statusdesc"`
	Message    string `json:"errormessage"`
}

PingdomError represents an error response from the Pingdom API.

func (*PingdomError) Error

func (r *PingdomError) Error() string

Return string representation of the PingdomError.

type PingdomResponse

type PingdomResponse struct {
	Message string `json:"message"`
}

PingdomResponse represents a general response from the Pingdom API.

type ProbeResponse

type ProbeResponse struct {
	ID         int    `json:"id"`
	Country    string `json:"country"`
	City       string `json:"city"`
	Name       string `json:"name"`
	Active     bool   `json:"active"`
	Hostname   string `json:"hostname"`
	IP         string `json:"ip"`
	IPv6       string `json:"ipv6"`
	CountryISO string `json:"countryiso"`
	Region     string `json:"region"`
}

ProbeResponse represents the JSON response for probes from the Pingdom API.

type ProbeService

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

ProbeService provides an interface to Pingdom probes.

func (*ProbeService) List

func (cs *ProbeService) List(params ...map[string]string) ([]ProbeResponse, error)

List return a list of probes from Pingdom.

type Result

type Result struct {
	ProbeID        int    `json:"probeid"`
	Time           int    `json:"time"`
	Status         string `json:"status"`
	ResponseTime   int    `json:"responsetime"`
	StatusDesc     string `json:"statusdesc"`
	StatusDescLong string `json:"statusdesclong"`
}

Result reprensents the JSON response for a detailed check result.

type ResultsResponse

type ResultsResponse struct {
	ActiveProbes []int    `json:"activeprobes"`
	Results      []Result `json:"results"`
}

ResultsResponse represents the JSON response for detailed check results from the Pingdom API.

type SummaryPerformanceMap

type SummaryPerformanceMap struct {
	Hours []SummaryPerformanceSummary `json:"hours,omitempty"`
	Days  []SummaryPerformanceSummary `json:"days,omitempty"`
	Weeks []SummaryPerformanceSummary `json:"weeks,omitempty"`
}

SummaryPerformanceMap is the performance broken down over different time intervals.

type SummaryPerformanceRequest

type SummaryPerformanceRequest struct {
	Id            int
	From          int
	To            int
	Resolution    string
	IncludeUptime bool
	Probes        string
	Order         string
}

SummaryPerformanceRequest is the API request to Pingdom for a SummaryPerformance.

func (SummaryPerformanceRequest) GetParams

func (csr SummaryPerformanceRequest) GetParams() (params map[string]string)

GetParams returns a map of params for a Pingdom SummaryPerformanceRequest.

func (SummaryPerformanceRequest) Valid

func (csr SummaryPerformanceRequest) Valid() error

Valid determines whether a SummaryPerformanceRequest contains valid fields for the Pingdom API.

type SummaryPerformanceResponse

type SummaryPerformanceResponse struct {
	Summary SummaryPerformanceMap `json:"summary"`
}

SummaryPerformanceResponse represents the JSON response for a summary performance from the Pingdom API.

type SummaryPerformanceSummary

type SummaryPerformanceSummary struct {
	AvgResponse int `json:"avgresponse"`
	Downtime    int `json:"downtime"`
	StartTime   int `json:"starttime"`
	Unmonitored int `json:"unmonitored"`
	Uptime      int `json:"uptime"`
}

SummaryPerformanceSummary is the metrics for a performance summary.

type TCPCheck

type TCPCheck struct {
	Name                     string `json:"name"`
	Hostname                 string `json:"hostname,omitempty"`
	Resolution               int    `json:"resolution,omitempty"`
	Paused                   bool   `json:"paused,omitempty"`
	SendNotificationWhenDown int    `json:"sendnotificationwhendown,omitempty"`
	NotifyAgainEvery         int    `json:"notifyagainevery,omitempty"`
	NotifyWhenBackup         bool   `json:"notifywhenbackup,omitempty"`
	IntegrationIds           []int  `json:"integrationids,omitempty"`
	Tags                     string `json:"tags,omitempty"`
	ProbeFilters             string `json:"probe_filters,omitempty"`
	UserIds                  []int  `json:"userids,omitempty"`
	TeamIds                  []int  `json:"teamids,omitempty"`
	Port                     int    `json:"port"`
	StringToSend             string `json:"stringtosend,omitempty"`
	StringToExpect           string `json:"stringtoexpect,omitempty"`
}

TCPCheck represents a Pingdom TCP check.

func (*TCPCheck) PostParams

func (ck *TCPCheck) PostParams() map[string]string

PostParams returns a map of parameters for a TCPCheck that can be sent along with an HTTP POST request. Same as PUT.

func (*TCPCheck) PutParams

func (ck *TCPCheck) PutParams() map[string]string

PutParams returns a map of parameters for a TCPCheck that can be sent along with an HTTP PUT request.

func (*TCPCheck) Valid

func (ck *TCPCheck) Valid() error

Valid determines whether the TCPCheck contains valid fields. This can be used to guard against sending illegal values to the Pingdom API.

type UserEmailResponse

type UserEmailResponse struct {
	Id       int    `json:"id"`
	Severity string `json:"severity"`
	Address  string `json:"address"`
}

UserEmailResponse represents the JSON response for a user email contact.

type UserSmsResponse

type UserSmsResponse struct {
	Id          int    `json:"id"`
	Severity    string `json:"severity"`
	CountryCode string `json:"country_code"`
	Number      string `json:"number"`
	Provider    string `json:"provider"`
}

UserSmsResponse represents the JSON response for a user SMS contact.

type UsersResponse

type UsersResponse struct {
	Id       int                 `json:"id"`
	Paused   string              `json:"paused,omitempty"`
	Username string              `json:"name,omitempty"`
	Sms      []UserSmsResponse   `json:"sms,omitempty"`
	Email    []UserEmailResponse `json:"email,omitempty"`
}

UsersResponse represents the JSON response for a Pingom User.

Jump to

Keyboard shortcuts

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