statuscake

package module
Version: v0.0.0-...-4e32615 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: MIT Imports: 12 Imported by: 114

README

statuscake

Build Status

statuscake is a Go pkg that implements a client for the statuscake API.

More documentation and examples at http://godoc.org/github.com/DreamItGetIT/statuscake.

Documentation

Overview

Package statuscake implements a client for statuscake.com API.

// list all `Tests`
c, err := statuscake.New(statuscake.Auth{Username: username, Apikey: apikey})
if err != nil {
  log.Fatal(err)
}

tests, err := c.Tests().All()
if err != nil {
  log.Fatal(err)
}

v := url.Values{}
v.Set("tags", "test1,test2")
testsWithFilter, err := c.Tests().AllWithFilter(v)
if err != nil {
  log.Fatal(err)
}

// delete a `Test`
err = c.Tests().Delete(TestID)

// create a test
t := &statuscake.Test{
  WebsiteName: "Foo",
  WebsiteURL:  "htto://example.com",
  ... other required args...
}

if err = t.Validate(); err != nil {
  log.Fatal(err)
}

t2, err := c.Tests().Update(t)
if err != nil {
  log.Fatal(err)
}
fmt.Printf("New Test created with id: %d\n", t2.TestID)

// get Tests details
t, err := tt.Detail(id)
...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError interface {
	APIError() string
}

APIError implements the error interface an it's used when the API response has errors.

type Auth

type Auth struct {
	Username string
	Apikey   string
}

Auth wraps the authorisation headers required for each request

type AuthenticationError

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

AuthenticationError implements the error interface and it's returned when API responses have authentication errors

func (*AuthenticationError) Error

func (e *AuthenticationError) Error() string

type Client

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

Client is the http client that wraps the remote API.

func New

func New(auth Auth) (*Client, error)

New returns a new Client

func (*Client) Tests

func (c *Client) Tests() Tests

Tests returns a client that implements the `Tests` API.

type ContactGroup

type ContactGroup struct {
	GroupName    string   `json:"GroupName"    url:"GroupName,omitempty"`
	Emails       []string `json:"Emails"`
	EmailsPut    string   `url:"Email,omitempty"`
	Mobiles      string   `json:"Mobiles"      url:"Mobile,omitempty"`
	Boxcar       string   `json:"Boxcar"       url:"Boxcar,omitempty"`
	Pushover     string   `json:"Pushover"     url:"Pushover,omitempty"`
	ContactID    int      `json:"ContactID"    url:"ContactID,omitempty"`
	DesktopAlert string   `json:"DesktopAlert" url:"DesktopAlert,omitempty"`
	PingURL      string   `json:"PingURL"      url:"PingURL,omitempty"`
}

ContactGroup represent the data received by the API with GET

type ContactGroups

type ContactGroups interface {
	All() ([]*ContactGroup, error)
	Detail(int) (*ContactGroup, error)
	Update(*ContactGroup) (*ContactGroup, error)
	Delete(int) error
	Create(*ContactGroup) (*ContactGroup, error)
}

ContactGroups represent the actions done with the API

func NewContactGroups

func NewContactGroups(c apiClient) ContactGroups

NewContactGroups return a new ssls

type PartialSsl

type PartialSsl struct {
	ID             int
	Domain         string
	Checkrate      string
	ContactGroupsC string
	AlertAt        string
	AlertExpiry    bool
	AlertReminder  bool
	AlertBroken    bool
	AlertMixed     bool
}

PartialSsl represent a ssl test creation or modification

func Partial

func Partial(s *Ssl) (*PartialSsl, error)

Partial return a PartialSsl corresponding to the Ssl

type Response

type Response struct {
	Success  bool   `json:"Success"`
	Message  string `json:"Message"`
	InsertID int    `json:"InsertID"`
}

Response represent the data received from the API

type Ssl

