diff --git a/plugins/inputs/webhooks/filestack/filestack_webhooks.go b/plugins/inputs/webhooks/filestack/filestack_webhooks.go index 38f05eab0..623737670 100644 --- a/plugins/inputs/webhooks/filestack/filestack_webhooks.go +++ b/plugins/inputs/webhooks/filestack/filestack_webhooks.go @@ -31,7 +31,7 @@ func (fs *FilestackWebhook) eventHandler(w http.ResponseWriter, r *http.Request) return } - event := &DialogEvent{} + event := &FilestackEvent{} err = json.Unmarshal(body, event) if err != nil { w.WriteHeader(http.StatusBadRequest) diff --git a/plugins/inputs/webhooks/filestack/filestack_webhooks_events.go b/plugins/inputs/webhooks/filestack/filestack_webhooks_events.go index 06b7db958..93f976f60 100644 --- a/plugins/inputs/webhooks/filestack/filestack_webhooks_events.go +++ b/plugins/inputs/webhooks/filestack/filestack_webhooks_events.go @@ -2,20 +2,20 @@ package filestack import "strconv" -type DialogEvent struct { +type FilestackEvent struct { Action string `json:"action"` TimeStamp int64 `json:"timestamp"` Id int `json:"id"` } -func (de *DialogEvent) Tags() map[string]string { +func (fe *FilestackEvent) Tags() map[string]string { return map[string]string{ - "action": de.Action, + "action": fe.Action, } } -func (de *DialogEvent) Fields() map[string]interface{} { +func (fe *FilestackEvent) Fields() map[string]interface{} { return map[string]interface{}{ - "id": strconv.Itoa(de.Id), + "id": strconv.Itoa(fe.Id), } } diff --git a/plugins/inputs/webhooks/filestack/filestack_webhooks_events_json_test.go b/plugins/inputs/webhooks/filestack/filestack_webhooks_events_json_test.go index 1af79c205..8243fe04a 100644 --- a/plugins/inputs/webhooks/filestack/filestack_webhooks_events_json_test.go +++ b/plugins/inputs/webhooks/filestack/filestack_webhooks_events_json_test.go @@ -39,3 +39,18 @@ func DialogOpenJSON() string { } }` } + +func UploadJSON() string { + return `{ + "action":"fp.upload", + "timestamp":1443444905, + "id":100946, + "text":{ + "url":"https://www.filestackapi.com/api/file/WAunDTTqQfCNWwUUyf6n", + "client":"Facebook", + "type":"image/jpeg", + "filename":"1579337399020824.jpg", + "size":139154 + } + }` +} diff --git a/plugins/inputs/webhooks/filestack/filestack_webhooks_test.go b/plugins/inputs/webhooks/filestack/filestack_webhooks_test.go index 47782b572..339f63a67 100644 --- a/plugins/inputs/webhooks/filestack/filestack_webhooks_test.go +++ b/plugins/inputs/webhooks/filestack/filestack_webhooks_test.go @@ -44,3 +44,22 @@ func TestParseError(t *testing.T) { t.Errorf("POST returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusBadRequest) } } + +func TestUploadEvent(t *testing.T) { + var acc testutil.Accumulator + fs := &FilestackWebhook{Path: "/filestack", acc: &acc} + resp := postWebhooks(fs, UploadJSON()) + if resp.Code != http.StatusOK { + t.Errorf("POST returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) + } + + fields := map[string]interface{}{ + "id": "100946", + } + + tags := map[string]string{ + "action": "fp.upload", + } + + acc.AssertContainsTaggedFields(t, "filestack_webhooks", fields, tags) +}