uptimerobotapi

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 7 Imported by: 1

README

uptimerobotapi Build Status Go Reference Go Report Card

A Go client for UptimeRobot API.

Usage

See the full API reference on Go.dev.

Client initialization

All API requests are made through uptimerobotapi.Client. Make sure to include an API token:

package main
import (
	"os"
	
	"github.com/exileed/uptimerobotapi"
)
func main() {
	client := uptimerobotapi.NewClient(os.Getenv("UPTIMEROBOT_API_TOKEN"))
	...
}
Making API requests

Use an initialized client to make API requests:

package main
import (
	"os"
	
	"github.com/exileed/uptimerobotapi"
)
func main() {
	client := uptimerobotapi.NewClient(os.Getenv("UPTIMEROBOT_API_TOKEN"))
	
	accounts, err := client.Account.GetAccountDetails()
	if err != nil {
		panic(err)
	}
	...
}
API Error Responses

For cases where your request results in an error from the API, you can use the errors.As() function from the standard library to extract the uptimerobotapi.APIError error value and inspect more details about the error, including the HTTP response code and UptimeRobot API Error Code.

package main

import (
	"fmt"
	
	"github.com/exileed/uptimerobotapi"
)


func main() {
	client := uptimerobotapi.NewClient("")
	account, err := client.Account.GetAccountDetails()
	var apiErr uptimerobotapi.APIError
		
	
		if errors.As(err, &apiErr){
			if apiErr.RateLimited() {
				fmt.Println("rate limited")
				return
			}

			fmt.Println("unknown status code:", apiErr.StatusCode)
		}

		panic(err)
	}
	fmt.Println(account)
}

Documentation

Index

Constants

View Source
const (
	StatFail = "fail"
	StatOk   = "ok"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// StatusCode is the HTTP response status code
	StatusCode int `json:"-"`

	Message string `json:"message,omitempty"`
}

APIError represents the error response received when an API call fails. The HTTP response code is set inside of the StatusCode field, with the Message

func (APIError) Error

func (e APIError) Error() string

Error returns the error message that came back with the API error.

func (APIError) RateLimited

func (e APIError) RateLimited() bool

RateLimited returns whether the response had a status of 429, and as such the client is rate limited. The PagerDuty rate limits should reset once per minute, and for the API they are an account-wide rate limit (not per API key or IP).

func (APIError) Temporary

func (e APIError) Temporary() bool

Temporary returns whether it was a temporary error, one of which is a RateLimited error.

type APIResponse

type APIResponse struct {
	Stat string `json:"stat"`
}

APIResponse is a response from the Uptime robot API

type Account

type Account struct {
	Email              string `json:"email"`
	UserId             int    `json:"user_id"`
	FirstName          string `json:"firstname"`
	SmsCredits         int    `json:"sms_credits"`
	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"`
	TotalMonitorsCount int    `json:"total_monitors_count"`
}

Account returns basic information for the account making the API request,

type AccountResp

type AccountResp struct {
	Object
	Account Account `json:"account"`
}

type AccountService

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

func (*AccountService) GetAccountDetails

func (ac *AccountService) GetAccountDetails() (*AccountResp, error)

GetAccountDetails Get https://uptimerobot.com/#getAccountDetailsWrap

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

type AlertContactEditResp

type AlertContactEditResp struct {
	Stat         string             `json:"stat"`
	AlertContact AlertContactSingle `json:"alertcontact"`
}

type AlertContactMonitor

type AlertContactMonitor struct {
	Id         string `json:"id"`
	Value      string `json:"value"`
	Type       int    `json:"type"`
	Threshold  int    `json:"threshold"`
	Recurrence int    `json:"recurrence"`
}

type AlertContactResp

type AlertContactResp struct {
	Stat          string         `json:"stat"`
	Limit         int            `json:"limit"`
	Offset        int            `json:"offset"`
	Total         int            `json:"total"`
	AlertContacts []AlertContact `json:"alert_contacts"`
}

type AlertContactService

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

func (*AlertContactService) DeleteAlertContact

func (ac *AlertContactService) DeleteAlertContact(id int) (*AlertContactEditResp, error)

DeleteAlertContact Get https://uptimerobot.com/#deleteAlertContactWrap

func (*AlertContactService) EditAlertContact

func (ac *AlertContactService) EditAlertContact(params EditAlertContactParams) (*AlertContactEditResp, error)

EditAlertContact Get https://uptimerobot.com/#editAlertContactWrap

func (*AlertContactService) GetAlertContacts

func (ac *AlertContactService) GetAlertContacts(params GetAlertContactsParams) (*AlertContactResp, error)

