uptimerobot

package
v0.13.4 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const KeywordExists = 1

KeywordExists represents a keyword check which is critical if the keyword is found.

View Source
const KeywordNotExists = 2

KeywordNotExists represents a keyword check which is critical if the keyword is not found.

View Source
const StatusDown = 9

StatusDown is the status value indicating that the monitor is currently down.

View Source
const StatusMaybeDown = 8

StatusMaybeDown is the status value indicating that the monitor may be down, but this has not yet been confirmed.

View Source
const StatusPaused = 0

StatusPaused is the status value which sets a monitor to paused status when calling EditMonitor.

View Source
const StatusResumed = 1

StatusResumed is the status value which sets a monitor to resumed (unpaused) status when calling EditMonitor.

View Source
const StatusUnknown = 1

StatusUnknown is the status value indicating that the monitor status is currently unknown.

View Source
const StatusUp = 2

StatusUp is the status value indicating that the monitor is currently up.

View Source
const SubTypeCustomPort = 99

SubTypeCustomPort represents a custom port monitor subtype.

View Source
const SubTypeFTP = 3

SubTypeFTP represents an FTP monitor subtype.

View Source
const SubTypeHTTP = 1

SubTypeHTTP represents an HTTP monitor subtype.

View Source
const SubTypeHTTPS = 2

SubTypeHTTPS represents an HTTPS monitor subtype.

View Source
const SubTypeIMAP = 6

SubTypeIMAP represents an IMAP monitor subtype.

View Source
const SubTypePOP3 = 5

SubTypePOP3 represents a POP3 monitor subtype.

View Source
const SubTypeSMTP = 4

SubTypeSMTP represents an SMTP monitor subtype.

View Source
const TypeHTTP = 1

TypeHTTP represents an HTTP monitor.

View Source
const TypeKeyword = 2

TypeKeyword represents a keyword monitor.

View Source
const TypePing = 3

TypePing represents a ping monitor.

View Source
const TypePort = 4

TypePort represents a port monitor.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Email           string `json:"email"`
	MonitorLimit    int    `json:"monitor_limit"`
	MonitorInterval int    `json:"monitor_interval"`
	UpMonitors      int    `json:"up_monitors"`
	DownMonitors    int    `json:"down_monitors"`
	PausedMonitors  int    `json:"paused_monitors"`
}

Account represents an Uptime Robot account.

func (Account) String

func (a Account) String() string

String returns a pretty-printed version of the account details.

type AlertContact

type AlertContact struct {
	ID           string `json:"id"`
	FriendlyName string `json:"friendly_name"`
	Type         int    `json:"type"`
	Status       int    `json:"status"`
	Value        string `json:"value"`
}

AlertContact represents an alert contact.

func (AlertContact) String

func (a AlertContact) String() string

String returns a pretty-printed version of the alert contact.

type Client

type Client struct {
	HTTPClient *http.Client
	URL        string
	Debug      io.Writer
	// contains filtered or unexported fields
}

Client represents an Uptime Robot client.

The HTTPClient field holds a pointer to the HTTP client which will be used to make the requests; the default client is configured with a timeout of 10 seconds. If you would like to use a client with different settings, create an http.Client with the parameters you want, and assign it to the HTTPClient field.

If the Debug field is set to any io.Writer (for example os.Stdout), then the client will dump all HTTP requests and responses to the supplied writer.

The URL field determines where requests will be sent; by default this is 'https://api.uptimerobot.com', but if you want to use an alternate or test server URL, set it here. For example, if you are writing tests which use the Uptime Robot client and you do not want it to make network calls, create an httptest.NewTLSServer and set the URL field to the test server's URL.

func New

func New(apiKey string) Client

New takes an Uptime Robot API key and returns a Client. See the documentation for the Client type for configuration options.

func (*Client) AllAlertContacts added in v0.11.0

func (c *Client) AllAlertContacts() ([]AlertContact, error)

AllAlertContacts returns all the AlertContacts associated with the account.

func (*Client) AllMonitors added in v0.11.0

func (c *Client) AllMonitors() ([]Monitor, error)

AllMonitors returns a slice of Monitors representing the monitors currently configured in your Uptime Robot account.

func (*Client) CreateMonitor added in v0.11.0

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

CreateMonitor takes a Monitor and creates a new Uptime Robot monitor with the specified details. It returns the ID of the newly created monitor, or an error if the operation failed.

func (*Client) DeleteMonitor added in v0.2.0

