Skip to content

Commit

Permalink
ignore times and duration optins to ignore down check result during r…
Browse files Browse the repository at this point in the history
…ecurring maintenance with service disruption for example - fix timezone
  • Loading branch information
tbr-sparklane committed Nov 30, 2020
1 parent 674e9bb commit 2c4b190
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions httpchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -200,10 +201,16 @@ func (c HTTPChecker) conclude(result Result) Result {
result.ThresholdRTT = c.ThresholdRTT

if len(c.IgnoreTimes) > 0 && c.IgnoreDuration > 0 {
now := time.Now().UTC()
timeZone := os.Getenv("TZ")
if timeZone == "" {
timeZone = "Europe/Paris"
}
location, _ := time.LoadLocation(timeZone)
now := time.Now().UTC().In(location)
for i := range c.IgnoreTimes {
start, _ := time.Parse("15:04:05", c.IgnoreTimes[i])
start, _ := time.ParseInLocation("15:04:05", c.IgnoreTimes[i], location)
start = start.AddDate(now.Year(), int(now.Month())-1, now.Day()-1)
start = start.In(location)
end := start.Add(c.IgnoreDuration)
if now.After(start) && now.Before(end) {
result.Healthy = true
Expand Down
11 changes: 9 additions & 2 deletions tlschecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net"
"os"
"time"
)

Expand Down Expand Up @@ -143,10 +144,16 @@ func (c TLSChecker) conclude(conns []*tls.Conn, result Result) Result {
}()

if len(c.IgnoreTimes) > 0 && c.IgnoreDuration > 0 {
now := time.Now().UTC()
timeZone := os.Getenv("TZ")
if timeZone == "" {
timeZone = "Europe/Paris"
}
location, _ := time.LoadLocation(timeZone)
now := time.Now().UTC().In(location)
for i := range c.IgnoreTimes {
start, _ := time.Parse("15:04:05", c.IgnoreTimes[i])
start, _ := time.ParseInLocation("15:04:05", c.IgnoreTimes[i], location)
start = start.AddDate(now.Year(), int(now.Month())-1, now.Day()-1)
start = start.In(location)
end := start.Add(c.IgnoreDuration)
if now.After(start) && now.Before(end) {
result.Healthy = true
Expand Down

0 comments on commit 2c4b190

Please sign in to comment.