Code Monkey home page Code Monkey logo

checkly-go-sdk's Introduction

Checkly Go SDK

Contributor Covenant Tests GoDoc Go Report Card GitHub go.mod Go version GitHub tag (latest by date)

This project is a Go SDK for Checkly monitoring service. It allows you to handle your checks, check groups, snippets, environments variables and everything you can do with our REST API.

Installation

To use the client library with your Checkly account, you will need an API Key for the account. Go to the Account Settings: API Keys page and click 'Create API Key'.

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

$ go mod init

Then, add the reference of checkly-go-sdk in a Go program using import:

import checkly "github.com/checkly/checkly-go-sdk"

Run any of the normal go commands (build/install/test) and the Go toolchain will resolve and fetch the checkly-go-sdk module automatically.

Alternatively, you can also explicitly go get the package into a project:

$ go get -u github.com/checkly/checkly-go-sdk

Getting Started

Create a new checkly Client by calling checkly.NewClient() (you will need to set your Checkly API Key and Account ID)

baseUrl := "https://api.checklyhq.com"
apiKey := os.Getenv("CHECKLY_API_KEY")
accountId := os.Getenv("CHECKLY_ACCOUNT_ID")

client := checkly.NewClient(
	baseUrl,
	apiKey,
	nil, //custom http client, defaults to http.DefaultClient
	nil, //io.Writer to output debug messages
)

client.SetAccountId(accountId)

Note: if you don't have an API key, you can create one at here

Create your first checks

Once you have a client, you can create a check. See here how to create your first API & Browser checks.

apiCheck := checkly.Check{
	Name:                 "My API Check",
	Type:                 checkly.TypeAPI,
	Frequency:            5,
	Activated:            true,
	Locations: []string{
		"eu-west-1",
		"ap-northeast-2",
	},
	Tags: []string{ "production" },
	Request: checkly.Request{
		Method: http.MethodGet,
		URL:    "https://api.checklyhq.com/v1",
	},
}

browserCheck := checkly.Check{
	Name:          "My Browser Check",
	Type:          checkly.TypeBrowser,
	Frequency:     5,
	Activated:     true,
	Locations:     []string{"eu-west-1"},
	Script: `const assert = require("chai").assert;
	const puppeteer = require("puppeteer");

	const browser = await puppeteer.launch();
	const page = await browser.newPage();
	await page.goto("https://example.com");
	const title = await page.title();

	assert.equal(title, "Example Site");
	await browser.close();`,
}

ctx := context.WithTimeout(context.Background(), time.Second * 5)
client.CreateCheck(ctx, apiCheck)
client.CreateCheck(ctx, browserCheck)

A complete example program! You can see an example program which creates a Checkly check in the demo folder.

Questions

For questions and support please open a new discussion. The issue list of this repo is exclusively for bug reports and feature/docs requests.

Issues

Please make sure to respect issue requirements and choose the proper issue template when opening an issue. Issues not conforming to the guidelines may be closed.

Contribution

Please make sure to read the Contributing Guide before making a pull request.

License

MIT

checkly-go-sdk's People

Contributors

abtris avatar antoine-c avatar bitfield avatar clample avatar dependabot[bot] avatar kjda avatar maxigimenez avatar ndom91 avatar pilimartinez avatar saaldjormike avatar shiini2 avatar tnolet avatar umutuzgur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

checkly-go-sdk's Issues

Add autoAssignAlerts query param to check and groups POST/PUT

We are trying to deprecate the old auto assigning of alert channels to checks. We still need to push a minor version of the go client + terraform so we can set the value to true and they don't get affected by this deprecation. The idea is that we don't assign any alert channels to a check/group automatically when no alert channel subscription is sent unless this query param is set the true

Minor code improvements

Apply some minor code improvements

  • no need to specifically mention the error will be non-nil, that is a well-known convention about how Golang works
// DeleteDashboard deletes the dashboard with the specified ID. It returns a
// non-nil error if the request failed.
  • Replace printf("%v", string(byteSlice)) with printf("%s", byteSlice)

  • Use t.Fail in test cases instead of t.Fatal

