Skip to content

alphagov/paas-go-pingdom

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pingdom-go

pingdom-go is a Go client library for the Pingdom API.

This currently supports working with basic HTTP (with specific details) and ping checks. It can also manage contacts who will be alerted in case of downtime.

Build Status: Build Status

Godoc: https://godoc.org/github.com/russellcardullo/go-pingdom/pingdom

Usage

Client

Pingdom handles single-user and multi-user accounts differently.

Construct a new single-user Pingdom client:

client := pingdom.NewClient("pingdom_username", "pingdom_password", "pingdom_api_key")

Construct a multi-user Pingdom client:

client := pingdom.NewMultiUserClient("pingdom_username", "pingdom_password", "pingdom_api_key", "pingdom_account_email")

The pingdom_account_email variable is the email address of the owner of the multi-user account. This is passed in the Account-Email header to the Pingdom API.

Using a Pingdom client, you can access supported services.

CheckService

This service manages pingdom Checks which are represented by the Check struct. When creating or updating Checks you must specify at a minimum the Name, Hostname and Resolution. Other fields are optional but if not set will be given the zero values for the underlying type.

More information on Checks from Pingdom: https://www.pingdom.com/features/api/documentation/#ResourceChecks

Get a list of all checks:

checks, err := client.Checks.List()
fmt.Println("Checks:", checks) // [{ID Name} ...]

Create a new HTTP check:

newCheck := pingdom.HttpCheck{Name: "Test Check", Hostname: "example.com", Resolution: 5}
check, err := client.Checks.Create(&newCheck)
fmt.Println("Created check:", check) // {ID, Name}

Create a new Ping check:

newCheck := pingdom.PingCheck{Name: "Test Check", Hostname: "example.com", Resolution: 5}
check, err := client.Checks.Create(&newCheck)
fmt.Println("Created check:", check) // {ID, Name}

Get details for a specific check:

checkDetails, err := client.Checks.Read(12345)

For checks with detailed information, check the specific details in the field Type (e.g. checkDetails.Type.HTTP).

Update a check:

updatedCheck := pingdom.HttpCheck{Name: "Updated Check", Hostname: "example2.com", Resolution: 5}
msg, err := client.Checks.Update(12345, &updatedCheck)

Delete a check:

msg, err := client.Checks.Delete(12345)

Create a notification contact:

newContact := pingdom.Contact{ Name: "John Doe", Email: "[email protected]", Defaultsmsprovider: "nexmo" }
contactResponse, err := client.Contacts.Create(&newContact)

Create a check with basic alert notification to a contact. Note that you must set ContactIds, UseLegacyNotifications, SendNotificationWhenDown and at least one of the SendTo* parameters:

newCheck := pingdom.HttpCheck{Name: "Test Check", Hostname: "example.com", Resolution: 5, ContactIds: []int{contactResponse.ID}, UseLegacyNotifications: true, SendNotificationWhenDown: 2, SendToEmail: true}
checkResponse, err := client.Checks.Create(&newCheck)

About

Pingdom API access from Go

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.6%
  • Makefile 0.4%