From 393b433467c158a5fc300308bf52c1aee06ba936 Mon Sep 17 00:00:00 2001 From: britannic Date: Mon, 12 Oct 2020 17:31:51 -0700 Subject: [PATCH] email notifier issue #820, #833, #841 workaround --- Makefile | 2 +- frontend/src/API.js | 2 +- frontend/src/pages/Help.vue | 52 ++++++++++++++++++++++++++++++++++--- notifiers/email.go | 13 +++++++--- notifiers/email_rendered.go | 3 ++- notifiers/generate.go | 4 +-- notifiers/notifiers.go | 6 +++-- 7 files changed, 68 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 097314e8..0a98568d 100644 --- a/Makefile +++ b/Makefile @@ -303,7 +303,7 @@ dockerhub: docker-build-dev: docker build --build-arg VERSION=${VERSION} -t statping/statping:latest --no-cache -f Dockerfile . - docker tag statping/statping:dev statping/statping:dev-v${VERSION} + docker tag hunterlong/statping:dev hunterlong/statping:dev-v${VERSION} post-release: frontend-build upload_to_s3 publish-homebrew dockerhub diff --git a/frontend/src/API.js b/frontend/src/API.js index 0eede1ca..511469b7 100644 --- a/frontend/src/API.js +++ b/frontend/src/API.js @@ -8,7 +8,7 @@ const tokenKey = "statping_auth"; class Api { constructor() { this.version = "0.90.70"; - this.commit = "8c89b7ed4b45885063afaba445249bdf51bb1982"; + this.commit = "ce360c64d9f4ea48519eeed77529bd17ba51a7a7"; } async oauth() { diff --git a/frontend/src/pages/Help.vue b/frontend/src/pages/Help.vue index 61654a40..023405f8 100755 --- a/frontend/src/pages/Help.vue +++ b/frontend/src/pages/Help.vue @@ -13,6 +13,8 @@ Notifiers + Issues and Solutions + Bulk Import Services Environment Variables @@ -326,6 +328,44 @@ func AttachNotifiers() error { +
+

Issues and Solutions

+ +
+

If you have issues with your Statping instance, this page will help you solve them. Before doing anything, I recommend updating to the latest version of Statping.

+ +

Update to Latest Version

+ +

Updating Statping is very simple, you can choose one of the options below: +- Run command: statping update (you may need to run sudo depending on your server) +- or Run command: curl -o- -L https://statping.com/install.sh | bash +- or download tar.gz file from Latest Releases and extract for statping.

+ +

Blank/White Page

+ +

If your Statping instance is only showing a blank white page, this means there’s an issue with CSS or JS assets. +- Update to the latest version of Statping +- Delete the assets folder if you have one +- Restart Statping instance

+ +

Database Migration Errors

+ +

If you notice a database error during migration, you can reset your Statping instance while keeping previous data so you won’t have to re-input. +- In your Statping directory (contains config.yml) run command: statping export. This will export all elements into a timestamped JSON file. This file will not include previous hits or failures. +- Delete assets folder if you have one. +- Delete and Recreate MySQL, Postgres database, or delete statping.db. +- Import previous data by running: statping import backup.json (replace backup.json with your exported filename)

+ +

Deleting Old Records

+ +
    +
  • DELETE FROM hits WHERE created_at < '2020-02-21 00:00:00'; // Delete hits older than
  • +
  • DELETE FROM failures WHERE created_at < '2020-02-21 00:00:00'; // Delete failures older than
  • +
+ +
+
+

Bulk Import Services

