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

Add pingdom transaction checks #568

Closed
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
49 changes: 49 additions & 0 deletions api/v1alpha1/endpointmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pingdomNew "github.com/karlderkaefer/pingdom-golang-client/pkg/pingdom/openapi"
)

// EndpointMonitorSpec defines the desired state of EndpointMonitor
Expand Down Expand Up @@ -60,6 +61,10 @@ type EndpointMonitorSpec struct {
// +optional
PingdomConfig *PingdomConfig `json:"pingdomConfig,omitempty"`

// Configuration for Pingdom Monitor Provider
// +optional
PingdomTransactionConfig *PingdomConfig `json:"pingdomTransactionConfig,omitempty"`

// Configuration for AppInsights Monitor Provider
// +optional
AppInsightsConfig *AppInsightsConfig `json:"appInsightsConfig,omitempty"`
Expand Down Expand Up @@ -280,6 +285,50 @@ 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"`
}

type PingdomTransactionConfig struct {
// Check status: active or inactive
// +optional
Paused bool `json:"paused,omitempty"`
// Custom message that is part of the email and webhook alerts
// +optional
CustomMessage string `json:"custom_message,omitempty"`
// TMS test intervals in minutes. Allowed intervals: 5,10,20,60,720,1440. The interval you're allowed to set may vary depending on your current plan.
// +optional
Interval int `json:"interval,omitempty"`
// Name of the region where the check is executed. Supported regions: us-east, us-west, eu, au
// +optional
Region string `json:"region,omitempty"`
// Send notification when down X times
SendNotificationWhenDown int64 `json:"send_notification_when_down,omitempty"`
// Check importance- how important are the alerts when the check fails. Allowed values: low, high
// +optional
SeverityLevel string `json:"severity_level,omitempty"`
// steps to be executed as part of the check
// +required
Steps []pingdomNew.Step `json:"steps"`
// Integration identifiers.
// +optional
Metadata pingdomNew.Metadata `json:"metadata,omitempty"`
// List of tags for a check. The tag name may contain the characters 'A-Z', 'a-z', '0-9', '_' and '-'. The maximum length of a tag is 64 characters.
Tags []string `json:"tags,omitempty"`

// `-` separated set list of integrations ids (e.g. "91166-12168")
// +optional
AlertIntegrations string `json:"alertIntegrations,omitempty"`
// `-` separated contact id's (e.g. "1234567_8_9-9876543_2_1")
// +optional
AlertContacts string `json:"alertContacts,omitempty"`
// `-` separated team id's (e.g. "1234567_8_9-9876543_2_1")
// +optional
TeamAlertContacts string `json:"teamAlertContacts,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"
```
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/go-logr/logr v1.2.0
github.com/grafana/synthetic-monitoring-agent v0.18.2
github.com/grafana/synthetic-monitoring-api-go-client v0.7.0
github.com/karlderkaefer/pingdom-golang-client v1.0.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/openshift/api v0.0.0-20200526144822-34f54f12813a
github.com/patrickmn/go-cache v2.1.0+incompatible
Expand Down Expand Up @@ -62,13 +63,13 @@ require (
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ github.com/google/s2a-go v0.1.4/go.mod h1:Ej+mSEMGRnqRzjc7VtF+jdBwYG5fuJfiZ8ELkj
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9aurXEpJX+U6FLtpYTdC3R06k=
github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
Expand Down Expand Up @@ -391,6 +391,8 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/karlderkaefer/pingdom-golang-client v1.0.0 h1:7RGD7gj8dJrXXjE9JgzHvGC424lXCbHXCGPBmtGKfkE=
github.com/karlderkaefer/pingdom-golang-client v1.0.0/go.mod h1:iHOA8APTy8wxam3QxKp/nGw9823gDIlMEpYiKp9+nrU=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand All @@ -415,8 +417,9 @@ github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
Expand Down
4 changes: 4 additions & 0 deletions pkg/monitors/monitor-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (mp *MonitorServiceProxy) OfType(mType string) MonitorServiceProxy {
mp.monitor = &uptimerobot.UpTimeMonitorService{}
case "Pingdom":
mp.monitor = &pingdom.PingdomMonitorService{}
case "PindomTransaction":
mp.monitor = &pingdom.PingdomTransactionMonitorService{}
case "StatusCake":
mp.monitor = &statuscake.StatusCakeMonitorService{}
case "Uptime":
Expand All @@ -59,6 +61,8 @@ func (mp *MonitorServiceProxy) ExtractConfig(spec endpointmonitorv1alpha1.Endpoi
config = spec.UptimeRobotConfig
case "Pingdom":
config = spec.PingdomConfig
case "PingdomTransaction":
config = spec.PingdomTransactionConfig
case "StatusCake":
config = spec.StatusCakeConfig
case "Uptime":
Expand Down
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
Loading