GetAlertContacts Get https://uptimerobot.com/#getAccountDetailsWrap The list of alert contacts

func (*AlertContactService) NewAlertContact

NewAlertContact Get https://uptimerobot.com/#newAlertContactWrap

type AlertContactSingle

type AlertContactSingle struct {
	Id int `json:"id"`
}

type AlertContactSingleResp

type AlertContactSingleResp struct {
	Stat         string             `json:"stat"`
	AlertContact AlertContactSingle `json:"alertcontact"`
}

type Client

type Client struct {

	// Token used to make authenticated API calls.
	Token string

	// Services used for talking to different parts of the UptimeRobot API.
	Account      AccountService
	AlertContact AlertContactService
	Monitor      MonitorService
	MWindow      MWindowService
	// contains filtered or unexported fields
}

A Client manages communication with the UptimeRobot API.

func NewClient

func NewClient(token string) *Client

NewClient returns a new UptimeRobot API client.

func NewClientWithConfig

func NewClientWithConfig(config *ClientConfig) *Client

NewClientWithConfig returns a new UptimeRobot API client.

type ClientConfig

type ClientConfig struct {
	// APIToken is the UptimeRobot API token to use for authentication.
	APIToken string

	// HTTPClient is your own HTTP client. The library will otherwise use a
	// parameter-less `&http.Client{}`, resulting in default everything.
	HTTPClient *http.Client

	// UserAgent User agent used when communicating with the UptimeRobot API.
	UserAgent *string
}

ClientConfig specifies configuration with which to initialize a UptimeRobot API client.

type DeleteAlertContactWrapper

type DeleteAlertContactWrapper struct {
	Id int `url:"id"`
}

DeleteAlertContactWrapper are wrapper for DeleteAlertContact.

type DeleteMWindowWrapper

type DeleteMWindowWrapper struct {
	Id int `url:"id"`
}

type DeleteOrResetMonitorsWrappers

type DeleteOrResetMonitorsWrappers struct {
	Id int `url:"id"`
}

type EditAlertContactParams

type EditAlertContactParams struct {
	Id           int     `url:"id"`
	Value        *string `url:"value,omitempty"`
	FriendlyName *string `url:"friendly_name,omitempty"`
}

EditAlertContactParams are parameters for EditAlertContact.

type EditMWindowParams

type EditMWindowParams struct {
	FriendlyName    string  `url:"friendly_name"`
	Url             string  `url:"url"`
	SubType         *int    `url:"sub_type,omitempty"`
	Port            *int    `url:"port,omitempty"`
	KeywordType     *int    `url:"keyword_type,omitempty"`
	KeywordCaseType *int    `json:"keyword_case_type,omitempty"`
	KeywordValue    *string `url:"keyword_value,omitempty"`
	Interval        *int    `url:"interval,omitempty"`
	Timeout         *int    `url:"timeout,omitempty"`
	HttpUsername    *string `url:"http_username,omitempty"`
	HttpPassword    *string `url:"http_username,omitempty"`
	HttpAuthType    *int    `url:"http_username,omitempty"`
	HttpMethod      *int    `url:"http_method,omitempty"`
	AlertContacts   *string `url:"alert_contacts,omitempty"`
	MWindows        *string `url:"mwindows,omitempty"`
	//CustomHttpHeaders  *string `url:"custom_http_headers,omitempty"`
	//CustomHttpStatuses *string `url:"custom_http_statuses,omitempty"`
	IgnoreSSLErrors *bool `url:"ignore_ssl_errors,omitempty"`
}

type EditMonitorsParams

type EditMonitorsParams struct {
	FriendlyName       string  `url:"friendly_name"`
	Url                string  `url:"url"`
	SubType            *int    `url:"sub_type,omitempty"`
	Port               *int    `url:"port,omitempty"`
	KeywordType        *int    `url:"keyword_type,omitempty"`
	KeywordCaseType    *int    `json:"keyword_case_type,omitempty"`
	KeywordValue       *string `url:"keyword_value,omitempty"`
	Interval           *int    `url:"interval,omitempty"`
	Timeout            *int    `url:"timeout,omitempty"`
	HttpUsername       *string `url:"http_username,omitempty"`
	HttpPassword       *string `url:"http_username,omitempty"`
	HttpAuthType       *int    `url:"http_username,omitempty"`
	HttpMethod         *int    `url:"http_method,omitempty"`
	AlertContacts      *string `url:"alert_contacts,omitempty"`
	MWindows           *string `url:"mwindows,omitempty"`
	CustomHttpHeaders  *string `url:"custom_http_headers,omitempty"`
	CustomHttpStatuses *string `url:"custom_http_statuses,omitempty"`
	IgnoreSSLErrors    *bool   `url:"ignore_ssl_errors,omitempty"`
}

