From 81923a3b7c589d242f83ccbf8ad0279813e53943 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Thu, 27 Sep 2018 23:57:03 -0700 Subject: [PATCH] email template - docs --- core/notifier/doc.go | 4 ++ notifiers/email.go | 82 ++++++++++++++++++++++++++++++++++--- notifiers/email_test.go | 6 +-- notifiers/notifiers_test.go | 10 ++++- notifiers/slack_test.go | 9 +--- types/doc.go | 3 +- 6 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 core/notifier/doc.go diff --git a/core/notifier/doc.go b/core/notifier/doc.go new file mode 100644 index 00000000..a52f008d --- /dev/null +++ b/core/notifier/doc.go @@ -0,0 +1,4 @@ +// Package Notifier contains the main functionality for the Statup Notification system +// +// by Hunter Long +package notifier diff --git a/notifiers/email.go b/notifiers/email.go index 841272fb..f8fd5f88 100644 --- a/notifiers/email.go +++ b/notifiers/email.go @@ -28,9 +28,79 @@ import ( ) const ( - MESSAGE = "\n\n\n \n \n Sample Email\n\n\n\n\n\n \n \n \n
\n \n\n \n \n \n
\n \n\n \n \n \n
\n

Looks Like Emails Work!

\n

\n Since you got this email, it confirms that your Statup Status Page email system is working correctly.\n

\n

\n

\n Enjoy using Statup!\n
Statup.io Team

\n\n \n\n
\n
\n
\n
\n\n" - FAILURE = "\n\n\n \n \n Sample Email\n\n\n\n\n\n \n \n \n
\n \n\n \n \n \n
\n \n\n \n \n \n
\n

{{ .Service.Name }} is Offline!

\n

\n Your Statup service '{{.Service.Name}}' has been triggered with a HTTP status code of '{{.Service.LastStatusCode}}' and is currently offline based on your requirements. This failure was created on {{.Service.CreatedAt}}.\n

\n\n {{if .Service.LastResponse }}\n

Last Response

\n

\n {{ .Service.LastResponse }}\n

\n {{end}}\n\n \n \n \n
\n View Service\n \n Statup Dashboard\n
\n
\n
\n
\n\n" - SUCCESS = "\n\n\n \n \n Sample Email\n\n\n\n\n\n \n \n \n
\n \n\n \n \n \n
\n \n\n \n \n \n
\n

{{ .Service.Name }} is Offline!

\n

\n Your Statup service '{{.Service.Name}}' has been triggered with a HTTP status code of '{{.Service.LastStatusCode}}' and is currently offline based on your requirements. This failure was created on {{.Service.CreatedAt}}.\n

\n\n {{if .Service.LastResponse }}\n

Last Response

\n

\n {{ .Service.LastResponse }}\n

\n {{end}}\n\n \n \n \n
\n View Service\n \n Statup Dashboard\n
\n
\n
\n
\n\n" + TEMPLATE = ` + + + + + Statup Email + + + + + + + +
+ + + + + +
+ +` ) var ( @@ -44,7 +114,7 @@ type Email struct { var emailer = &Email{¬ifier.Notification{ Method: "email", Title: "Email", - Description: "Send emails via SMTP when notification are online or offline.", + Description: "Send emails via SMTP when services are online or offline.", Author: "Hunter Long", AuthorUrl: "https://github.com/hunterlong", Form: []notifier.NotificationForm{{ @@ -113,7 +183,7 @@ func (u *Email) OnFailure(s *types.Service, f *types.Failure) { email := &EmailOutgoing{ To: emailer.GetValue("var2"), Subject: fmt.Sprintf("Service %v is Failing", s.Name), - Template: FAILURE, + Template: TEMPLATE, Data: interface{}(s), From: emailer.GetValue("var1"), } @@ -127,7 +197,7 @@ func (u *Email) OnSuccess(s *types.Service) { email := &EmailOutgoing{ To: emailer.GetValue("var2"), Subject: fmt.Sprintf("Service %v is Back Online", s.Name), - Template: SUCCESS, + Template: TEMPLATE, Data: interface{}(s), From: emailer.GetValue("var1"), } diff --git a/notifiers/email_test.go b/notifiers/email_test.go index d4f44c12..514cef90 100644 --- a/notifiers/email_test.go +++ b/notifiers/email_test.go @@ -69,13 +69,11 @@ func TestEmailNotifier(t *testing.T) { emailer.Port = int(EMAIL_PORT) emailer.Delay = time.Duration(100 * time.Millisecond) - message := "this is a test email!" - testEmail = &EmailOutgoing{ To: emailer.GetValue("var2"), Subject: fmt.Sprintf("Service %v is Failing", TestService.Name), - Template: MESSAGE, - Data: interface{}(message), + Template: TEMPLATE, + Data: TestService, From: emailer.GetValue("var1"), } }) diff --git a/notifiers/notifiers_test.go b/notifiers/notifiers_test.go index dce1a4ea..e274d0c2 100644 --- a/notifiers/notifiers_test.go +++ b/notifiers/notifiers_test.go @@ -22,6 +22,7 @@ import ( "github.com/hunterlong/statup/utils" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/sqlite" + "time" ) var ( @@ -31,6 +32,7 @@ var ( ) var TestService = &types.Service{ + Id: 1, Name: "Interpol - All The Rage Back Home", Domain: "https://www.youtube.com/watch?v=-u6DvRyyKGU", ExpectedStatus: 200, @@ -38,10 +40,16 @@ var TestService = &types.Service{ Type: "http", Method: "GET", Timeout: 20, + LastStatusCode: 404, + Expected: "test example", + LastResponse: "this is an example response", + CreatedAt: time.Now().Add(-24 * time.Hour), } var TestFailure = &types.Failure{ - Issue: "testing", + Issue: "testing", + Service: 1, + CreatedAt: time.Now().Add(-12 * time.Hour), } var TestUser = &types.User{ diff --git a/notifiers/slack_test.go b/notifiers/slack_test.go index ae366232..66ac359a 100644 --- a/notifiers/slack_test.go +++ b/notifiers/slack_test.go @@ -24,13 +24,8 @@ import ( ) var ( - SLACK_URL string - slackMessage = `{"text":"this is a test from the Slack notifier!"}` - slackTestMessage = SlackMessage{ - Service: TestService, - Template: FAILURE, - Time: time.Now().Unix(), - } + SLACK_URL string + slackMessage = `{"text":"this is a test from the Slack notifier!"}` ) func init() { diff --git a/types/doc.go b/types/doc.go index e968d183..99b7faf2 100644 --- a/types/doc.go +++ b/types/doc.go @@ -1,5 +1,4 @@ -// Package type contains all of the structs for objects in Statup including -// services, hits, failures, Core, and others. +// Package types contains all of the structs for objects in Statup including services, hits, failures, Core, and others. // // by Hunter Long package types