deadmanssnitch

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: MIT Imports: 6 Imported by: 1

README

go-deadmanssnitch GoDoc Go Report Card License

go-deadmanssnitch is a Go client library for the Dead Man's Snitch API.

Installation

Make sure you have a working Go environment. To install, simply run:

go get github.com/PremiereGlobal/go-deadmanssnitch

Usage

package main

import (
  "github.com/PremiereGlobal/go-deadmanssnitch"
)

var apiKey = "" // Set your api key here

func main() {

  client := deadmanssnitch.NewClient(apiKey)
  ...
}

For more information, read the godoc package documentation.

Examples

Check-In
  var	snitchToken = "" // Set your snitch token here
  err := client.CheckIn(snitchToken)
  if err != nil {
    panic(err)
  }
List All Snitches
  snitches, err := client.ListSnitches([]string{})
  if err != nil {
    panic(err)
  }
Create Snitch
  snitch := deadmanssnitch.Snitch {
    Name:      "testSnitch",
    Interval:  "hourly",
    AlertType: "basic",
    Tags:      []string{"test"},
    Notes:     "This is an example snitch",
  }

  createdSnitch, err := client.CreateSnitch(&snitch)
  if err != nil {
    panic(createdSnitch)
  }

Testing the Client Library

Tests will validate API calls by creating a test snitch, checking in and updating the snitch using all of the methods. It will then delete the snitch after waiting wait seconds (to allow for manual verification).

go test -v --args -apikey=<apiKey> -wait 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is the Dead Man's Snitch API client

func NewClient

func NewClient(apiKey string) *Client

NewClient creates a new API client

func (*Client) AddTags

func (c *Client) AddTags(token string, newTags []string) error

AddTags adds the given tags to the snitch, leaving existing tags unchanged

func (*Client) CheckIn

func (c *Client) CheckIn(token string) error

CheckIn calls the check-in url for the snitch

func (*Client) CreateSnitch

func (c *Client) CreateSnitch(snitch *Snitch) (*Snitch, error)

CreateSnitch creates a new snitch

func (*Client) DeleteSnitch

func (c *Client) DeleteSnitch(token string) error

DeleteSnitch deletes a snitch

func (*Client) GetSnitch

func (c *Client) GetSnitch(token string) (*Snitch, error)

GetSnitch returns a single snitch

func (*Client) ListSnitches

func (c *Client) ListSnitches(filters []string) (*[]Snitch, error)

ListSnitches returns a list of snitches with the provided `filters`. An empty filter will result in all snitches.

func (*Client) PauseSnitch

func (c *Client) PauseSnitch(token string) error

PauseSnitch pauses a snitch

func (*Client) RemoveTags

func (c *Client) RemoveTags(token string, rmTags []string) error

RemoveTags removes the given tags from the snitch

func (*Client) UpdateSnitch

func (c *Client) UpdateSnitch(token string, updatedSnitch *Snitch) (*Snitch, error)

UpdateSnitch updates the snitch identified by `token` The `updatedSnitch` parameter accepts a Snitch object in which you may provide only the attributes you wish to change. Empty fields in the object will not be touched.

type ErrorResponse

type ErrorResponse struct {
	ErrorType   string       `json:"type"`
	ErrorString string       `json:"error"`
	Validations []Validation `json:"validations"`
}

ErrorResponse represents the structure of a API error

type Snitch

type Snitch struct {

	// The snitch's identifying token.
	Token string `json:"token,omitempty"`

	// API URL to retrieve data about this specific Snitch.
	Href string `json:"href,omitempty"`

	// The name of the snitch.
	Name string `json:"name,omitempty"`

	// The list of keyword tags for this snitch.
	Tags []string `json:"tags,omitempty"`

	// The status of the snitch. It could be:
	// "pending"	The snitch is new and your job has not yet checked in.
	// "healthy"	Your job has checked in since the beginning of the last period.
	// "failed"	Your job has not checked in since the beginning of the last period. (At least one alert has been sent.)
	// "errored"	Your job has reported that is has errored. (At least one alert has been sent.) Error Notices are only available on some plans.
	// "paused"	The snitch has been paused and will not worry about your failing job until your job checks-in again after you fix it.
	Status string `json:"status,omitempty"`

	// Any user-supplied notes about this snitch.
	Notes string `json:"notes,omitempty"`

	// The last time your job checked in healthy, as an ISO 8601 datetime with millisecond precision. The timezone is always UTC. If your job has not checked in healthy yet, this will be null.
	CheckedInAt string `json:"checked_in_at,omitempty"`

	// The url your job should hit to check-in.
	CheckInURL string `json:"check_in_url,omitempty"`

	// The size of the period window. If your job does not check-in during an entire period, you will be notified and the snitch status will show up as "failed". The interval can be "15_minute", "30_minute", "hourly", "daily", "weekly", or "monthly".
	Interval string `json:"interval,omitempty"`

	// The type of alerts the snitch will use. basic will have a static deadline that it will expect to hear from it by, while smart will learn when your snitch checks in, moving the deadline closer so you can be alerted sooner.
	AlertType string `json:"alert_type,omitempty"`

	// When the snitch was created, as an ISO 8601 datetime with millisecond precision. The timezone is always UTC.
	CreatedAt string `json:"created_at,omitempty"`
}

Snitch represents the details of a snitch

type Validation

type Validation struct {
	Attribute string `json:"attribute"`
	Message   string `json:"message"`
}

Validation contains the details of a API field validation error

Jump to

Keyboard shortcuts

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