webhook

package module
v0.0.0-...-561234b Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2014 License: MIT Imports: 10 Imported by: 0

README

circonus-webhooks-golang

Build Status

Work in progress! Do not depend on the CLI API quite yet. We will be trying this out internally first.

Generic Circonus Webhook Notification Handlers in Golang (concept borrowed from https://github.com/circonus-labs/circonus-webhooks-python). Decided to implement this in Go to receive the benefits of static compilation (reduce dependencies).

This repository contains custom webhook proxies that allow you to specify this binary as the webhook URL to forward to other web services in the format that they understand (e.g. Hipchat).

Documentation

Index

Constants

View Source
const CirconusTimeFormat = "Mon, 02 Jan 2006 15:04:05"

CirconusTimeFormat represents the datetime format Circonus sends times in the webhook payload

Variables

View Source
var CirconusAccountTimezone = time.Local

CirconusAccountTimezone represents the timezone the account is in since the webhook payload lacks this information. Exposed globally so it can be overridden.

Functions

This section is empty.

Types

type CirconusAlert

type CirconusAlert struct {
	ID         int                `json:"alert_id"`
	Severity   int                `json:"severity"`
	Value      CirconusAlertValue `json:"alert_value"`
	Time       CirconusTime       `json:"alert_time"`
	URL        string             `json:"alert_url"`
	Agent      string             `json:"agent"`
	CheckName  string             `json:"check_name"`
	MetricName string             `json:"metric_name"`

	ClearTime  CirconusTime       `json:"clear_time"`
	ClearValue CirconusAlertValue `json:"clear_value"`
}

CirconusAlert represents an alert in the JSON payload sent via Circonus webhook

func (*CirconusAlert) IsRecovery

func (a *CirconusAlert) IsRecovery() bool

IsRecovery returns whether the alert represents a recovery rather than an alert

type CirconusAlertValue

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

CirconusAlertValue represents the value of an alert in Circonus Circonus will encode string or a numeric value in the JSON payload, but we will just consider it a string to be safe.

func (*CirconusAlertValue) String

func (cav *CirconusAlertValue) String() string

String returns the underlying string value

func (*CirconusAlertValue) UnmarshalJSON

func (cav *CirconusAlertValue) UnmarshalJSON(body []byte) (err error)

UnmarshalJSON interprets the value as a string regardless of whether it is a numeric value or not

type CirconusPayload

type CirconusPayload struct {
	AccountName string           `json:"account_name"`
	Alerts      []*CirconusAlert `json:"alerts"`
}

CirconusPayload represents the JSON payload sent via Circonus webhook

type CirconusTime

type CirconusTime struct {
	time.Time
}

CirconusTime represents a time in the Circonus webhook payload This is needed to parse the format Circonus sends times in

func (*CirconusTime) UnmarshalJSON

func (ct *CirconusTime) UnmarshalJSON(body []byte) (err error)

UnmarshalJSON parse the time in the format expected from Circonus in the timezone specified globally

type Handler

type Handler interface {
	Name() string
	Route() string
	Register(*mux.Router)
	Usage() string
}

Handler is the interface that webhook proxies should implement so that they can be hooked into the server

type HipchatHandler

type HipchatHandler struct {
	HipchatClient    *hipchat.Client
	AlertTemplate    *template.Template
	RecoveryTemplate *template.Template
	AlertColor       string
	RecoveryColor    string
	From             string
}

HipchatHandler handles webhook requests by forwarding them to the Hipchat API

func NewHipchatHandler

func NewHipchatHandler() *HipchatHandler

NewHipchatHandler creates a new by reading the environment

func (*HipchatHandler) Name

func (hh *HipchatHandler) Name() string

Name returns the name of the handler

func (*HipchatHandler) Register

func (hh *HipchatHandler) Register(r *mux.Router)

Register adds the Hipchat handler to the router

func (*HipchatHandler) Route

func (hh *HipchatHandler) Route() string

Route returns the route to mount the handler at

func (*HipchatHandler) ServeHTTP

func (hh *HipchatHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP parses Circonus webhook payload and sends messages to Hipchat

func (*HipchatHandler) Usage

func (hh *HipchatHandler) Usage() string

Usage returns a string to show to the user about configuration of this hook

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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