Go(lang) client library for Cachet (open source status page system).

cachet

GoDoc Build Status Go Report Card

Go(lang) client library for Cachet (open source status page system).

Features

  • Full API support
    • Components
    • Incidents
    • Metrics
    • Subscribers
  • Various authentication methods (Basic Auth and Token based)
  • Fully tested

Installation

It is go gettable

$ go get github.com/andygrunwald/cachet

(optional) to run unit / example tests:

$ cd $GOPATH/src/github.com/andygrunwald/cachet
$ go test -v ./...

API

Please have a look at the GoDoc documentation for a detailed API description.

Authentication

Cachet supports two different ways for authentication: BasicAuth and API Token. Both are supported by this library.

For BasicAuth you need to call the AuthenticationService and apply your email address and your password:

client.Authentication.SetBasicAuth("[email protected]", "test123")

To use the API Token way, you do nearly the same but use the SetTokenAuth function:

client.Authentication.SetTokenAuth("MY-SECRET-TOKEN")

Examples

Further a few examples how the API can be used. A few more examples are available in the GoDoc examples section.

Ping

Call the API test endpoint. Example without error handling. Full example available in the GoDoc examples section.

package main

import (
    "fmt"
    "github.com/andygrunwald/cachet"
)

func main() {
    client, _ := cachet.NewClient("https://demo.cachethq.io/", nil)
    pong, resp, _ := client.General.Ping()

    fmt.Printf("Result: %s\n", pong)
    fmt.Printf("Status: %s\n", resp.Status)

    // Output: Result: Pong!
    // Status: 200 OK
}

Create a new component

Calling /components. Example without error handling. Full example available in the GoDoc examples section.

package main

import (
    "fmt"
    "github.com/andygrunwald/cachet"
)

func main() {
    client, _ := cachet.NewClient("https://demo.cachethq.io/", nil)
    client.Authentication.SetBasicAuth("[email protected]", "test123")

    component := &cachet.Component{
        Name:        "Beer Fridge",
        Description: "Status of the beer fridge in the kitchen",
        Status:      cachet.ComponentStatusOperational,
    }
    newComponent, resp, _ := client.Components.Create(component)

    fmt.Printf("Result: %s\n", newComponent.Name)
    if newComponent.ID > 0 {
        fmt.Println("ID > 0!")
    }
    fmt.Printf("Status: %s\n", resp.Status)

    // Output: Beer Fridge
    // ID > 0!
    // Status: 200 OK
}

Supported versions

Tested with v1.2.1 of Cachet. It may works with older and / or newer versions. Newer versions will be supported. Older versions not.

License

This project is released under the terms of the MIT license.

Contribution and Contact

Contribution, in any kind of way, is highly welcome! It doesn't matter if you are not able to write code. Creating issues or holding talks and help other people to use cachet is contribution, too! A few examples:

  • Correct typos in the README / documentation
  • Reporting bugs
  • Implement a new feature or endpoint
  • Sharing the love if cachet and help people to get use to it

If you are new to pull requests, checkout Collaborating on projects using issues and pull requests / Creating a pull request. If you've found a bug, a typo, have a question or a want to request new feature, please report it as a GitHub issue.

For other queries, i'm available on Twitter (@andygrunwald).

