From 479dead075e666d59be341cda17f75f651dc2e09 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Fri, 3 Nov 2017 13:16:09 -0400 Subject: [PATCH 01/11] Revert "Updated Test JSON" This reverts commit 92caf33fff56eb730be62f235ede68d2e833db83. --- plugins/inputs/webhooks/particle/particle_webhooks_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_test.go index 53252ff17..850b2c4fc 100644 --- a/plugins/inputs/webhooks/particle/particle_webhooks_test.go +++ b/plugins/inputs/webhooks/particle/particle_webhooks_test.go @@ -72,8 +72,8 @@ func NewItemJSON() string { "humidity": 44.937500, "pressure": 998.998901, "altitude": 119.331436, - "broadband": 1266.0, - "infrared": 528.0, + "broadband": 1266, + "infrared": 528, "lux": 0.0 } }, From e1f478383eac51fb42eaa133435c249cf9fb41e2 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Fri, 3 Nov 2017 13:17:10 -0400 Subject: [PATCH 02/11] Revert "Updated Test JSON" This reverts commit 92caf33fff56eb730be62f235ede68d2e833db83. --- plugins/inputs/webhooks/particle/particle_webhooks_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_test.go index 53252ff17..850b2c4fc 100644 --- a/plugins/inputs/webhooks/particle/particle_webhooks_test.go +++ b/plugins/inputs/webhooks/particle/particle_webhooks_test.go @@ -72,8 +72,8 @@ func NewItemJSON() string { "humidity": 44.937500, "pressure": 998.998901, "altitude": 119.331436, - "broadband": 1266.0, - "infrared": 528.0, + "broadband": 1266, + "infrared": 528, "lux": 0.0 } }, From f6ea405c7aaf23dd96e7f8709b0db63842319fb4 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Fri, 3 Nov 2017 13:18:17 -0400 Subject: [PATCH 03/11] Revert "Small fixes" This reverts commit a987118b010ca3827c1ee8ebe691f6f6bd287ac5. --- plugins/inputs/webhooks/particle/README.md | 4 ++-- plugins/inputs/webhooks/particle/particle_webhooks_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/webhooks/particle/README.md b/plugins/inputs/webhooks/particle/README.md index 3c345daa8..e7b206b53 100644 --- a/plugins/inputs/webhooks/particle/README.md +++ b/plugins/inputs/webhooks/particle/README.md @@ -1,10 +1,10 @@ # particle webhooks -You should configure your Particle.io's Webhooks to point at the `webhooks` service. To do this go to `(https://console.particle.io/)[https://console.particle.io]` and click `Integrations > New Integration > Webhook`. In the resulting page set `URL` to `http://:1619/particle`, and under `Advanced Settings` click on `JSON` and add: +You should configure your Particle.io's Webhooks to point at the `webhooks` service. To do this go to `console.particle.io/` and click `Integrations > New Integration > Webhook`. In the resulting page set `URL` to `http://:1619/particle`, and under `Advanced Settings` click on `JSON` and add: ``` { - "influx_db": "your_measurement_name" + "influx_db": "your_database_name" } ``` diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_test.go index 850b2c4fc..eecf26e14 100644 --- a/plugins/inputs/webhooks/particle/particle_webhooks_test.go +++ b/plugins/inputs/webhooks/particle/particle_webhooks_test.go @@ -74,7 +74,7 @@ func NewItemJSON() string { "altitude": 119.331436, "broadband": 1266, "infrared": 528, - "lux": 0.0 + "lux": 0 } }, "ttl": 60, From 9acf7f18cad33d68d9365c10d2f8794e88ffa672 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Fri, 3 Nov 2017 13:18:30 -0400 Subject: [PATCH 04/11] Revert "Updated README.md" This reverts commit a6ada03b910ffa5ac8bc85ad52a1b789dc99aae6. --- plugins/inputs/webhooks/particle/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inputs/webhooks/particle/README.md b/plugins/inputs/webhooks/particle/README.md index e7b206b53..d11b6f7fb 100644 --- a/plugins/inputs/webhooks/particle/README.md +++ b/plugins/inputs/webhooks/particle/README.md @@ -28,7 +28,7 @@ String data = String::format("{ \"tags\" : { Particle.publish("event_name", data, PRIVATE); ``` Escaping the "" is required in the source file on the Particle device. -The number of tag values and field values is not restricted so you can send as many values per webhook call as you'd like. +The number of tag values and field values is not restrictied so you can send as many values per webhook call as you'd like. From ae9c881d33c65748f4dfc663ba8906c7c3ed8b35 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Fri, 3 Nov 2017 13:28:00 -0400 Subject: [PATCH 05/11] Revert "Update README.md" This reverts commit 8ed00af10a9a5950850f27a5c196dcc0245166b0. --- plugins/inputs/webhooks/particle/README.md | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/plugins/inputs/webhooks/particle/README.md b/plugins/inputs/webhooks/particle/README.md index d11b6f7fb..1212b742a 100644 --- a/plugins/inputs/webhooks/particle/README.md +++ b/plugins/inputs/webhooks/particle/README.md @@ -1,15 +1,6 @@ # particle webhooks -You should configure your Particle.io's Webhooks to point at the `webhooks` service. To do this go to `console.particle.io/` and click `Integrations > New Integration > Webhook`. In the resulting page set `URL` to `http://:1619/particle`, and under `Advanced Settings` click on `JSON` and add: - -``` -{ - "influx_db": "your_database_name" -} -``` - -If required, enter your username and password, etc. and then click `Save` - +You should configure your Rollbar's Webhooks to point at the `webhooks` service. To do this go to `particle.com/` and click `Settings > Notifications > Webhook`. In the resulting page set `URL` to `http://:1619/particle`, and click on `Enable Webhook Integration`. ## Events @@ -27,9 +18,9 @@ String data = String::format("{ \"tags\" : { ); Particle.publish("event_name", data, PRIVATE); ``` -Escaping the "" is required in the source file on the Particle device. +Escaping the "" is required in the source file. The number of tag values and field values is not restrictied so you can send as many values per webhook call as you'd like. - +You will need to enable JSON messages in the Webhooks setup of Particle.io See [webhook doc](https://docs.particle.io/reference/webhooks/) From 1b7a1d9228e3f32550f369c7bc3f3cfe1c8fc696 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Fri, 3 Nov 2017 13:28:35 -0400 Subject: [PATCH 06/11] Revert "bug fixes and refactoring" This reverts commit 86961cc8143e3b2edfaabb97c639030754ea9edc. --- .../webhooks/particle/particle_webhooks.go | 59 +++++++----------- .../particle/particle_webhooks_events.go | 22 +++++++ .../particle_webhooks_events_json_test.go | 39 ++++++++++++ .../particle/particle_webhooks_test.go | 60 ++++--------------- 4 files changed, 91 insertions(+), 89 deletions(-) create mode 100644 plugins/inputs/webhooks/particle/particle_webhooks_events.go create mode 100644 plugins/inputs/webhooks/particle/particle_webhooks_events_json_test.go diff --git a/plugins/inputs/webhooks/particle/particle_webhooks.go b/plugins/inputs/webhooks/particle/particle_webhooks.go index 258619856..813bd0665 100644 --- a/plugins/inputs/webhooks/particle/particle_webhooks.go +++ b/plugins/inputs/webhooks/particle/particle_webhooks.go @@ -2,40 +2,14 @@ package particle import ( "encoding/json" + "github.com/gorilla/mux" + "github.com/influxdata/telegraf" + "io/ioutil" "log" "net/http" "time" - - "github.com/gorilla/mux" - "github.com/influxdata/telegraf" ) -type event struct { - Name string `json:"event"` - Data data `json:"data"` - TTL int `json:"ttl"` - PublishedAt string `json:"published_at"` - Database string `json:"influx_db"` -} - -type data struct { - Tags map[string]string `json:"tags"` - Fields map[string]interface{} `json:"values"` -} - -func newEvent() *event { - return &event{ - Data: data{ - Tags: make(map[string]string), - Fields: make(map[string]interface{}), - }, - } -} - -func (e *event) Time() (time.Time, error) { - return time.Parse("2006-01-02T15:04:05Z", e.PublishedAt) -} - type ParticleWebhook struct { Path string acc telegraf.Accumulator @@ -49,19 +23,26 @@ func (rb *ParticleWebhook) Register(router *mux.Router, acc telegraf.Accumulator func (rb *ParticleWebhook) eventHandler(w http.ResponseWriter, r *http.Request) { defer r.Body.Close() - e := newEvent() - if err := json.NewDecoder(r.Body).Decode(e); err != nil { - log.Println(err) + data, err := ioutil.ReadAll(r.Body) + if err != nil { w.WriteHeader(http.StatusBadRequest) return } - - pTime, err := e.Time() - if err != nil { - pTime = time.Now() - log.Printf("error parsing particle event time: %s. Using telegraf host time instead: %s", e.PublishedAt, pTime) + dummy := &DummyData{} + if err := json.Unmarshal(data, dummy); err != nil { + w.WriteHeader(http.StatusBadRequest) + return } - - rb.acc.AddFields(e.Name, e.Data.Fields, e.Data.Tags, pTime) + pd := &ParticleData{} + if err := json.Unmarshal([]byte(dummy.Data), pd); err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } + pTime, err := dummy.Time() + if err != nil { + log.Printf("Time Conversion Error") + pTime = time.Now() + } + rb.acc.AddFields(dummy.InfluxDB, pd.Fields, pd.Tags, pTime) w.WriteHeader(http.StatusOK) } diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_events.go b/plugins/inputs/webhooks/particle/particle_webhooks_events.go new file mode 100644 index 000000000..089536525 --- /dev/null +++ b/plugins/inputs/webhooks/particle/particle_webhooks_events.go @@ -0,0 +1,22 @@ +package particle + +import ( + "time" +) + +type DummyData struct { + Event string `json:"event"` + Data string `json:"data"` + Ttl int `json:"ttl"` + PublishedAt string `json:"published_at"` + InfluxDB string `json:"influx_db"` +} +type ParticleData struct { + Event string `json:"event"` + Tags map[string]string `json:"tags"` + Fields map[string]interface{} `json:"values"` +} + +func (d *DummyData) Time() (time.Time, error) { + return time.Parse("2006-01-02T15:04:05Z", d.PublishedAt) +} diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_events_json_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_events_json_test.go new file mode 100644 index 000000000..aef0537e9 --- /dev/null +++ b/plugins/inputs/webhooks/particle/particle_webhooks_events_json_test.go @@ -0,0 +1,39 @@ +package particle + +func NewItemJSON() string { + return ` + { + "event": "temperature", + "data": "{ + "tags": { + "id": "230035001147343438323536", + "location": "TravelingWilbury" + }, + "values": { + "temp_c": 26.680000, + "temp_f": 80.024001, + "humidity": 44.937500, + "pressure": 998.998901, + "altitude": 119.331436, + "broadband": 1266, + "infrared": 528, + "lux": 0 + } + }", + "ttl": 60, + "published_at": "2017-09-28T21:54:10.897Z", + "coreid": "123456789938323536", + "userid": "1234ee123ac8e5ec1231a123d", + "version": 10, + "public": false, + "productID": 1234, + "name": "sensor" + "influx_db": "mydata" + }` +} +func UnknowJSON() string { + return ` + { + "event": "roger" + }` +} diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_test.go index eecf26e14..c62e0f0c8 100644 --- a/plugins/inputs/webhooks/particle/particle_webhooks_test.go +++ b/plugins/inputs/webhooks/particle/particle_webhooks_test.go @@ -1,16 +1,17 @@ package particle import ( + "github.com/influxdata/telegraf/testutil" + "log" "net/http" "net/http/httptest" "strings" "testing" - - "github.com/influxdata/telegraf/testutil" ) func postWebhooks(rb *ParticleWebhook, eventBody string) *httptest.ResponseRecorder { req, _ := http.NewRequest("POST", "/", strings.NewReader(eventBody)) + log.Printf("eventBody: %s\n", eventBody) w := httptest.NewRecorder() w.Code = 500 @@ -20,10 +21,10 @@ func postWebhooks(rb *ParticleWebhook, eventBody string) *httptest.ResponseRecor } func TestNewItem(t *testing.T) { - t.Parallel() var acc testutil.Accumulator rb := &ParticleWebhook{Path: "/particle", acc: &acc} resp := postWebhooks(rb, NewItemJSON()) + log.Printf("Respnse: %s\n", resp.Body) if resp.Code != http.StatusOK { t.Errorf("POST new_item returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) } @@ -31,12 +32,12 @@ func TestNewItem(t *testing.T) { fields := map[string]interface{}{ "temp_c": 26.680000, "temp_f": 80.024001, - "infrared": 528.0, - "lux": 0.0, "humidity": 44.937500, "pressure": 998.998901, "altitude": 119.331436, - "broadband": 1266.0, + "broadband": 1266, + "infrared": 528, + "lux": 0, } tags := map[string]string{ @@ -44,54 +45,13 @@ func TestNewItem(t *testing.T) { "location": "TravelingWilbury", } - acc.AssertContainsTaggedFields(t, "temperature", fields, tags) + acc.AssertContainsTaggedFields(t, "particle_webhooks", fields, tags) } - func TestUnknowItem(t *testing.T) { - t.Parallel() - var acc testutil.Accumulator - rb := &ParticleWebhook{Path: "/particle", acc: &acc} + rb := &ParticleWebhook{Path: "/particle"} resp := postWebhooks(rb, UnknowJSON()) + log.Printf("Response: %s\n", resp.Body) if resp.Code != http.StatusOK { t.Errorf("POST unknown returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) } } - -func NewItemJSON() string { - return ` - { - "event": "temperature", - "data": { - "tags": { - "id": "230035001147343438323536", - "location": "TravelingWilbury" - }, - "values": { - "temp_c": 26.680000, - "temp_f": 80.024001, - "humidity": 44.937500, - "pressure": 998.998901, - "altitude": 119.331436, - "broadband": 1266, - "infrared": 528, - "lux": 0 - } - }, - "ttl": 60, - "published_at": "2017-09-28T21:54:10.897Z", - "coreid": "123456789938323536", - "userid": "1234ee123ac8e5ec1231a123d", - "version": 10, - "public": false, - "productID": 1234, - "name": "sensor", - "influx_db": "mydata" - }` -} - -func UnknowJSON() string { - return ` - { - "event": "roger" - }` -} From 0e0e91ef1e3fe4a1321bad97ae6e73e95038b232 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Fri, 3 Nov 2017 13:28:54 -0400 Subject: [PATCH 07/11] Revert "New Particle Plugin" This reverts commit ba462f5c9474407160123cda908db7fdb4bb1daa. --- .txt | 0 plugins/inputs/webhooks/particle/README.md | 26 --------- .../webhooks/particle/particle_webhooks.go | 48 ---------------- .../particle/particle_webhooks_events.go | 22 ------- .../particle_webhooks_events_json_test.go | 39 ------------- .../particle/particle_webhooks_test.go | 57 ------------------- plugins/inputs/webhooks/webhooks.go | 5 -- plugins/inputs/webhooks/webhooks_test.go | 6 -- 8 files changed, 203 deletions(-) delete mode 100644 .txt delete mode 100644 plugins/inputs/webhooks/particle/README.md delete mode 100644 plugins/inputs/webhooks/particle/particle_webhooks.go delete mode 100644 plugins/inputs/webhooks/particle/particle_webhooks_events.go delete mode 100644 plugins/inputs/webhooks/particle/particle_webhooks_events_json_test.go delete mode 100644 plugins/inputs/webhooks/particle/particle_webhooks_test.go diff --git a/.txt b/.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/plugins/inputs/webhooks/particle/README.md b/plugins/inputs/webhooks/particle/README.md deleted file mode 100644 index 1212b742a..000000000 --- a/plugins/inputs/webhooks/particle/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# particle webhooks - -You should configure your Rollbar's Webhooks to point at the `webhooks` service. To do this go to `particle.com/` and click `Settings > Notifications > Webhook`. In the resulting page set `URL` to `http://:1619/particle`, and click on `Enable Webhook Integration`. - -## Events - -Your Particle device should publish an event that contains a JSON in the form of: -``` -String data = String::format("{ \"tags\" : { - \"tag_name\": \"tag_value\", - \"other_tag\": \"other_value\" - }, - \"values\": { - \"value_name\": %f, - \"other_value\": %f, - } - }", value_value, other_value - ); - Particle.publish("event_name", data, PRIVATE); -``` -Escaping the "" is required in the source file. -The number of tag values and field values is not restrictied so you can send as many values per webhook call as you'd like. - -You will need to enable JSON messages in the Webhooks setup of Particle.io - -See [webhook doc](https://docs.particle.io/reference/webhooks/) diff --git a/plugins/inputs/webhooks/particle/particle_webhooks.go b/plugins/inputs/webhooks/particle/particle_webhooks.go deleted file mode 100644 index 813bd0665..000000000 --- a/plugins/inputs/webhooks/particle/particle_webhooks.go +++ /dev/null @@ -1,48 +0,0 @@ -package particle - -import ( - "encoding/json" - "github.com/gorilla/mux" - "github.com/influxdata/telegraf" - "io/ioutil" - "log" - "net/http" - "time" -) - -type ParticleWebhook struct { - Path string - acc telegraf.Accumulator -} - -func (rb *ParticleWebhook) Register(router *mux.Router, acc telegraf.Accumulator) { - router.HandleFunc(rb.Path, rb.eventHandler).Methods("POST") - log.Printf("I! Started the webhooks_particle on %s\n", rb.Path) - rb.acc = acc -} - -func (rb *ParticleWebhook) eventHandler(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - data, err := ioutil.ReadAll(r.Body) - if err != nil { - w.WriteHeader(http.StatusBadRequest) - return - } - dummy := &DummyData{} - if err := json.Unmarshal(data, dummy); err != nil { - w.WriteHeader(http.StatusBadRequest) - return - } - pd := &ParticleData{} - if err := json.Unmarshal([]byte(dummy.Data), pd); err != nil { - w.WriteHeader(http.StatusBadRequest) - return - } - pTime, err := dummy.Time() - if err != nil { - log.Printf("Time Conversion Error") - pTime = time.Now() - } - rb.acc.AddFields(dummy.InfluxDB, pd.Fields, pd.Tags, pTime) - w.WriteHeader(http.StatusOK) -} diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_events.go b/plugins/inputs/webhooks/particle/particle_webhooks_events.go deleted file mode 100644 index 089536525..000000000 --- a/plugins/inputs/webhooks/particle/particle_webhooks_events.go +++ /dev/null @@ -1,22 +0,0 @@ -package particle - -import ( - "time" -) - -type DummyData struct { - Event string `json:"event"` - Data string `json:"data"` - Ttl int `json:"ttl"` - PublishedAt string `json:"published_at"` - InfluxDB string `json:"influx_db"` -} -type ParticleData struct { - Event string `json:"event"` - Tags map[string]string `json:"tags"` - Fields map[string]interface{} `json:"values"` -} - -func (d *DummyData) Time() (time.Time, error) { - return time.Parse("2006-01-02T15:04:05Z", d.PublishedAt) -} diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_events_json_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_events_json_test.go deleted file mode 100644 index aef0537e9..000000000 --- a/plugins/inputs/webhooks/particle/particle_webhooks_events_json_test.go +++ /dev/null @@ -1,39 +0,0 @@ -package particle - -func NewItemJSON() string { - return ` - { - "event": "temperature", - "data": "{ - "tags": { - "id": "230035001147343438323536", - "location": "TravelingWilbury" - }, - "values": { - "temp_c": 26.680000, - "temp_f": 80.024001, - "humidity": 44.937500, - "pressure": 998.998901, - "altitude": 119.331436, - "broadband": 1266, - "infrared": 528, - "lux": 0 - } - }", - "ttl": 60, - "published_at": "2017-09-28T21:54:10.897Z", - "coreid": "123456789938323536", - "userid": "1234ee123ac8e5ec1231a123d", - "version": 10, - "public": false, - "productID": 1234, - "name": "sensor" - "influx_db": "mydata" - }` -} -func UnknowJSON() string { - return ` - { - "event": "roger" - }` -} diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_test.go deleted file mode 100644 index c62e0f0c8..000000000 --- a/plugins/inputs/webhooks/particle/particle_webhooks_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package particle - -import ( - "github.com/influxdata/telegraf/testutil" - "log" - "net/http" - "net/http/httptest" - "strings" - "testing" -) - -func postWebhooks(rb *ParticleWebhook, eventBody string) *httptest.ResponseRecorder { - req, _ := http.NewRequest("POST", "/", strings.NewReader(eventBody)) - log.Printf("eventBody: %s\n", eventBody) - w := httptest.NewRecorder() - w.Code = 500 - - rb.eventHandler(w, req) - - return w -} - -func TestNewItem(t *testing.T) { - var acc testutil.Accumulator - rb := &ParticleWebhook{Path: "/particle", acc: &acc} - resp := postWebhooks(rb, NewItemJSON()) - log.Printf("Respnse: %s\n", resp.Body) - if resp.Code != http.StatusOK { - t.Errorf("POST new_item returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) - } - - fields := map[string]interface{}{ - "temp_c": 26.680000, - "temp_f": 80.024001, - "humidity": 44.937500, - "pressure": 998.998901, - "altitude": 119.331436, - "broadband": 1266, - "infrared": 528, - "lux": 0, - } - - tags := map[string]string{ - "id": "230035001147343438323536", - "location": "TravelingWilbury", - } - - acc.AssertContainsTaggedFields(t, "particle_webhooks", fields, tags) -} -func TestUnknowItem(t *testing.T) { - rb := &ParticleWebhook{Path: "/particle"} - resp := postWebhooks(rb, UnknowJSON()) - log.Printf("Response: %s\n", resp.Body) - if resp.Code != http.StatusOK { - t.Errorf("POST unknown returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) - } -} diff --git a/plugins/inputs/webhooks/webhooks.go b/plugins/inputs/webhooks/webhooks.go index 794b55168..698cde159 100644 --- a/plugins/inputs/webhooks/webhooks.go +++ b/plugins/inputs/webhooks/webhooks.go @@ -15,7 +15,6 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/webhooks/github" "github.com/influxdata/telegraf/plugins/inputs/webhooks/mandrill" "github.com/influxdata/telegraf/plugins/inputs/webhooks/papertrail" - "github.com/influxdata/telegraf/plugins/inputs/webhooks/particle" "github.com/influxdata/telegraf/plugins/inputs/webhooks/rollbar" ) @@ -35,7 +34,6 @@ type Webhooks struct { Mandrill *mandrill.MandrillWebhook Rollbar *rollbar.RollbarWebhook Papertrail *papertrail.PapertrailWebhook - Particle *particle.ParticleWebhook srv *http.Server } @@ -64,9 +62,6 @@ func (wb *Webhooks) SampleConfig() string { [inputs.webhooks.papertrail] path = "/papertrail" - - [inputs.webhooks.particle] - path = "/particle" ` } diff --git a/plugins/inputs/webhooks/webhooks_test.go b/plugins/inputs/webhooks/webhooks_test.go index 1a5fa4aa1..6d3448870 100644 --- a/plugins/inputs/webhooks/webhooks_test.go +++ b/plugins/inputs/webhooks/webhooks_test.go @@ -6,7 +6,6 @@ import ( "github.com/influxdata/telegraf/plugins/inputs/webhooks/github" "github.com/influxdata/telegraf/plugins/inputs/webhooks/papertrail" - "github.com/influxdata/telegraf/plugins/inputs/webhooks/particle" "github.com/influxdata/telegraf/plugins/inputs/webhooks/rollbar" ) @@ -34,9 +33,4 @@ func TestAvailableWebhooks(t *testing.T) { if !reflect.DeepEqual(wb.AvailableWebhooks(), expected) { t.Errorf("expected to be %v.\nGot %v", expected, wb.AvailableWebhooks()) } - wb.Particle = &particle.ParticleWebhook{Path: "/particle"} - expected = append(expected, wb.Particle) - if !reflect.DeepEqual(wb.AvailableWebhooks(), expected) { - t.Errorf("expected to be %v.\nGot %v", expected, wb.AvailableWebhooks()) - } } From b573039af4252654b02c882e41b99c2067e46164 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 3 Nov 2017 21:06:59 -0700 Subject: [PATCH 08/11] Revert changes since 9b0af4478 --- .gitignore | 1 - plugins/inputs/webhooks/particle/README.md | 35 ------- .../webhooks/particle/particle_webhooks.go | 67 ------------- .../particle/particle_webhooks_test.go | 97 ------------------- 4 files changed, 200 deletions(-) delete mode 100644 plugins/inputs/webhooks/particle/README.md delete mode 100644 plugins/inputs/webhooks/particle/particle_webhooks.go delete mode 100644 plugins/inputs/webhooks/particle/particle_webhooks_test.go diff --git a/.gitignore b/.gitignore index e93bc8dff..8269337df 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ tivan .idea *~ *# -.DS_Store diff --git a/plugins/inputs/webhooks/particle/README.md b/plugins/inputs/webhooks/particle/README.md deleted file mode 100644 index 3c345daa8..000000000 --- a/plugins/inputs/webhooks/particle/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# particle webhooks - -You should configure your Particle.io's Webhooks to point at the `webhooks` service. To do this go to `(https://console.particle.io/)[https://console.particle.io]` and click `Integrations > New Integration > Webhook`. In the resulting page set `URL` to `http://:1619/particle`, and under `Advanced Settings` click on `JSON` and add: - -``` -{ - "influx_db": "your_measurement_name" -} -``` - -If required, enter your username and password, etc. and then click `Save` - - -## Events - -Your Particle device should publish an event that contains a JSON in the form of: -``` -String data = String::format("{ \"tags\" : { - \"tag_name\": \"tag_value\", - \"other_tag\": \"other_value\" - }, - \"values\": { - \"value_name\": %f, - \"other_value\": %f, - } - }", value_value, other_value - ); - Particle.publish("event_name", data, PRIVATE); -``` -Escaping the "" is required in the source file on the Particle device. -The number of tag values and field values is not restricted so you can send as many values per webhook call as you'd like. - - - -See [webhook doc](https://docs.particle.io/reference/webhooks/) diff --git a/plugins/inputs/webhooks/particle/particle_webhooks.go b/plugins/inputs/webhooks/particle/particle_webhooks.go deleted file mode 100644 index 258619856..000000000 --- a/plugins/inputs/webhooks/particle/particle_webhooks.go +++ /dev/null @@ -1,67 +0,0 @@ -package particle - -import ( - "encoding/json" - "log" - "net/http" - "time" - - "github.com/gorilla/mux" - "github.com/influxdata/telegraf" -) - -type event struct { - Name string `json:"event"` - Data data `json:"data"` - TTL int `json:"ttl"` - PublishedAt string `json:"published_at"` - Database string `json:"influx_db"` -} - -type data struct { - Tags map[string]string `json:"tags"` - Fields map[string]interface{} `json:"values"` -} - -func newEvent() *event { - return &event{ - Data: data{ - Tags: make(map[string]string), - Fields: make(map[string]interface{}), - }, - } -} - -func (e *event) Time() (time.Time, error) { - return time.Parse("2006-01-02T15:04:05Z", e.PublishedAt) -} - -type ParticleWebhook struct { - Path string - acc telegraf.Accumulator -} - -func (rb *ParticleWebhook) Register(router *mux.Router, acc telegraf.Accumulator) { - router.HandleFunc(rb.Path, rb.eventHandler).Methods("POST") - log.Printf("I! Started the webhooks_particle on %s\n", rb.Path) - rb.acc = acc -} - -func (rb *ParticleWebhook) eventHandler(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - e := newEvent() - if err := json.NewDecoder(r.Body).Decode(e); err != nil { - log.Println(err) - w.WriteHeader(http.StatusBadRequest) - return - } - - pTime, err := e.Time() - if err != nil { - pTime = time.Now() - log.Printf("error parsing particle event time: %s. Using telegraf host time instead: %s", e.PublishedAt, pTime) - } - - rb.acc.AddFields(e.Name, e.Data.Fields, e.Data.Tags, pTime) - w.WriteHeader(http.StatusOK) -} diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_test.go deleted file mode 100644 index 850b2c4fc..000000000 --- a/plugins/inputs/webhooks/particle/particle_webhooks_test.go +++ /dev/null @@ -1,97 +0,0 @@ -package particle - -import ( - "net/http" - "net/http/httptest" - "strings" - "testing" - - "github.com/influxdata/telegraf/testutil" -) - -func postWebhooks(rb *ParticleWebhook, 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) { - t.Parallel() - var acc testutil.Accumulator - rb := &ParticleWebhook{Path: "/particle", acc: &acc} - 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) - } - - fields := map[string]interface{}{ - "temp_c": 26.680000, - "temp_f": 80.024001, - "infrared": 528.0, - "lux": 0.0, - "humidity": 44.937500, - "pressure": 998.998901, - "altitude": 119.331436, - "broadband": 1266.0, - } - - tags := map[string]string{ - "id": "230035001147343438323536", - "location": "TravelingWilbury", - } - - acc.AssertContainsTaggedFields(t, "temperature", fields, tags) -} - -func TestUnknowItem(t *testing.T) { - t.Parallel() - var acc testutil.Accumulator - rb := &ParticleWebhook{Path: "/particle", acc: &acc} - resp := postWebhooks(rb, UnknowJSON()) - if resp.Code != http.StatusOK { - t.Errorf("POST unknown returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) - } -} - -func NewItemJSON() string { - return ` - { - "event": "temperature", - "data": { - "tags": { - "id": "230035001147343438323536", - "location": "TravelingWilbury" - }, - "values": { - "temp_c": 26.680000, - "temp_f": 80.024001, - "humidity": 44.937500, - "pressure": 998.998901, - "altitude": 119.331436, - "broadband": 1266, - "infrared": 528, - "lux": 0.0 - } - }, - "ttl": 60, - "published_at": "2017-09-28T21:54:10.897Z", - "coreid": "123456789938323536", - "userid": "1234ee123ac8e5ec1231a123d", - "version": 10, - "public": false, - "productID": 1234, - "name": "sensor", - "influx_db": "mydata" - }` -} - -func UnknowJSON() string { - return ` - { - "event": "roger" - }` -} From f3d90bdac6b03593f19a24456d435911e336d777 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 3 Nov 2017 21:52:45 -0700 Subject: [PATCH 09/11] Update http_listener certs --- .../http_listener/http_listener_test.go | 115 ++++++++---------- scripts/tls-certs.sh | 4 +- 2 files changed, 54 insertions(+), 65 deletions(-) diff --git a/plugins/inputs/http_listener/http_listener_test.go b/plugins/inputs/http_listener/http_listener_test.go index 2d4da8940..d79e9576a 100644 --- a/plugins/inputs/http_listener/http_listener_test.go +++ b/plugins/inputs/http_listener/http_listener_test.go @@ -34,82 +34,71 @@ cpu_load_short,host=server06 value=12.0 1422568543702900257 emptyMsg = "" serviceRootPEM = `-----BEGIN CERTIFICATE----- -MIIBxzCCATCg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9eyyMfJHJihlobXA+QY= +MIICXQIBAAKBgQCwlGyzVp9cqtwiNCgCnaR0kilPZhr4xFBcnXxvQ8/uzOHaWKxj +XWR38cKR3gPh5+4iSmzMdo3HDJM5ks6imXGnp+LPOA5iNewnpLNs7UxA2arwKH/6 +4qIaAXAtf5jE46wZIMgc2EW9wGL3dxC0JY8EXPpBFB/3J8gADkorFR8lwwIDAQAB +AoGBAJaFHxfMmjHK77U0UnrQWFSKFy64cftmlL4t/Nl3q7L68PdIKULWZIMeEWZ4 +I0UZiFOwr4em83oejQ1ByGSwekEuiWaKUI85IaHfcbt+ogp9hY/XbOEo56OPQUAd +bEZv1JqJOqta9Ug1/E1P9LjEEyZ5F5ubx7813rxAE31qKtKJAkEA1zaMlCWIr+Rj +hGvzv5rlHH3wbOB4kQFXO4nqj3J/ttzR5QiJW24STMDcbNngFlVcDVju56LrNTiD +dPh9qvl7nwJBANILguR4u33OMksEZTYB7nQZSurqXsq6382zH7pTl29ANQTROHaM +PKC8dnDWq8RGTqKuvWblIzzGIKqIMovZo10CQC96T0UXirITFolOL3XjvAuvFO1Q +EAkdXJs77805m0dCK+P1IChVfiAEpBw3bKJArpAbQIlFfdI953JUp5SieU0CQEub +BSSEKMjh/cxu6peEHnb/262vayuCFKkQPu1sxWewLuVrAe36EKCy9dcsDmv5+rgo +Odjdxc9Madm4aKlaT6kCQQCpAgeblDrrxTrNQ+Typzo37PlnQrvI+0EceAUuJ72G +P0a+YZUeHNRqT2pPN9lMTAZGGi3CtcF2XScbLNEBeXge -----END RSA PRIVATE KEY-----` - clientRootPEM = `-----BEGIN CERTIFICATE----- -MIIBxzCCATCgAwIBAgIJAOLq2g9+9TVgMA0GCSqGSIb3DQEBCwUAMBYxFDASBgNV -BAMMC1RlbGVncmFmIENBMB4XDTE3MTAwMjIyNDMwOFoXDTE3MTEwMTIyNDMwOFow -FjEUMBIGA1UEAwwLVGVsZWdyYWYgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ -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O6lIcOwJBALX4xChoMUF9k0IxSQzlz//seQYDkQNsE7y9IgAOXkzp +RaR4pzgPbnKj7atG+2dBnffWfE+1Mcy0INDAO6WxPg0= -----END RSA PRIVATE KEY-----` ) diff --git a/scripts/tls-certs.sh b/scripts/tls-certs.sh index 39e8cf359..b37d6541a 100644 --- a/scripts/tls-certs.sh +++ b/scripts/tls-certs.sh @@ -15,7 +15,7 @@ new_certs_dir = ./certs_by_serial private_key = ./private/cakey.pem serial = ./serial -default_crl_days = 7 +default_crl_days = 3650 default_days = 3650 default_md = sha256 @@ -53,7 +53,7 @@ basicConstraints = CA:false keyUsage = keyEncipherment extendedKeyUsage = 1.3.6.1.5.5.7.3.1 EOF -openssl req -x509 -config ./openssl.conf -newkey rsa:1024 -out ./certs/cacert.pem -keyout ./private/cakey.pem -subj "/CN=Telegraf CA/" -nodes && +openssl req -x509 -config ./openssl.conf -days 3650 -newkey rsa:1024 -out ./certs/cacert.pem -keyout ./private/cakey.pem -subj "/CN=Telegraf CA/" -nodes && # Create server keypair openssl genrsa -out ./private/serverkey.pem 1024 && From ad6946cd8cc4dd4db3837291b20ce7a60abea1c8 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Sat, 4 Nov 2017 09:14:52 -0400 Subject: [PATCH 10/11] Undo Revert "Revert changes since 9b0af4478" This reverts commit 2c31345c70dac556664f12a39e68cd7c85856e4e. --- .gitignore | 1 + plugins/inputs/webhooks/particle/README.md | 35 +++++++ .../webhooks/particle/particle_webhooks.go | 67 +++++++++++++ .../particle/particle_webhooks_test.go | 97 +++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 plugins/inputs/webhooks/particle/README.md create mode 100644 plugins/inputs/webhooks/particle/particle_webhooks.go create mode 100644 plugins/inputs/webhooks/particle/particle_webhooks_test.go diff --git a/.gitignore b/.gitignore index 8269337df..e93bc8dff 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ tivan .idea *~ *# +.DS_Store diff --git a/plugins/inputs/webhooks/particle/README.md b/plugins/inputs/webhooks/particle/README.md new file mode 100644 index 000000000..3c345daa8 --- /dev/null +++ b/plugins/inputs/webhooks/particle/README.md @@ -0,0 +1,35 @@ +# particle webhooks + +You should configure your Particle.io's Webhooks to point at the `webhooks` service. To do this go to `(https://console.particle.io/)[https://console.particle.io]` and click `Integrations > New Integration > Webhook`. In the resulting page set `URL` to `http://:1619/particle`, and under `Advanced Settings` click on `JSON` and add: + +``` +{ + "influx_db": "your_measurement_name" +} +``` + +If required, enter your username and password, etc. and then click `Save` + + +## Events + +Your Particle device should publish an event that contains a JSON in the form of: +``` +String data = String::format("{ \"tags\" : { + \"tag_name\": \"tag_value\", + \"other_tag\": \"other_value\" + }, + \"values\": { + \"value_name\": %f, + \"other_value\": %f, + } + }", value_value, other_value + ); + Particle.publish("event_name", data, PRIVATE); +``` +Escaping the "" is required in the source file on the Particle device. +The number of tag values and field values is not restricted so you can send as many values per webhook call as you'd like. + + + +See [webhook doc](https://docs.particle.io/reference/webhooks/) diff --git a/plugins/inputs/webhooks/particle/particle_webhooks.go b/plugins/inputs/webhooks/particle/particle_webhooks.go new file mode 100644 index 000000000..258619856 --- /dev/null +++ b/plugins/inputs/webhooks/particle/particle_webhooks.go @@ -0,0 +1,67 @@ +package particle + +import ( + "encoding/json" + "log" + "net/http" + "time" + + "github.com/gorilla/mux" + "github.com/influxdata/telegraf" +) + +type event struct { + Name string `json:"event"` + Data data `json:"data"` + TTL int `json:"ttl"` + PublishedAt string `json:"published_at"` + Database string `json:"influx_db"` +} + +type data struct { + Tags map[string]string `json:"tags"` + Fields map[string]interface{} `json:"values"` +} + +func newEvent() *event { + return &event{ + Data: data{ + Tags: make(map[string]string), + Fields: make(map[string]interface{}), + }, + } +} + +func (e *event) Time() (time.Time, error) { + return time.Parse("2006-01-02T15:04:05Z", e.PublishedAt) +} + +type ParticleWebhook struct { + Path string + acc telegraf.Accumulator +} + +func (rb *ParticleWebhook) Register(router *mux.Router, acc telegraf.Accumulator) { + router.HandleFunc(rb.Path, rb.eventHandler).Methods("POST") + log.Printf("I! Started the webhooks_particle on %s\n", rb.Path) + rb.acc = acc +} + +func (rb *ParticleWebhook) eventHandler(w http.ResponseWriter, r *http.Request) { + defer r.Body.Close() + e := newEvent() + if err := json.NewDecoder(r.Body).Decode(e); err != nil { + log.Println(err) + w.WriteHeader(http.StatusBadRequest) + return + } + + pTime, err := e.Time() + if err != nil { + pTime = time.Now() + log.Printf("error parsing particle event time: %s. Using telegraf host time instead: %s", e.PublishedAt, pTime) + } + + rb.acc.AddFields(e.Name, e.Data.Fields, e.Data.Tags, pTime) + w.WriteHeader(http.StatusOK) +} diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_test.go new file mode 100644 index 000000000..850b2c4fc --- /dev/null +++ b/plugins/inputs/webhooks/particle/particle_webhooks_test.go @@ -0,0 +1,97 @@ +package particle + +import ( + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/influxdata/telegraf/testutil" +) + +func postWebhooks(rb *ParticleWebhook, 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) { + t.Parallel() + var acc testutil.Accumulator + rb := &ParticleWebhook{Path: "/particle", acc: &acc} + 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) + } + + fields := map[string]interface{}{ + "temp_c": 26.680000, + "temp_f": 80.024001, + "infrared": 528.0, + "lux": 0.0, + "humidity": 44.937500, + "pressure": 998.998901, + "altitude": 119.331436, + "broadband": 1266.0, + } + + tags := map[string]string{ + "id": "230035001147343438323536", + "location": "TravelingWilbury", + } + + acc.AssertContainsTaggedFields(t, "temperature", fields, tags) +} + +func TestUnknowItem(t *testing.T) { + t.Parallel() + var acc testutil.Accumulator + rb := &ParticleWebhook{Path: "/particle", acc: &acc} + resp := postWebhooks(rb, UnknowJSON()) + if resp.Code != http.StatusOK { + t.Errorf("POST unknown returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) + } +} + +func NewItemJSON() string { + return ` + { + "event": "temperature", + "data": { + "tags": { + "id": "230035001147343438323536", + "location": "TravelingWilbury" + }, + "values": { + "temp_c": 26.680000, + "temp_f": 80.024001, + "humidity": 44.937500, + "pressure": 998.998901, + "altitude": 119.331436, + "broadband": 1266, + "infrared": 528, + "lux": 0.0 + } + }, + "ttl": 60, + "published_at": "2017-09-28T21:54:10.897Z", + "coreid": "123456789938323536", + "userid": "1234ee123ac8e5ec1231a123d", + "version": 10, + "public": false, + "productID": 1234, + "name": "sensor", + "influx_db": "mydata" + }` +} + +func UnknowJSON() string { + return ` + { + "event": "roger" + }` +} From 29e48c082a8ccf6a92da753e7c42175036d03982 Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Sat, 4 Nov 2017 09:19:37 -0400 Subject: [PATCH 11/11] Revert "Undo Revert "Revert changes since 9b0af4478"" This reverts commit 6e6aefe5da23bfc942d8652ac140179993639182. --- .gitignore | 1 - plugins/inputs/webhooks/particle/README.md | 35 ------- .../webhooks/particle/particle_webhooks.go | 67 ------------- .../particle/particle_webhooks_test.go | 97 ------------------- 4 files changed, 200 deletions(-) delete mode 100644 plugins/inputs/webhooks/particle/README.md delete mode 100644 plugins/inputs/webhooks/particle/particle_webhooks.go delete mode 100644 plugins/inputs/webhooks/particle/particle_webhooks_test.go diff --git a/.gitignore b/.gitignore index e93bc8dff..8269337df 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ tivan .idea *~ *# -.DS_Store diff --git a/plugins/inputs/webhooks/particle/README.md b/plugins/inputs/webhooks/particle/README.md deleted file mode 100644 index 3c345daa8..000000000 --- a/plugins/inputs/webhooks/particle/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# particle webhooks - -You should configure your Particle.io's Webhooks to point at the `webhooks` service. To do this go to `(https://console.particle.io/)[https://console.particle.io]` and click `Integrations > New Integration > Webhook`. In the resulting page set `URL` to `http://:1619/particle`, and under `Advanced Settings` click on `JSON` and add: - -``` -{ - "influx_db": "your_measurement_name" -} -``` - -If required, enter your username and password, etc. and then click `Save` - - -## Events - -Your Particle device should publish an event that contains a JSON in the form of: -``` -String data = String::format("{ \"tags\" : { - \"tag_name\": \"tag_value\", - \"other_tag\": \"other_value\" - }, - \"values\": { - \"value_name\": %f, - \"other_value\": %f, - } - }", value_value, other_value - ); - Particle.publish("event_name", data, PRIVATE); -``` -Escaping the "" is required in the source file on the Particle device. -The number of tag values and field values is not restricted so you can send as many values per webhook call as you'd like. - - - -See [webhook doc](https://docs.particle.io/reference/webhooks/) diff --git a/plugins/inputs/webhooks/particle/particle_webhooks.go b/plugins/inputs/webhooks/particle/particle_webhooks.go deleted file mode 100644 index 258619856..000000000 --- a/plugins/inputs/webhooks/particle/particle_webhooks.go +++ /dev/null @@ -1,67 +0,0 @@ -package particle - -import ( - "encoding/json" - "log" - "net/http" - "time" - - "github.com/gorilla/mux" - "github.com/influxdata/telegraf" -) - -type event struct { - Name string `json:"event"` - Data data `json:"data"` - TTL int `json:"ttl"` - PublishedAt string `json:"published_at"` - Database string `json:"influx_db"` -} - -type data struct { - Tags map[string]string `json:"tags"` - Fields map[string]interface{} `json:"values"` -} - -func newEvent() *event { - return &event{ - Data: data{ - Tags: make(map[string]string), - Fields: make(map[string]interface{}), - }, - } -} - -func (e *event) Time() (time.Time, error) { - return time.Parse("2006-01-02T15:04:05Z", e.PublishedAt) -} - -type ParticleWebhook struct { - Path string - acc telegraf.Accumulator -} - -func (rb *ParticleWebhook) Register(router *mux.Router, acc telegraf.Accumulator) { - router.HandleFunc(rb.Path, rb.eventHandler).Methods("POST") - log.Printf("I! Started the webhooks_particle on %s\n", rb.Path) - rb.acc = acc -} - -func (rb *ParticleWebhook) eventHandler(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - e := newEvent() - if err := json.NewDecoder(r.Body).Decode(e); err != nil { - log.Println(err) - w.WriteHeader(http.StatusBadRequest) - return - } - - pTime, err := e.Time() - if err != nil { - pTime = time.Now() - log.Printf("error parsing particle event time: %s. Using telegraf host time instead: %s", e.PublishedAt, pTime) - } - - rb.acc.AddFields(e.Name, e.Data.Fields, e.Data.Tags, pTime) - w.WriteHeader(http.StatusOK) -} diff --git a/plugins/inputs/webhooks/particle/particle_webhooks_test.go b/plugins/inputs/webhooks/particle/particle_webhooks_test.go deleted file mode 100644 index 850b2c4fc..000000000 --- a/plugins/inputs/webhooks/particle/particle_webhooks_test.go +++ /dev/null @@ -1,97 +0,0 @@ -package particle - -import ( - "net/http" - "net/http/httptest" - "strings" - "testing" - - "github.com/influxdata/telegraf/testutil" -) - -func postWebhooks(rb *ParticleWebhook, 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) { - t.Parallel() - var acc testutil.Accumulator - rb := &ParticleWebhook{Path: "/particle", acc: &acc} - 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) - } - - fields := map[string]interface{}{ - "temp_c": 26.680000, - "temp_f": 80.024001, - "infrared": 528.0, - "lux": 0.0, - "humidity": 44.937500, - "pressure": 998.998901, - "altitude": 119.331436, - "broadband": 1266.0, - } - - tags := map[string]string{ - "id": "230035001147343438323536", - "location": "TravelingWilbury", - } - - acc.AssertContainsTaggedFields(t, "temperature", fields, tags) -} - -func TestUnknowItem(t *testing.T) { - t.Parallel() - var acc testutil.Accumulator - rb := &ParticleWebhook{Path: "/particle", acc: &acc} - resp := postWebhooks(rb, UnknowJSON()) - if resp.Code != http.StatusOK { - t.Errorf("POST unknown returned HTTP status code %v.\nExpected %v", resp.Code, http.StatusOK) - } -} - -func NewItemJSON() string { - return ` - { - "event": "temperature", - "data": { - "tags": { - "id": "230035001147343438323536", - "location": "TravelingWilbury" - }, - "values": { - "temp_c": 26.680000, - "temp_f": 80.024001, - "humidity": 44.937500, - "pressure": 998.998901, - "altitude": 119.331436, - "broadband": 1266, - "infrared": 528, - "lux": 0.0 - } - }, - "ttl": 60, - "published_at": "2017-09-28T21:54:10.897Z", - "coreid": "123456789938323536", - "userid": "1234ee123ac8e5ec1231a123d", - "version": 10, - "public": false, - "productID": 1234, - "name": "sensor", - "influx_db": "mydata" - }` -} - -func UnknowJSON() string { - return ` - { - "event": "roger" - }` -}