func (c *Client) DeleteMonitor(ID int64) error

DeleteMonitor takes a monitor ID and deletes the corresponding monitor. It returns an error if the operation failed.

func (*Client) EnsureMonitor added in v0.6.0

func (c *Client) EnsureMonitor(m Monitor) (int64, error)

EnsureMonitor takes a Monitor and creates a new Uptime Robot monitor with the specified details, if a monitor for the same URL does not already exist. It returns the ID of the newly created monitor or the existing monitor if it already existed, or an error if the operation failed.

func (*Client) GetAccountDetails

func (c *Client) GetAccountDetails() (Account, error)

GetAccountDetails returns an Account representing the account details.

func (*Client) GetMonitor added in v0.11.0

func (c *Client) GetMonitor(ID int64) (Monitor, error)

GetMonitor takes an int64 representing the ID number of an existing monitor, and returns the corresponding Monitor, or an error if the operation failed.

func (*Client) MakeAPICall

func (c *Client) MakeAPICall(verb string, r *Response, data []byte) error

MakeAPICall calls the Uptime Robot API with the specified verb and data, and stores the returned data in the Response struct.

func (*Client) PauseMonitor added in v0.9.0

func (c *Client) PauseMonitor(m Monitor) (Monitor, error)

PauseMonitor takes a Monitor with the ID field set, and attempts to set the monitor status to paused via the API. It returns a Monitor with the ID field set to the ID of the monitor, or an error if the operation failed.

func (*Client) SearchMonitors added in v0.11.0

func (c *Client) SearchMonitors(s string) ([]Monitor, error)

SearchMonitors returns a slice of Monitors whose FriendlyName or URL match the search string.

func (*Client) StartMonitor added in v0.9.0

func (c *Client) StartMonitor(m Monitor) (Monitor, error)

StartMonitor takes a Monitor with the ID field set, and attempts to set the monitor status to resumed (unpaused) via the API. It returns a Monitor with the ID field set to the ID of the monitor, or an error if the operation failed.

type Error

type Error map[string]interface{}

Error represents an API error response.

type Monitor

type Monitor struct {
	ID            int64    `json:"id,omitempty"`
	FriendlyName  string   `json:"friendly_name"`
	URL           string   `json:"url"`
	Type          int      `json:"type"`
	SubType       int      `json:"sub_type,omitempty"`
	KeywordType   int      `json:"keyword_type,omitempty"`
	Port          int      `json:"port"`
	KeywordValue  string   `json:"keyword_value,omitempty"`
	AlertContacts []string `json:"alert_contacts,omitempty"`
	Status        int      `json:"status,omitempty"`
}

Monitor represents an Uptime Robot monitor.

func (Monitor) FriendlyKeywordType added in v0.8.0

func (m Monitor) FriendlyKeywordType() string

FriendlyKeywordType returns a human-readable name for the monitor keyword type.

func (Monitor) FriendlyStatus added in v0.13.0

func (m Monitor) FriendlyStatus() string

func (Monitor) FriendlySubType added in v0.8.0

func (m Monitor) FriendlySubType() string

FriendlySubType returns a human-readable name for the monitor subtype, including the port number.

func (Monitor) FriendlyType

func (m Monitor) FriendlyType() string

FriendlyType returns a human-readable name for the monitor type.

func (Monitor) MarshalJSON added in v0.11.0

func (m Monitor) MarshalJSON() ([]byte, error)

MarshalJSON converts a Monitor struct into its string JSON representation, handling the special encoding of the alert_contacts field.

func (Monitor) String

func (m Monitor) String() string

String returns a pretty-printed version of the monitor.

func (*Monitor) UnmarshalJSON added in v0.11.0

func (m *Monitor) UnmarshalJSON(data []byte) error

UnmarshalJSON converts a JSON monitor representation to a Monitor struct, handling the Uptime Robot API's invalid encoding of integer zeros as empty strings.

type Pagination added in v0.12.0

type Pagination struct {
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
	Total  int `json:"total"`
}

Pagination represents the pagination info of an API response.

type Response

type Response struct {
	Stat          string         `json:"stat"`
	Account       Account        `json:"account"`
	Monitors      []Monitor      `json:"monitors"`
	Monitor       Monitor        `json:"monitor"`
	AlertContacts []AlertContact `json:"alert_contacts"`
	Error         Error          `json:"error,omitempty"`
	Pagination    Pagination     `json:"pagination"`
}

Response represents an API response.

Jump to

Keyboard shortcuts

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