updown

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: Apache-2.0 Imports: 7 Imported by: 1

README

Codacy badge Coverage Status GitHub Actions CI Status GitHub Actions CodeQL Status

CI StatusContributingLicense


updown is a Go package for working with the updown.io public API.

[!NOTE] Please note that this package only supports retrieving data from the API (i.e. you cannot create or modify checks with this package).

CI Status

Branch Status
master CI
develop CI

Contributing

Before contributing to this project please read our Contributing Guidelines.

License

Apache License, Version 2.0

Documentation

Index

Constants

View Source
const (
	EVENT_DOWN             = "check.down"
	EVENT_UP               = "check.up"
	EVENT_SSL_INVALID      = "check.ssl_invalid"
	EVENT_SSL_VALID        = "check.ssl_valid"
	EVENT_SSL_EXPIRTAION   = "check.ssl_expiration"
	EVENT_SSL_RENEWED      = "check.ssl_renewed"
	EVENT_PERFORMANCE_DROP = "check.performance_drop"
)

Variables

View Source
var (
	ErrEmptyAPIKey   = errors.New("API key is empty")
	ErrNilClient     = errors.New("Client is nil")
	ErrEmptyToken    = errors.New("Token is empty")
	ErrEmptyPulseURL = errors.New("Pulse URL is empty")
)

Functions

func SendPulse added in v0.1.0

func SendPulse(url, payload string) (string, error)

SendPulse sends "pulse" request to updown and returns request UUID

https://updown.io/doc/how-pulse-cron-monitoring-works

Types

type Cert

type Cert struct {
	Subject   string `json:"subject"`
	Issuer    string `json:"issuer"`
	From      Date   `json:"from"`
	To        Date   `json:"to"`
	Algorithm string `json:"algorithm"`
}

Cert contains SSL certificate info

type Check

type Check struct {
	Token             string            `json:"token"`
	URL               string            `json:"url"`
	Alias             string            `json:"alias"`
	LastStatus        int               `json:"last_status"`
	Uptime            float64           `json:"uptime"`
	IsDown            bool              `json:"down"`
	DownSince         Date              `json:"down_since"`
	UpSince           Date              `json:"up_since"`
	Error             string            `json:"error"`
	Period            int               `json:"period"`
	Apdex             float64           `json:"apdex_t"`
	StringMatch       string            `json:"string_match"`
	IsEnabled         bool              `json:"enabled"`
	IsPublished       bool              `json:"published"`
	LastCheckAt       Date              `json:"last_check_at"`
	NextCheckAt       Date              `json:"next_check_at"`
	CreatedAt         Date              `json:"created_at"`
	MuteUntil         Date              `json:"mute_until"`
	FaviconURL        string            `json:"favicon_url"`
	HTTPVerb          string            `json:"http_verb"`
	HTTPBody          string            `json:"http_body"`
	Recipients        []string          `json:"recipients"`
	DisabledLocations []string          `json:"disabled_locations"`
	CustomHeaders     map[string]string `json:"custom_headers"`
	SSL               *SSLStatus        `json:"ssl,omitempty"`
	Metrics           *Metrics          `json:"metrics,omitempty"`
}

Check contains check info

func (c *Check) Link() string

Link returns URL of check info page

type Checks

type Checks []*Check

Checks is a slice with checks

func (Checks) Get added in v0.1.0

func (c Checks) Get(tokenOrAlias string) *Check

Get returns check with given token or alias

type Client

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

Client is Updown API client

func NewClient

func NewClient(apiKey string) (*Client, error)

NewClient creates new client instance

func (*Client) Calls

func (c *Client) Calls() uint

Calls returns total number of API calls made by the client

func (*Client) GetCheck

func (c *Client) GetCheck(token string, withMetrics bool) (*Check, error)

GetCheck returns info about check with given token

https://updown.io/api#GET-/api/checks/:token

func (*Client) GetChecks

func (c *Client) GetChecks() (Checks, error)

GetChecks returns info about all checks

https://updown.io/api#GET-/api/checks

func (*Client) GetDowntimes

func (c *Client) GetDowntimes(token string, detailed bool) (Downtimes, error)

GetDowntimes returns all the downtimes of a check

https://updown.io/api#GET-/api/checks/:token/downtimes

func (*Client) GetMetrics

func (c *Client) GetMetrics(token string, options MetricsOptions) (*Metrics, error)

GetMetrics returns detailed metrics about the check

https://updown.io/api#GET-/api/checks/:token/metrics

func (*Client) GetNodes

func (c *Client) GetNodes() (Nodes, error)

GetNodes return list of all updown.io servers (monitoring & webhooks)

https://updown.io/api#GET-/api/nodes

func (*Client) GetNodesIPs

func (c *Client) GetNodesIPs() ([]string, error)

GetNodesIPs returns list all updown.io servers addresses

https://updown.io/api#GET-/api/nodes/ips

func (*Client) GetNodesIPsV4

func (c *Client) GetNodesIPsV4() ([]string, error)

GetNodesIPsV4 returns list all updown.io servers IPv4 addresses

https://updown.io/api#GET-/api/nodes/ipv4

func (*Client) GetNodesIPsV6

func (c *Client) GetNodesIPsV6() ([]string, error)

GetNodesIPsV6 returns list all updown.io servers IPv6 addresses

https://updown.io/api#GET-/api/nodes/ipv6

func (*Client) GetRecipients

func (c *Client) GetRecipients() (Recipients, error)

GetRecipients returns list all the possible alert recipients/channels on your account

https://updown.io/api#GET-/api/recipients

func (*Client) GetStatusPages

func (c *Client) GetStatusPages() (StatusPages, error)

GetStatusPages returns list all your status pages

https://updown.io/api#GET-/api/status-pages

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(app, version string)

SetUserAgent sets client user agent

type Date

type Date struct {
	time.Time
}

Date is JSON date

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(b []byte) error

UnmarshalJSON parses JSON date

type Downtime

type Downtime struct {
	ID          string           `json:"id"`
	DetailsURL  string           `json:"details_url"`
	Error       string           `json:"error"`
	StartedAt   Date             `json:"started_at"`
	EndedAt     Date             `json:"ended_at"`
	Duration    int              `json:"duration"`
	IsPartial   bool             `json:"partial"`
	DownResults []*DowntimeCheck `json:"down_results"`
	UpResults   []*DowntimeCheck `json:"up_results"`
}

Downtime contains info about downtime

type DowntimeCheck

type DowntimeCheck struct {
	ID         string            `json:"id"`
	Status     string            `json:"status"`
	DetailsURL string            `json:"details_url"`
	Request    *DowntimeRequest  `json:"request"`
	Response   *DowntimeResponse `json:"response"`
}

type DowntimeIPv4Check

type DowntimeIPv4Check struct {
	Status          string            `json:"status"`
	IP              string            `json:"ip"`
	Code            int               `json:"code"`
	Timings         *DowntimeTimings  `json:"timings"`
	ReceivedHeaders map[string]string `json:"received_headers"`
}

DowntimeIPv4Check contains info about check through IPv4 network

type DowntimeIPv6Check

type DowntimeIPv6Check struct {
	Status  string           `json:"status"`
	IP      string           `json:"ip"`
	Code    int              `json:"code"`
	Timings *DowntimeTimings `json:"timings"`
}

DowntimeIPv6Check contains info about check through IPv6 network

type DowntimeRequest

type DowntimeRequest struct {
	SentAt      Date              `json:"sent_at"`
	HTTPMethod  string            `json:"http_method"`
	HTTPVersion string            `json:"http_version"`
	SentHeaders map[string]string `json:"sent_headers"`
	Node        string            `json:"node"`
}

DowntimeRequest contains info with downtime check request

type DowntimeResponse

type DowntimeResponse struct {
	ReceivedAt      Date              `json:"received_at"`
	FinalURL        string            `json:"final_url"`
	Code            int               `json:"code"`
	IP              string            `json:"ip"`
	ReceivedHeaders map[string]string `json:"received_headers"`
}

DowntimeResponse contains info with downtime check response

type DowntimeTimings

type DowntimeTimings struct {
	NameLookup float64 `json:"namelookup"`
	Connection float64 `json:"connection"`
	Handshake  float64 `json:"handshake"`
	Response   float64 `json:"response"`
	Total      float64 `json:"total"`
}

DowntimeTimings contains downtime check timings

type Downtimes

type Downtimes []*Downtime

Downtimes is slice with downtimes

type Event

type Event struct {
	Type        string `json:"event"`
	Time        Date   `json:"time"`
	Description string `json:"description"`
	Check       *Check `json:"check"`
}

Event contains basic event data

type EventDown

type EventDown struct {
	Event
	Downtime *Downtime `json:"downtime"`
}

EventDown sent when a check goes down (after confirmation)

https://updown.io/api#check.down

type EventPerformanceDrop

type EventPerformanceDrop struct {
	Event
	ApdexDropped string              `json:"apdex_dropped"`
	LastMetrics  *PerformanceMetrics `json:"last_metrics"`
}

EventPerformanceDrop sent when the Apdex drops more than 30% below the lowest of the last 5 hours

https://updown.io/api#check.performance_drop

type EventSSLExpiration

type EventSSLExpiration struct {
	Event
	SSL *SSL `json:"ssl"`
}

EventSSLExpiration sent when your SSL certificate approaches expiration date (1, 7, 14, and 30 days before for 1y certs)

https://updown.io/api#check.ssl_expiration

type EventSSLInvalid

