mirror of https://github.com/statping/statping
remove unused
parent
ed1abd31d9
commit
24ccf94e3d
|
@ -106,13 +106,13 @@ func (s *Service) checkTcp(record bool) *Service {
|
||||||
conn, err := net.DialTimeout("tcp", domain, time.Duration(s.Timeout)*time.Second)
|
conn, err := net.DialTimeout("tcp", domain, time.Duration(s.Timeout)*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if record {
|
if record {
|
||||||
RecordFailure(s, fmt.Sprintf("TCP Dial Error %v", err))
|
recordFailure(s, fmt.Sprintf("TCP Dial Error %v", err))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
if err := conn.Close(); err != nil {
|
if err := conn.Close(); err != nil {
|
||||||
if record {
|
if record {
|
||||||
RecordFailure(s, fmt.Sprintf("TCP Socket Close Error %v", err))
|
recordFailure(s, fmt.Sprintf("TCP Socket Close Error %v", err))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func (s *Service) checkTcp(record bool) *Service {
|
||||||
s.Latency = t2.Sub(t1).Seconds()
|
s.Latency = t2.Sub(t1).Seconds()
|
||||||
s.LastResponse = ""
|
s.LastResponse = ""
|
||||||
if record {
|
if record {
|
||||||
RecordSuccess(s)
|
recordSuccess(s)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
dnsLookup, err := s.dnsCheck()
|
dnsLookup, err := s.dnsCheck()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if record {
|
if record {
|
||||||
RecordFailure(s, fmt.Sprintf("Could not get IP address for domain %v, %v", s.Domain, err))
|
recordFailure(s, fmt.Sprintf("Could not get IP address for domain %v, %v", s.Domain, err))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if record {
|
if record {
|
||||||
RecordFailure(s, fmt.Sprintf("HTTP Error %v", err))
|
recordFailure(s, fmt.Sprintf("HTTP Error %v", err))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
s.Latency = t2.Sub(t1).Seconds()
|
s.Latency = t2.Sub(t1).Seconds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if record {
|
if record {
|
||||||
RecordFailure(s, fmt.Sprintf("HTTP Error %v", err))
|
recordFailure(s, fmt.Sprintf("HTTP Error %v", err))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
s.LastResponse = string(contents)
|
s.LastResponse = string(contents)
|
||||||
s.LastStatusCode = response.StatusCode
|
s.LastStatusCode = response.StatusCode
|
||||||
if record {
|
if record {
|
||||||
RecordFailure(s, fmt.Sprintf("HTTP Response Body did not match '%v'", s.Expected))
|
recordFailure(s, fmt.Sprintf("HTTP Response Body did not match '%v'", s.Expected))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -187,14 +187,14 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
//s.LastResponse = string(contents)
|
//s.LastResponse = string(contents)
|
||||||
s.LastStatusCode = response.StatusCode
|
s.LastStatusCode = response.StatusCode
|
||||||
if record {
|
if record {
|
||||||
RecordFailure(s, fmt.Sprintf("HTTP Status Code %v did not match %v", response.StatusCode, s.ExpectedStatus))
|
recordFailure(s, fmt.Sprintf("HTTP Status Code %v did not match %v", response.StatusCode, s.ExpectedStatus))
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
s.LastStatusCode = response.StatusCode
|
s.LastStatusCode = response.StatusCode
|
||||||
s.Online = true
|
s.Online = true
|
||||||
if record {
|
if record {
|
||||||
RecordSuccess(s)
|
recordSuccess(s)
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -209,12 +209,8 @@ func (s *Service) Check(record bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type HitData struct {
|
// recordSuccess will create a new 'hit' record in the database for a successful/online service
|
||||||
Latency float64
|
func recordSuccess(s *Service) {
|
||||||
}
|
|
||||||
|
|
||||||
// RecordSuccess will create a new 'hit' record in the database for a successful/online service
|
|
||||||
func RecordSuccess(s *Service) {
|
|
||||||
s.Online = true
|
s.Online = true
|
||||||
s.LastOnline = time.Now()
|
s.LastOnline = time.Now()
|
||||||
hit := &types.Hit{
|
hit := &types.Hit{
|
||||||
|
@ -227,8 +223,8 @@ func RecordSuccess(s *Service) {
|
||||||
notifier.OnSuccess(s.Service)
|
notifier.OnSuccess(s.Service)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecordFailure will create a new 'failure' record in the database for a offline service
|
// recordFailure will create a new 'failure' record in the database for a offline service
|
||||||
func RecordFailure(s *Service, issue string) {
|
func recordFailure(s *Service, issue string) {
|
||||||
s.Online = false
|
s.Online = false
|
||||||
fail := &types.Failure{
|
fail := &types.Failure{
|
||||||
Service: s.Id,
|
Service: s.Id,
|
||||||
|
|
|
@ -98,34 +98,3 @@ func (f *Checkin) Ago() string {
|
||||||
got, _ := timeago.TimeAgoWithTime(time.Now(), f.Last)
|
got, _ := timeago.TimeAgoWithTime(time.Now(), f.Last)
|
||||||
return got
|
return got
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (c *Checkin) Run() {
|
|
||||||
// if c.Interval == 0 {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// fmt.Println("checking: ", c.Api)
|
|
||||||
// between := time.Now().Sub(c.Last).Seconds()
|
|
||||||
// if between > float64(c.Interval) {
|
|
||||||
// guard := make(chan struct{})
|
|
||||||
// c.RecheckCheckinFailure(guard)
|
|
||||||
// <-guard
|
|
||||||
// }
|
|
||||||
// time.Sleep(1 * time.Second)
|
|
||||||
// c.Run()
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s *Service) StartCheckins() {
|
|
||||||
// for _, c := range s.Checkins {
|
|
||||||
// checkin := c.(*Checkin)
|
|
||||||
// go checkin.Run()
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func CheckinProcess() {
|
|
||||||
// for _, s := range CoreApp.DbServices {
|
|
||||||
// for _, c := range s.Checkins {
|
|
||||||
// checkin := c
|
|
||||||
// go checkin.Run()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
|
@ -25,6 +25,10 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ErrorResponse struct {
|
||||||
|
Error string
|
||||||
|
}
|
||||||
|
|
||||||
// LoadConfig will attempt to load the 'config.yml' file in a specific directory
|
// LoadConfig will attempt to load the 'config.yml' file in a specific directory
|
||||||
func LoadConfig(directory string) (*DbConfig, error) {
|
func LoadConfig(directory string) (*DbConfig, error) {
|
||||||
var configs *types.DbConfig
|
var configs *types.DbConfig
|
||||||
|
@ -131,7 +135,3 @@ func DeleteConfig() {
|
||||||
utils.Log(3, err)
|
utils.Log(3, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorResponse struct {
|
|
||||||
Error string
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,9 +34,8 @@ var (
|
||||||
DbSession *gorm.DB
|
DbSession *gorm.DB
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) allHits() *gorm.DB {
|
type DbConfig struct {
|
||||||
var hits []*Hit
|
*types.DbConfig
|
||||||
return servicesDB().Find(s).Related(&hits)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// failuresDB returns the 'failures' database column
|
// failuresDB returns the 'failures' database column
|
||||||
|
@ -64,20 +63,12 @@ func usersDB() *gorm.DB {
|
||||||
return DbSession.Model(&types.User{})
|
return DbSession.Model(&types.User{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// commDB returns the 'communications' database column
|
|
||||||
func commDB() *gorm.DB {
|
|
||||||
return DbSession.Model(¬ifier.Notification{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// hitsDB returns the 'hits' database column
|
// hitsDB returns the 'hits' database column
|
||||||
func checkinDB() *gorm.DB {
|
func checkinDB() *gorm.DB {
|
||||||
return DbSession.Model(&types.Checkin{})
|
return DbSession.Model(&types.Checkin{})
|
||||||
}
|
}
|
||||||
|
|
||||||
type DbConfig struct {
|
// HitsBetween returns the gorm database query for a collection of service hits between a time range
|
||||||
*types.DbConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) HitsBetween(t1, t2 time.Time) *gorm.DB {
|
func (s *Service) HitsBetween(t1, t2 time.Time) *gorm.DB {
|
||||||
selector := Dbtimestamp(3600)
|
selector := Dbtimestamp(3600)
|
||||||
return DbSession.Debug().Model(&types.Hit{}).Select(selector).Where("service = ? AND created_at BETWEEN ? AND ?", s.Id, t1.UTC().Format(types.TIME), t2.UTC().Format(types.TIME)).Group("timeframe")
|
return DbSession.Debug().Model(&types.Hit{}).Select(selector).Where("service = ? AND created_at BETWEEN ? AND ?", s.Id, t1.UTC().Format(types.TIME), t2.UTC().Format(types.TIME)).Group("timeframe")
|
||||||
|
|
|
@ -59,14 +59,6 @@ func reverseHits(input []*types.Hit) []*types.Hit {
|
||||||
return append(reverseHits(input[1:]), input[0])
|
return append(reverseHits(input[1:]), input[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectHitsGroupBy returns all hits from the group by function
|
|
||||||
func (s *Service) SelectHitsGroupBy(group string) ([]*types.Hit, error) {
|
|
||||||
var hits []*types.Hit
|
|
||||||
col := hitsDB().Where("service = ?", s.Id)
|
|
||||||
err := col.Find(&hits)
|
|
||||||
return hits, err.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
// TotalHits returns the total amount of successful hits a service has
|
// TotalHits returns the total amount of successful hits a service has
|
||||||
func (s *Service) TotalHits() (uint64, error) {
|
func (s *Service) TotalHits() (uint64, error) {
|
||||||
var count uint64
|
var count uint64
|
||||||
|
|
|
@ -112,7 +112,7 @@ func InsertSampleHits() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InsertSampleCore() error {
|
func insertSampleCore() error {
|
||||||
core := &types.Core{
|
core := &types.Core{
|
||||||
Name: "Statup Sample Data",
|
Name: "Statup Sample Data",
|
||||||
Description: "This data is only used to testing",
|
Description: "This data is only used to testing",
|
||||||
|
@ -148,7 +148,7 @@ func insertSampleUsers() {
|
||||||
|
|
||||||
// InsertSampleData will create the example/dummy services for a brand new Statup installation
|
// InsertSampleData will create the example/dummy services for a brand new Statup installation
|
||||||
func InsertLargeSampleData() error {
|
func InsertLargeSampleData() error {
|
||||||
InsertSampleCore()
|
insertSampleCore()
|
||||||
InsertSampleData()
|
InsertSampleData()
|
||||||
insertSampleUsers()
|
insertSampleUsers()
|
||||||
s6 := ReturnService(&types.Service{
|
s6 := ReturnService(&types.Service{
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hunterlong/statup/core"
|
"github.com/hunterlong/statup/core"
|
||||||
|
"github.com/hunterlong/statup/core/notifier"
|
||||||
"github.com/hunterlong/statup/source"
|
"github.com/hunterlong/statup/source"
|
||||||
"github.com/hunterlong/statup/types"
|
"github.com/hunterlong/statup/types"
|
||||||
"github.com/hunterlong/statup/utils"
|
"github.com/hunterlong/statup/utils"
|
||||||
|
@ -98,7 +99,8 @@ func logsLineHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type exportData struct {
|
type exportData struct {
|
||||||
Services []types.ServiceInterface
|
Core *core.Core `json:"core"`
|
||||||
|
Notifiers types.AllNotifiers `json:"notifiers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportHandler(w http.ResponseWriter, r *http.Request) {
|
func exportHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -107,8 +109,19 @@ func exportHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := exportData{core.CoreApp.Services}
|
var notifiers []*notifier.Notification
|
||||||
|
for _, v := range core.CoreApp.Notifications {
|
||||||
|
notifier := v.(notifier.Notifier)
|
||||||
|
notifiers = append(notifiers, notifier.Select())
|
||||||
|
}
|
||||||
|
|
||||||
|
data := exportData{core.CoreApp, notifiers}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(data)
|
json.NewEncoder(w).Encode(data)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Disposition", "attachment; filename=Wiki.png")
|
||||||
|
w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
|
||||||
|
w.Header().Set("Content-Length", r.Header.Get("Content-Length"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ var (
|
||||||
httpServer *http.Server
|
httpServer *http.Server
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RunHTTPServer will start a HTTP server on a specific IP and port
|
||||||
func RunHTTPServer(ip string, port int) error {
|
func RunHTTPServer(ip string, port int) error {
|
||||||
host := fmt.Sprintf("%v:%v", ip, port)
|
host := fmt.Sprintf("%v:%v", ip, port)
|
||||||
utils.Log(1, "Statup HTTP Server running on http://"+host)
|
utils.Log(1, "Statup HTTP Server running on http://"+host)
|
||||||
|
@ -62,6 +63,7 @@ func RunHTTPServer(ip string, port int) error {
|
||||||
return httpServer.ListenAndServe()
|
return httpServer.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsAuthenticated returns true if the HTTP request is authenticated
|
||||||
func IsAuthenticated(r *http.Request) bool {
|
func IsAuthenticated(r *http.Request) bool {
|
||||||
if os.Getenv("GO_ENV") == "test" {
|
if os.Getenv("GO_ENV") == "test" {
|
||||||
return true
|
return true
|
||||||
|
@ -82,6 +84,7 @@ func IsAuthenticated(r *http.Request) bool {
|
||||||
return session.Values["authenticated"].(bool)
|
return session.Values["authenticated"].(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// executeResponse will render a HTTP response for the front end user
|
||||||
func executeResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}, redirect interface{}) {
|
func executeResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}, redirect interface{}) {
|
||||||
utils.Http(r)
|
utils.Http(r)
|
||||||
if url, ok := redirect.(string); ok {
|
if url, ok := redirect.(string); ok {
|
||||||
|
@ -172,6 +175,7 @@ func executeResponse(w http.ResponseWriter, r *http.Request, file string, data i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// executeJSResponse will render a Javascript response
|
||||||
func executeJSResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}) {
|
func executeJSResponse(w http.ResponseWriter, r *http.Request, file string, data interface{}) {
|
||||||
render, err := source.JsBox.String(file)
|
render, err := source.JsBox.String(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -187,9 +191,8 @@ func executeJSResponse(w http.ResponseWriter, r *http.Request, file string, data
|
||||||
t.Execute(w, data)
|
t.Execute(w, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
executeResponse(w, r, "error_404.html", nil, nil)
|
executeResponse(w, r, "error_404.html", nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DbConfig types.DbConfig
|
|
||||||
|
|
Loading…
Reference in New Issue