mirror of https://github.com/statping/statping
Merge d8c12c77e8
into fd889a14c0
commit
79602055e1
|
@ -3,13 +3,14 @@ package handlers
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/statping/statping/types/errors"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/statping/statping/source"
|
"github.com/statping/statping/source"
|
||||||
|
"github.com/statping/statping/types/errors"
|
||||||
|
"github.com/statping/statping/types/services"
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -202,6 +203,23 @@ func returnJson(d interface{}, w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(d)
|
json.NewEncoder(w).Encode(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func returnLastResponse(s *services.Service, w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Go does not currently
|
||||||
|
// support sending user-defined 1xx informational headers,
|
||||||
|
// with the exception of 100-continue response header that the
|
||||||
|
// Server sends automatically when the Request.Body is read.
|
||||||
|
// https://golang.org/src/net/http/server.go?s=3003:5866#L150
|
||||||
|
|
||||||
|
if s.LastStatusCode >= 100 {
|
||||||
|
w.WriteHeader(s.LastStatusCode)
|
||||||
|
w.Write([]byte(s.DownText))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusTeapot)
|
||||||
|
w.Write([]byte("☄ Last Status Code Not Set!"))
|
||||||
|
}
|
||||||
|
|
||||||
// error404Handler is a HTTP handler for 404 error pages
|
// error404Handler is a HTTP handler for 404 error pages
|
||||||
func error404Handler(w http.ResponseWriter, r *http.Request) {
|
func error404Handler(w http.ResponseWriter, r *http.Request) {
|
||||||
if usingSSL {
|
if usingSSL {
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/statping/statping/source"
|
"github.com/statping/statping/source"
|
||||||
"github.com/statping/statping/types/core"
|
"github.com/statping/statping/types/core"
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
"net/http"
|
|
||||||
"net/http/pprof"
|
|
||||||
|
|
||||||
_ "github.com/statping/statping/types/metrics"
|
_ "github.com/statping/statping/types/metrics"
|
||||||
)
|
)
|
||||||
|
@ -127,6 +128,7 @@ func Router() *mux.Router {
|
||||||
api.Handle("/api/services/{id}/failures", authenticated(servicesDeleteFailuresHandler, false)).Methods("DELETE")
|
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", scoped(apiServiceHitsHandler)).Methods("GET")
|
||||||
api.Handle("/api/services/{id}/hits", authenticated(apiServiceHitsDeleteHandler, false)).Methods("DELETE")
|
api.Handle("/api/services/{id}/hits", authenticated(apiServiceHitsDeleteHandler, false)).Methods("DELETE")
|
||||||
|
api.Handle("/api/services/{id}/lastresponse", authenticated(apiServiceLastResponseHandler, false)).Methods("GET")
|
||||||
|
|
||||||
// API SERVICE CHART DATA Routes
|
// API SERVICE CHART DATA Routes
|
||||||
api.Handle("/api/services/{id}/hits_data", http.HandlerFunc(apiServiceDataHandler)).Methods("GET")
|
api.Handle("/api/services/{id}/hits_data", http.HandlerFunc(apiServiceDataHandler)).Methods("GET")
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/statping/statping/database"
|
"github.com/statping/statping/database"
|
||||||
"github.com/statping/statping/types/errors"
|
"github.com/statping/statping/types/errors"
|
||||||
|
@ -8,7 +10,6 @@ import (
|
||||||
"github.com/statping/statping/types/hits"
|
"github.com/statping/statping/types/hits"
|
||||||
"github.com/statping/statping/types/services"
|
"github.com/statping/statping/types/services"
|
||||||
"github.com/statping/statping/utils"
|
"github.com/statping/statping/utils"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type serviceOrder struct {
|
type serviceOrder struct {
|
||||||
|
@ -317,3 +318,14 @@ func apiServiceHitsHandler(r *http.Request) interface{} {
|
||||||
query.Find(&hts)
|
query.Find(&hts)
|
||||||
return hts
|
return hts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func apiServiceLastResponseHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
service, err := findService(r)
|
||||||
|
if err != nil {
|
||||||
|
sendErrorJson(err, w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
returnLastResponse(service, w, r)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue