mirror of https://github.com/statping/statping
fix for updating fields
parent
136831e70d
commit
a43d7834b9
|
@ -1,5 +1,7 @@
|
|||
# 0.90.65 (08-24-2020)
|
||||
- Fixed issue with dashboard not logging in (notifier panic)
|
||||
- Modified static email templates to github.com/statping/emails
|
||||
- Modified Regenerate API function to keep API_SECRET env
|
||||
|
||||
# 0.90.64 (08-18-2020)
|
||||
- Modified max-width for container to 1012px, larger UI
|
||||
|
|
|
@ -148,20 +148,20 @@ func InitApp() error {
|
|||
if _, err := core.Select(); err != nil {
|
||||
return err
|
||||
}
|
||||
// init Sentry error monitoring (its useful)
|
||||
utils.SentryInit(core.App.AllowReports.Bool)
|
||||
// init prometheus metrics
|
||||
metrics.InitMetrics()
|
||||
// connect each notifier, added them into database if needed
|
||||
notifiers.InitNotifiers()
|
||||
// select all services in database and store services in a mapping of Service pointers
|
||||
if _, err := services.SelectAllServices(true); err != nil {
|
||||
return err
|
||||
}
|
||||
// start routines for each service checking process
|
||||
services.CheckServices()
|
||||
// connect each notifier, added them into database if needed
|
||||
notifiers.InitNotifiers()
|
||||
// start routine to delete old records (failures, hits)
|
||||
go database.Maintenance()
|
||||
// init Sentry error monitoring (its useful)
|
||||
utils.SentryInit(core.App.AllowReports.Bool)
|
||||
core.App.Setup = true
|
||||
core.App.Started = utils.Now()
|
||||
return nil
|
||||
|
|
1
go.mod
1
go.mod
|
@ -30,6 +30,7 @@ require (
|
|||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/spf13/viper v1.6.3
|
||||
github.com/statping/emails v1.0.0
|
||||
github.com/stretchr/testify v1.5.1
|
||||
github.com/t-tiger/gorm-bulk-insert/v2 v2.0.1
|
||||
github.com/tdewolff/minify/v2 v2.8.0 // indirect
|
||||
|
|
3
go.sum
3
go.sum
|
@ -568,6 +568,9 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
|
|||
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
|
||||
github.com/spf13/viper v1.6.3 h1:pDDu1OyEDTKzpJwdq4TiuLyMsUgRa/BT5cn5O62NoHs=
|
||||
github.com/spf13/viper v1.6.3/go.mod h1:jUMtyi0/lB5yZH/FjyGAoH7IMNrIhlBf6pXZmbMDvzw=
|
||||
github.com/statping/emails v1.0.0 h1:90hGweEhr8wIFiy34KCkiFqGJlkug2gAQLVR6oSCFNU=
|
||||
github.com/statping/emails v1.0.0/go.mod h1:xFU85jXaiWQadqHqu/jDrGsAn6WPSk1WgKyTVuFm0TI=
|
||||
github.com/statping/statping v0.90.64/go.mod h1:lbyNPB73IjWtnommV4wSejYfgUT1yLhhqelMjl1ZBb8=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
|
|
@ -31,10 +31,12 @@ func apiIndexHandler(r *http.Request) interface{} {
|
|||
}
|
||||
|
||||
func apiRenewHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
core.App.ApiSecret = utils.NewSHA256Hash()
|
||||
err = core.App.Update()
|
||||
if err != nil {
|
||||
newApi := utils.Params.GetString("API_SECRET")
|
||||
if newApi == "" {
|
||||
newApi = utils.NewSHA256Hash()
|
||||
}
|
||||
core.App.ApiSecret = newApi
|
||||
if err := core.App.Update(); err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ import (
|
|||
func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var notifs []notifications.Notification
|
||||
for _, n := range services.AllNotifiers() {
|
||||
log.Warningln(n)
|
||||
no := n.Select()
|
||||
log.Warningln(no.Method)
|
||||
notif, err := notifications.Find(no.Method)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
|
|
|
@ -64,7 +64,7 @@ var AmazonSNS = &amazonSNS{¬ifications.Notification{
|
|||
Type: "text",
|
||||
Title: "SNS Topic ARN",
|
||||
SmallText: "The ARN of the Topic",
|
||||
DbField: "host",
|
||||
DbField: "Host",
|
||||
Placeholder: "arn:aws:sns:us-west-2:123456789012:YourTopic",
|
||||
Required: true,
|
||||
}}},
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
package notifiers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/go-mail/mail"
|
||||
"github.com/statping/emails"
|
||||
"github.com/statping/statping/types/core"
|
||||
"github.com/statping/statping/types/failures"
|
||||
"github.com/statping/statping/types/notifications"
|
||||
"github.com/statping/statping/types/notifier"
|
||||
"github.com/statping/statping/types/services"
|
||||
"github.com/statping/statping/utils"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
var _ notifier.Notifier = (*emailer)(nil)
|
||||
|
@ -92,7 +91,7 @@ type emailOutgoing struct {
|
|||
// OnFailure will trigger failing service
|
||||
func (e *emailer) OnFailure(s services.Service, f failures.Failure) (string, error) {
|
||||
subject := fmt.Sprintf("Service %s is Offline", s.Name)
|
||||
tmpl := renderEmail(s, f, emailFailure)
|
||||
tmpl := renderEmail(s, f, emails.Failure)
|
||||
email := &emailOutgoing{
|
||||
To: e.Var2.String,
|
||||
Subject: subject,
|
||||
|
@ -105,7 +104,7 @@ 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) {
|
||||
subject := fmt.Sprintf("Service %s is Back Online", s.Name)
|
||||
tmpl := renderEmail(s, failures.Failure{}, emailSuccess)
|
||||
tmpl := renderEmail(s, failures.Failure{}, emails.Success)
|
||||
email := &emailOutgoing{
|
||||
To: e.Var2.String,
|
||||
Subject: subject,
|
||||
|
@ -116,27 +115,18 @@ func (e *emailer) OnSuccess(s services.Service) (string, error) {
|
|||
}
|
||||
|
||||
func renderEmail(s services.Service, f failures.Failure, emailData string) string {
|
||||
wr := bytes.NewBuffer(nil)
|
||||
tmpl := template.New("email")
|
||||
tmpl, err := tmpl.Parse(emailData)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return emailData
|
||||
}
|
||||
|
||||
data := replacer{
|
||||
Core: *core.App,
|
||||
Service: s,
|
||||
Failure: f,
|
||||
Custom: nil,
|
||||
}
|
||||
|
||||
if err = tmpl.ExecuteTemplate(wr, "email", data); err != nil {
|
||||
output, err := emails.Parse(emailData, data)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return emailData
|
||||
}
|
||||
|
||||
return wr.String()
|
||||
return output
|
||||
}
|
||||
|
||||
// OnTest triggers when this notifier has been saved
|
||||
|
|
|
@ -56,10 +56,11 @@ func ReplaceTemplate(tmpl string, data replacer) string {
|
|||
|
||||
func Add(notifs ...services.ServiceNotifier) {
|
||||
for _, n := range notifs {
|
||||
services.AddNotifier(n)
|
||||
if err := n.Select().Create(); err != nil {
|
||||
notif := n.Select()
|
||||
if err := notif.Create(); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
services.AddNotifier(n)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ func LoadConfigForm(r *http.Request) (*DbConfig, error) {
|
|||
Email: email,
|
||||
Location: utils.Directory,
|
||||
Language: language,
|
||||
SendReports: reports,
|
||||
AllowReports: reports,
|
||||
}
|
||||
|
||||
return confg, nil
|
||||
|
|
|
@ -59,7 +59,7 @@ func LoadConfigs(cfgFile string) (*DbConfig, error) {
|
|||
if db.Language != "" {
|
||||
p.Set("LANGUAGE", db.Language)
|
||||
}
|
||||
if db.SendReports {
|
||||
if db.AllowReports {
|
||||
p.Set("ALLOW_REPORTS", true)
|
||||
}
|
||||
if db.LetsEncryptEmail != "" {
|
||||
|
@ -88,7 +88,7 @@ func LoadConfigs(cfgFile string) (*DbConfig, error) {
|
|||
Location: utils.Directory,
|
||||
SqlFile: p.GetString("SQL_FILE"),
|
||||
Language: p.GetString("LANGUAGE"),
|
||||
SendReports: p.GetBool("ALLOW_REPORTS"),
|
||||
AllowReports: p.GetBool("ALLOW_REPORTS"),
|
||||
LetsEncryptEnable: p.GetBool("LETSENCRYPT_ENABLE"),
|
||||
LetsEncryptHost: p.GetString("LETSENCRYPT_HOST"),
|
||||
LetsEncryptEmail: p.GetString("LETSENCRYPT_EMAIL"),
|
||||
|
|
|
@ -14,7 +14,7 @@ type DbConfig struct {
|
|||
DbPort int `yaml:"port" json:"-"`
|
||||
ApiSecret string `yaml:"api_secret" json:"-"`
|
||||
Language string `yaml:"language" json:"language"`
|
||||
SendReports bool `yaml:"send_reports" json:"send_reports"`
|
||||
AllowReports bool `yaml:"allow_reports" json:"allow_reports"`
|
||||
Project string `yaml:"-" json:"-"`
|
||||
Description string `yaml:"-" json:"-"`
|
||||
Domain string `yaml:"-" json:"-"`
|
||||
|
@ -26,8 +26,28 @@ type DbConfig struct {
|
|||
SqlFile string `yaml:"sqlfile,omitempty" json:"-"`
|
||||
LetsEncryptHost string `yaml:"letsencrypt_host,omitempty" json:"letsencrypt_host"`
|
||||
LetsEncryptEmail string `yaml:"letsencrypt_email,omitempty" json:"letsencrypt_email"`
|
||||
LetsEncryptEnable bool `yaml:"letsencrypt_enable" json:"letsencrypt_enable"`
|
||||
LetsEncryptEnable bool `yaml:"letsencrypt_enable,omitempty" json:"letsencrypt_enable"`
|
||||
LocalIP string `yaml:"-" json:"-"`
|
||||
|
||||
DisableHTTP bool `yaml:"disable_http" json:"disable_http"`
|
||||
DemoMode bool `yaml:"demo_mode" json:"demo_mode"`
|
||||
DisableLogs bool `yaml:"disable_logs" json:"disable_logs"`
|
||||
UseAssets bool `yaml:"use_assets" json:"use_assets"`
|
||||
BasePath bool `yaml:"base_path" json:"base_path"`
|
||||
|
||||
AdminUser string `yaml:"admin_user" json:"admin_user"`
|
||||
AdminPassword string `yaml:"admin_password" json:"admin_password"`
|
||||
AdminEmail string `yaml:"admin_email" json:"admin_email"`
|
||||
|
||||
MaxOpenConnections int `yaml:"db_open_connections" json:"db_open_connections"`
|
||||
MaxIdleConnections int `yaml:"db_idle_connections" json:"db_idle_connections"`
|
||||
MaxLifeConnections int `yaml:"db_max_life_connections" json:"db_max_life_connections"`
|
||||
|
||||
SampleData bool `yaml:"sample_data" json:"sample_data"`
|
||||
UseCDN bool `yaml:"use_cdn" json:"use_cdn"`
|
||||
DisableColors bool `yaml:"disable_colors" json:"disable_colors"`
|
||||
|
||||
PostgresSSLMode string `yaml:"postgres_ssl" json:"postgres_ssl"`
|
||||
|
||||
Db database.Database `yaml:"-" json:"-"`
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package notifications
|
|||
|
||||
import (
|
||||
"github.com/statping/statping/database"
|
||||
"github.com/statping/statping/types/null"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -34,10 +35,25 @@ func Find(method string) (*Notification, error) {
|
|||
return &n, nil
|
||||
}
|
||||
|
||||
// BeforeCreate is a NULL constraint fix for postgres
|
||||
func (n *Notification) BeforeCreate() error {
|
||||
n.Host = null.NewNullString("")
|
||||
n.Port = null.NewNullInt64(0)
|
||||
n.Username = null.NewNullString("")
|
||||
n.Password = null.NewNullString("")
|
||||
n.Var1 = null.NewNullString("")
|
||||
n.Var2 = null.NewNullString("")
|
||||
n.ApiKey = null.NewNullString("")
|
||||
n.ApiSecret = null.NewNullString("")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *Notification) Create() error {
|
||||
var p Notification
|
||||
q := db.Where("method = ?", n.Method).Find(&p)
|
||||
if q.RecordNotFound() {
|
||||
log.Infof("Notifier %s was not found, adding into database...\n", n.Method)
|
||||
log.Infoln(n.Method, n.Id, n.Title, n.Host.String)
|
||||
if err := db.Create(n).Error(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -38,12 +38,10 @@ type Notification struct {
|
|||
AuthorUrl string `gorm:"-" json:"author_url"`
|
||||
Icon string `gorm:"-" json:"icon"`
|
||||
Delay time.Duration `gorm:"-" json:"delay,string"`
|
||||
Running chan bool `gorm:"-" json:"-"`
|
||||
|
||||
Form []NotificationForm `gorm:"-" json:"form"`
|
||||
LastSent time.Time `gorm:"-" json:"-"`
|
||||
LastSentCount int `gorm:"-" json:"-"`
|
||||
sentCount int `gorm:"-" json:"-"`
|
||||
Logs []*NotificationLog `gorm:"-" json:"logs,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -59,8 +57,6 @@ func (n *Notification) Logger() *logrus.Logger {
|
|||
return log.WithField("notifier", n.Method).Logger
|
||||
}
|
||||
|
||||
type RunFunc func(interface{}) error
|
||||
|
||||
type Values struct {
|
||||
Host string
|
||||
Port int64
|
||||
|
|
|
@ -226,6 +226,7 @@ func SelectAllServices(start bool) (map[int64]*Service, error) {
|
|||
if len(allServices) > 0 {
|
||||
return allServices, nil
|
||||
}
|
||||
log.Infof("Preparing to monitor %d services...\n", len(allServices))
|
||||
for _, s := range all() {
|
||||
s.Failures = s.AllFailures().LastAmount(limitedFailures)
|
||||
s.prevOnline = true
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package utils
|
||||
|
||||
var (
|
||||
StartTime = Now()
|
||||
)
|
Loading…
Reference in New Issue