type Ssl struct {
	ID             string              `json:"id"                 url:"id,omitempty"`
	Domain         string              `json:"domain"             url:"domain,omitempty"`
	Checkrate      int                 `json:"checkrate"          url:"checkrate,omitempty"`
	ContactGroupsC string              `                          url:"contact_groups,omitempty"`
	AlertAt        string              `json:"alert_at"           url:"alert_at,omitempty"`
	AlertReminder  bool                `json:"alert_reminder"     url:"alert_expiry,omitempty"`
	AlertExpiry    bool                `json:"alert_expiry"       url:"alert_reminder,omitempty"`
	AlertBroken    bool                `json:"alert_broken"       url:"alert_broken,omitempty"`
	AlertMixed     bool                `json:"alert_mixed"        url:"alert_mixed,omitempty"`
	Paused         bool                `json:"paused"`
	IssuerCn       string              `json:"issuer_cn"`
	CertScore      string              `json:"cert_score"`
	CipherScore    string              `json:"cipher_score"`
	CertStatus     string              `json:"cert_status"`
	Cipher         string              `json:"cipher"`
	ValidFromUtc   string              `json:"valid_from_utc"`
	ValidUntilUtc  string              `json:"valid_until_utc"`
	MixedContent   []map[string]string `json:"mixed_content"`
	Flags          map[string]bool     `json:"flags"`
	ContactGroups  []string            `json:"contact_groups"`
	LastReminder   int                 `json:"last_reminder"`
	LastUpdatedUtc string              `json:"last_updated_utc"`
}

Ssl represent the data received by the API with GET

type Ssls

type Ssls interface {
	All() ([]*Ssl, error)

	Detail(string) (*Ssl, error)
	Update(*PartialSsl) (*Ssl, error)
	UpdatePartial(*PartialSsl) (*PartialSsl, error)
	Delete(ID string) error
	CreatePartial(*PartialSsl) (*PartialSsl, error)
	Create(*PartialSsl) (*Ssl, error)
	// contains filtered or unexported methods
}

Ssls represent the actions done wit the API

func NewSsls

func NewSsls(c apiClient) Ssls

NewSsls return a new ssls

type Test

