Skip to content

Commit

Permalink
Merge pull request #356 from stakater/add-comparator-uptimerobot
Browse files Browse the repository at this point in the history
Add comparator for  uptimerobot
  • Loading branch information
ahmedwaleedmalik committed Aug 4, 2021
2 parents 524a419 + 9b39450 commit 5b57db4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
22 changes: 16 additions & 6 deletions pkg/monitors/uptime/uptime-monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ func TestGetAllMonitors(t *testing.T) {
service := UpTimeMonitorService{}
provider := util.GetProviderWithName(config, "Uptime")
if provider == nil {
panic("Failed to find provider")
log.Error(nil, "Failed to find provider")
return
}

// If test Config is passed skip the test
if provider.ApiKey == "API_KEY" {
return
Expand All @@ -37,9 +39,11 @@ func TestAddMonitorWithCorrectValues(t *testing.T) {

service := UpTimeMonitorService{}
provider := util.GetProviderWithName(config, "Uptime")
if nil == provider {
panic("Failed to find provider")
if provider == nil {
log.Error(nil, "Failed to find provider")
return
}

// If test Config is passed skip the test
if provider.ApiKey == "API_KEY" {
return
Expand Down Expand Up @@ -75,8 +79,10 @@ func TestUpdateMonitorWithCorrectValues(t *testing.T) {
service := UpTimeMonitorService{}
provider := util.GetProviderWithName(config, "Uptime")
if provider == nil {
panic("Failed to find provider")
log.Error(nil, "Failed to find provider")
return
}

// If test Config is passed skip the test
if provider.ApiKey == "API_KEY" {
return
Expand Down Expand Up @@ -143,8 +149,10 @@ func TestAddMonitorWithIncorrectValues(t *testing.T) {

provider := util.GetProviderWithName(config, "Uptime")
if provider == nil {
panic("Failed to find provider")
log.Error(nil, "Failed to find provider")
return
}

// If test Config is passed skip the test
if provider.ApiKey == "API_KEY" {
return
Expand Down Expand Up @@ -176,8 +184,10 @@ func TestEqualMonitor(t *testing.T) {

provider := util.GetProviderWithName(config, "Uptime")
if provider == nil {
panic("Failed to find provider")
log.Error(nil, "Failed to find provider")
return
}

// If test Config is passed skip the test
if provider.ApiKey == "API_KEY" {
return
Expand Down
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 5b57db4

Please sign in to comment.