...
 
Commits (2)
......@@ -9,14 +9,13 @@ import (
// Config defines the application configuration
type Config struct {
AllowWrite bool
ListenAddr string `default:"127.0.0.1:7000" yaml:"listen_addr"`
PublicURL string `required:"true" yaml:"public_url"`
publicURL *url.URL
ListenAddr string `default:"127.0.0.1:7000" yaml:"listen_addr"`
Verbose bool `default:"false" yaml:"verbose"`
SendInterval string `default:"1h" yaml:"send_interval"`
PublicURL string `required:"true" yaml:"public_url"`
publicURL *url.URL
Verbose bool `default:"false" yaml:"verbose"`
AllowWrite bool
Database string `default:"data.db" yaml:"database"`
......
......@@ -12,12 +12,10 @@ func TestBlockedEvent(t *testing.T) {
in interface{}
out interface{}
}{
{tags["type"], "blocked"},
{tags["email"], "blocked@mailjet.com"},
{fields["mj_message_id"], uint64(13792286917004336)},
{fields["mj_campaign_id"], uint64(380)},
{fields["mj_contact_id"], uint64(19092)},
{fields["mj_campaign_payload"], ""},
{fields["email"], "blocked@mailjet.com"},
{tags["mj_message_id"], "13792286917004336"},
{tags["mj_campaign_id"], "380"},
{tags["mj_contact_id"], "19092"},
{tags["error_related_to"], "recipient"},
{tags["error"], "user unknown"},
......
package event
import "fmt"
// BounceEvent define a bounce event occurred on mailjet side
type BounceEvent struct {
baseEvent
......@@ -18,9 +20,9 @@ func (e *BounceEvent) Point() (map[string]string, map[string]interface{}) {
tags, fields := e.baseEvent.Point()
tags["error_related_to"] = e.ErrorRelatedTo
tags["error"] = e.Error
fields["blocked"] = e.Blocked
fields["hard_bounce"] = e.HardBounce
fields["comment"] = e.Comment
tags["blocked"] = fmt.Sprintf("%t", e.Blocked)
tags["hard_bounce"] = fmt.Sprintf("%t", e.HardBounce)
tags["comment"] = e.Comment
return tags, fields
}
......
......@@ -12,18 +12,16 @@ func TestBounceEvent(t *testing.T) {
in interface{}
out interface{}
}{
{tags["type"], "bounce"},
{tags["email"], "bounce@mailjet.com"},
{fields["mj_message_id"], uint64(13792286917004336)},
{fields["mj_campaign_id"], uint64(2)},
{fields["mj_contact_id"], uint64(199)},
{fields["mj_campaign_payload"], ""},
{fields["email"], "bounce@mailjet.com"},
{tags["mj_message_id"], "13792286917004336"},
{tags["mj_campaign_id"], "2"},
{tags["mj_contact_id"], "199"},
{fields["blocked"], false},
{fields["hard_bounce"], true},
{tags["error_related_to"], "recipient"},
{tags["error"], "user unknown"},
{fields["comment"], "Host or domain name not found: Host not found"},
{tags["blocked"], "false"},
{tags["hard_bounce"], "true"},
{tags["comment"], "Host or domain name not found: Host not found"},
} {
if test.in != test.out {
t.Errorf("%s != %s", test.in, test.out)
......
......@@ -12,14 +12,12 @@ func TestClickEvent(t *testing.T) {
in interface{}
out interface{}
}{
{tags["type"], "click"},
{tags["email"], "api@mailjet.com"},
{fields["mj_message_id"], uint64(19421777836302490)},
{fields["mj_campaign_id"], uint64(7272)},
{fields["mj_contact_id"], uint64(4)},
{fields["mj_campaign_payload"], ""},
{fields["email"], "api@mailjet.com"},
{tags["mj_message_id"], "19421777836302490"},
{tags["mj_campaign_id"], "7272"},
{tags["mj_contact_id"], "4"},
{fields["ip"], "127.0.0.1"},
{tags["ip"], "127.0.0.1"},
{tags["geo"], "FR"},
{tags["user_agent"], "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36"},
......
......@@ -134,15 +134,12 @@ func (e *baseEvent) String() string {
// Point return all tags and fields for influxdb
func (e *baseEvent) Point() (map[string]string, map[string]interface{}) {
tags := make(map[string]string)
fields := make(map[string]interface{})
tags["mj_message_id"] = fmt.Sprintf("%d", e.MailjetMessageID)
tags["mj_campaign_id"] = fmt.Sprintf("%d", e.MailjetCampaignID)
tags["mj_contact_id"] = fmt.Sprintf("%d", e.MailjetContactID)
fields["uuid"] = e.UUID
tags["type"] = e.Event
tags["email"] = e.Email
fields["mj_message_id"] = e.MailjetMessageID
fields["mj_campaign_id"] = e.MailjetCampaignID
fields["mj_contact_id"] = e.MailjetContactID
fields["mj_campaign_payload"] = e.CustomCampaign
fields := make(map[string]interface{})
fields["email"] = e.Email
return tags, fields
}
......
......@@ -12,7 +12,7 @@ type OpenEvent struct {
// Point return all tags and fields for influxdb
func (e *OpenEvent) Point() (map[string]string, map[string]interface{}) {
tags, fields := e.baseEvent.Point()
fields["ip"] = e.IP
tags["ip"] = e.IP
tags["geo"] = e.Geo
tags["user_agent"] = e.UserAgent
......
......@@ -12,14 +12,12 @@ func TestOpenEvent(t *testing.T) {
in interface{}
out interface{}
}{
{tags["type"], "open"},
{tags["email"], "api@mailjet.com"},
{fields["mj_message_id"], uint64(19421777396190490)},
{fields["mj_campaign_id"], uint64(7173)},
{fields["mj_contact_id"], uint64(320)},
{fields["mj_campaign_payload"], ""},
{fields["email"], "api@mailjet.com"},
{tags["mj_message_id"], "19421777396190490"},
{tags["mj_campaign_id"], "7173"},
{tags["mj_contact_id"], "320"},
{fields["ip"], "127.0.0.1"},
{tags["ip"], "127.0.0.1"},
{tags["geo"], "US"},
{tags["user_agent"], "Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0"},
} {
......
......@@ -10,7 +10,7 @@ type SentEvent struct {
// Point return all tags and fields for influxdb
func (e *SentEvent) Point() (map[string]string, map[string]interface{}) {
tags, fields := e.baseEvent.Point()
fields["smtp_reply"] = e.SMTPReply
tags["smtp_reply"] = e.SMTPReply
return tags, fields
}
......
......@@ -12,14 +12,12 @@ func TestSentEvent(t *testing.T) {
in interface{}
out interface{}
}{
{tags["type"], "sent"},
{tags["email"], "api@mailjet.com"},
{fields["mj_message_id"], uint64(19421777835146490)},
{fields["mj_campaign_id"], uint64(7257)},
{fields["mj_contact_id"], uint64(4)},
{fields["mj_campaign_payload"], ""},
{fields["email"], "api@mailjet.com"},
{tags["mj_message_id"], "19421777835146490"},
{tags["mj_campaign_id"], "7257"},
{tags["mj_contact_id"], "4"},
{fields["smtp_reply"], "sent (250 2.0.0 OK 1433333948 fa5si855896wjc.199 - gsmtp)"},
{tags["smtp_reply"], "sent (250 2.0.0 OK 1433333948 fa5si855896wjc.199 - gsmtp)"},
} {
if test.in != test.out {
t.Errorf("%s != %s", test.in, test.out)
......
......@@ -12,12 +12,10 @@ func TestSpamEvent(t *testing.T) {
in interface{}
out interface{}
}{
{tags["type"], "spam"},
{tags["email"], "bounce@mailjet.com"},
{fields["mj_message_id"], uint64(13792286917004336)},
{fields["mj_campaign_id"], uint64(1898)},
{fields["mj_contact_id"], uint64(10920)},
{fields["mj_campaign_payload"], ""},
{fields["email"], "bounce@mailjet.com"},
{tags["mj_message_id"], "13792286917004336"},
{tags["mj_campaign_id"], "1898"},
{tags["mj_contact_id"], "10920"},
{tags["source"], "JMRPP"},
} {
......
package event
import "fmt"
// UnsubEvent define a unsub event occurred on mailjet side
type UnsubEvent struct {
OpenEvent
......@@ -10,7 +12,7 @@ type UnsubEvent struct {
// Point return all tags and fields for influxdb
func (e *UnsubEvent) Point() (map[string]string, map[string]interface{}) {
tags, fields := e.OpenEvent.Point()
fields["mj_list_id"] = e.MailjetListID
tags["mj_list_id"] = fmt.Sprintf("%d", e.MailjetListID)
return tags, fields
}
......
......@@ -12,18 +12,16 @@ func TestUnsubEvent(t *testing.T) {
in interface{}
out interface{}
}{
{tags["type"], "unsub"},
{tags["email"], "api@mailjet.com"},
{fields["mj_message_id"], uint64(20547674933128000)},
{fields["mj_campaign_id"], uint64(7276)},
{fields["mj_contact_id"], uint64(126)},
{fields["mj_campaign_payload"], ""},
{fields["email"], "api@mailjet.com"},
{tags["mj_message_id"], "20547674933128000"},
{tags["mj_campaign_id"], "7276"},
{tags["mj_contact_id"], "126"},
{fields["ip"], "127.0.0.1"},
{tags["ip"], "127.0.0.1"},
{tags["geo"], "FR"},
{tags["user_agent"], "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0)"},
{fields["mj_list_id"], uint64(1)},
{tags["mj_list_id"], "1"},
} {
if test.in != test.out {
t.Errorf("%s != %s", test.in, test.out)
......
......@@ -15,7 +15,10 @@ var (
func NewStore(a *App) *bolt.DB {
ReadOnly := !a.config.AllowWrite
log.Printf("opening database=%s readonly=%t\n", a.config.Database, ReadOnly)
if a.config.Verbose {
log.Printf("opening database=%s readonly=%t\n", a.config.Database, ReadOnly)
}
db, err := bolt.Open(a.config.Database, 0600, &bolt.Options{ReadOnly: ReadOnly})
if err != nil {
log.Fatalln(err)
......