Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
480 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" : "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.