fixed notifier panic

pull/805/head
hunterlong 2020-08-29 19:02:23 -07:00
parent 3051206a7a
commit ee52eaa96b
10 changed files with 25 additions and 33 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ snap
prime
stage
parts
assets_backup
certs
releases
core/rice-box.go

View File

@ -7,8 +7,8 @@ const tokenKey = "statping_auth";
class Api {
constructor() {
this.version = "0.90.64";
this.commit = "130cc3ede7463ec9af8d62abb84992e2a0ef453c";
this.version = "0.90.65";
this.commit = "3051206a7a843b97c92462a536f1c54ee92fbab8";
}
async oauth() {

View File

@ -2275,7 +2275,7 @@ OluFxewsEO0QNDrfFb+0gnjYlnGqOFcZjUMXbDdY5oLSPtXohynuTK1qyQ==
</div>
<div class="text-center small text-dim" v-pre>
Automatically generated from Statping's Wiki on 2020-08-22 21:27:09.3468 &#43;0000 UTC
Automatically generated from Statping's Wiki on 2020-08-30 00:32:40.685063 &#43;0000 UTC
</div>
</div>

View File

@ -13,17 +13,7 @@ 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)
sendErrorJson(err, w, r)
return
}
updated := no.UpdateFields(notif)
notifs = append(notifs, *updated)
notifs = append(notifs, *n.Select())
}
sort.Sort(notifications.NotificationOrder(notifs))
returnJson(notifs, w, r)

View File

@ -68,12 +68,8 @@ func Router() *mux.Router {
}
if source.UsingAssets(dir) {
indexHandler := http.FileServer(http.Dir(dir + "/assets/"))
r.PathPrefix("/css/").Handler(http.StripPrefix(basePath, staticAssets("css")))
r.PathPrefix("/favicon/").Handler(http.StripPrefix(basePath, staticAssets("favicon")))
r.PathPrefix("/robots.txt").Handler(http.StripPrefix(basePath, indexHandler))
r.PathPrefix("/banner.png").Handler(http.StripPrefix(basePath, indexHandler))
prefixed := http.StripPrefix(basePath+"assets/", http.FileServer(http.Dir(dir+"/assets/")))
r.PathPrefix("/assets/").Handler(prefixed)
} else {
tmplFileSrv := http.FileServer(source.TmplBox.HTTPBox())
tmplBoxHandler := http.StripPrefix(basePath, tmplFileSrv)

View File

@ -37,6 +37,8 @@ func InitNotifiers() {
Gotify,
AmazonSNS,
)
services.UpdateNotifiers()
}
func ReplaceTemplate(tmpl string, data replacer) string {

View File

@ -9,7 +9,6 @@ import (
"github.com/statping/statping/types/null"
"github.com/statping/statping/types/services"
"github.com/statping/statping/utils"
"regexp"
"strings"
"time"
)
@ -94,10 +93,5 @@ func (s *slack) OnSave() (string, error) {
}
func (s *slack) Valid(values notifications.Values) error {
regex := `https\:\/\/hooks\.slack\.com/services/[A-Z0-9]{7,11}/[A-Z0-9]{7,11}/[a-zA-Z0-9]{20,22}`
r := regexp.MustCompile(regex)
if !r.MatchString(values.Host) {
return errors.New("slack webhook does not match with expected regex " + regex)
}
return nil
}

View File

@ -25,6 +25,15 @@ func (n *Notification) Values() Values {
}
}
func All() []*Notification {
var n []*Notification
q := db.Find(&n)
if q.Error() != nil {
return nil
}
return n
}
func Find(method string) (*Notification, error) {
var n Notification
q := db.Where("method = ?", method).Find(&n)

View File

@ -6,13 +6,6 @@ import (
"gopkg.in/yaml.v2"
)
func (s NullString) Scan(value interface{}) error {
if s.Valid {
s.String = value.(string)
}
return nil
}
func (s NullString) Value() (driver.Value, error) {
return s.String, nil
}

View File

@ -11,6 +11,13 @@ func AddNotifier(n ServiceNotifier) {
allNotifiers[notif.Method] = n
}
func UpdateNotifiers() {
for _, n := range notifications.All() {
notifier := allNotifiers[n.Method]
notifier.Select().UpdateFields(n)
}
}
func sendSuccess(s *Service) {
if !s.AllowNotifications.Bool {
return