telegraf/plugins/inputs/webhooks/particle/particle_webhooks_models.go

52 lines
889 B
Go
Raw Normal View History

2016-07-31 23:56:28 +00:00
package particle
import (
"fmt"
"log"
"time"
"github.com/influxdata/telegraf"
)
const meas = "particle"
type Event interface {
NewMetric() telegraf.Metric
}
type ParticleEvent struct {
2016-08-01 00:30:34 +00:00
Event string `schema:"event"`
Data int `schema:"data"`
PublishedAt time.Time `schema:"published_at"`
CoreID string `schema:"coreid"`
2016-07-31 23:56:28 +00:00
}
func (pe ParticleEvent) String() string {
2016-08-01 00:30:34 +00:00
return fmt.Sprintf(`
2016-07-31 23:56:28 +00:00
Event == {
event: %v,
data: %v,
published: %v,
coreid: %v
}`,
2016-08-01 00:30:34 +00:00
pe.Event,
pe.Data,
pe.PublishedAt,
pe.CoreID)
2016-07-31 23:56:28 +00:00
}
func (pe ParticleEvent) NewMetric() telegraf.Metric {
2016-08-01 00:30:34 +00:00
t := map[string]string{
"event": pe.Event,
"coreid": pe.CoreID,
}
f := map[string]interface{}{
"data": pe.Data,
}
m, err := telegraf.NewMetric(pe.Event, t, f, pe.PublishedAt)
if err != nil {
log.Fatalf("Failed to create %v event", meas)
}
return m
}