type EventSSLInvalid struct {
	Event
	SSL *SSL `json:"ssl"`
}

EventSSLInvalid sent when the SSL certificate is considered invalid

https://updown.io/api#check.ssl_invalid

type EventSSLRenewed

type EventSSLRenewed struct {
	Event
	SSL *SSLRenew `json:"ssl"`
}

EventSSLRenewed sent when the SSL certificate was renewed close to expiration (recovery for check.ssl_expiration)

https://updown.io/api#check.ssl_renewed

type EventSSLValid

type EventSSLValid struct {
	Event
	SSL *SSL `json:"ssl"`
}

EventSSLValid sent when SSL certificate is valid again (recovery after a check.ssl_invalid event)

https://updown.io/api#check.ssl_valid

type EventUp

type EventUp struct {
	Event
	Downtime *Downtime `json:"downtime"`
}

EventUp sent when a check is back up (recovery following a check.down event)

https://updown.io/api#check.up

type Metrics

type Metrics struct {
	Uptime   float64       `json:"uptime"`
	Apdex    float64       `json:"apdex"`
	Timings  *TimingStats  `json:"timings"`
	Requests *RequestStats `json:"requests"`
}

Metrics is apdex metrics

type MetricsOptions

type MetricsOptions struct {
	From    time.Time
	To      time.Time
	GroupBy string
}

MetricsOptions is options for metrics request

type Node

type Node struct {
	IP          string  `json:"ip"`
	IPv6        string  `json:"ip6"`
	City        string  `json:"city"`
	Country     string  `json:"country"`
	CountryCode string  `json:"country_code"`
	Lat         float64 `json:"lat"`
	Lon         float64 `json:"lng"`
}

Node contains info about check node

type Nodes

type Nodes map[string]*Node

Nodes is a map of check nodes

type PerformanceApdex

type PerformanceApdex struct {
	Date  time.Time
	Apdex float64
}

PerformanceApdex contains apdex metric

type PerformanceMetrics

type PerformanceMetrics struct {
	Metrics []*PerformanceApdex
}

PerformanceMetrics is performance drop metrics

func (*PerformanceMetrics) UnmarshalJSON

func (d *PerformanceMetrics) UnmarshalJSON(b []byte) error

UnmarshalJSON parses performance metrics

type Recipient

type Recipient struct {
	ID    string `json:"id"`
	Type  string `json:"type"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

Recipient contains info about alert recipient

type Recipients

type Recipients []*Recipient

Recipients is a slice with recipients

type RequestStats

type RequestStats struct {
	Samples        int                `json:"samples"`
	Failures       int                `json:"failures"`
	Satisfied      int                `json:"satisfied"`
	Tolerated      int                `json:"tolerated"`
	ByResponseTime *ResponseTimeStats `json:"by_response_time"`
}

RequestStats contains check requests statistics

type ResponseTimeStats

type ResponseTimeStats struct {
	Under125 int `json:"under125"`
	Under250 int `json:"under250"`
	Under500 int `json:"under500"`
	Under1k  int `json:"under1000"`
	Under2k  int `json:"under2000"`
	Under4k  int `json:"under4000"`
	Under8k  int `json:"under8000"`
	Under16k int `json:"under16000"`
	Under32k int `json:"under32000"`
}

ResponseTimeStats contains check response time statistics

type SSL

type SSL struct {
	Cert                 *Cert  `json:"cert"`
	Error                string `json:"error"`
	DaysBeforeExpiration int    `json:"days_before_expiration"`
}

SSL contains info about SSL certificate and it's status

type SSLRenew

type SSLRenew struct {
	NewCert *Cert `json:"new_cert"`
	OldCert *Cert `json:"old_cert"`
}

SSLRenew contains info about renewed certificate

type SSLStatus

type SSLStatus struct {
	TestedAt  Date   `json:"tested_at"`
	ExpiresAt Date   `json:"expires_at"`
	IsValid   bool   `json:"valid"`
	Error     string `json:"error"`
}

SSLStatus contains info about SSL certificate status

type StatusPage

type StatusPage struct {
	Token       string   `json:"token"`
	URL         string   `json:"url"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Visibility  string   `json:"visibility"`
	AccessKey   string   `json:"access_key"`
	Checks      []string `json:"checks"`
}

StatusPage contains info about status check

type StatusPages

type StatusPages []*StatusPage

StatusPages is a slice with status pages

type TimingStats

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

Timings check timings info

type Webhook

type Webhook []*WebhookEvent

Webhook contains webhook payload

func ParseWebhook

func ParseWebhook(data []byte) (Webhook, error)

ParseWebhook parses webhook data

type WebhookEvent

type WebhookEvent struct {
	Type  string
	Event any
}

WebhookEvent contains webhook event data

Jump to

Keyboard shortcuts

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