Browse Source

fixed notifier panic

pull/805/head
hunterlong 2 years ago
parent
commit
ee52eaa96b
  1. 1
      .gitignore
  2. 4
      frontend/src/API.js
  3. 2
      frontend/src/pages/Help.vue
  4. 12
      handlers/notifications.go
  5. 8
      handlers/routes.go
  6. 2
      notifiers/notifiers.go
  7. 6
      notifiers/slack.go
  8. 9
      types/notifications/database.go
  9. 7
      types/null/marshal.go
  10. 7
      types/services/notifications.go

1
.gitignore vendored

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

4
frontend/src/API.js

@ -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() {

2
frontend/src/pages/Help.vue

@ -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>

12
handlers/notifications.go

@ -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)

8
handlers/routes.go

@ -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)

2
notifiers/notifiers.go

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

6
notifiers/slack.go

@ -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
}

9
types/notifications/database.go

@ -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)

7
types/null/marshal.go

@ -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
}

7
types/services/notifications.go

@ -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

Loading…
Cancel
Save