Add input plugin for rollbar service. (#1247)
* Report rollbar events. Signed-off-by: Cyril Duez <cyril@stormz.me> Signed-off-by: François de Metz <francois@stormz.me> * Fix indent with go fmt. * Add test for rollbar webhooks. * Report more data from new_item event. * Handle new deploy webhook. Signed-off-by: Cyril Duez <cyril@stormz.me> Signed-off-by: François de Metz <francois@stormz.me> * Update default port. * Add readme. * Add rollbar_webhooks to the readme. * Add rollbar_webhooks to plugins list. * Add tag level for new_item event. * Update readme. * Update changelog.
This commit is contained in:
committed by
Cameron Sparr
parent
d736c7235a
commit
c78b6cdb4e
74
plugins/inputs/rollbar_webhooks/rollbar_webhooks_test.go
Normal file
74
plugins/inputs/rollbar_webhooks/rollbar_webhooks_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package rollbar_webhooks
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
func postWebhooks(rb *RollbarWebhooks, eventBody string) *httptest.ResponseRecorder {
|
||||
req, _ := http.NewRequest("POST", "/", strings.NewReader(eventBody))
|
||||
w := httptest.NewRecorder()
|
||||
w.Code = 500
|
||||
|
||||
rb.eventHandler(w, req)
|
||||
|
||||
return w
|
||||
}
|
||||
|
||||
func TestNewItem(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
rb := NewRollbarWebhooks()
|
||||
resp := postWebhooks(rb, NewItemJSON())
|
||||
if resp.Code != http.StatusOK {
|
||||
t.Errorf("POST new_item returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)
|
||||
}
|
||||
rb.Gather(&acc)
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"id": 272716944,
|
||||
}
|
||||
|
||||
tags := map[string]string{
|
||||
"event": "new_item",
|
||||
"environment": "production",
|
||||
"project_id": "90",
|
||||
"language": "python",
|
||||
"level": "error",
|
||||
}
|
||||
|
||||
acc.AssertContainsTaggedFields(t, "rollbar_webhooks", fields, tags)
|
||||
}
|
||||
|
||||
func TestDeploy(t *testing.T) {
|
||||
var acc testutil.Accumulator
|
||||
rb := NewRollbarWebhooks()
|
||||
resp := postWebhooks(rb, DeployJSON())
|
||||
if resp.Code != http.StatusOK {
|
||||
t.Errorf("POST deploy returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)
|
||||
}
|
||||
rb.Gather(&acc)
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"id": 187585,
|
||||
}
|
||||
|
||||
tags := map[string]string{
|
||||
"event": "deploy",
|
||||
"environment": "production",
|
||||
"project_id": "90",
|
||||
}
|
||||
|
||||
acc.AssertContainsTaggedFields(t, "rollbar_webhooks", fields, tags)
|
||||
}
|
||||
|
||||
func TestUnknowItem(t *testing.T) {
|
||||
rb := NewRollbarWebhooks()
|
||||
resp := postWebhooks(rb, UnknowJSON())
|
||||
if resp.Code != http.StatusOK {
|
||||
t.Errorf("POST unknow returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user