Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
bugfix: timestamp as epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
myoung34 committed Aug 25, 2022
1 parent acdd6ee commit 6b8e010
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 30 deletions.
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,46 @@ logfile = /var/log/foo.log # defaults to stdout
# SQLite example
[sqlite]
enabled = true
file = /etc/tilty/tilt.sqlite
# Generic application/json example
[webhook]
url = http://www.foo.com
headers = {"Content-Type": "application/json"}
template = {"color": "{{ color }}", "gravity": {{ gravity }}, "mac": "{{ mac }}", "temp": {{ temp }}, "timestamp": "{{ timestamp }}"}
method = POST
enabled = true
url = "http://www.foo.com"
headers = "{\"Content-Type\": \"application/json\"}"
template = "{\"color\": \"{{.Color}}\", \"gravity\": {{.Gravity}}, \"mac\": \"{{.Mac}}\", \"temp\": {{.Temp}}, \"timestamp\": \"{{.Timestamp}}\", \"gravity_unit\": \"G\", \"temp_unit\": \"F\"}"
method = "POST"
# Brewstat.us example
[webhook]
url = https://www.brewstat.us/tilt/0yjRbGd2/log
headers = {"Content-Type": "application/x-www-form-urlencoded; charset=utf-8"}
template = {"Color": "{{ color }}", "SG": {{ gravity }}, "Temp": {{ temp }}, "Timepoint": "{{ timestamp }}"}
method = POST
enabled = true
url = "https://www.brewstat.us/tilt/0yjRbGd2/log"
headers = "{\"Content-Type\": \"application/json\"}"
template = "{\"Color\": \"{{.Color}}\", \"SG\": {{.Gravity}}, \"Temp\": {{.Temp}}, \"Timepoint\": \"{{.Timestamp}}\"}"
method = "POST"
# Brewers Friend example
[webhook]
url = https://log.brewersfriend.com/tilt/3009ec67c6d81276185c90824951bd32bg
headers = {"Content-Type": "application/x-www-form-urlencoded"}
template = {"SG": {{ gravity }}, "Temp": {{ temp }}, "Color": "{{ color }}"}
method = POST
enabled = true
url = "https://log.brewersfriend.com/tilt/3009ec67c6d81276185c90824951bd32bg"
headers = "{\"Content-Type\": \"application/json\"}"
template = "{\"SG\": \"{{.Gravity}}\", \"Temp\": {{.Temp}}, \"Color\": {{.Color}}}"
method = "POST"
# Brewfather custom stream example
[webhook]
url = https://log.brewfather.net/stream?id=aTHF9WlXKrAb1C
headers = {"Content-Type": "application/json"}
template = {"name": "Tilt {{ color }}", "gravity": {{ gravity }}, "gravity_unit": "G", "temp": {{ temp }}, "temp_unit": "F"}
method = POST
enabled = true
url = "https://log.brewfather.net/stream?id=aTHF9WlXKrAb1C"
headers = "{\"Content-Type\": \"application/json\"}"
template = "{\"name\": \"Tilt {{.Color}}\", \"gravity\": {{.Gravity}}, \"gravity_unit\": \"G\", \"temp\": {{.Temp}}, \"temp_unit\": \"F\"}"
method = "POST"
[datadog]
enabled = true
# Note: make sure that the dd agent has DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true
host = statsdhost.corp.com
port = 8125
statsd_host = "statsdhost.corp.com"
statsd_port = 8125
```

Expand Down
2 changes: 1 addition & 1 deletion emitters/datadog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestDatadogEmit(t *testing.T) {
Major: 65,
Minor: 1098,
Rssi: -7,
Timestamp: "2019-11-10 23:59:00 +0000 UTC",
Timestamp: 1661445284,
}
resp, err := DatadogEmitWithClient(payload, sampleConfig.ConfigData.Get("datadog"), &statsd.NoOpClient{})
assert.Equal(t, nil, err)
Expand Down
2 changes: 1 addition & 1 deletion emitters/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ type Template struct {
Gravity string
Mac string
Temp string
Timestamp string
Timestamp int64
}
2 changes: 1 addition & 1 deletion emitters/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestSQLite(t *testing.T) {
Major: 65,
Minor: 1098,
Rssi: -7,
Timestamp: "2019-11-10 23:59:00 +0000 UTC",
Timestamp: 1661445284,
}
resp, err := SQLiteEmit(payload, sampleConfig.ConfigData.Get("sqlite"))
assert.Equal(t, nil, err)
Expand Down
5 changes: 4 additions & 1 deletion emitters/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ func WebhookEmit(payload tilt.TiltPayload, emitterConfig interface{}) (string, e
}
level.Info(tilt.Logger).Log("emitters.webhook", fmt.Sprintf("%+v", payload))

tmpl, err := template.New("test").Parse(`{"name": "Tilt {{.Color}}", "gravity": {{.Gravity}}, "gravity_unit": "G", "temp": {{.Temp}}, "temp_unit": "F"}`)
tmpl, err := template.New("webhook").Parse(`{"name": "Tilt {{.Color}}", "gravity": {{.Gravity}}, "gravity_unit": "G", "temp": {{.Temp}}, "temp_unit": "F"}`)
if len(webhook.Template) > 0 {
tmpl, err = template.New("webhook").Parse(webhook.Template)
}
if err != nil {
level.Error(tilt.Logger).Log("emitters.webhook", err)
return "", err
Expand Down
12 changes: 6 additions & 6 deletions emitters/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ func TestWebhook(t *testing.T) {
Major: 90,
Minor: 1024,
Rssi: -67,
Timestamp: "2009-11-10 23:00:00 +0000 UTC",
Timestamp: 1661445284,
},
Enabled: true,
Url: "http://something.com",
Headers: "{\"Content-Type\": \"application/json\", \"Foo\": \"bar\"}",
Template: "{\"color\": \"{{ color }}\", \"gravity\": {{ gravity }}, \"mac\": \"{{ mac }}\", \"temp\": {{ temp }}, \"timestamp\": \"{{ timestamp }}\"}",
Template: "{\"color\": \"{{.Color}}\", \"gravity\": {{.Gravity}}, \"mac\": \"{{.Mac}}\", \"temp\": {{.Temp}}, \"timestamp\": \"{{.Timestamp}}\", \"gravity_unit\": \"G\", \"temp_unit\": \"F\"}",
Method: "POST",
},
out: TiltTest{
Response: "{\"Response\":\"{\\\"name\\\": \\\"Tilt RED\\\", \\\"gravity\\\": 1024, \\\"gravity_unit\\\": \\\"G\\\", \\\"temp\\\": 90, \\\"temp_unit\\\": \\\"F\\\"}\"}",
Response: "{\"Response\":\"{\\\"color\\\": \\\"RED\\\", \\\"gravity\\\": 1024, \\\"mac\\\": \\\"11:22:33:44:55\\\", \\\"temp\\\": 90, \\\"timestamp\\\": \\\"1661445284\\\", \\\"gravity_unit\\\": \\\"G\\\", \\\"temp_unit\\\": \\\"F\\\"}\"}",
CallCount: 1,
CallSignature: "POST http://something.com",
},
Expand All @@ -75,16 +75,16 @@ func TestWebhook(t *testing.T) {
Major: 65,
Minor: 1098,
Rssi: -7,
Timestamp: "2019-11-10 23:59:00 +0000 UTC",
Timestamp: 1661445284,
},
Enabled: true,
Url: "http://fake.com",
Headers: "{\"Content-Type\": \"application/json\"}",
Template: "{\"color\": \"{{ color }}\", \"gravity\": {{ gravity }}, \"mac\": \"{{ mac }}\", \"temp\": {{ temp }}, \"timestamp\": \"{{ timestamp }}\"}",
Template: "{\"color\": \"{{.Color}}\", \"gravity\": {{.Gravity}}, \"mac\": \"{{.Mac}}\", \"temp\": {{.Temp}}, \"timestamp\": \"{{.Timestamp}}\", \"gravity_unit\": \"G\", \"temp_unit\": \"F\"}",
Method: "GET",
},
out: TiltTest{
Response: "{\"Response\":\"{\\\"name\\\": \\\"Tilt BLACK\\\", \\\"gravity\\\": 1098, \\\"gravity_unit\\\": \\\"G\\\", \\\"temp\\\": 65, \\\"temp_unit\\\": \\\"F\\\"}\"}",
Response: "{\"Response\":\"{\\\"color\\\": \\\"BLACK\\\", \\\"gravity\\\": 1098, \\\"mac\\\": \\\"66:77:88:99:00\\\", \\\"temp\\\": 65, \\\"timestamp\\\": \\\"1661445284\\\", \\\"gravity_unit\\\": \\\"G\\\", \\\"temp_unit\\\": \\\"F\\\"}\"}",
CallCount: 2,
CallSignature: "GET http://fake.com",
},
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func OnPeripheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int)
Major: _tilt.Major,
Minor: _tilt.Minor,
Rssi: rssi,
Timestamp: time.Now().String(),
Timestamp: time.Now().UTC().Unix(),
}
err = validate.Struct(payload)
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion tilt/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ type TiltPayload struct {
Major uint16
Minor uint16
Rssi int
Timestamp string
Timestamp int64
}

0 comments on commit 6b8e010

Please sign in to comment.