Skip to content

Commit

Permalink
feat(pingdom): add post data field (#1) (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
karlderkaefer committed Nov 29, 2023
1 parent d327c58 commit db108ec
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api/v1alpha1/endpointmonitor_types.go
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
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
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
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

0 comments on commit db108ec

Please sign in to comment.