uptime

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 13 Imported by: 1

README

go-uptime

A Go client library for Uptime.com

Supported resources:

  • Checks
  • Tags
  • Outages
  • Integrations

Installation

go get -u github.com/uptime-com/uptime-client-go

Run Tests

go test -v ./uptime

Documentation

To view godocs locally, run godoc. Open http://localhost:6060 in a web browser and navigate to the go-uptime package under Third party.

The Uptime.com API Docs may also be a useful reference.

Usage Examples

Please see the examples directory for usage examples.

Credits

Contributions are welcome! Please feel free to fork and submit a pull request with any improvements.

go-uptime was originally created by Kyle Gentle, with support from Elias Laham and the Dev Team at Uptime.com.

Contributors

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int

func Int(v int) *int

Int is a helper function that allocations a new int value to store v and returns a pointer to it.

func Int64

func Int64(v int64) *int64

Int64 is a helper function that allocations a new int64 value to store v and returns a pointer to it.

Types

type Alert

type Alert struct {
	PK                   int64      `json:"pk,omitempty"`
	URL                  string     `json:"url,omitempty"`
	CreatedAt            *time.Time `json:"created_at,omitempty"`
	MonitoringServerName string     `json:"monitoring_server_name,omitempty"`
	MonitoringServerIPv4 *net.IP    `json:"monitoring_server_ipv4,omitempty"`
	MonitoringServerIPv6 *net.IP    `json:"monitoring_server_ipv6,omitempty"`
	Location             string     `json:"location,omitempty"`
	Output               string     `json:"output,omitempty"`
}

Alert represents an alert generated during an outage.

type Check

type Check struct {
	PK        int    `json:"pk,omitempty"`
	CheckType string `json:"check_type,omitempty"`
	URL       string `json:"url,omitempty"`
	Name      string `json:"name,omitempty"`

	Address   string `json:"msp_address,omitempty"`
	Port      int    `json:"msp_port,omitempty"`
	IPVersion string `json:"msp_use_ip_version,omitempty"`

	Interval    int      `json:"msp_interval,omitempty"`
	Locations   []string `json:"locations,omitempty"`
	Sensitivity int      `json:"msp_sensitivity,omitempty"`
	Threshold   int      `json:"msp_threshold,omitempty"`

	Headers      string `json:"msp_headers,omitempty"`
	Username     string `json:"msp_username,omitempty"`
	Password     string `json:"msp_password,omitempty"`
	SendString   string `json:"msp_send_string,omitempty"`
	ExpectString string `json:"msp_expect_string,omitempty"`

	ContactGroups []string `json:"contact_groups,omitempty"`
	Tags          []string `json:"tags,omitempty"`
	Escalations   []string `json:"escalations,omitempty"`

	Notes                  string `json:"msp_notes,omitempty"`
	IncludeInGlobalMetrics bool   `json:"msp_include_in_global_metrics,omitempty"`

	// For DNS checks
	DNSServer     string `json:"msp_dns_server,omitempty"`
	DNSRecordType string `json:"msp_dns_record_type,omitempty"`

	// For IMAP, POP checks
	Encryption string `json:"msp_encrytion,omitempty"`

	// For Transaction checks
	Script string `json:"msp_script,omitempty"`

	// For SSL checks
	Protocol string `json:"msp_protocol,omitempty"`
}

Check represents a check in Uptime.com.

type CheckListOptions

type CheckListOptions struct {
	Page                  int      `url:"page,omitempty"`
	PageSize              int      `url:"page_size,omitempty"`
	Search                string   `url:"search,omitempty"`
	Ordering              string   `url:"ordering,omitempty"`
	MonitoringServiceType string   `url:"monitoring_service_type,omitempty"`
	IsPaused              bool     `url:"is_paused,omitempty"`
	StateIsUp             bool     `url:"state_is_up,omitempty"`
	Tag                   []string `url:"tag,omitempty"`
}

CheckListOptions specifies the optional parameters to the CheckService.List method.

type CheckListResponse

type CheckListResponse struct {
	Count    int      `json:"count,omitempty"`
	Next     string   `json:"next,omitempty"`
	Previous string   `json:"previous,omitempty"`
	Results  []*Check `json:"results,omitempty"`
}

type CheckResponse

type CheckResponse struct {
	Messages map[string]interface{} `json:"messages,omitempty"`
	Results  Check                  `json:"results,omitempty"`
}

type CheckService

type CheckService service

func (*CheckService) Create

func (s *CheckService) Create(ctx context.Context, check *Check) (*Check, *http.Response, error)

Create a new check in Uptime.com based on the provided Check.

Example
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

cfg := uptime.Config{
	Token:            os.Getenv("UPTIME_TOKEN"),
	RateMilliseconds: 2000,
}
api, err := uptime.NewClient(&cfg)
if err != nil {
	panic(err)
}

