Skip to content

Commit

Permalink
Merge branch 'master' into mysql-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Jun 6, 2019
2 parents bc5edac + 98190a2 commit 0439462
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 227 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -232,6 +232,7 @@ dev-deps:
$(GOGET) github.com/ararog/timeago
$(GOGET) gopkg.in/natefinch/lumberjack.v2
$(GOGET) golang.org/x/crypto/bcrypt
$(GOGET) github.com/99designs/gqlgen

# remove files for a clean compile/build
clean:
Expand Down Expand Up @@ -261,6 +262,7 @@ tag:

generate:
cd source && go generate
cd handlers/graphql && go generate

# compress built binaries into tar.gz and zip formats
compress:
Expand Down
17 changes: 14 additions & 3 deletions core/checker.go
Expand Up @@ -122,10 +122,18 @@ func (s *Service) dnsCheck() (float64, error) {
return subTime, err
}

func isIPv6(address string) bool {
return strings.Count(address, ":") >= 2
}

// checkIcmp will send a ICMP ping packet to the service
func (s *Service) checkIcmp(record bool) *Service {
p := fastping.NewPinger()
ra, err := net.ResolveIPAddr("ip4:icmp", s.Domain)
resolveIP := "ip4:icmp"
if isIPv6(s.Domain) {
resolveIP = "ip6:icmp"
}
ra, err := net.ResolveIPAddr(resolveIP, s.Domain)
if err != nil {
recordFailure(s, fmt.Sprintf("Could not send ICMP to service %v, %v", s.Domain, err))
return s
Expand Down Expand Up @@ -158,17 +166,20 @@ func (s *Service) checkTcp(record bool) *Service {
domain := fmt.Sprintf("%v", s.Domain)
if s.Port != 0 {
domain = fmt.Sprintf("%v:%v", s.Domain, s.Port)
if isIPv6(s.Domain) {
domain = fmt.Sprintf("[%v]:%v", s.Domain, s.Port)
}
}
conn, err := net.DialTimeout(s.Type, domain, time.Duration(s.Timeout)*time.Second)
if err != nil {
if record {
recordFailure(s, fmt.Sprintf("%v Dial Error %v", s.Type, err))
recordFailure(s, fmt.Sprintf("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("%v Socket Close Error %v", strings.ToUpper(s.Type), err))
}
return s
}
Expand Down
112 changes: 56 additions & 56 deletions handlers/graphql/generated.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions handlers/routes.go
Expand Up @@ -88,7 +88,7 @@ func Router() *mux.Router {
r.Handle("/settings/bulk_import", authenticated(bulkImportHandler, true)).Methods("POST")

// SERVICE Routes
r.Handle("/services", http.HandlerFunc(servicesHandler)).Methods("GET")
r.Handle("/services", authenticated(servicesHandler, true)).Methods("GET")
r.Handle("/service/{id}", http.HandlerFunc(servicesViewHandler)).Methods("GET")
r.Handle("/service/{id}/edit", authenticated(servicesViewHandler, true)).Methods("GET")
r.Handle("/service/{id}/delete_failures", authenticated(servicesDeleteFailuresHandler, true)).Methods("GET")
Expand All @@ -101,7 +101,7 @@ func Router() *mux.Router {
r.Handle("/api/groups/{id}", readOnly(apiGroupHandler, false)).Methods("GET")
r.Handle("/api/groups/{id}", authenticated(apiGroupUpdateHandler, false)).Methods("POST")
r.Handle("/api/groups/{id}", authenticated(apiGroupDeleteHandler, false)).Methods("DELETE")
r.Handle("/api/groups/reorder", authenticated(apiGroupReorderHandler, false)).Methods("POST")
r.Handle("/api/reorder/groups", authenticated(apiGroupReorderHandler, false)).Methods("POST")

// API Routes
r.Handle("/api", authenticated(apiIndexHandler, false))
Expand All @@ -112,7 +112,7 @@ func Router() *mux.Router {
r.Handle("/api/services", readOnly(apiAllServicesHandler, false)).Methods("GET")
r.Handle("/api/services", authenticated(apiCreateServiceHandler, false)).Methods("POST")
r.Handle("/api/services/{id}", readOnly(apiServiceHandler, false)).Methods("GET")
r.Handle("/api/services/reorder", authenticated(reorderServiceHandler, false)).Methods("POST")
r.Handle("/api/reorder/services", authenticated(reorderServiceHandler, false)).Methods("POST")
r.Handle("/api/services/{id}/running", authenticated(apiServiceRunningHandler, false)).Methods("POST")
r.Handle("/api/services/{id}/data", cached("30s", "application/json", http.HandlerFunc(apiServiceDataHandler))).Methods("GET")
r.Handle("/api/services/{id}/ping", cached("30s", "application/json", http.HandlerFunc(apiServicePingDataHandler))).Methods("GET")
Expand Down

0 comments on commit 0439462

Please sign in to comment.