diff --git a/Dockerfile b/Dockerfile index e707ada1..d972f408 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,6 +28,6 @@ WORKDIR /app VOLUME /app EXPOSE $PORT -HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl -s "http://localhost:$PORT/health" | jq -r -e ".online==true" +HEALTHCHECK --interval=60s --timeout=10s --retries=3 CMD curl -s "http://localhost:$PORT/health" | jq -r -e ".online==true" CMD statping -port $PORT diff --git a/core/database.go b/core/database.go index da127124..4b4bb9f8 100644 --- a/core/database.go +++ b/core/database.go @@ -253,9 +253,11 @@ func (c *Core) Connect(retry bool, location string) error { } } log.WithFields(utils.ToFields(dbSession)).Debugln("connected to database") - if dbType == "sqlite3" { - dbSession.DB().SetMaxOpenConns(1) - } + + dbSession.DB().SetMaxOpenConns(5) + dbSession.DB().SetMaxIdleConns(5) + dbSession.DB().SetConnMaxLifetime(1 * time.Minute) + if dbSession.DB().Ping() == nil { DbSession = dbSession if utils.VerboseMode >= 4 { diff --git a/handlers/handlers.go b/handlers/handlers.go index 4887889f..1e54a6dd 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -194,7 +194,6 @@ func loadTemplate(w http.ResponseWriter, r *http.Request) error { return err } // render all templates - mainTemplate.Funcs(handlerFuncs(w, r)) for _, temp := range templates { tmp, _ := source.TmplBox.String(temp) mainTemplate, err = mainTemplate.Parse(tmp) diff --git a/handlers/middleware.go b/handlers/middleware.go index cdfd9edf..02c6df44 100644 --- a/handlers/middleware.go +++ b/handlers/middleware.go @@ -33,10 +33,9 @@ func basicAuthHandler(next http.Handler) http.Handler { } // sendLog is a http middleware that will log the duration of request and other useful fields -func sendLog(handler func(w http.ResponseWriter, r *http.Request)) http.Handler { +func sendLog(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { t1 := utils.Now() - handler(w, r) t2 := utils.Now().Sub(t1) if r.RequestURI == "/logs/line" { return @@ -46,6 +45,7 @@ func sendLog(handler func(w http.ResponseWriter, r *http.Request)) http.Handler WithField("method", r.Method). WithField("load_micro_seconds", t2.Microseconds()). Infoln(fmt.Sprintf("%v (%v) | IP: %v", r.RequestURI, r.Method, r.Host)) + next.ServeHTTP(w, r) }) } diff --git a/handlers/routes.go b/handlers/routes.go index 7770b0d6..343a3b23 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -38,13 +38,14 @@ var ( func Router() *mux.Router { dir := utils.Directory CacheStorage = NewStorage() - r := mux.NewRouter() + r := mux.NewRouter().StrictSlash(true) if os.Getenv("AUTH_USERNAME") != "" && os.Getenv("AUTH_PASSWORD") != "" { authUser = os.Getenv("AUTH_USERNAME") authPass = os.Getenv("AUTH_PASSWORD") r.Use(basicAuthHandler) } - r.Handle("/", sendLog(indexHandler)) + r.Use(sendLog) + r.Handle("/", http.HandlerFunc(indexHandler)) if source.UsingAssets(dir) { indexHandler := http.FileServer(http.Dir(dir + "/assets/")) r.PathPrefix("/css/").Handler(http.StripPrefix("/css/", http.FileServer(http.Dir(dir+"/assets/css")))) @@ -61,12 +62,12 @@ func Router() *mux.Router { r.PathPrefix("/favicon.ico").Handler(http.FileServer(source.TmplBox.HTTPBox())) r.PathPrefix("/banner.png").Handler(http.FileServer(source.TmplBox.HTTPBox())) } - r.Handle("/charts.js", sendLog(renderServiceChartsHandler)) - r.Handle("/setup", sendLog(setupHandler)).Methods("GET") - r.Handle("/setup", sendLog(processSetupHandler)).Methods("POST") - r.Handle("/dashboard", sendLog(dashboardHandler)).Methods("GET") - r.Handle("/dashboard", sendLog(loginHandler)).Methods("POST") - r.Handle("/logout", sendLog(logoutHandler)) + r.Handle("/charts.js", http.HandlerFunc(renderServiceChartsHandler)) + r.Handle("/setup", http.HandlerFunc(setupHandler)).Methods("GET") + r.Handle("/setup", http.HandlerFunc(processSetupHandler)).Methods("POST") + r.Handle("/dashboard", http.HandlerFunc(dashboardHandler)).Methods("GET") + r.Handle("/dashboard", http.HandlerFunc(loginHandler)).Methods("POST") + r.Handle("/logout", http.HandlerFunc(logoutHandler)) r.Handle("/plugins/download/{name}", authenticated(pluginsDownloadHandler, true)) r.Handle("/plugins/{name}/save", authenticated(pluginSavedHandler, true)).Methods("POST") r.Handle("/help", authenticated(helpHandler, true)) @@ -97,11 +98,11 @@ func Router() *mux.Router { // SERVICE Routes r.Handle("/services", authenticated(servicesHandler, true)).Methods("GET") r.Handle("/service/create", authenticated(createServiceHandler, true)).Methods("GET") - r.Handle("/service/{id}", sendLog(servicesViewHandler)).Methods("GET") + r.Handle("/service/{id}", readOnly(servicesViewHandler, true)).Methods("GET") r.Handle("/service/{id}/edit", authenticated(servicesViewHandler, true)).Methods("GET") r.Handle("/service/{id}/delete_failures", authenticated(servicesDeleteFailuresHandler, true)).Methods("GET") - r.Handle("/group/{id}", sendLog(groupViewHandler)).Methods("GET") + r.Handle("/group/{id}", http.HandlerFunc(groupViewHandler)).Methods("GET") // API Routes r.Handle("/api", authenticated(apiIndexHandler, false)) @@ -163,7 +164,7 @@ func Router() *mux.Router { r.Handle("/api/checkin/{api}", authenticated(apiCheckinHandler, false)).Methods("GET") r.Handle("/api/checkin", authenticated(checkinCreateHandler, false)).Methods("POST") r.Handle("/api/checkin/{api}", authenticated(checkinDeleteHandler, false)).Methods("DELETE") - r.Handle("/checkin/{api}", sendLog(checkinHitHandler)) + r.Handle("/checkin/{api}", http.HandlerFunc(checkinHitHandler)) // Static Files Routes r.PathPrefix("/files/postman.json").Handler(http.StripPrefix("/files/", http.FileServer(source.TmplBox.HTTPBox()))) @@ -172,10 +173,10 @@ func Router() *mux.Router { // API Generic Routes r.Handle("/metrics", readOnly(prometheusHandler, false)) - r.Handle("/health", sendLog(healthCheckHandler)) + r.Handle("/health", http.HandlerFunc(healthCheckHandler)) r.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.Dir(dir+"/.well-known")))) - r.NotFoundHandler = sendLog(error404Handler) + r.NotFoundHandler = http.HandlerFunc(error404Handler) return r } diff --git a/notifiers/mobile.go b/notifiers/mobile.go index 277d10f7..4d193bb4 100644 --- a/notifiers/mobile.go +++ b/notifiers/mobile.go @@ -117,12 +117,6 @@ func (u *mobilePush) OnSuccess(s *types.Service) { // OnSave triggers when this notifier has been saved func (u *mobilePush) OnSave() error { - msg := &pushArray{ - Message: "The Mobile Notifier has been saved", - Title: "Notification Saved", - Topic: mobileIdentifier, - } - u.AddQueue("saved", msg) return nil } diff --git a/version.txt b/version.txt index 996d8ee8..65d19681 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.80.69 +0.80.70