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)
|
||||
if err != nil {
|
||||
if record {
|
||||
RecordFailure(s, fmt.Sprintf("TCP Dial Error %v", err))
|
||||
recordFailure(s, fmt.Sprintf("TCP Dial Error %v", err))
|
||||
}
|
||||
return s
|
||||
}
|
||||
if err := conn.Close(); err != nil {
|
||||
if record {
|
||||
RecordFailure(s, fmt.Sprintf("TCP Socket Close Error %v", err))
|
||||
recordFailure(s, fmt.Sprintf("TCP Socket Close Error %v", err))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ func (s *Service) checkTcp(record bool) *Service {
|
|||
s.Latency = t2.Sub(t1).Seconds()
|
||||
s.LastResponse = ""
|
||||
if record {
|
||||
RecordSuccess(s)
|
||||
recordSuccess(s)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
|||
dnsLookup, err := s.dnsCheck()
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
|||
}
|
||||
if err != nil {
|
||||
if record {
|
||||
RecordFailure(s, fmt.Sprintf("HTTP Error %v", err))
|
||||
recordFailure(s, fmt.Sprintf("HTTP Error %v", err))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
|||
s.Latency = t2.Sub(t1).Seconds()
|
||||
if err != nil {
|
||||
if record {
|
||||
RecordFailure(s, fmt.Sprintf("HTTP Error %v", err))
|
||||
recordFailure(s, fmt.Sprintf("HTTP Error %v", err))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
|||
s.LastResponse = string(contents)
|
||||
s.LastStatusCode = response.StatusCode
|
||||
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
|
||||
}
|
||||
|
@ -187,14 +187,14 @@ func (s *Service) checkHttp(record bool) *Service {
|
|||
//s.LastResponse = string(contents)
|
||||
s.LastStatusCode = response.StatusCode
|
||||
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
|
||||
}
|
||||
s.LastStatusCode = response.StatusCode
|
||||
s.Online = true
|
||||
if record {
|
||||
RecordSuccess(s)
|
||||
recordSuccess(s)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
@ -209,12 +209,8 @@ func (s *Service) Check(record bool) {
|
|||
}
|
||||
}
|
||||
|
||||
type HitData struct {
|
||||
Latency float64
|
||||
}
|
||||
|
||||
// RecordSuccess will create a new 'hit' record in the database for a successful/online service
|
||||
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.LastOnline = time.Now()
|
||||
hit := &types.Hit{
|
||||
|
@ -227,8 +223,8 @@ func RecordSuccess(s *Service) {
|
|||
notifier.OnSuccess(s.Service)
|
||||
}
|
||||
|
||||
// RecordFailure will create a new 'failure' record in the database for a offline service
|
||||
func RecordFailure(s *Service, issue string) {
|
||||
// recordFailure will create a new 'failure' record in the database for a offline service
|
||||
func recordFailure(s *Service, issue string) {
|
||||
s.Online = false
|
||||
fail := &types.Failure{
|
||||
Service: s.Id,
|
||||
|
|
|
@ -98,34 +98,3 @@ func (f *Checkin) Ago() string {
|
|||
got, _ := timeago.TimeAgoWithTime(time.Now(), f.Last)
|
||||
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"
|
||||
)
|
||||
|
||||
type ErrorResponse struct {
|
||||
Error string
|
||||
}
|
||||
|
||||
// LoadConfig will attempt to load the 'config.yml' file in a specific directory
|
||||
func LoadConfig(directory string) (*DbConfig, error) {
|
||||
var configs *types.DbConfig
|
||||
|
@ -131,7 +135,3 @@ func DeleteConfig() {
|
|||
utils.Log(3, err)
|
||||
}
|
||||
}
|
||||
|
||||
type ErrorResponse struct {
|
||||
Error string
|
||||
}
|
||||
|
|
|
@ -34,9 +34,8 @@ var (
|
|||
DbSession *gorm.DB
|
||||
)
|
||||
|
||||
func (s *Service) allHits() *gorm.DB {
|
||||
var hits []*Hit
|
||||
return servicesDB().Find(s).Related(&hits)
|
||||
type DbConfig struct {
|
||||
*types.DbConfig
|
||||
}
|
||||
|
||||
// failuresDB returns the 'failures' database column
|
||||
|
@ -64,20 +63,12 @@ func usersDB() *gorm.DB {
|
|||
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
|
||||
func checkinDB() *gorm.DB {
|
||||
return DbSession.Model(&types.Checkin{})
|
||||
}
|
||||
|
||||
type DbConfig struct {
|
||||
*types.DbConfig
|
||||
}
|
||||
|
||||
// HitsBetween returns the gorm database query for a collection of service hits between a time range
|
||||
func (s *Service) HitsBetween(t1, t2 time.Time) *gorm.DB {
|
||||
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")
|
||||
|
|
|
@ -59,14 +59,6 @@ func reverseHits(input []*types.Hit) []*types.Hit {
|
|||
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
|
||||
func (s *Service) TotalHits() (uint64, error) {
|
||||
var count uint64
|
||||
|
|
|
@ -112,7 +112,7 @@ func InsertSampleHits() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func InsertSampleCore() error {
|
||||
func insertSampleCore() error {
|
||||
core := &types.Core{
|
||||
Name: "Statup Sample Data",
|
||||
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
|
||||
func InsertLargeSampleData() error {
|
||||
InsertSampleCore()
|
||||
insertSampleCore()
|
||||
InsertSampleData()
|
||||
insertSampleUsers()
|
||||
s6 := ReturnService(&types.Service{
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/hunterlong/statup/core"
|
||||
"github.com/hunterlong/statup/core/notifier"
|
||||
"github.com/hunterlong/statup/source"
|
||||
"github.com/hunterlong/statup/types"
|
||||
"github.com/hunterlong/statup/utils"
|
||||
|
@ -98,7 +99,8 @@ func logsLineHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
type exportData struct {
|
||||
Services []types.ServiceInterface
|
||||
Core *core.Core `json:"core"`
|
||||
Notifiers types.AllNotifiers `json:"notifiers"`
|
||||
}
|
||||
|
||||
func exportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -107,8 +109,19 @@ func exportHandler(w http.ResponseWriter, r *http.Request) {
|
|||
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")
|
||||
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
|
||||
)
|
||||
|
||||
// RunHTTPServer will start a HTTP server on a specific IP and port
|
||||
func RunHTTPServer(ip string, port int) error {
|
||||
host := fmt.Sprintf("%v:%v", ip, port)
|
||||
utils.Log(1, "Statup HTTP Server running on http://"+host)
|
||||
|
@ -62,6 +63,7 @@ func RunHTTPServer(ip string, port int) error {
|
|||
return httpServer.ListenAndServe()
|
||||
}
|
||||
|
||||
// IsAuthenticated returns true if the HTTP request is authenticated
|
||||
func IsAuthenticated(r *http.Request) bool {
|
||||
if os.Getenv("GO_ENV") == "test" {
|
||||
return true
|
||||
|
@ -82,6 +84,7 @@ func IsAuthenticated(r *http.Request) 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{}) {
|
||||
utils.Http(r)
|
||||
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{}) {
|
||||
render, err := source.JsBox.String(file)
|
||||
if err != nil {
|
||||
|
@ -187,9 +191,8 @@ func executeJSResponse(w http.ResponseWriter, r *http.Request, file string, data
|
|||
t.Execute(w, data)
|
||||
}
|
||||
|
||||
// error404Handler is a HTTP handler for 404 error pages
|
||||
func error404Handler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
executeResponse(w, r, "error_404.html", nil, nil)
|
||||
}
|
||||
|
||||
type DbConfig types.DbConfig
|
||||
|
|
Loading…
Reference in New Issue