Skip to content

Commit

Permalink
feat: add comparator for uptimerobot
Browse files Browse the repository at this point in the history
Comparator should check for differences in desired and observed state and should only trigger put/post api requests if there is a drift
  • Loading branch information
ahmedwaleedmalik committed Aug 4, 2021
1 parent 81170e9 commit 9b39450
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/monitors/uptimerobot/uptime-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package uptimerobot
import (
"encoding/json"
"errors"
"fmt"
Http "net/http"
"net/url"
"reflect"
"strconv"
"strings"

Expand All @@ -21,9 +23,15 @@ type UpTimeMonitorService struct {
statusPageService UpTimeStatusPageService
}

// Default Interval for status checking
const DefaultInterval = 300

func (monitor *UpTimeMonitorService) Equal(oldMonitor models.Monitor, newMonitor models.Monitor) bool {
// TODO: Retrieve oldMonitor config and compare it here
return false
if !(reflect.DeepEqual(monitor.processProviderConfig(oldMonitor, false), monitor.processProviderConfig(newMonitor, false))) {
log.Info(fmt.Sprintf("There are some new changes in %s monitor", newMonitor.Name))
return false
}
return true
}

func (monitor *UpTimeMonitorService) Setup(p config.Provider) {
Expand Down Expand Up @@ -196,6 +204,9 @@ func (monitor *UpTimeMonitorService) processProviderConfig(m models.Monitor, cre

if providerConfig != nil && providerConfig.Interval > 0 {
body += "&interval=" + strconv.Itoa(providerConfig.Interval)
} else {
// Uptime robot adds a default interval of 5 minutes, if it is not specified
body += "&interval=" + strconv.Itoa(DefaultInterval)
}

if providerConfig != nil && len(providerConfig.MaintenanceWindows) != 0 {
Expand Down

0 comments on commit 9b39450

Please sign in to comment.