changed stuff

pull/1097/head
Rhythm 2022-02-25 14:47:45 +05:30
parent a21b72b154
commit 48decee356
2 changed files with 9 additions and 7 deletions

View File

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

View File

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