type EditMonitorsWrappers

type EditMonitorsWrappers struct {
	Id int `url:"id"`
	EditMonitorsParams
}

type ErrorResponse

type ErrorResponse struct {
	Stat  string   `json:"stat"`
	Error APIError `json:"error"`
}

type GetAlertContactsParams

type GetAlertContactsParams struct {
	Offset        *int    `url:"offset,omitempty"`
	Limit         *int    `url:"limit,omitempty"`
	AlertContacts *string `url:"alert_contacts,omitempty"`
}

GetAlertContactsParams are parameters for GetAlertContacts.

type GetMWindowParams

type GetMWindowParams struct {
	FriendlyName string `url:"friendly_name"`
	Type         string `url:"type"`
	Value        string `url:"value"`
	StartTime    string `url:"start_time"`
	Duration     string `url:"duration"`
	Offset       int    `url:"offset,omitempty"`
	Limit        *int   `url:"limit,omitempty"`
}

type GetMonitorsParams

type GetMonitorsParams struct {
	Monitors               *string `url:"monitors,omitempty"`
	Types                  *string `url:"types,omitempty"`
	Statuses               *string `url:"statuses,omitempty"`
	CustomUptimeRatios     *string `url:"custom_uptime_ratios,omitempty"`
	CustomUptimeDurations  int     `url:"custom_down_durations,omitempty"`
	AllTimeUptimeRation    int     `url:"all_time_uptime_ratio,omitempty"`
	AllTimeUptimeDurations int     `url:"all_time_uptime_durations,omitempty"`
	Logs                   int     `url:"logs,omitempty"`
	AlertContacts          int     `url:"alert_contacts,omitempty"`
	MWindows               int     `url:"mwindows,omitempty"`
	SSL                    int     `url:"ssl,omitempty"`
	CustomHttpHeaders      int     `url:"custom_http_headers,omitempty"`
	CustomHttpStatuses     int     `url:"custom_http_statuses,omitempty"`
	Timezone               int     `url:"timezone,omitempty"`
	Offset                 int     `url:"offset,omitempty"`
	Limit                  *int    `url:"limit,omitempty"`
	Search                 *string `url:"search,omitempty"`
}

type MWindow

type MWindow struct {
	Id           int    `json:"id"`
	User         int    `json:"user"`
	Type         int    `json:"type"`
	FriendlyName string `json:"friendly_name"`
	// StartTime comes from API as a string value with a format like “18:20.”
	StartTime string `json:"start_time"`
	Duration  int    `json:"duration"`
	Value     string `json:"value"`
	Status    int    `json:"status"`
}

type MWindowResp

type MWindowResp struct {
	Stat    string `json:"stat"`
	MWindow struct {
		Id     int  `json:"id"`
		Status *int `json:"status"`
	} `json:"mwindow"`
}

type MWindowService

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

func (*MWindowService) DeleteMWindow

func (ms *MWindowService) DeleteMWindow(id int) (*MWindowResp, error)

DeleteMWindow Get https://uptimerobot.com/#deleteMwindowWrap

func (*MWindowService) EditMWindow

func (ms *MWindowService) EditMWindow(params EditMWindowParams) (*MWindowResp, error)

EditMWindow Get https://uptimerobot.com/#editMWindow

func (*MWindowService) GetMWindows

func (ms *MWindowService) GetMWindows(params GetMWindowParams) (*MWindowsResp, error)

GetMWindows Get https://uptimerobot.com/#getMWindows

func (*MWindowService) NewMWindow

func (ms *MWindowService) NewMWindow(params NewMWindowParams) (*MWindowsResp, error)

NewMWindow Get https://uptimerobot.com/#newMWindow

type MWindowsResp

type MWindowsResp struct {
	Stat       string     `json:"stat"`
	Pagination Pagination `json:"pagination"`
	MWindows   []MWindow  `json:"mwindows"`
}

type Monitor

type Monitor struct {
	Id           int    `json:"id"`
	FriendlyName string `json:"friendly_name"`
	Url          string `json:"url"`
	Type         int    `json:"type"`
	// sub_type, port and keyword_type are returned as either an integer or an empty string,
	// which Go doesn't allow: https://github.com/golang/go/issues/22182
	SubType         interface{}            `json:"sub_type"`
	Port            interface{}            `json:"port"`
	KeywordType     interface{}            `json:"keyword_type"`
	KeywordCaseType *int                   `json:"keyword_case_type"`
	KeywordValue    string                 `json:"keyword_value"`
	HttpUsername    string                 `json:"http_username"`
	HttpPassword    string                 `json:"http_password"`
	Interval        int                    `json:"interval"`
	Timeout         int                    `json:"timeout"`
	Status          int                    `json:"status"`
	CreateDatetime  int                    `json:"create_datetime"`
	MonitorGroup    int                    `json:"monitor_group"`
	IsGroupMain     int                    `json:"is_group_main"`
	Logs            []MonitorLog           `json:"logs"`
	AlertContacts   *[]AlertContactMonitor `json:"alert_contacts"`
	SSL             *MonitorSSL            `json:"ssl"`
}

