Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions api/v1alpha1/endpointmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,45 @@ type UptimeRobotConfig struct {
// Defines which http status codes are treated as up or down
// For ex: 200:0_401:1_503:1 (to accept 200 as down and 401 and 503 as up)
CustomHTTPStatuses string `json:"customHTTPStatuses,omitempty"`

// Optional sub-type for HTTP monitors (e.g. "HTTPS", "ping", etc.)
SubType string `json:"subType,omitempty"`

// Optional TCP/UDP port to use when applicable (e.g. 443 for HTTPS)
Port int `json:"port,omitempty"`

// Timeout in seconds before considering the monitored site unresponsive
Timeout int `json:"timeout,omitempty"`

// Username for basic HTTP authentication if required by the target URL
HTTPAuthUsername string `json:"httpAuthUsername,omitempty"`

// Password for basic HTTP authentication
HTTPAuthPassword string `json:"httpAuthPassword,omitempty"`

// Authentication type: 1 = Basic Auth, 2 = Digest Auth
HTTPAuthType int `json:"httpAuthType,omitempty"`

// Type of HTTP POST request: e.g., "application/x-www-form-urlencoded"
PostType string `json:"postType,omitempty"`

// POST body value to be submitted with the request
PostValue string `json:"postValue,omitempty"`

// HTTP method used for the check: e.g., "GET", "POST"
HTTPMethod string `json:"httpMethod,omitempty"`

// Content-Type of the HTTP POST request (e.g. "application/json")
PostContentType string `json:"postContentType,omitempty"`

// Set of custom HTTP headers in JSON format (e.g. {"Authorization": "Bearer TOKEN"})
CustomHTTPHeaders string `json:"customHttpHeaders,omitempty"`

// If set to 1, SSL errors will be ignored for HTTPS monitors
IgnoreSSLErrors int `json:"ignoreSSLErrors,omitempty"`

// If set to 1, disables expiration notifications for domains
DisableDomainExpireNotifications int `json:"disableDomainExpireNotifications,omitempty"`
}

// UptimeConfig defines the configuration for Uptime Monitor Provider
Expand Down
91 changes: 87 additions & 4 deletions pkg/monitors/uptimerobot/uptime-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,26 +256,109 @@ func (monitor *UpTimeMonitorService) processProviderConfig(m models.Monitor, cre
body += "&type=2"

if providerConfig != nil && len(providerConfig.KeywordExists) != 0 {

if strings.Contains(strings.ToLower(providerConfig.KeywordExists), "yes") {
body += "&keyword_type=1"
} else if strings.Contains(strings.ToLower(providerConfig.KeywordExists), "no") {
body += "&keyword_type=2"
}

} else {
body += "&keyword_type=1" // By default 1 (check if keyword exists)
}

// Keyword Value (Required for keyword monitoring)
if providerConfig != nil && len(providerConfig.KeywordValue) != 0 {
body += "&keyword_value=" + providerConfig.KeywordValue
body += "&keyword_value=" + url.QueryEscape(providerConfig.KeywordValue)
} else {
log.Error(nil, "Monitor is of type Keyword but the `keyword-value` is missing")
}
}
} else {
body += "&type=1" // By default monitor is of type HTTP
}

// SubType (Optional for certain types)
if providerConfig != nil && len(providerConfig.SubType) != 0 {
body += "&sub_type=" + url.QueryEscape(providerConfig.SubType)
}

// Port (Optional for certain types)
if providerConfig != nil && providerConfig.Port > 0 {
body += "&port=" + strconv.Itoa(providerConfig.Port)
}

// Interval (Optional, in seconds)
if providerConfig != nil && providerConfig.Interval > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @dguihal commented we need to remove this block

body += "&interval=" + strconv.Itoa(providerConfig.Interval)
} else {
body += "&interval=" + strconv.Itoa(DefaultInterval)
}
Comment on lines +289 to +294
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed (duplicates of lines 237-242), generates an error: "Error: "interval" must be a string"


// Timeout (Optional, in seconds)
if providerConfig != nil && providerConfig.Timeout > 0 {
body += "&timeout=" + strconv.Itoa(providerConfig.Timeout)
}

// HTTP Auth (Optional)
if providerConfig != nil && len(providerConfig.HTTPAuthUsername) != 0 && len(providerConfig.HTTPAuthPassword) != 0 {
body += "&http_username=" + url.QueryEscape(providerConfig.HTTPAuthUsername)
body += "&http_password=" + url.QueryEscape(providerConfig.HTTPAuthPassword)
if providerConfig.HTTPAuthType > 0 {
body += "&http_auth_type=" + strconv.Itoa(providerConfig.HTTPAuthType)
}
}

