updown: github.com/AntoineAugusti/updown Index | Files

package updown

import "github.com/AntoineAugusti/updown"

Index

Package Files

cache.go checks.go client.go downtimes.go metrics.go nodes.go

Variables

var ErrTokenNotFound = errors.New("Could not determine a token for the given name")

ErrTokenNotFound indicates that we cannot find a token for the given name

func CheckResponse Uses

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

type Cache Uses

type Cache interface {
    Has(key string) bool
    Put(key, value string)
    Get(key string) (has bool, value string)
}

Cache lets you cache indefinitely values

type Check Uses

type Check struct {
    Token             string            `json:"token,omitempty"`
    URL               string            `json:"url,omitempty"`
    Alias             string            `json:"alias,omitempty"`
    LastStatus        int               `json:"last_status,omitempty"`
    Uptime            float64           `json:"uptime,omitempty"`
    Down              bool              `json:"down,omitempty"`
    DownSince         string            `json:"down_since,omitempty"`
    Error             string            `json:"error,omitempty"`
    Period            int               `json:"period,omitempty"`
    Apdex             float64           `json:"apdex_t,omitempty"`
    Enabled           bool              `json:"enabled,omitempty"`
    Published         bool              `json:"published,omitempty"`
    LastCheckAt       string            `json:"last_check_at,omitempty"`
    NextCheckAt       string            `json:"next_check_at,omitempty"`
    FaviconURL        string            `json:"favicon_url,omitempty"`
    SSL               SSL               `json:"ssl,omitempty"`
    StringMatch       string            `json:"string_match,omitempty"`
    MuteUntil         string            `json:"mute_until,omitempty"`
    DisabledLocations []string          `json:"disabled_locations,omitempty"`
    CustomHeaders     map[string]string `json:"custom_headers,omitempty"`
}

Check represents a check performed by Updown on a regular basis

type CheckItem Uses

type CheckItem struct {
    // The URL you want to monitor
    URL string `json:"url,omitempty"`
    // Interval in seconds (30, 60, 120, 300 or 600)
    Period int `json:"period,omitempty"`
    // APDEX threshold in seconds (0.125, 0.25, 0.5 or 1.0)
    Apdex float64 `json:"apdex_t,omitempty"`
    // Is the check enabled
    Enabled bool `json:"enabled,omitempty"`
    // Shall the status page be public
    Published bool `json:"published,omitempty"`
    // Human readable name
    Alias string `json:"alias,omitempty"`
    // Search for this string in the page
    StringMatch string `json:"string_match,omitempty"`
    // Mute notifications until given time, accepts a time, 'recovery' or 'forever'
    MuteUntil string `json:"mute_until,omitempty"`
    // Disabled monitoring locations. It's an array of abbreviated location names
    DisabledLocations []string `json:"disabled_locations,omitempty"`
    // The HTTP headers you want in updown requests
    CustomHeaders map[string]string `json:"custom_headers,omitempty"`
}

CheckItem represents a new check you want to be performed by Updown

type CheckService Uses

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

CheckService interacts with the checks section of the API

func (*CheckService) Add Uses

func (s *CheckService) Add(data CheckItem) (Check, *http.Response, error)

Add adds a new check you want to be performed

func (*CheckService) Get Uses

func (s *CheckService) Get(token string) (Check, *http.Response, error)

Get gets a single check by its token

func (*CheckService) List Uses

func (s *CheckService) List() ([]Check, *http.Response, error)

List lists all the checks

func (*CheckService) Remove Uses

func (s *CheckService) Remove(token string) (bool, *http.Response, error)

Remove removes a check from Updown by its token

func (*CheckService) TokenForAlias Uses

func (s *CheckService) TokenForAlias(name string) (string, error)

TokenForAlias finds the Updown token for a check's alias

func (*CheckService) Update Uses

func (s *CheckService) Update(token string, data CheckItem) (Check, *http.Response, error)

Update updates a check performed by Updown

type Client Uses

type Client struct {

    // Base URL for API requests
    BaseURL *url.URL

    // User agent for client
    UserAgent string

    // APIKey to use for the API
    APIKey string

    // Services used for communications with the API
    Check    CheckService
    Downtime DowntimeService
    Metric   MetricService
    Node     NodeService
    // contains filtered or unexported fields
}

Client manages communication the API

func NewClient Uses

func NewClient(apiKey string, httpClient *http.Client) *Client

NewClient returns a new API client.

func (*Client) Do Uses

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

Do sends an API request and returns the API response. 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. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest Uses

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

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

type Downtime Uses

type Downtime struct {
    Error     string `json:"error,omitempty"`
    StartedAt string `json:"started_at,omitempty"`
    EndedAt   string `json:"ended_at,omitempty"`
    Duration  int    `json:"duration,omitempty"`
}