type Test struct {
	// TestID is an int, use this to get more details about this test. If not provided will insert a new check, else will update
	TestID int `json:"TestID" querystring:"TestID" querystringoptions:"omitempty"`

	// Sent tfalse To Unpause and true To Pause.
	Paused bool `json:"Paused" querystring:"Paused"`

	// Website name. Tags are stripped out
	WebsiteName string `json:"WebsiteName" querystring:"WebsiteName"`

	// CustomHeader. A special header that will be sent along with the HTTP tests.
	CustomHeader string `json:"CustomHeader" querystring:"CustomHeader"`

	// Use to populate the test with a custom user agent
	UserAgent string `json:"UserAgent" queryString:"UserAgent"`

	// Test location, either an IP (for TCP and Ping) or a fully qualified URL for other TestTypes
	WebsiteURL string `json:"WebsiteURL" querystring:"WebsiteURL"`

	// A Port to use on TCP Tests
	Port int `json:"Port" querystring:"Port"`

	// Contact group ID - deprecated in favor of ContactGroup but still provided in the API detail response
	ContactID int `json:"ContactID"`

	// Contact group IDs - will return list of ints or empty if not provided
	ContactGroup []string `json:"ContactGroup" querystring:"ContactGroup"`

	// Current status at last test
	Status string `json:"Status"`

	// 1 Day Uptime
	Uptime float64 `json:"Uptime"`

	// Any test locations seperated by a comma (using the Node Location IDs)
	NodeLocations []string `json:"NodeLocations" querystring:"NodeLocations"`

	// Timeout in an int form representing seconds.
	Timeout int `json:"Timeout" querystring:"Timeout"`

	// A URL to ping if a site goes down.
	PingURL string `json:"PingURL" querystring:"PingURL"`

	Confirmation int `json:"Confirmation,string" querystring:"Confirmation"`

	// The number of seconds between checks.
	CheckRate int `json:"CheckRate" querystring:"CheckRate"`

	// A Basic Auth User account to use to login
	BasicUser string `json:"BasicUser" querystring:"BasicUser"`

	// If BasicUser is set then this should be the password for the BasicUser
	BasicPass string `json:"BasicPass" querystring:"BasicPass"`

	// Set 1 to enable public reporting, 0 to disable
	Public int `json:"Public" querystring:"Public"`

	// A URL to a image to use for public reporting
	LogoImage string `json:"LogoImage" querystring:"LogoImage"`

	// Set to 0 to use branding (default) or 1 to disable public reporting branding
	Branding int `json:"Branding" querystring:"Branding"`

	// Used internally by the statuscake API
	WebsiteHost string `json:"WebsiteHost" querystring:"WebsiteHost"`

	// Enable virus checking or not. 1 to enable
	Virus int `json:"Virus" querystring:"Virus"`

	// A string that should either be found or not found.
	FindString string `json:"FindString" querystring:"FindString"`

	// If the above string should be found to trigger a alert. true will trigger if FindString found
	DoNotFind bool `json:"DoNotFind" querystring:"DoNotFind"`

	// What type of test type to use. Accepted values are HTTP, TCP, PING
	TestType string `json:"TestType" querystring:"TestType"`

	// Use 1 to TURN OFF real browser testing
	RealBrowser int `json:"RealBrowser" querystring:"RealBrowser"`

	// How many minutes to wait before sending an alert
	TriggerRate int `json:"TriggerRate" querystring:"TriggerRate"`

	// Tags should be seperated by a comma - no spacing between tags (this,is,a set,of,tags)
	TestTags []string `json:"TestTags" querystring:"TestTags"`

	// Comma Seperated List of StatusCodes to Trigger Error on (on Update will replace, so send full list each time)
	StatusCodes string `json:"StatusCodes" querystring:"StatusCodes" querystringoptions:"omitempty"`

	// Set to 1 to enable the Cookie Jar. Required for some redirects.
	UseJar int `json:"UseJar" querystring:"UseJar"`

	// Raw POST data seperated by an ampersand
	PostRaw string `json:"PostRaw" querystring:"PostRaw"`

	// POST Body data, json
	PostBody string `json:"PostBody" querystring:"PostBody"`

	// Use to specify the expected Final URL in the testing process
	FinalEndpoint string `json:"FinalEndpoint" querystring:"FinalEndpoint"`

	// Use to enable SSL validation
	EnableSSLAlert bool `json:"EnableSSLAlert" querystring:"EnableSSLAlert"`

	// Use to specify whether redirects should be followed
	FollowRedirect bool `json:"FollowRedirect" querystring:"FollowRedirect"`

	// DNS Tests only. Hostname or IP of DNS server to use.
	DNSServer string `json:"DNSServer" querystring:"DNSServer"`

	// DNS Tests only. IP to compare against WebsiteURL value.
	DNSIP string `json:"DNSIP" querystring:"DNSIP"`
}

Test represents a statuscake Test

func (Test) ToURLValues

func (t Test) ToURLValues() url.Values

ToURLValues returns url.Values of all fields required to create/update a Test.

func (*Test) Validate

func (t *Test) Validate() error

Validate checks if the Test is valid. If it's invalid, it returns a ValidationError with all invalid fields. It returns nil otherwise.

type Tests

type Tests interface {
	All() ([]*Test, error)
	AllWithFilter(url.Values) ([]*Test, error)
	Detail(int) (*Test, error)
	Update(*Test) (*Test, error)
	Delete(TestID int) error
}

Tests is a client that implements the `Tests` API.

type ValidationError

type ValidationError map[string]string

ValidationError is a map where the key is the invalid field and the value is a message describing why the field is invalid.

func (ValidationError) Error

func (e ValidationError) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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