diff --git a/api/v1alpha1/endpointmonitor_types.go b/api/v1alpha1/endpointmonitor_types.go index fa3700d2..5cee3e27 100644 --- a/api/v1alpha1/endpointmonitor_types.go +++ b/api/v1alpha1/endpointmonitor_types.go @@ -280,6 +280,12 @@ type PingdomConfig struct { // At this day your check will be considered down and if applicable a down alert will be sent. // +optional SSLDownDaysBefore int `json:"sslDownDaysBefore,omitempty"` + + // Data that should be posted to the web page, for example submission data for a sign-up or login form. + // The data needs to be formatted in the same way as a web browser would send it to the web server. + // Because post data contains sensitive secret this field is only reference to a environment variable. + // +optional + PostDataEnvVar string `json:"postDataEnvVar,omitempty"` } // AppInsightsConfig defines the configuration for AppInsights Monitor Provider diff --git a/charts/ingressmonitorcontroller/crds/endpointmonitor.stakater.com_endpointmonitors.yaml b/charts/ingressmonitorcontroller/crds/endpointmonitor.stakater.com_endpointmonitors.yaml index 9b920f70..5367c583 100644 --- a/charts/ingressmonitorcontroller/crds/endpointmonitor.stakater.com_endpointmonitors.yaml +++ b/charts/ingressmonitorcontroller/crds/endpointmonitor.stakater.com_endpointmonitors.yaml @@ -88,6 +88,13 @@ spec: paused: description: Set to "true" to pause checks type: boolean + postDataEnvVar: + description: Data that should be posted to the web page, for example + submission data for a sign-up or login form. The data needs + to be formatted in the same way as a web browser would send + it to the web server. Because post data contains sensitive secret + this field is only reference to a environment variable. + type: string requestHeaders: description: Custom pingdom request headers type: string diff --git a/docs/pingdom-configuration.md b/docs/pingdom-configuration.md index 3f2d7f10..37059af0 100644 --- a/docs/pingdom-configuration.md +++ b/docs/pingdom-configuration.md @@ -44,6 +44,34 @@ Pingdom supports checks completing basic auth requirements. In `EndpointMonitor` For example; setting the field like `basicAuthUser: health-service` will set the username field to 'health-service' and will retrieve the password via `os.Getenv('health-service')` and set this appropriately. +### Post Data checks + +In case you need add post data to your request, you can use the field `postDataEnvVar`. +The value must match a environment variable that contains the post data to be sent. + +For example; setting the field like `postDataEnvVar: monitor-user` will set the post data field to the value of the environment variable `monitor-user`. + +To add the environment variable in helm context, first create a secret e.g. + +```yaml +kind: Secret +apiVersion: v1 +metadata: + name: stakater-post-data +stringData: + monitor-user: "username=stakater&password=stakater" +type: Opaque +``` + +Then we reference secret in the env context of helm chart + +```yaml +envFrom: + - secretRef: + name: stakater-post-data +``` + +If you set postData the request method will be automatically POST. ## Example: @@ -67,4 +95,5 @@ spec: alertIntegrations: "91166-12168" alertContacts: "1234567_8_9-9876543_2_1,1234567_8_9-9876543_2_2" teamAlertContacts: "1234567_8_9-9876543_2_1,1234567_8_9-9876543_2_2" + postDataEnvVar: "monitor-user" ``` diff --git a/pkg/monitors/pingdom/pingdom-monitor.go b/pkg/monitors/pingdom/pingdom-monitor.go index c8b54184..e4312cf0 100644 --- a/pkg/monitors/pingdom/pingdom-monitor.go +++ b/pkg/monitors/pingdom/pingdom-monitor.go @@ -2,6 +2,7 @@ package pingdom import ( "encoding/json" + "errors" "fmt" "net/url" "os" @@ -258,9 +259,19 @@ func (service *PingdomMonitorService) addConfigToHttpCheck(httpCheck *pingdom.Ht } } - // Enable SSL validation if providerConfig != nil { + // Enable SSL validation httpCheck.VerifyCertificate = &providerConfig.VerifyCertificate + // Add post data if exists + if len(providerConfig.PostDataEnvVar) > 0 { + postDataValue := os.Getenv(providerConfig.PostDataEnvVar) + if postDataValue != "" { + httpCheck.PostData = postDataValue + log.Info("Post data detected. Setting post data for httpCheck to value of environment variable: " + providerConfig.PostDataEnvVar) + } else { + log.Error(errors.New("Error reading post data from environment variable"), "Environment Variable %s does not exist", providerConfig.PostDataEnvVar) + } + } } // Set certificate not valid before, default to 28 days to accommodate Let's Encrypt 30 day renewals + 2 days grace period.