From 8c0543a16198c0c91e3d4d4fe22749ce90676b70 Mon Sep 17 00:00:00 2001 From: hunterlong Date: Tue, 25 Aug 2020 13:38:47 -0700 Subject: [PATCH] notifier panic fix --- CHANGELOG.md | 3 +++ database/grouping.go | 22 +++++++++++----------- handlers/notifications.go | 10 ++++++++-- handlers/routes.go | 1 + handlers/services.go | 13 +++++++++++++ types/checkins/database_hits.go | 2 +- types/incidents/database.go | 2 +- version.txt | 2 +- 8 files changed, 39 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 588e4c25..3f9e1466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.90.65 (08-24-2020) +- Fixed issue with dashboard not logging in (notifier panic) + # 0.90.64 (08-18-2020) - Modified max-width for container to 1012px, larger UI - Added failure sparklines in the Services list view diff --git a/database/grouping.go b/database/grouping.go index ff953e24..28bce658 100644 --- a/database/grouping.go +++ b/database/grouping.go @@ -70,19 +70,19 @@ func (t *TimeVar) ToValues() ([]*TimeValue, error) { } // GraphData will return all hits or failures -func (g *GroupQuery) GraphData(by By) ([]*TimeValue, error) { - g.db = g.db.MultipleSelects( - g.db.SelectByTime(g.Group), +func (b *GroupQuery) GraphData(by By) ([]*TimeValue, error) { + b.db = b.db.MultipleSelects( + b.db.SelectByTime(b.Group), by.String(), ).Group("timeframe").Order("timeframe", true) - caller, err := g.ToTimeValue() + caller, err := b.ToTimeValue() if err != nil { return nil, err } - if g.FillEmpty { - return caller.FillMissing(g.Start, g.End) + if b.FillEmpty { + return caller.FillMissing(b.Start, b.End) } return caller.ToValues() } @@ -90,8 +90,8 @@ func (g *GroupQuery) GraphData(by By) ([]*TimeValue, error) { // ToTimeValue will format the SQL rows into a JSON format for the API. // [{"timestamp": "2006-01-02T15:04:05Z", "amount": 468293}] // TODO redo this entire function, use better SQL query to group by time -func (g *GroupQuery) ToTimeValue() (*TimeVar, error) { - rows, err := g.db.Rows() +func (b *GroupQuery) ToTimeValue() (*TimeVar, error) { + rows, err := b.db.Rows() if err != nil { return nil, err } @@ -102,8 +102,8 @@ func (g *GroupQuery) ToTimeValue() (*TimeVar, error) { if err := rows.Scan(&timeframe, &amount); err != nil { log.Error(err, timeframe) } - trueTime, _ := g.db.ParseTime(timeframe) - newTs := types.FixedTime(trueTime, g.Group) + trueTime, _ := b.db.ParseTime(timeframe) + newTs := types.FixedTime(trueTime, b.Group) tv := &TimeValue{ Timeframe: newTs, @@ -111,7 +111,7 @@ func (g *GroupQuery) ToTimeValue() (*TimeVar, error) { } data = append(data, tv) } - return &TimeVar{g, data}, nil + return &TimeVar{b, data}, nil } func (t *TimeVar) FillMissing(current, end time.Time) ([]*TimeValue, error) { diff --git a/handlers/notifications.go b/handlers/notifications.go index 5f2c3dd6..81ed915f 100644 --- a/handlers/notifications.go +++ b/handlers/notifications.go @@ -14,8 +14,14 @@ func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) { var notifs []notifications.Notification for _, n := range services.AllNotifiers() { no := n.Select() - notif, _ := notifications.Find(no.Method) - notifs = append(notifs, *no.UpdateFields(notif)) + 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) } sort.Sort(notifications.NotificationOrder(notifs)) returnJson(notifs, w, r) diff --git a/handlers/routes.go b/handlers/routes.go index 346583e1..8254101f 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -132,6 +132,7 @@ func Router() *mux.Router { api.Handle("/api/services/{id}/failures", scoped(apiServiceFailuresHandler)).Methods("GET") api.Handle("/api/services/{id}/failures", authenticated(servicesDeleteFailuresHandler, false)).Methods("DELETE") api.Handle("/api/services/{id}/hits", scoped(apiServiceHitsHandler)).Methods("GET") + api.Handle("/api/services/{id}/hits", authenticated(apiServiceHitsDeleteHandler, false)).Methods("DELETE") // API SERVICE CHART DATA Routes api.Handle("/api/services/{id}/hits_data", cached("30s", "application/json", apiServiceDataHandler)).Methods("GET") diff --git a/handlers/services.go b/handlers/services.go index 37bc682f..135ddccf 100644 --- a/handlers/services.go +++ b/handlers/services.go @@ -237,6 +237,19 @@ func apiServiceTimeDataHandler(w http.ResponseWriter, r *http.Request) { returnJson(uptimeData, w, r) } +func apiServiceHitsDeleteHandler(w http.ResponseWriter, r *http.Request) { + service, err := findService(r) + if err != nil { + sendErrorJson(err, w, r) + return + } + if err := service.AllHits().DeleteAll(); err != nil { + sendErrorJson(err, w, r) + return + } + sendJsonAction(service, "delete", w, r) +} + func apiServiceDeleteHandler(w http.ResponseWriter, r *http.Request) { service, err := findService(r) if err != nil { diff --git a/types/checkins/database_hits.go b/types/checkins/database_hits.go index bcea292c..b97c926d 100644 --- a/types/checkins/database_hits.go +++ b/types/checkins/database_hits.go @@ -8,7 +8,7 @@ func (c *Checkin) LastHit() *CheckinHit { func (c *Checkin) Hits() []*CheckinHit { var hits []*CheckinHit - dbHits.Where("checkin = ?", c.Id).Order("DESC").Find(&hits) + dbHits.Where("checkin = ?", c.Id).Order("id DESC").Find(&hits) c.AllHits = hits return hits } diff --git a/types/incidents/database.go b/types/incidents/database.go index 315ba06b..7260cb61 100644 --- a/types/incidents/database.go +++ b/types/incidents/database.go @@ -34,7 +34,7 @@ func (i *Incident) BeforeCreate() error { } func (i *Incident) AfterFind() { - db.Model(i).Related(&i.Updates).Order("DESC") + db.Model(i).Related(&i.Updates).Order("id DESC") metrics.Query("incident", "find") } diff --git a/version.txt b/version.txt index e23d7df8..18dfe4ba 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.90.64 +0.90.65