// Post Type (Optional)
if providerConfig != nil && len(providerConfig.PostType) != 0 {
body += "&post_type=" + url.QueryEscape(providerConfig.PostType)
}

// Post Value (Optional)
if providerConfig != nil && len(providerConfig.PostValue) != 0 {
body += "&post_value=" + url.QueryEscape(providerConfig.PostValue)
}

// HTTP Method (Optional)
if providerConfig != nil && len(providerConfig.HTTPMethod) != 0 {
body += "&http_method=" + url.QueryEscape(providerConfig.HTTPMethod)
}

// Post Content Type (Optional)
if providerConfig != nil && len(providerConfig.PostContentType) != 0 {
body += "&post_content_type=" + url.QueryEscape(providerConfig.PostContentType)
}

// Alert Contacts (Optional)
if providerConfig != nil && len(providerConfig.AlertContacts) != 0 {
body += "&alert_contacts=" + url.QueryEscape(providerConfig.AlertContacts)
} else {
body += "&alert_contacts=" + url.QueryEscape(monitor.alertContacts)
Comment on lines +330 to +334
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed (duplicates of lines 231-235), generates an error: "Error: "alert_contacts" must be a string"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

}

// Maintenance Windows (Optional)
if providerConfig != nil && len(providerConfig.MaintenanceWindows) != 0 {
body += "&mwindows=" + url.QueryEscape(providerConfig.MaintenanceWindows)
}

// Custom HTTP Headers (Optional, must be sent as a JSON object)
if providerConfig != nil && len(providerConfig.CustomHTTPHeaders) != 0 {
body += "&custom_http_headers=" + url.QueryEscape(providerConfig.CustomHTTPHeaders)
}

// Custom HTTP Statuses (Optional, must be sent in specific format)
if providerConfig != nil && len(providerConfig.CustomHTTPStatuses) != 0 {
body += "&custom_http_statuses=" + url.QueryEscape(providerConfig.CustomHTTPStatuses)
}

// Ignore SSL Errors (Optional)
if providerConfig != nil && providerConfig.IgnoreSSLErrors > 0 {
body += "&ignore_ssl_errors=" + strconv.Itoa(providerConfig.IgnoreSSLErrors)
}

// Disable Domain Expire Notifications (Optional)
if providerConfig != nil && providerConfig.DisableDomainExpireNotifications > 0 {
body += "&disable_domain_expire_notifications=" + strconv.Itoa(providerConfig.DisableDomainExpireNotifications)
}

return body
}

Expand Down Expand Up @@ -324,4 +407,4 @@ func (monitor *UpTimeMonitorService) updateStatusPages(statusPages string, monit
if err != nil {
log.Info("Monitor couldn't be added to status page: " + err.Error())
}
}
}
36 changes: 20 additions & 16 deletions pkg/monitors/uptimerobot/uptime-responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@ type UptimeMonitorPagination struct {
}

type UptimeMonitorMonitor struct {
ID int `json:"id"`
FriendlyName string `json:"friendly_name"`
URL string `json:"url"`
Type int `json:"type"`
SubType string `json:"sub_type"`
KeywordType int `json:"keyword_type"`
KeywordValue string `json:"keyword_value"`
HTTPUsername string `json:"http_username"`
HTTPPassword string `json:"http_password"`
Port string `json:"port"`
Interval int `json:"interval"`
Status int `json:"status"`
CreateDatetime int `json:"create_datetime"`
Logs []UptimeMonitorLogs `json:"logs"`
AlertContacts []UptimeMonitorAlertContacts `json:"alert_contacts"`
ID int `json:"id"`
FriendlyName string `json:"friendly_name"`
URL string `json:"url"`
Type int `json:"type"`
SubType string `json:"sub_type"`
KeywordType int `json:"keyword_type"`
KeywordValue string `json:"keyword_value"`
HTTPUsername string `json:"http_username"`
HTTPPassword string `json:"http_password"`
Port string `json:"port"`
Interval int `json:"interval"`
Status int `json:"status"`
CreateDatetime int `json:"create_datetime"`
Logs []UptimeMonitorLogs `json:"logs"`
AlertContacts []UptimeMonitorAlertContacts `json:"alert_contacts"`
SSL int `json:"ssl"`
Timeout int `json:"timeout"`
CustomHTTPStatuses string `json:"custom_http_statuses"`
CustomHeader string `json:"custom_header"`
}

type UptimeMonitorAlertContacts struct {
Expand Down Expand Up @@ -91,4 +95,4 @@ type UptimeStatusPagesResponse struct {
Total int `json:"total"`
} `json:"pagination"`
StatusPages []UptimePublicStatusPage `json:"psps"`
}
}
Loading