For more reference take a look at this PR discussion #44

Add CheckResult type and functions to ListCheckResults & RetrieveCheckResult

We have a use case of the checkly sdk where we need to retrieve the last check result to update the state of the server. In order to achieve this, the following needs to be added:

  1. A type on CheckResult to model the response of this request https://www.checklyhq.com/docs/api/#retrieve-a-check-result.
  2. A function that makes the call to the above endpoint to retrieve a check request
  3. A function that makes a call to the endpoint https://www.checklyhq.com/docs/api/#lists-all-check-results to retrieve a list of all check requests for a check

feature: add private locations support

  • Add a new PrivateLocation type
  • Add CRUD methods
  • Allow private location assignments in check/groups
  • Add the required tests (unit & integrations)
  • Update docs and examples

Convert ChecklyClient to an interface

It is currently not possible to mock ChecklyClient since it is a struct. We should convert it to an interface so it can be used easily for testing locally

AlertSettings field of Check struct should be a pointer value

The AlertSettings field of the Check struct is currently a struct. The result is that when this field is omitted, the resulting JSON still contains the value. This is not what the API expects or what is documented in the API docs.

This can be see here: https://play.golang.org/p/cupZglCunSx
Which prints:

{"alertSettings":{"runBasedEscalation":{},"timeBasedEscalation":{},"reminders":{},"sslCertificates":{"enabled":false,"alertThreshold":0}}}

If you were to change the AlertSettings field to a pointer type, the resulting JSON will be what's expected.

This can be seen here: https://play.golang.org/p/YbWYjwaW3RU
Which prints:

{}

This is also true for the subfields of AlertSettings:

  • RunBasedEscalation
  • TimeBasedEscalation
  • Reminders
  • SSLCertificates

Typo on example demo

Checking the demo can be detect the following typo

...
client.Debug = os.Stdout // this throw an error because Debug property are unexported

Create new methods for checks CRUD

  • Flag existing methods as deprecated
  • Add more verbose method names (with the same functionality) to be consistent with the other resources:
    CreateCheck
    UpdateCheck
    DeleteCheck
    GetCheck
    
  • Use new check create endpoints for check creation

Add check-groups API

We recently opened up the /check-groups/ endpoint in the public API. We want to start creating groups in Terraform. For this we need to expose the the check-groups endpoint in the SDK.

The implementation should address the following endpoints:

GET /v1/check-groups
POST /v1/check-groups
DELETE /v1/check-groups/{id}
GET /v1/check-groups/{id}

Support Private Locations

  • Add a new PrivateLocation type
  • Add CRUD methods
  • Allow private location assignments in check/groups
  • Add the required tests (unit & integrations)
  • Update docs and examples

The to and from parameters should be optional in the CheckResultsFilter

When retrieving the check results list, it returns an empty result if the from and to query parameters are not filled. However, our public API does not have that restriction: if the parameters aren't there we still get a result. The preferred functionality is that the query parameters should be added only if they are present in the CheckResultsFilter.

This was reported by @ogbuaguno in our private support channel

bug: slice types should be omitted when empty, else they are 'null' in resulting JSON

The resulting JSON for the checkly.Check struct contains null values for slice values that are not provided. Examples of this are:

  • Check.Locations
  • Check.EnvironmentVariables
  • Check.Tags
  • Request.Headers
  • Request.QueryParameters
  • Request.Assertions

We should add the ,omitempty annotation so that these values are not passed as null in the JSON.

Add support for Public Dashboards

  • Create a new Dashboard type (follow public API specs)
  • Add CRUD Dashboard operations (create, retrieve, update, delete)
  • Add new test cases and fixtures (unit and integration)
  • Add basic documentation and examples

Use examples/demo/main.go to locally test your code and use go run main.go to run the script.

Add skipSSL request param for create check of type API

There is now a new param "skipSSL" available when creating an API check, it allows a user to skip the SSL check on request. It's very useful when someone is still in development phase and has self signed certificate for example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.