_, res, err := api.Checks.Create(ctx, &uptime.Check{
	CheckType:     "HTTP",
	Address:       "https://uptime.com",
	Interval:      1,
	Threshold:     15,
	Locations:     []string{"US East", "US West"},
	ContactGroups: []string{"examples"}, // must exist
	Tags:          []string{"examples"}, // must exist
})
if err != nil {
	panic(err)
}
fmt.Println(res.Status)
Output:

200 OK

func (*CheckService) Delete

func (s *CheckService) Delete(ctx context.Context, pk int) (*http.Response, error)

Delete a check.

Example
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()

cfg := uptime.Config{
	Token:            os.Getenv("UPTIME_TOKEN"),
	RateMilliseconds: 2000,
}
api, err := uptime.NewClient(&cfg)
if err != nil {
	panic(err)
}

checks, res, err := api.Checks.List(ctx, &uptime.CheckListOptions{
	Tag: []string{"examples"},
})
if err != nil {
	panic(err)
}
fmt.Println(res.Status)

for _, check := range checks {
	res, err := api.Checks.Delete(ctx, check.PK)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Status)
}
Output:

200 OK
200 OK

func (*CheckService) Get

func (s *CheckService) Get(ctx context.Context, pk int) (*Check, *http.Response, error)

func (*CheckService) List

func (s *CheckService) List(ctx context.Context, opt *CheckListOptions) ([]*Check, *http.Response, error)

func (*CheckService) ListAll

func (s *CheckService) ListAll(ctx context.Context, opt *CheckListOptions) ([]*Check, error)

func (*CheckService) Stats

Stats gets statistics on the specified check.

func (*CheckService) Update

func (s *CheckService) Update(ctx context.Context, check *Check) (*Check, *http.Response, error)

Update a check.

type CheckStats

type CheckStats struct {
	Date         string `json:"date"`
	Outages      int    `json:"outages"`
	DowntimeSecs int    `json:"downtime_secs"`
}

CheckStats represents the check statistics for a given day.

type CheckStatsOptions

type CheckStatsOptions struct {
	StartDate              string
	EndDate                string
	Location               string
	LocationsResponseTimes bool
	IncludeAlerts          bool
	Download               bool
	PDF                    bool
}

CheckStatsOptions specifies the parameters to the CheckService.Stats method.

type CheckStatsResponse

type CheckStatsResponse struct {
	StartDate  string           `json:"start_date"`
	EndDate    string           `json:"end_date"`
	Statistics []*CheckStats    `json:"statistics"`
	Totals     CheckStatsTotals `json:"totals"`
}

CheckStatsResponse represents the API's response to a Stats query.

type CheckStatsTotals

type CheckStatsTotals struct {
	Outages      int   `json:"outages,omitempty"`
	DowntimeSecs int64 `json:"downtime_secs,omitempty"`
}

CheckStatsTotals represents the 'totals' section of check statistics in Uptime.com.

type Client

type Client struct {

	// Base URL for API requests. BaseURL should always be specified
	// with a trailing slash.
	BaseURL   *url.URL
	UserAgent string
	Config    *Config

	Checks       *CheckService
	Outages      *OutageService
	Tags         *TagService
	Integrations *IntegrationService
	// contains filtered or unexported fields
}

Client manages communication with the Uptime.com API.

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns a new client for the Client.com API.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the response from Uptime.com. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request for Uptime.com. urlStr may be a relative URL (with NO preceding slash), which will be resolved relative to the BaseURL of the Client.

type Config

type Config struct {
	BaseURL          string
	HTTPClient       *http.Client
	Token            string
	UserAgent        string
	RateMilliseconds int
}

Config represents the configuration for an Client.com client

type Error

