-
-
Notifications
You must be signed in to change notification settings - Fork 119
+ Add UptimeRobot all monitors features #632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ import ( | |
| "reflect" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| endpointmonitorv1alpha1 "github.com/stakater/IngressMonitorController/v2/api/v1alpha1" | ||
| "github.com/stakater/IngressMonitorController/v2/pkg/config" | ||
|
|
@@ -68,17 +67,6 @@ func (monitor *UpTimeMonitorService) GetByName(name string) (*models.Monitor, er | |
| } | ||
|
|
||
| return nil, nil | ||
| } else if response.StatusCode == Http.StatusTooManyRequests { | ||
| log.Info("Too many requests, Monitor waiting for timeout: " + name) | ||
| retryAfter := response.Header.Get("Retry-After") | ||
| if retryAfter != "" { | ||
| seconds, err := strconv.Atoi(retryAfter) | ||
| if err == nil { | ||
| time.Sleep(time.Duration(seconds) * time.Second) | ||
| return monitor.GetByName(name) // Retry after the specified delay | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| errorString := "GetByName Request failed for name: " + name + ". Status Code: " + strconv.Itoa(response.StatusCode) | ||
|
|
@@ -164,16 +152,6 @@ func (monitor *UpTimeMonitorService) Add(m models.Monitor) { | |
| } else { | ||
| log.Info("Monitor couldn't be added: " + m.Name + ". Error: " + f.Error.Message) | ||
| } | ||
| } else if response.StatusCode == Http.StatusTooManyRequests { | ||
| log.Info("Too many requests, Monitor waiting for timeout: " + m.Name) | ||
| retryAfter := response.Header.Get("Retry-After") | ||
| if retryAfter != "" { | ||
| seconds, err := strconv.Atoi(retryAfter) | ||
| if err == nil { | ||
| time.Sleep(time.Duration(seconds) * time.Second) | ||
| monitor.Add(m) // Retry after the specified delay | ||
| } | ||
| } | ||
| } else { | ||
| log.Info("AddMonitor Request failed. Status Code: " + strconv.Itoa(response.StatusCode)) | ||
| } | ||
|
|
@@ -200,16 +178,6 @@ func (monitor *UpTimeMonitorService) Update(m models.Monitor) { | |
| } else { | ||
| log.Info("Monitor couldn't be updated: " + m.Name + ". Error: " + f.Error.Message) | ||
| } | ||
| } else if response.StatusCode == Http.StatusTooManyRequests { | ||
| log.Info("Too many requests, Monitor waiting for timeout: " + m.Name) | ||
| retryAfter := response.Header.Get("Retry-After") | ||
| if retryAfter != "" { | ||
| seconds, err := strconv.Atoi(retryAfter) | ||
| if err == nil { | ||
| time.Sleep(time.Duration(seconds) * time.Second) | ||
| monitor.Update(m) // Retry after the specified delay | ||
| } | ||
| } | ||
| } else { | ||
| log.Info("UpdateMonitor Request failed. Status Code: " + strconv.Itoa(response.StatusCode)) | ||
| } | ||
|
|
@@ -228,54 +196,117 @@ func (monitor *UpTimeMonitorService) processProviderConfig(m models.Monitor, cre | |
| // Retrieve provider configuration | ||
| providerConfig, _ := m.Config.(*endpointmonitorv1alpha1.UptimeRobotConfig) | ||
|
|
||
| if providerConfig != nil && len(providerConfig.AlertContacts) != 0 { | ||
| body += "&alert_contacts=" + providerConfig.AlertContacts | ||
| } else { | ||
| body += "&alert_contacts=" + monitor.alertContacts | ||
| } | ||
|
|
||
| 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 { | ||
| body += "&mwindows=" + providerConfig.MaintenanceWindows | ||
| } | ||
|
|
||
| if providerConfig != nil && len(providerConfig.CustomHTTPStatuses) != 0 { | ||
| body += "&custom_http_statuses=" + providerConfig.CustomHTTPStatuses | ||
| } | ||
|
|
||
| // Type (Required) | ||
| if providerConfig != nil && len(providerConfig.MonitorType) != 0 { | ||
| if strings.Contains(strings.ToLower(providerConfig.MonitorType), "http") { | ||
| body += "&type=1" | ||
| } else if strings.Contains(strings.ToLower(providerConfig.MonitorType), "keyword") { | ||
| 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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| } | ||
|
|
||
|
|
@@ -324,4 +355,4 @@ func (monitor *UpTimeMonitorService) updateStatusPages(statusPages string, monit | |
| if err != nil { | ||
| log.Info("Monitor couldn't be added to status page: " + err.Error()) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a maintainer or anything but I'm interested in the addition of the missing UptimeRobot features, thanks for the PR!
I'm just wondering, why did you remove the code to handle HTTP 429 response status?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rollback the missing parts in the last commit.
Thanks @eneiss for your review !
I hope someone can help these features be part of the project asap.
Best regads,
Didier