From 48decee356195b1bc9b2bc7a99d729a07d6ea10d Mon Sep 17 00:00:00 2001 From: Rhythm <35167328+kRhythm@users.noreply.github.com> Date: Fri, 25 Feb 2022 14:47:45 +0530 Subject: [PATCH] changed stuff --- handlers/services.go | 10 ++++++---- types/downtimes/database.go | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/handlers/services.go b/handlers/services.go index 0b2829d7..6e97420d 100644 --- a/handlers/services.go +++ b/handlers/services.go @@ -550,12 +550,14 @@ func apiAllServicesStatusHandler(w http.ResponseWriter, r *http.Request) { dtime := downtimes.FindDowntime2() log.Println("FindDowntime2 results") log.Println(dtime) - /*for i := 0; i < len(dtime); i+=1 { + fmt.Println(dtime) + for i := 0; i < len(dtime); i+=1 { downtimeVar := dtime[i] serviceVar, _ := services.Find(downtimeVar.ServiceId) - - m[downtimeVar.ServiceId] = downtimeVar - }*/ + if serviceVar.Online ==false { + m[downtimeVar.ServiceId] = downtimeVar + } + } } else { dtime := findAllDowntimes(t) for i := 0; i < len(dtime); i += 1 { diff --git a/types/downtimes/database.go b/types/downtimes/database.go index 62a7a600..b14fe553 100644 --- a/types/downtimes/database.go +++ b/types/downtimes/database.go @@ -67,9 +67,9 @@ func FindDowntime(timeVar time.Time) []Downtime { return downtime } -func FindDowntime2() interface{} { - var downtime interface{} - db.Raw("SELECT DISTINCT ON (downtimes.service) downtimes.* FROM downtimes ORDER BY service ASC, start DESC;").Scan(&downtime) +func FindDowntime2() []Downtime { + var downtime []Downtime + db.Raw("select d1.* from downtimes d1 left join downtimes d2 on d1.service = d2.service and d2.start > d1.start where d2.service is NULL;").Scan(&downtime) //db.Select("downtimes.*").Joins("left join downtimes as d2 on d2.service = downtimes.service AND downtimes.start < d2.start").Where("d2.end = ?",nil).Find(&downtime) return downtime }