diff --git a/api/v1alpha1/endpointmonitor_types.go b/api/v1alpha1/endpointmonitor_types.go index 96c17273..96cbcd3c 100644 --- a/api/v1alpha1/endpointmonitor_types.go +++ b/api/v1alpha1/endpointmonitor_types.go @@ -113,6 +113,16 @@ 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"` + + // Defines custom http headers to sent to monitored url + // +optional + CustomHTTPHeaders []HttpHeader `json:"customHTTPHeaders,omitempty"` +} + +// Represents a http header +type HttpHeader struct { + Name string `json:"name"` + Value string `json:"value"` } // UptimeConfig defines the configuration for Uptime Monitor Provider @@ -317,7 +327,6 @@ type PingdomConfig struct { // PingdomTransactionConfig defines the configuration for Pingdom Transaction Monitor Provider type PingdomTransactionConfig struct { - // Check status: active or inactive // +optional Paused bool `json:"paused,omitempty"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 87f4f2ad..69a90901 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -109,7 +109,7 @@ func (in *EndpointMonitorSpec) DeepCopyInto(out *EndpointMonitorSpec) { if in.UptimeRobotConfig != nil { in, out := &in.UptimeRobotConfig, &out.UptimeRobotConfig *out = new(UptimeRobotConfig) - **out = **in + (*in).DeepCopyInto(*out) } if in.UptimeConfig != nil { in, out := &in.UptimeConfig, &out.UptimeConfig @@ -213,6 +213,21 @@ func (in *GrafanaConfig) DeepCopy() *GrafanaConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HttpHeader) DeepCopyInto(out *HttpHeader) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HttpHeader. +func (in *HttpHeader) DeepCopy() *HttpHeader { + if in == nil { + return nil + } + out := new(HttpHeader) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *IngressURLSource) DeepCopyInto(out *IngressURLSource) { *out = *in @@ -380,6 +395,11 @@ func (in *UptimeConfig) DeepCopy() *UptimeConfig { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *UptimeRobotConfig) DeepCopyInto(out *UptimeRobotConfig) { *out = *in + if in.CustomHTTPHeaders != nil { + in, out := &in.CustomHTTPHeaders, &out.CustomHTTPHeaders + *out = make([]HttpHeader, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UptimeRobotConfig. diff --git a/config/crd/bases/endpointmonitor.stakater.com_endpointmonitors.yaml b/config/crd/bases/endpointmonitor.stakater.com_endpointmonitors.yaml index cdc4d985..3faf5a9e 100644 --- a/config/crd/bases/endpointmonitor.stakater.com_endpointmonitors.yaml +++ b/config/crd/bases/endpointmonitor.stakater.com_endpointmonitors.yaml @@ -365,6 +365,21 @@ spec: description: The uptimerobot alertContacts to be associated with this monitor type: string + customHTTPHeaders: + description: Defines custom http headers to sent to monitored + url + items: + description: Represents a http header + properties: + name: + type: string + value: + type: string + required: + - name + - value + type: object + type: array customHTTPStatuses: description: |- Defines which http status codes are treated as up or down diff --git a/pkg/monitors/uptimerobot/uptime-monitor.go b/pkg/monitors/uptimerobot/uptime-monitor.go index 838a67d7..2018cdb7 100644 --- a/pkg/monitors/uptimerobot/uptime-monitor.go +++ b/pkg/monitors/uptimerobot/uptime-monitor.go @@ -249,6 +249,18 @@ func (monitor *UpTimeMonitorService) processProviderConfig(m models.Monitor, cre body += "&custom_http_statuses=" + providerConfig.CustomHTTPStatuses } + if providerConfig != nil && len(providerConfig.CustomHTTPHeaders) != 0 { + headers := map[string]string{} + for _, header := range providerConfig.CustomHTTPHeaders { + headers[header.Name] = header.Value + } + out, err := json.Marshal(headers) + if err != nil { + log.Error(err, "Unable to marshal headers to JSON") + } + body += "&custom_http_headers=" + url.PathEscape(string(out)) + } + if providerConfig != nil && len(providerConfig.MonitorType) != 0 { if strings.Contains(strings.ToLower(providerConfig.MonitorType), "http") { body += "&type=1"