type Error struct {
	Response    *http.Response
	ErrorCode   string              `json:"error_code"`
	Message     string              `json:"error_message"`
	ErrorFields map[string][]string `json:"error_fields,omitempty"`
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

type Integration

type Integration struct {
	PK   int    `json:"pk,omitempty"`
	URL  string `json:"url,omitempty"`
	Name string `json:"name,omitempty"`

	Module        string   `json:"module,omitempty"`
	ContactGroups []string `json:"contact_groups,omitempty"`
	APIEndpoint   string   `json:"api_endpoint,omitempty"`
	APIKey        string   `json:"api_key,omitempty"`
	Teams         string   `json:"teams,omitempty"`
	Tags          string   `json:"tags,omitempty"`
	AutoResolve   bool     `json:"autoresolve,omitempty"`
}

Integration represents an integration in Uptime.com.

type IntegrationListOptions

type IntegrationListOptions struct {
	Page     int    `url:"page,omitempty"`
	PageSize int    `url:"page_size,omitempty"`
	Search   string `url:"search,omitempty"`
	Ordering string `url:"ordering,omitempty"`
	Module   string `url:"module,omitempty"`
}

type IntegrationListResponse

type IntegrationListResponse struct {
	Count    int            `json:"count,omitempty"`
	Next     string         `json:"next,omitempty"`
	Previous string         `json:"previous,omitempty"`
	Results  []*Integration `json:"results,omitempty"`
}

type IntegrationResponse

type IntegrationResponse struct {
	Messages map[string]interface{} `json:"messages,omitempty"`
	Results  Integration            `json:"results,omitempty"`
}

type IntegrationService

type IntegrationService service

func (*IntegrationService) Create

func (s *IntegrationService) Create(ctx context.Context, integration *Integration) (*Integration, *http.Response, error)

Create a new integration in Uptime.com based on the provided Integration.

func (*IntegrationService) Delete

func (s *IntegrationService) Delete(ctx context.Context, pk int) (*http.Response, error)

Delete an integration.

func (*IntegrationService) Get

func (*IntegrationService) List

func (*IntegrationService) ListAll

func (*IntegrationService) Update

func (s *IntegrationService) Update(ctx context.Context, integration *Integration) (*Integration, *http.Response, error)

Update an integration.

type Outage

type Outage struct {
	PK                         int64     `json:"pk,omitempty"`
	URL                        string    `json:"url,omitempty"`
	CreatedAt                  time.Time `json:"created_at,omitempty"`
	ResolvedAt                 time.Time `json:"resolved_at,omitempty"`
	DurationSecs               int64     `json:"duration_secs,omitempty"`
	IgnoreAlertURL             string    `json:"ignore_alert_url,omitempty"`
	CheckPK                    int64     `json:"check_pk,omitempty"`
	CheckURL                   string    `json:"check_url,omitempty"`
	CheckAddresss              string    `json:"check_address,omitempty"`
	CheckName                  string    `json:"check_name,omitempty"`
	CheckMonitoringServiceType string    `json:"check_monitoring_service_type,omitempty"`
	StateIsUp                  bool      `json:"state_is_up,omitempty"`
	Ignored                    bool      `json:"ignored,omitempty"`
	NumLocationsDown           int       `json:"num_locations_down,omitempty"`
	AllAlerts                  *[]Alert  `json:"all_alerts,omitempty"`
}

Outage represents an outage reported by Uptime.com.

type OutageListOptions

type OutageListOptions struct {
	Page                       int    `url:"page,omitempty"`
	PageSize                   int    `url:"page_size,omitempty"`
	Search                     string `url:"search,omitempty"`
	Ordering                   string `url:"ordering,omitempty"`
	CheckMonitoringServiceType string `url:"check_monitoring_service_type,omitempty"`
}

OutageListOptions specifies the optional parameters to the OutagesService.List and OutagesService.ListByServiceType methods.

type OutageListResponse

type OutageListResponse struct {
	Count    int       `json:"count,omitempty"`
	Next     string    `json:"next,omitempty"`
	Previous string    `json:"previous,omitempty"`
	Results  []*Outage `json:"results,omitempty"`
}

OutageListResponse represents a page of Outage results returned by the Uptime.com API.

type OutageService

type OutageService service

OutageService handles communication with the outage related methods of the Uptime.com API.

Uptime.com API docs: https://uptime.com/api/v1/docs/#!/outages/

func (*OutageService) Get

func (s *OutageService) Get(ctx context.Context, pk string) (*Outage, *http.Response, error)

Get a single outage.

func (*OutageService) List

List all outages on the account.

type Tag

type Tag struct {
	PK       int    `json:"pk,omitempty"`
	URL      string `json:"url,omitempty"`
	Tag      string `json:"tag,omitempty"`
	ColorHex string `json:"color_hex,omitempty"`
}

Tag represents a check tag in Uptime.com.

type TagListOptions

type TagListOptions struct {
	Page     int    `url:"page,omitempty"`
	PageSize int    `url:"page_size,omitempty"`
	Search   string `url:"search,omitempty"`
	Ordering string `url:"ordering,omitempty"`
}

type TagListResponse

type TagListResponse struct {
	Count    int    `json:"count,omitempty"`
	Next     string `json:"next,omitempty"`
	Previous string `json:"previous,omitempty"`
	Results  []*Tag `json:"results,omitempty"`
}

TagListOptions specifies the optional parameters to the TagService.List method.

type TagResponse

type TagResponse struct {
	Messages map[string]interface{} `json:"messages,omitempty"`
	Results  Tag                    `json:"results,omitempty"`
}

type TagService

type TagService service

func (*TagService) Create

func (s *TagService) Create(ctx context.Context, tag *Tag) (*Tag, *http.Response, error)

Create creates a new check tag in Uptime.com.

func (*TagService) Delete

func (s *TagService) Delete(ctx context.Context, pk int) (*http.Response, error)

Delete removes an Uptime.com tag.

func (*TagService) Get

func (s *TagService) Get(ctx context.Context, pk int) (*Tag, *http.Response, error)

Get retrieves a specific tag from Uptime.com.

func (*TagService) List

func (s *TagService) List(ctx context.Context, opt *TagListOptions) ([]*Tag, *http.Response, error)

List retrieves a list of Uptime.com check tags.

func (*TagService) Update

func (s *TagService) Update(ctx context.Context, tag *Tag) (*Tag, *http.Response, error)

Update updates an Uptime.com tag in-place.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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