uptimerobot

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MonitorSubTypes = map[float64]string{
	1:  "HTTP (80)",
	2:  "HTTPS (443)",
	3:  "FTP (21)",
	4:  "SMTP (25)",
	5:  "POP3 (110)",
	6:  "IMAP (143)",
	99: "Custom Port",
}

MonitorSubTypes maps a numeric monitor subtype to the name of the monitor subtype.

View Source
var MonitorTypes = map[int]string{
	1: "HTTP",
	2: "keyword",
	3: "ping",
	4: "port",
}

MonitorTypes maps an integer monitor type to the name of the monitor type.

Functions

func MonitorType

func MonitorType(t string) int

MonitorType returns the monitor type number associated with the given type name.

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 UptimeRobot 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 {
	Debug io.Writer
	// contains filtered or unexported fields
}

Client represents an UptimeRobot client. If the Debug field is set to an io.Writer, then the client will dump API requests to it instead of calling the real API.

func New

func New(apiKey string) Client

New takes an UptimeRobot API key and returns a Client.

func (*Client) DeleteMonitor added in v0.2.0

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

DeleteMonitor takes a Monitor with the ID field set, and deletes the corresponding monitor. It returns a Monitor with the ID field set to the ID of the deleted monitor, or an error if the operation failed.

func (*Client) EnsureMonitor added in v0.6.0

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

EnsureMonitor takes a Monitor and creates a new UptimeRobot monitor with the specified details, if a monitor for the same URL does not already exist. It returns a Monitor with the ID field set to 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) GetAlertContacts

func (c *Client) GetAlertContacts() (contacts []AlertContact, err error)

GetAlertContacts returns all the AlertContacts associated with the account.

func (*Client) GetMonitors

func (c *Client) GetMonitors() (monitors []Monitor, err error)

GetMonitors returns a slice of Monitors representing the existing monitors.

func (*Client) GetMonitorsBySearch

func (c *Client) GetMonitorsBySearch(s string) (monitors []Monitor, err error)

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

func (*Client) MakeAPICall

func (c *Client) MakeAPICall(verb string, r *Response, params Params) error

MakeAPICall calls the UptimeRobot API with the specified verb and stores the returned data in the Response struct.

func (*Client) NewMonitor

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

NewMonitor takes a Monitor and creates a new UptimeRobot monitor with the specified details. It returns a Monitor with the ID field set to the ID of the newly created monitor, or an error if the operation failed.

type Error

type Error map[string]interface{}

Error represents an API error.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient represents an http.Client, or a mock equivalent.

type Monitor

type Monitor struct {
	ID           int64  `json:"id"`
	FriendlyName string `json:"friendly_name"`
	URL          string `json:"url"`
	Type         int    `json:"type"`
	// keyword_type, sub_type, and port are returned as either an integer
	// (if set) or an empty string (if unset), which Go's JSON library won't
	// parse for integer fields: https://github.com/golang/go/issues/22182
	SubType       interface{} `json:"sub_type"`
	KeywordType   interface{} `json:"keyword_type"`
	Port          interface{} `json:"port"`
	KeywordValue  string      `json:"keyword_value"`
	AlertContacts []string    `json:"alert_contacts"`
}

Monitor represents an UptimeRobot 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) 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) String

func (m Monitor) String() string

String returns a pretty-printed version of the monitor.

type Params

type Params map[string]string

Params holds optional parameters for API calls.

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"`
}

Response represents an API response.

Jump to

Keyboard shortcuts

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