Downtime represents a downtime period for a check

type DowntimeService Uses

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

DowntimeService interacts with the downtimes section of the API

func (*DowntimeService) List Uses

func (s *DowntimeService) List(token string, pageNb int) ([]Downtime, *http.Response, error)

List lists all known downtimes for a check

type ErrorResponse Uses

type ErrorResponse struct {
    // HTTP response that caused this error
    Response *http.Response

    // Error message
    Message string
}

An ErrorResponse reports the error caused by an API request

func (*ErrorResponse) Error Uses

func (r *ErrorResponse) Error() string

type Host Uses

type Host struct {
    IP          string `json:"ip,omitempty"`
    City        string `json:"city,omitempty"`
    Country     string `json:"country,omitempty"`
    CountryCode string `json:"country_code,omitempty"`
}

Host represents the host where the check was made

type IPs Uses

type IPs []string

IPs represents IP addresses in v4 or v6

type MemoryCache Uses

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

MemoryCache is a cache that works in memory

func NewMemoryCache Uses

func NewMemoryCache() *MemoryCache

NewMemoryCache creates a new memory cache

func (*MemoryCache) Get Uses

func (c *MemoryCache) Get(key string) (has bool, value string)

Get gets a value from the cache by its key and tells if it was found or not

func (*MemoryCache) Has Uses

func (c *MemoryCache) Has(key string) bool

Has determines if we can find in the cache a key for the given value

func (*MemoryCache) Put Uses

func (c *MemoryCache) Put(key, value string)

Put associates a key to a given value in the cache

type MetricItem Uses

type MetricItem struct {
    Apdex    float64  `json:"apdex,omitempty"`
    Requests Requests `json:"requests,omitempty"`
    Timings  Timings  `json:"timings,omitempty"`
    Host     Host     `json:"host,omitempty"`
}

MetricItem is basically the core metric

type MetricService Uses

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

MetricService interacts with the metrics section of the API

func (*MetricService) List Uses

func (s *MetricService) List(token, group, from, to string) (Metrics, *http.Response, error)

List lists metrics available for a check identified by a taken, grouped by the given group (host|time) over a period

type Metrics Uses

type Metrics map[string]MetricItem

Metrics represents multiple metrics

type NodeDetails Uses

type NodeDetails struct {
    IP          string `json:"ip,omitempty"`
    IP6         string `json:"ip6,omitempty"`
    City        string `json:"city,omitempty"`
    Country     string `json:"country,omitempty"`
    CountryCode string `json:"country_code,omitempty"`
}

NodeDetails gives information about a node

type NodeService Uses

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

NodeService interacts with the nodes section of the API

func (*NodeService) List Uses

func (s *NodeService) List() (Nodes, *http.Response, error)

List gets the nodes performing checks

func (*NodeService) ListIPv4 Uses

func (s *NodeService) ListIPv4() (IPs, *http.Response, error)

ListIPv4 gets the list of IPv4 performing checks

func (*NodeService) ListIPv6 Uses

func (s *NodeService) ListIPv6() (IPs, *http.Response, error)

ListIPv6 gets the list of IPv6 performing checks

type Nodes Uses

type Nodes map[string]NodeDetails

Nodes represents multiple nodes

type Requests Uses

type Requests struct {
    Samples      int          `json:"samples,omitempty"`
    Failures     int          `json:"failures,omitempty"`
    Satisfied    int          `json:"satisfied,omitempty"`
    Tolerated    int          `json:"tolerated,omitempty"`
    ResponseTime ResponseTime `json:"by_response_time,omitempty"`
}

Requests gives statistics about requests made to check the status

type ResponseTime Uses

type ResponseTime struct {
    Under125  int `json:"under125,omitempty"`
    Under250  int `json:"under250,omitempty"`
    Under500  int `json:"under500,omitempty"`
    Under1000 int `json:"under1000,omitempty"`
    Under2000 int `json:"under2000,omitempty"`
    Under4000 int `json:"under4000,omitempty"`
}

ResponseTime represents the response times in milliseconds

type SSL Uses

type SSL struct {
    TestedAt string `json:"tested_at,omitempty"`
    Valid    bool   `json:"valid,omitempty"`
    Error    string `json:"error,omitempty"`
}

SSL represents the SSL section of a check

type Timings Uses

type Timings struct {
    Redirect   int `json:"redirect,omitempty"`
    NameLookup int `json:"namelookup,omitempty"`
    Connection int `json:"connection,omitempty"`
    Handshake  int `json:"handshake,omitempty"`
    Response   int `json:"response,omitempty"`
    Total      int `json:"total,omitempty"`
}

Timings represents the amount of time taken by each part of the connection

Package updown imports 10 packages (graph). Updated 2018-05-31. Refresh now. Tools for package owners.