Skip to content
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

feat(pingdom): add post data field #556

Merged
merged 1 commit into from
Nov 29, 2023
Merged
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
6 changes: 6 additions & 0 deletions api/v1alpha1/endpointmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions docs/pingdom-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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"
```
13 changes: 12 additions & 1 deletion pkg/monitors/pingdom/pingdom-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pingdom

import (
"encoding/json"
"errors"
"fmt"
"net/url"
"os"
Expand Down Expand Up @@ -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.
Expand Down
Loading