Skip to content

Commit

Permalink
add support for alert targets
Browse files Browse the repository at this point in the history
  • Loading branch information
louism517 committed Sep 12, 2017
1 parent 91db02f commit db52fa1
Show file tree
Hide file tree
Showing 9 changed files with 480 additions and 27 deletions.
17 changes: 11 additions & 6 deletions README.md
@@ -1,12 +1,17 @@
# Golang Wavefront Client [![GoDoc](https://godoc.org/github.com/spaceapegames/go-wavefront?status.svg)](https://godoc.org/github.com/spaceapegames/go-wavefront) [![Build Status](https://travis-ci.org/spaceapegames/go-wavefront.svg?branch=master)](https://travis-ci.org/spaceapegames/go-wavefront)

Golang SDK for interacting with the Wavefront v2 API, and sending metrics through a Wavefront proxy.
Golang SDK for interacting with the Wavefront v2 API, and sending metrics through a Wavefront proxy.

## Usage
## Usage

### API Client

Presently support for querying, searching, alerts and events.

Presently support for:
* Querying
* Searching
* Dashboard Management
* Alert (and Alert Target) Management
* Events Management

Please see the [examples](examples) directory for an example on how to use each, or check out the [documentation](https://godoc.org/github.com/spaceapegames/go-wavefront).

Expand Down Expand Up @@ -71,6 +76,6 @@ func main() {

## Contributing

Pull requests are welcomed.
Pull requests are welcomed.

If you'd like to contribute to this project, please raise an issue and indicate that you'd like to take on the work prior to submitting a pull request.
If you'd like to contribute to this project, please raise an issue and indicate that you'd like to take on the work prior to submitting a pull request.
2 changes: 1 addition & 1 deletion alert.go
Expand Up @@ -17,7 +17,7 @@ type Alert struct {
// AdditionalInfo is any extra information about the Alert
AdditionalInfo string `json:"additionalInformation"`

// Target is a comma-separated list of email targets for the Alert
// Target is a comma-separated list of targets for the Alert
Target string `json:"target"`

// Condition is the condition under which the Alert will fire
Expand Down
20 changes: 0 additions & 20 deletions examples/blah.go

This file was deleted.

58 changes: 58 additions & 0 deletions examples/target.go
@@ -0,0 +1,58 @@
package main

import (
"io/ioutil"
"log"

"github.com/spaceapegames/go-wavefront"
)

func main() {
config := &wavefront.Config{
Address: "spaceape.wavefront.com",
Token: "xxxx-xxxx-xxxx-xxxx-xxxx",
}
client, err := wavefront.NewClient(config)

if err != nil {
log.Fatal(err)
}

client.Debug(true)

targets := client.Targets()

tmpl, _ := ioutil.ReadFile("./target-template.tmpl")

target := wavefront.Target{
Title: "test target",
Description: "testing something",
Method: "WEBHOOK",
Recipient: "https://hooks.slack.com/services/test/me",
ContentType: "application/json",
CustomHeaders: map[string]string{
"Testing": "true",
},
Triggers: []string{"ALERT_OPENED", "ALERT_RESOLVED"},
Template: string(tmpl),
}

// Create the target on Wavefront
err = targets.Create(&target)
if err != nil {
log.Fatal(err)
}

// The ID field is now set, so we can update or delete the Target
target.Description = "new description"
err = targets.Update(&target)
if err != nil {
log.Fatal(err)
}

err = targets.Delete(&target)
if err != nil {
log.Fatal(err)
}

}
29 changes: 29 additions & 0 deletions fixtures/create-target-response.json
@@ -0,0 +1,29 @@
{
"status" : {
"result" : "OK",
"code" : 200,
"message" : ""
},
"response" : {
"updatedEpochMillis" : 1505224633193,
"updaterId" : "bob@example.com",
"emailSubject" : "",
"title" : "test target",
"method" : "WEBHOOK",
"customHttpHeaders" : {
"Testing" : "true"
},
"contentType" : "application/json",
"creatorId" : "bob@example.com",
"id" : "7",
"customerId" : "testy",
"description" : "testing something",
"triggers" : [
"ALERT_OPENED",
"ALERT_RESOLVED"
],
"recipient" : "https://hooks.slack.com/services/1224/3344",
"createdEpochMillis" : 1505224633193,
"template" : ""
}
}
57 changes: 57 additions & 0 deletions fixtures/list-targets.json
@@ -0,0 +1,57 @@
{
"status": {
"result": "OK",
"message": "",
"code": 200
},
"response": {
"items": [
{
"method": "WEBHOOK",
"contentType": "application/json",
"id": "1",
"description": "Webhook for Slack",
"customerId": "testing",
"createdEpochMillis": 1502198558402,
"updatedEpochMillis": 1505204057427,
"updaterId": "ops@example.com",
"creatorId": "bob@example.com",
"title": "Slack On Call",
"template": "{{! https://docs.wavefront.com/webhooks_managing.html#customizing-a-webhook-template }}\n{{#setDefaultIterationLimit}}500{{/setDefaultIterationLimit}}\n{{#setFailingLimit}}500{{/setFailingLimit}}\n{{#setInMaintenanceLimit}}500{{/setInMaintenanceLimit}}\n{{#setNewlyFailingLimit}}500{{/setNewlyFailingLimit}}\n{{#setRecoveredLimit}}500{{/setRecoveredLimit}}\n{\n \"attachments\": [\n {\n \"fallback\": \"{{#jsonEscape}}{{{subject}}} {{{reason}}} [{{{severity}}}] {{{name}}}{{/jsonEscape}}\",\n \"pretext\": \"{{#jsonEscape}}{{{subject}}} {{{reason}}} [{{{severity}}}] {{{name}}}{{/jsonEscape}}\",\n \"mrkdwn_in\": [\n \"text\",\n \"pretext\",\n \"fields\"\n ],\n \"fields\": [\n {\n \"title\": \"Severity\",\n \"value\": \"{{#jsonEscape}}{{{severity}}}{{/jsonEscape}}\",\n \"short\": true\n },\n {\n \"title\": \"URL\",\n \"value\": \"<{{{url}}}>\",\n \"short\": true\n },\n {\n \"title\": \"Additional Info\",\n \"value\": \"{{#jsonEscape}}{{{additionalInformation}}}{{/jsonEscape}}\",\n \"short\": false\n }\n ]\n }\n ]\n}\n",
"triggers": [
"ALERT_OPENED",
"ALERT_RESOLVED"
],
"recipient": "https://hooks.slack.com/services/1234/5678",
"customHttpHeaders": {
"Testing" : "true"
},
"emailSubject": ""
},
{
"method": "EMAIL",
"id": "2",
"description": "Email Target",
"customerId": "testing",
"createdEpochMillis": 1505122637180,
"updatedEpochMillis": 1505208854347,
"updaterId": "ops@example.com",
"creatorId": "ops@example.com",
"title": "Email Target",
"template": "{{! https://docs.wavefront.com/webhooks_managing.html#customizing-a-webhook-template }}\n{{#setDefaultIterationLimit}}500{{/setDefaultIterationLimit}}\n{{#setFailingLimit}}500{{/setFailingLimit}}\n{{#setInMaintenanceLimit}}500{{/setInMaintenanceLimit}}\n{{#setNewlyFailingLimit}}500{{/setNewlyFailingLimit}}\n{{#setRecoveredLimit}}500{{/setRecoveredLimit}}\n{\n \"attachments\": [\n {\n \"fallback\": \"{{#jsonEscape}}{{{subject}}} {{{reason}}} [{{{severity}}}] {{{name}}}{{/jsonEscape}}\",\n \"pretext\": \"{{#jsonEscape}}{{{subject}}} {{{reason}}} [{{{severity}}}] {{{name}}}{{/jsonEscape}}\",\n \"mrkdwn_in\": [\n \"text\",\n \"pretext\",\n \"fields\"\n ],\n \"fields\": [\n {\n \"title\": \"Severity\",\n \"value\": \"{{#jsonEscape}}{{{severity}}}{{/jsonEscape}}\",\n \"short\": true\n },\n {\n \"title\": \"URL\",\n \"value\": \"<{{{url}}}>\",\n \"short\": true\n },\n {\n \"title\": \"Additional Info\",\n \"value\": \"{{#jsonEscape}}{{{additionalInformation}}}{{/jsonEscape}}\",\n \"short\": false\n }\n ]\n }\n ]\n}",
"triggers": [
"ALERT_OPENED",
"ALERT_RESOLVED"
],
"recipient": "https://hooks.slack.com/services/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",
"customHttpHeaders": {},
"emailSubject": "Alert alert",
"recipient" : "bob@example.com"
}
],
"offset": 0,
"limit": 100,
"totalItems": 3,
"moreItems": false
}
}
36 changes: 36 additions & 0 deletions fixtures/target-template.tmpl
@@ -0,0 +1,36 @@
{{! https://docs.wavefront.com/webhooks_managing.html#customizing-a-webhook-template }}
{{#setDefaultIterationLimit}}500{{/setDefaultIterationLimit}}
{{#setFailingLimit}}500{{/setFailingLimit}}
{{#setInMaintenanceLimit}}500{{/setInMaintenanceLimit}}
{{#setNewlyFailingLimit}}500{{/setNewlyFailingLimit}}
{{#setRecoveredLimit}}500{{/setRecoveredLimit}}
{
"attachments": [
{
"fallback": "{{#jsonEscape}}{{{subject}}} {{{reason}}} [{{{severity}}}] {{{name}}}{{/jsonEscape}}",
"pretext": "{{#jsonEscape}}{{{subject}}} {{{reason}}} [{{{severity}}}] {{{name}}}{{/jsonEscape}}",
"mrkdwn_in": [
"text",
"pretext",
"fields"
],
"fields": [
{
"title": "Severity",
"value": "{{#jsonEscape}}{{{severity}}}{{/jsonEscape}}",
"short": true
},
{
"title": "URL",
"value": "<{{{url}}}>",
"short": true
},
{
"title": "Additional Info",
"value": "{{#jsonEscape}}{{{additionalInformation}}}{{/jsonEscape}}",
"short": false
}
]
}
]
}

0 comments on commit db52fa1

Please sign in to comment.