Owner
Andy Grunwald
I solve problems and put things into production.
Andy Grunwald
Comments
  • Multiple updates

    Multiple updates

    This PR contains multiple updates to reflect current API endpoints and parameters.

    Major improvements were done at:

    • Separate component_groups from components and incident_updates from incident to keep same syntax for function names
    • Improved current tests and added new tests for new endpoints and parameters (I am still planning to add new tests for testing other features)
    • Merge querystring parameters to contains all available filters for any endpoint and also parameters that are specific to a given endpoint
    • Others

    I know it is an huge pull request, so feel free to ask me anything about it.

  • Subscribers retain their component subscription

    Subscribers retain their component subscription

    If I subscribe an email, un-subscribe it, then subscribe it again, I'm registered twice every for components.

    Here's an excerpt of the metrics that are sent back. Please note that the "subscriptions" array has several entries with the same "component_id".

    { "id": 2, "email": "[email protected]", "verify_code": "xxxx", "verified_at": "Monday 16th January 2017 09:48:41", "created_at": "2017-01-16 09:47:39", "updated_at": "2017-01-16 09:48:41", "global": true, "subscriptions": [ { "id": 21, "subscriber_id": 2, "component_id": 1, "created_at": "2017-01-16 14:36:46", "updated_at": "2017-01-16 14:36:46" }, { "id": 22, "subscriber_id": 2, "component_id": 2, "created_at": "2017-01-16 14:36:46", "updated_at": "2017-01-16 14:36:46" }, { "id": 23, "subscriber_id": 2, "component_id": 3, "created_at": "2017-01-16 14:36:46", "updated_at": "2017-01-16 14:36:46" }, { "id": 24, "subscriber_id": 2, "component_id": 4, "created_at": "2017-01-16 14:36:46", "updated_at": "2017-01-16 14:36:46" }, { "id": 25, "subscriber_id": 2, "component_id": 1, "created_at": "2017-01-16 14:38:35", "updated_at": "2017-01-16 14:38:35" }, { "id": 26, "subscriber_id": 2, "component_id": 2, "created_at": "2017-01-16 14:38:35", "updated_at": "2017-01-16 14:38:35" }, { "id": 27, "subscriber_id": 2, "component_id": 3, "created_at": "2017-01-16 14:38:35", "updated_at": "2017-01-16 14:38:35" }, { "id": 28, "subscriber_id": 2, "component_id": 4, "created_at": "2017-01-16 14:38:35", "updated_at": "2017-01-16 14:38:35" }, { "id": 29, "subscriber_id": 2, "component_id": 1, "created_at": "2017-01-16 14:47:39", "updated_at": "2017-01-16 14:47:39" }, { "id": 30, "subscriber_id": 2, "component_id": 2, "created_at": "2017-01-16 14:47:39", "updated_at": "2017-01-16 14:47:39" }, { "id": 31, "subscriber_id": 2, "component_id": 3, "created_at": "2017-01-16 14:47:39", "updated_at": "2017-01-16 14:47:39" }, { "id": 32, "subscriber_id": 2, "component_id": 4, "created_at": "2017-01-16 14:47:39", "updated_at": "2017-01-16 14:47:39" } ] }

    Also, you can see the problem in the subscribers page (see attached file)

    cachetbug

  • Multiple updates

    Multiple updates

    This PR contains multiple updates to reflect current API endpoints and parameters.

    Major improvements were done at:

    • separate component_groups from components and incident_updates from incident to keep same syntax for function names
    • Improved current tests and added new tests for new endpoints and parameters (I am still planning to add new tests for testing other features)
    • Merge querystring parameters to contains all available filters for any endpoint and also parameters that are specific to a given endpoint
    • Others

    I know it is an huge pull request, so feel free to ask me anything about it.

  • Subscribers receive too much emails

    Subscribers receive too much emails

    The context is:

    • A cachet page that monitors the state of a service.
    • The service availability is verified every 10 minutes, and the cachet component is updated with the value.
    • Subscribers want to be warned whenever the service changes state.

    Currently, the user is warned whenever the component state is updated, regardless of the value.

    Solution: send notification email only when new information is available (for example: the component state is updated with a different status than the current one).

    Workaround: update the component only when the value has actually changed. The problem with this is that the person looking at the component has no way of knowing the state of the service was actually monitored.

  • 406 Not Acceptable

    406 Not Acceptable

    I'm receiving this error when running the tests:

    --- FAIL: ExampleGeneralService_Ping (0.66s)
    panic: API call to https://demo.cachethq.io/api/v1/ping failed: 406 Not Acceptable [recovered]
        panic: API call to https://demo.cachethq.io/api/v1/ping failed: 406 Not Acceptable
    
    goroutine 1 [running]:
    testing.runExample.func2(0xece73579b, 0xc8097b5a36, 0x56b520, 0xc8200b63f0, 0xc820032010, 0xc8201e7500, 0x3f5480, 0x1a, 0x447750, 0x3f5a20, ...)
        /usr/local/Cellar/go/1.5.3/libexec/src/testing/example.go:93 +0x3f9
    github.com/andygrunwald/cachet_test.ExampleGeneralService_Ping()
        /Users/eminetto/Documents/Projects/moveis-simonetti/consulta-cpf-cnpj-server/src/github.com/andygrunwald/cachet/cachet_example_test.go:16 +0xf7
    testing.runExample(0x3f5480, 0x1a, 0x447750, 0x3f5a20, 0x1d, 0x0)
        /usr/local/Cellar/go/1.5.3/libexec/src/testing/example.go:98 +0x3cb
    testing.RunExamples(0x447778, 0x567660, 0x2, 0x2, 0xf7301)
        /usr/local/Cellar/go/1.5.3/libexec/src/testing/example.go:36 +0x31b
    testing.(*M).Run(0xc820063ef8, 0xf74a3)
        /usr/local/Cellar/go/1.5.3/libexec/src/testing/testing.go:495 +0xac
    main.main()
        github.com/andygrunwald/cachet/_test/_testmain.go:132 +0x116
    
    goroutine 17 [syscall, locked to thread]:
    runtime.goexit()
        /usr/local/Cellar/go/1.5.3/libexec/src/runtime/asm_amd64.s:1721 +0x1
    
    goroutine 227 [runnable]:
    syscall.Syscall(0x6, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/Cellar/go/1.5.3/libexec/src/syscall/asm_darwin_amd64.s:16 +0x5
    syscall.Close(0x6, 0x0, 0x0)
        /usr/local/Cellar/go/1.5.3/libexec/src/syscall/zsyscall_darwin_amd64.go:404 +0x4a
    net.(*netFD).destroy(0xc8201fcfc0)
        /usr/local/Cellar/go/1.5.3/libexec/src/net/fd_unix.go:135 +0x46
    net.(*netFD).decref(0xc8201fcfc0)
        /usr/local/Cellar/go/1.5.3/libexec/src/net/fd_unix.go:153 +0x40
    net.(*netFD).Close(0xc8201fcfc0, 0x0, 0x0)
        /usr/local/Cellar/go/1.5.3/libexec/src/net/fd_unix.go:199 +0x87
    net.(*conn).Close(0xc8200d64d8, 0x0, 0x0)
        /usr/local/Cellar/go/1.5.3/libexec/src/net/net.go:196 +0xab
    crypto/tls.(*Conn).Close(0xc8200e8b00, 0x0, 0x0)
        /usr/local/Cellar/go/1.5.3/libexec/src/crypto/tls/conn.go:953 +0xe3
    net/http.(*persistConn).closeLocked(0xc820155600)
        /usr/local/Cellar/go/1.5.3/libexec/src/net/http/transport.go:1248 +0x4e
    net/http.(*persistConn).close(0xc820155600)
        /usr/local/Cellar/go/1.5.3/libexec/src/net/http/transport.go:1242 +0x7a
    net/http.(*persistConn).readLoop(0xc820155600)
        /usr/local/Cellar/go/1.5.3/libexec/src/net/http/transport.go:1004 +0x954
    created by net/http.(*Transport).dialConn
        /usr/local/Cellar/go/1.5.3/libexec/src/net/http/transport.go:685 +0xc78
    
    goroutine 228 [select]:
    net/http.(*persistConn).writeLoop(0xc820155600)
        /usr/local/Cellar/go/1.5.3/libexec/src/net/http/transport.go:1009 +0x40c
    created by net/http.(*Transport).dialConn
        /usr/local/Cellar/go/1.5.3/libexec/src/net/http/transport.go:686 +0xc9d
    exit status 2
    FAIL    github.com/andygrunwald/cachet  0.696s
    

    My go version is go1.5.3 darwin/amd64

  • Document missing OpenAPI/Swagger-Defintion/API-Spec

    Document missing OpenAPI/Swagger-Defintion/API-Spec

    One thought would be if we can generate this client. An API Spec file would be required for it. A few discussions have been ongoing, but no progress/merge yet regarding this topic. See:

    • https://github.com/CachetHQ/Docs/issues/9
    • https://github.com/CachetHQ/Cachet/issues/2903
    • https://github.com/CachetHQ/Cachet/pull/2929
    • https://github.com/CachetHQ/Cachet/issues/3468

    The goal of this task: Document this in the README, that this client lib is manually created + that new API endpoints must be added manually.

Display last GitLab project git commit. Page is optimized for an e-paper device.
Display last GitLab project git commit. Page is optimized for an e-paper device.

git-on-epaper A gitlab webhook for push notifications on a project. The webhook serves a HTML that shows the last push on the project with the followi

Dec 12, 2022
Startpage - Lambda for reading rss feeds and generating a minimal start page for a static site

startpage generate a startpage of links for a static site hosted via AWS What It

Sep 6, 2022
Support for Usagi API developed by @DanielaGC. The library is written in Go Lang

?? Usagi API - Wrapper This library is simple and easy to use and was developed entirely for Usagi API written in Go Lang. ??‍?? Example package main

Oct 18, 2021
A productivity tools to diagnose list of exported URL status from Google Search Console, Analytics, Sitemap URL...etc.

google-url-checker A productivity tools to diagnose list of exported URL status from Google Search Console, Analytics, Sitemap URL...etc. A quick way

Dec 31, 2021
DiscSpam is the best free and open source tool to spam/raid Discord servers.
DiscSpam is the best free and open source tool to spam/raid Discord servers.

DiscSpam Fast, Free, Easy to use Discord.com raid tool Report Bug , Request Feature About The Project There are a few Discord raid tools on GitHub, ho

Dec 27, 2022
This is the new api repository for Feel the Movies. Written in Go, totally open source.
This is the new api repository for Feel the Movies. Written in Go, totally open source.

This is the new API repository for Feel the Movies. Written in Go, totally open source. App Currently available for Android only. I have plans for an

Sep 18, 2022
🐥 Sturdy is an open-source, real-time, version control platform for startups
🐥 Sturdy is an open-source, real-time, version control platform for startups

Welcome to Sturdy! ?? ?? Real-time code collaboration. Sturdy is an open-source version control platform that allows you to interact with your code at

Dec 24, 2022
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.
A Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Kinesumer is a Go client implementing a client-side distributed consumer group client for Amazon Kinesis.

Jan 5, 2023
Clusterpedia-client - clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Jan 7, 2022
Client-go - Clusterpedia-client supports the use of native client-go mode to call the clusterpedia API

clusterpedia-client supports the use of native client-go mode to call the cluste

Dec 5, 2022
Aoe4-client - Client library for aoe4 leaderboards etc

AOE4 Client Overview This is a go client used to query AOE4 data from either the

Jan 18, 2022
Go API Client for NASA's Open APIs

Go Client for Nasa Open APIs Description The Go Client for Nasa Open APIs is a Go Client for the following Nasa Open APIs: APOD: Astronomy Picture of

Sep 24, 2021
Simple Go client for open-meteo.com

Open-Meteo-Go A simple go client for the open meteo API. It supports all options of the API as of Sept 20 2021. Usage Simple example: package main im

Dec 15, 2022
School POC of an AES implementation in an API/Client system

poc_aes_implement School POC of an AES implementation in an API/Client system How to use : Start the api with : poc-aes -api start Client commands : p

Nov 29, 2021
Go library for querying Source servers

go-steam go-steam is a Go library for querying Source servers. Requirements Go 1.1 or above Installation go get -u github.com/sostronk/go-steam To us

Oct 28, 2022
Client for the cloud-iso-client

cloud-iso-client Client for the cloud-iso-client. Register an API token Before using this client library, you need to register an API token under your

Dec 6, 2021
Go-http-client: An enhanced http client for Golang
Go-http-client: An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev ?? This package provides you a http client package for your http requests. Y

Jan 7, 2023
Nutanix-client-go - Go client for the Nutanix Prism V3 API

nutanix-client-go This repository contains portions of the Nutanix API client code in nutanix/terraform-provider-nutanix. It has been extracted to red

Jan 6, 2022
Balabola-go-client - GO client for Yandex balabola service

Balabola GO Client GO client for Yandex balabola service Yandex warning The neur

Jan 29, 2022