@@ -422,10 +462,12 @@ services:
  • DB_PASS - Database password
  • DB_PORT - Database port (5432, 3306, …)
  • DB_DATABASE - Database connection’s database name
  • +
  • DB_DSN - Database DSN string (postgres, mysql, sqlite)
  • +
  • READ_ONLY - Run in a read only mode, this will not create, update, or delete records (false)
  • POSTGRES_SSLMODE - Enable Postgres SSL Mode ‘ssl_mode=VALUE’ (enable/disable/verify-full/verify-ca)
  • MAX_OPEN_CONN - Set Maximum Open Connections for database server (default: 25)
  • MAX_IDLE_CONN - Set Maximum Idle Connections for database server (default: 25)
  • -
  • MAX_LIFE_CONN - Set Maximum Life Connections for database server (default: 25)
  • +
  • MAX_LIFE_CONN - Set Maximum Life Connections for database server (default: 5 minutes)
  • PREFIX - Add a prefix string to each Prometheus metric (default is empty)
  • @@ -454,7 +496,7 @@ services:
  • LOGS_MAX_SIZE - Maximum size for log files (defaults to 16 MB)

  • -
  • LANGUAGE - Language to use (en, fr, ru, more to come…)

    +
  • LANGUAGE - Language to use (en, fr, it, ru, zh, de, ko, ja)

    Assets

  • @@ -463,6 +505,10 @@ services:
  • USE_ASSETS - Automatically use assets from ‘assets folder’ (true/false)

  • +
    +

    If you have issues with Statping not loading frontend files, delete the assets folder and reboot.

    +
    +

    Automatic Fills

    -Automatically generated from Statping's Wiki on 2020-09-15 19:09:14.703237 +0000 UTC +Automatically generated from Statping's Wiki on 2020-10-13 00:26:29.680492 +0000 UTC
    diff --git a/notifiers/email.go b/notifiers/email.go index 2980c705..dd012024 100644 --- a/notifiers/email.go +++ b/notifiers/email.go @@ -3,6 +3,7 @@ package notifiers import ( "crypto/tls" "fmt" + "github.com/go-mail/mail" "github.com/statping/emails" "github.com/statping/statping/types/core" @@ -90,8 +91,9 @@ type emailOutgoing struct { // OnFailure will trigger failing service func (e *emailer) OnFailure(s services.Service, f failures.Failure) (string, error) { + subscriber := e.Var2.String subject := fmt.Sprintf("Service %s is Offline", s.Name) - tmpl := renderEmail(s, f, emails.Failure) + tmpl := renderEmail(s, subscriber, f, emails.Failure) email := &emailOutgoing{ To: e.Var2.String, Subject: subject, @@ -103,8 +105,9 @@ func (e *emailer) OnFailure(s services.Service, f failures.Failure) (string, err // OnSuccess will trigger successful service func (e *emailer) OnSuccess(s services.Service) (string, error) { + subscriber := e.Var2.String subject := fmt.Sprintf("Service %s is Back Online", s.Name) - tmpl := renderEmail(s, failures.Failure{}, emails.Success) + tmpl := renderEmail(s, subscriber, failures.Failure{}, emails.Success) email := &emailOutgoing{ To: e.Var2.String, Subject: subject, @@ -114,11 +117,12 @@ func (e *emailer) OnSuccess(s services.Service) (string, error) { return tmpl, e.dialSend(email) } -func renderEmail(s services.Service, f failures.Failure, emailData string) string { +func renderEmail(s services.Service, subscriber string, f failures.Failure, emailData string) string { data := replacer{ Core: *core.App, Service: s, Failure: f, + Email: subscriber, Custom: nil, } output, err := emails.Parse(emailData, data) @@ -131,12 +135,13 @@ func renderEmail(s services.Service, f failures.Failure, emailData string) strin // OnTest triggers when this notifier has been saved func (e *emailer) OnTest() (string, error) { + subscriber := e.Var2.String service := services.Example(true) subject := fmt.Sprintf("Service %v is Back Online", service.Name) email := &emailOutgoing{ To: e.Var2.String, Subject: subject, - Template: renderEmail(service, failures.Example(), emailFailure), + Template: renderEmail(service, subscriber, failures.Example(), emailFailure), From: e.Var1.String, } return subject, e.dialSend(email) diff --git a/notifiers/email_rendered.go b/notifiers/email_rendered.go index 4d2da9e8..9006182a 100755 --- a/notifiers/email_rendered.go +++ b/notifiers/email_rendered.go @@ -1,4 +1,4 @@ -// DO NOT EDIT ** This file was generated with go generate on 2020-08-21 21:37:06.638898 +0000 UTC ** DO NOT EDIT // +// DO NOT EDIT ** This file was generated with go generate on 2020-10-13 00:26:28.325328 +0000 UTC ** DO NOT EDIT // package notifiers const emailSuccess = `Statping Service Notification
    Sphero
    {{.Service.Name}} is currently offline, you might want to check it.
    Offline for {{.Service.Downtime.Human}}
    View Dashboard
    Service Domain
    {{.Service.Domain}}
    Current Issue
    {{.Failure.Issue}}
     
    You are receiving this email because one of your services has changed on your Statping instance. You can modify this email on the Email Notifier page in Settings.
    © Statping
    Statping.com         Github         Privacy        
    ` + diff --git a/notifiers/generate.go b/notifiers/generate.go index e9efbf87..b156167d 100644 --- a/notifiers/generate.go +++ b/notifiers/generate.go @@ -111,7 +111,7 @@ const emailFailureMJML = ` Offline for {{.Service.Downtime.Human}} - View Dashboard + View Dashboard @@ -203,7 +203,7 @@ const emailSuccessMJML = ` Offline for {{.Service.Downtime.Human}} - View Dashboard + View Dashboard diff --git a/notifiers/notifiers.go b/notifiers/notifiers.go index ec23bd1e..4443b1ca 100644 --- a/notifiers/notifiers.go +++ b/notifiers/notifiers.go @@ -2,12 +2,13 @@ package notifiers import ( "bytes" + "html/template" + "time" + "github.com/statping/statping/types/core" "github.com/statping/statping/types/failures" "github.com/statping/statping/types/services" "github.com/statping/statping/utils" - "html/template" - "time" ) //go:generate go run generate.go @@ -18,6 +19,7 @@ type replacer struct { Core core.Core Service services.Service Failure failures.Failure + Email string Custom map[string]string }