type MonitorLog

type MonitorLog struct {
	Type     int `json:"type"`
	Datetime int `json:"datetime"`
	Duration int `json:"duration"`
}

type MonitorSSL

type MonitorSSL struct {
	Brand                string      `json:"brand"`
	Product              string      `json:"product"`
	Expires              int         `json:"expires"`
	LastCheck            interface{} `json:"last_check"`
	IgnoreErrors         int         `json:"ignore_errors"`
	DisableNotifications int         `json:"disable_notifications"`
}

type MonitorService

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

func (*MonitorService) DeleteMonitor

func (ms *MonitorService) DeleteMonitor(id int) (*MonitorsSingResp, error)

DeleteMonitor Get https://uptimerobot.com/#deleteMonitorWrap

func (*MonitorService) EditMonitor

func (ms *MonitorService) EditMonitor(id int, request EditMonitorsParams) (*MonitorsSingResp, error)

EditMonitor Get https://uptimerobot.com/#editMonitorWrap

func (*MonitorService) GetMonitors

func (ms *MonitorService) GetMonitors(params GetMonitorsParams) (*MonitorsResp, error)

GetMonitors Get https://uptimerobot.com/#getMonitorsWrap

func (*MonitorService) NewMonitor

func (ms *MonitorService) NewMonitor(params NewMonitorsParams) (*MonitorsSingResp, error)

NewMonitor Get https://uptimerobot.com/#newMonitorWrap

func (*MonitorService) ResetMonitor

func (ms *MonitorService) ResetMonitor(id int) (*MonitorsSingResp, error)

ResetMonitor Get https://uptimerobot.com/#resetMonitorWrap

type MonitorSingle

type MonitorSingle struct {
	Id     int  `json:"id"`
	Status *int `json:"status"`
}

type MonitorsResp

type MonitorsResp struct {
	Stat       string     `json:"stat"`
	Pagination Pagination `json:"pagination"`
	Monitors   []Monitor  `json:"monitors"`
}

type MonitorsSingResp

type MonitorsSingResp struct {
	Stat    string        `json:"stat"`
	Monitor MonitorSingle `json:"monitor"`
}

type NewAlertContactParams

type NewAlertContactParams struct {
	TypeContact  string `url:"type"`
	Value        string `url:"value"`
	FriendlyName string `url:"friendly_name"`
}

NewAlertContactParams are parameters for NewAlertContact.

type NewMWindowParams

type NewMWindowParams struct {
	FriendlyName string `url:"friendly_name"`
	Type         string `url:"type"`
	Value        string `url:"value"`
	StartTime    string `url:"start_time"`
	Duration     string `url:"duration"`
}

type NewMonitorsParams

type NewMonitorsParams struct {
	Type               int     `url:"type"`
	FriendlyName       string  `url:"friendly_name"`
	Url                string  `url:"url"`
	SubType            *int    `url:"sub_type,omitempty"`
	Port               *int    `url:"port,omitempty"`
	KeywordType        *int    `url:"keyword_type,omitempty"`
	KeywordCaseType    *int    `json:"keyword_case_type,omitempty"`
	KeywordValue       *string `url:"keyword_value,omitempty"`
	Interval           *int    `url:"interval,omitempty"`
	Timeout            *int    `url:"timeout,omitempty"`
	HttpUsername       *string `url:"http_username,omitempty"`
	HttpPassword       *string `url:"http_username,omitempty"`
	HttpAuthType       *int    `url:"http_username,omitempty"`
	HttpMethod         *int    `url:"http_method,omitempty"`
	AlertContacts      *string `url:"alert_contacts,omitempty"`
	MWindows           *string `url:"mwindows,omitempty"`
	CustomHttpHeaders  *string `url:"custom_http_headers,omitempty"`
	CustomHttpStatuses *string `url:"custom_http_statuses,omitempty"`
	IgnoreSSLErrors    *bool   `url:"ignore_ssl_errors,omitempty"`
}

type Object

type Object struct {
	Stat string `json:"stat"`
}

Object contains the common fields of every resource in the UptimeRobot API.

type Pagination

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

Jump to

Keyboard shortcuts

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