Documentation
¶
Overview ¶
Package observery implements the observery API in Go. See https://observery.com/apidocs/#introduction for more info.
Index ¶
- func PtrBool(b bool) *bool
- func PtrInt(i int) *int
- func PtrString(s string) *string
- func WebhookHandler(f func(*Webhook, error)) func(w http.ResponseWriter, r *http.Request)
- type Client
- func (c *Client) CreateCheck(ctx context.Context, req *CreateCheckRequest) (*CreateCheckResponse, error)
- func (c *Client) CreateContact(ctx context.Context, req *CreateContactRequest) (*CreateContactResponse, error)
- func (c *Client) DeleteCheck(ctx context.Context, id string) (*DeleteCheckResponse, error)
- func (c *Client) DeleteContact(ctx context.Context, id string) (*DeleteContactResponse, error)
- func (c *Client) GetCheck(ctx context.Context, id string) (*GetCheckResponse, error)
- func (c *Client) GetContact(ctx context.Context, id string) (*GetContactResponse, error)
- func (c *Client) GetOutage(ctx context.Context, id string) (*GetOutageResponse, error)
- func (c *Client) ListChecks(ctx context.Context) (*ListChecksResponse, error)
- func (c *Client) ListContacts(ctx context.Context) (*ListContactsResponse, error)
- func (c *Client) ListOutages(ctx context.Context) (*ListOutagesResponse, error)
- func (c *Client) UpdateCheck(ctx context.Context, req *UpdateCheckRequest) (*UpdateCheckResponse, error)
- func (c *Client) UpdateContact(ctx context.Context, req *UpdateContactRequest) (*UpdateContactResponse, error)
- type CreateCheckRequest
- type CreateCheckResponse
- type CreateContactRequest
- type CreateContactResponse
- type DeleteCheckResponse
- type DeleteContactResponse
- type GetCheckResponse
- type GetContactResponse
- type GetOutageResponse
- type ListChecksResponse
- type ListContactsResponse
- type ListOutagesResponse
- type UpdateCheckRequest
- type UpdateCheckResponse
- type UpdateContactRequest
- type UpdateContactResponse
- type Webhook
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WebhookHandler ¶
WebhookHandler takes a function that will be called whenever the handler is called by the observery.com webhook. The func f will be called in a goroutine so it doesn't tie up the observery caller in the event that f is a long running task.
Example ¶
callback := func(w *Webhook, e error) {
//Do something
}
http.HandleFunc("/observery", WebhookHandler(callback))
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main entry point into the observery API and its endpoints.
func (*Client) CreateCheck ¶
func (c *Client) CreateCheck(ctx context.Context, req *CreateCheckRequest) (*CreateCheckResponse, error)
CreateCheck a new check.
func (*Client) CreateContact ¶
func (c *Client) CreateContact(ctx context.Context, req *CreateContactRequest) (*CreateContactResponse, error)
CreateContact creates a new contact. New contacts must be verified in the front-end.
func (*Client) DeleteCheck ¶
DeleteCheck deletes an existing check.
func (*Client) DeleteContact ¶
DeleteContact deletes an existing contact.
func (*Client) GetContact ¶
GetContact returns an invidual contact corresponding to the id.
func (*Client) ListChecks ¶
func (c *Client) ListChecks(ctx context.Context) (*ListChecksResponse, error)
ListChecks returns all of the checks.
func (*Client) ListContacts ¶
func (c *Client) ListContacts(ctx context.Context) (*ListContactsResponse, error)
ListContacts returns all of the contacts.
func (*Client) ListOutages ¶
func (c *Client) ListOutages(ctx context.Context) (*ListOutagesResponse, error)
ListOutages returns the 100 most recent outages.
func (*Client) UpdateCheck ¶
func (c *Client) UpdateCheck(ctx context.Context, req *UpdateCheckRequest) (*UpdateCheckResponse, error)
UpdateCheck an existing check.
func (*Client) UpdateContact ¶
func (c *Client) UpdateContact(ctx context.Context, req *UpdateContactRequest) (*UpdateContactResponse, error)
UpdateContact updates an existing contact.
type CreateCheckRequest ¶
type CreateCheckRequest struct {
// Type is the type of check to create. Will be one of:
// http, ping, ssh, ftp, pop, smtp, imap or cert.
Type string `form:"type"`
// Name of the check.
Name string `form:"name"`
// Active is true if the check is active.
Active bool `form:"active"`
// Interval (in minutes) this check should run.
Interval int `form:"interval"`
// Contacts is a comma-separated list of checks ids to map to this check.
Contacts string `form:"contacts"`
// URL holds the URL to check for Type 'http'. Mandatory for 'http' checks.
URL *string `form:"url"`
// Username for http or ftp, optional.
Username *string `form:"username"`
// Password for http or ftp, optional
Password *string `form:"password"`
// SendData is the data to send for an 'http' check, optional.
SendData *string `form:"sendData"`
// HTTPHeaders is an optional field for 'http' checks.
// Headers need to be formatted as 'key: value'. One heaer per line.
HTTPHeaders *string `form:"httpHeaders"`
// Host to check, required for ping, ssh, ftp, pop, smtp, imap and cert types.
Host *string `form:"host"`
// Port to check, optional for ssh, ftp, pop, smtp, imap and cert types.
Port *int `form:"port"`
// Secure tells the check to use the secure version of the protocol for:
// ftp, pop, smtp and imap, optional.
Secure *bool `form:"secure"`
// CertExpirationDays is the number of days until cert expiration that
// should result in down status in cert type, required.
CertExpirationDays *int `form:"certExpirationDays"`
}
CreateCheckRequest holds the values for creating a new check.
type CreateCheckResponse ¶
type CreateCheckResponse struct {
// Success returns true if the update was successful, false otherwise.
Success bool `json:"success"`
// Reason is a human readable message about the status of the request.
Reason string `json:"reason"`
// Reasons is a slice of Field/Error messages that explain why the create
// was unsuccessful.
Reasons []struct {
// Field is the name of the field that was incorrect.
Field string `json:"field"`
// Error is the actual error message that caused the failure.
Error string `json:"error"`
} `json:"reasons"`
// Result contains information about the request.
Result struct {
// ID of the newly created check.
ID string `json:"id"`
// Message from the server about the success or failure of the request.
Message string `json:"message"`
} `json:"result"`
}
CreateCheckResponse is the response from the API when calling Client.CreateCheck.
type CreateContactRequest ¶
type CreateContactRequest struct {
// Type holds the type of contact. Must be email or sms.
Type string `form:"type"`
// Name for the contact.
Name string `form:"name"`
// Email address for the contact. Required for type email.
Email string `form:"email"`
// Number is the phone number for sending SMS messages. Must be in the
// following format: +{country code}{phone number}. For example:
// +18885551234
Number string `form:"number"`
// Enabled determines whether the contact should receive messages.
Enabled bool `form:"enabled"`
// Format specifies what size of message the contact should receive.
// Only applies to type email and must be either 'short' or 'long'.
Format string `form:"format"`
// Checks is a comma separated list of check ids that should be
// contacted when the check changes state.
Checks string `form:"checks"`
}
CreateContactRequest holds the values for creating a new contact.
type CreateContactResponse ¶
type CreateContactResponse struct {
// Success returns false if the Contact couldn't be created.
Success bool `json:"success"`
// Reason will hold a message about why the Contact couldn't be created.
Reason string `json:"reason"`
// Reasons is a slice of error messages.
Reasons []struct {
// Field contains the name of the field that contained an error.
Field string `json:"field"`
// Error is the message that explains why the field was invalid.
Error string `json:"error"`
} `json:"reasons"`
// Result will be populated when the contact was successfully created.
Result *struct {
// ID of the newly created contact.
ID string `json:"id"`
// Message holds the success string.
Message string `json:"message"`
} `json:"result"`
}
CreateContactResponse is the response from the API when calling Client.CreateContact.
type DeleteCheckResponse ¶
type DeleteCheckResponse struct {
// Success returns true if the update was successful, false otherwise.
Success bool `json:"success"`
// Result is a message from the server about the requested action.
Result string `json:"result"`
}
DeleteCheckResponse holds the server response when calling Client.DeleteCheck.
type DeleteContactResponse ¶
type DeleteContactResponse struct {
// Success returns false if the contact couldn't be deleted. The reason
// will be held in DeleteContactResponse.Result.
Success bool `json:"success"`
// Result holds a message explaining the DeleteContactResponse.Success
// response.
Result string `json:"result"`
}
DeleteContactResponse holds the server response when calling Contact.Delete.
type GetCheckResponse ¶
type GetCheckResponse struct {
// Success will be false in the event of a failure.
Success bool `json:"success"`
// Reason will contain a message about why the request failed.
Reason string `json:"Reason"`
// Check hold the requested check.
Check struct {
// ID of the check.
ID string `json:"id"`
// Name of the check.
Name string `json:"name"`
// Type will be one of: http, ping, ssh, ftp, pop, smtp, imap or cert.
Type string `json:"type"`
// State is the current state of the check. Possible states are:
// up, down or waiting.
State string `json:"state"`
// Since holds the time of the last state change.
Since string `json:"since"`
// OutageID is the outage id if the check is currently down.
OutageID *string `json:"outageId"`
// URL to check if Check.Type is 'http'.
URL *string `json:"url"`
// Active is true when the check is being execute.
Active bool `json:"active"`
// Interval is how often the check in minutes.
Interval int `json:"interval"`
// EmailNotificationDelay is how long in minutes observery will wait to
// notify of an outage.
EmailNotificationDelay int `json:"emailNotificationDelay"`
// SmsNotificationDelay is how long in minutes observery will wait to
// notify of an outage.
SmsNotificationDelay int `json:"smsNotificationDelay"`
// InMaintenance returns true if the check is currently in
// a maintenance window.
InMaintenance bool `json:"inMaintenance"`
// MaintenanceModeActive return true if maintenance mode is currently
// active.
MaintenanceModeActive bool `json:"maintenanceModeActive"`
// MaintenanceSchedules configured for this check.
MaintenanceSchedules []struct {
// Days is a comma-separated list of days.
Days string `json:"days"`
// Start is when the maintenance schedule starts.
Start time.Time `json:"start"`
// Stop is when the maintenance schedule ends.
Stop time.Time `json:"stop"`
// Timezone for this maintenance schedule in continent/city format.
Timezone string `json:"timezone"`
} `json:"maintenanceSchedules"`
// Contacts that are mapped to this is check.
Contacts []struct {
// ID of the contact.
ID string `json:"id"`
// Name of the contact.
Name string `json:"name"`
} `json:"contacts"`
} `json:"result"`
}
GetCheckResponse is the response when calling Client.GetCheck.
type GetContactResponse ¶
type GetContactResponse struct {
// Success returns false if there was an error. A failure message will be
// stored in Reason.
Success bool `json:"success"`
// Reason will be populated if Success is false.
Reason string `json:"reason"`
// Contact
Contact struct {
// ID of the contact.
ID string `json:"id"`
// Type of contact. Will be 'email' or 'sms'.
Type string `json:"type"`
// Name of the contact.
Name string `json:"name"`
// Verified is true if the contact has been verified.
Verified bool `json:"verified"`
// Enabled returns true if the contact is enabled. If true the contact
// will receive updates.
Enabled bool `json:"enabled"`
// Email holds the email address of the contact if Type is 'email'.
Email *string `json:"email"`
// Format will be either 'short' or 'long'. Only applicable to Type
// 'email'.
Format *string `json:"format"`
// Number is the telephone number used for 'sms' messages.
Number *string `json:"number"`
// CheckMappingCount is the number of checks mapped to this Contact.
CheckMappingCount int `json:"checkMappingCount"`
// Checks contains all of the checks mapped to this Contact.
Checks []struct {
// ID of the Check.
ID string `json:"id"`
// Name of the check.
Name string `json:"name"`
// Type of check, 'email' or 'sms'
Type string `json:"type"`
} `json:"checks"`
} `json:"result"`
}
GetContactResponse is the response when calling Client.GetContact.
type GetOutageResponse ¶
type GetOutageResponse struct {
// Success returns true if the request was successful and false otherwise.
Success bool
// Result is a message from the server about the requested action.
Reason string
// Outage contains the information about the requested outage.
Outage struct {
// ID of the outage.
ID string
// CheckID of the check that the outage belongs to.
CheckID string
// CheckName is the friendly name of the check that the outage belongs
// to.
CheckName string
// Ongoing returns true it the outage is ongoing.
Ongoing bool
// Start of when the outage began.
Start time.Time
// Stop is the date/time when the outage concluded.
Stop time.Time
// Duration of the outage.
Duration time.Duration
// ResponseTime is how long it took for end point to respond when it
// came back online.
ResponseTime time.Duration
// Details is a human readable message about what caused the outage.
Details string
}
}
GetOutageResponse contains the server response when requesting an individual outage.
type ListChecksResponse ¶
type ListChecksResponse struct {
// Success will be false in the event of a failure.
Success bool
// Reason will contain a message about why the request failed.
Reason string
// Checks is a list of all checks.
Checks []struct {
// ID of the check.
ID string
// Name of the check.
Name string
// Active
Active bool
// Type will be one of: http, ping, ssh, ftp, pop, smtp, imap or cert.
Type string
// State is the current state of the check. Possible states are:
// up, down or waiting.
State string
// Since holds the time of the last state change.
Since time.Time
// URL is the url to check for type http.
URL string
// Host holds the host for ping, ssh, ftp, pop, smtp, imap and cert.
Host string
}
}
ListChecksResponse is the response when calling Client.ListChecks.
type ListContactsResponse ¶
type ListContactsResponse struct {
// Success returns false if there was an error. A failure message will be
// stored in Reason.
Success bool `json:"success"`
// Reason will be populated if Success is false.
Reason string `json:"reason"`
// Contacts holds
Contacts []struct {
// ID of the contact.
ID string `json:"id"`
// Type will be 'email' or 'sms'.
Type string `json:"type"`
// Name is the friendly name of the contact.
Name string `json:"name"`
// Verified returns true if the contact has been verified.
Verified bool `json:"verified"`
// Enabled returns true if the contact is enabled. If true the contact
// will receive updates.
Enabled bool `json:"enabled"`
// Email holds the email address of the contact if Type is 'email'.
Email *string `json:"email,omitempty"`
// Format will be either 'short' or 'long'. Only applicable to Type
// 'email'.
Format *string `json:"format,omitempty"`
// CheckMappingCount is the number of checks mapped to this Contact.
CheckMappingCount int `json:"checkMappingCount"`
// Number is the telephone number used for 'sms' messages.
Number *string `json:"number,omitempty"`
} `json:"result"`
}
ListContactsResponse is the response when calling Client.ListContacts.
type ListOutagesResponse ¶
type ListOutagesResponse struct {
// Success returns true if the request was successful and false otherwise.
Success bool
// Result is a message from the server about the requested action.
Reason string
// Outage is a slice of outages.
Outages []struct {
// ID of the outage.
ID string
// CheckID of the check that the outage belongs to.
CheckID string
// CheckName is the friendly name of the check that the outage belongs
// to.
CheckName string
// Ongoing returns true it the outage is ongoing.
Ongoing bool
// Start of when the outage began.
Start time.Time
// Stop is the date/time when the outage concluded.
Stop time.Time
// Duration of the outage.
Duration time.Duration
}
}
ListOutagesResponse contains the server response when requesting multiple outages.
type UpdateCheckRequest ¶
type UpdateCheckRequest struct {
// ID of the check to be updated
ID string
// Name of the check.
Name *string `form:"name"`
// is check active.
Active *bool `form:"active"`
// Interval (in minutes) this check is ran.
Interval *int `form:"interval"`
// Contacts comma-separated list of checks ids to map to this check.
Contacts *string `form:"contacts"`
// URL of website to check.
URL *string `form:"url"`
// Username for http or ftp, optional
Username *string `form:"username"`
// Password for http or ftp, optional
Password *string `form:"password"`
// SendData is post data to send for http, optional
SendData *string `form:"sendData"`
// HTTPHeaders to send for http, optional.
// Headers need to be formatted as 'key: value'. One heaer per line.
HTTPHeaders *string `form:"httpHeaders"`
// Host to check, required for ping, ssh, ftp, pop, smtp, imap and cert
// types.
Host *string `form:"host"`
// Port to check, optional for ssh, ftp, pop, smtp, imap and cert types
Port *int `form:"port"`
// whether to use the secure version of the protocol for ftp, pop, smtp
// and imap, optional.
Secure *bool `form:"secure"`
// CertExpirationDays is the number of days until cert expiration that
// should result in down status in cert type, required.
CertExpirationDays *int `form:"certExpirationDays"`
}
UpdateCheckRequest holds the values for updating an existing check.
type UpdateCheckResponse ¶
type UpdateCheckResponse struct {
// Success returns true if the update was successful, false otherwise.
Success bool `json:"success"`
// Result contains information about the update.
Result struct {
// ID of the check that was updated.
ID string `json:"id"`
// Message from the server about the success or failure of the update.
Message string `json:"message"`
} `json:"result"`
}
UpdateCheckResponse holds the response from the API that is returned from Client.UpdateCheck.
type UpdateContactRequest ¶
type UpdateContactRequest struct {
// ID of the Contact to update.
ID string `form:"-"`
// Name of the contact.
Name *string `form:"name"`
// Enabled determines whether the contact should receive messages.
Enabled *bool `form:"enabled"`
// Format specifies what size of message the contact should receive.
// Only applies to type email and must be either 'short' or 'long'.
Format *string `form:"format"`
// Checks is a comma separated list of check ids that should be
// contacted when the check changes state.
Checks *string `form:"checks"`
}
UpdateContactRequest holds the values for updating an existing contact. Only updated when populated.
type UpdateContactResponse ¶
type UpdateContactResponse struct {
// Success returns false if the Contact couldn't be updated.
Success bool `json:"success"`
// Reason will hold a message about why the Contact couldn't be updated.
Reason string `json:"reason"`
// Reasons is a slice of error messages.
Reasons []struct {
// Field contains the name of the field that contained an error.
Field string `json:"field"`
// Error is the message that explains why the field was invalid.
Error string `json:"error"`
} `json:"reasons"`
// Result will be populated when the contact was successfully updated.
Result *struct {
// ID of the updated contact.
ID string `json:"id"`
// Message holds the success string.
Message string `json:"message"`
} `json:"result"`
}
UpdateContactResponse holds the response from the API that is returned from Contact.Update.
type Webhook ¶
type Webhook struct {
// CheckID is the unique identifier of the check.
CheckID string `form:"checkId"`
// CheckName is user supplied name of the check.
CheckName string `form:"checkName"`
// CheckType is the check type and is one of the following:
// * http
// * ping
// * ssh
// * ftp
// * pop
// * smtp
// * imap
// * cert
CheckType string `form:"checkType"`
// State indicates whether the check was up or dowm.
State string `form:"state"`
// HTTPStatusCode holds the status code if the type is http.
HTTPStatusCode int `form:"httpStatusCode"`
// ResponseTime holds the duration of the last response.
ResponseTime time.Duration `form:"responseTime"`
// TimedOut indicates whether the check timed out waiting for a response.
TimedOut bool `form:"timedOut"`
// Details holds any additional details.
Details string `form:"details"`
}
Webhook is a struct for holding information from observery webhooks. https://observery.com/account/_/integration/webhook
