Skip to content

Commit

Permalink
Merge pull request #287 from artemlive/feature/pingdom-api-migrate
Browse files Browse the repository at this point in the history
IMC pingdom api v3.1 support with small improvements and documentation fixes
  • Loading branch information
ahmedwaleedmalik authored Oct 22, 2020
2 parents 5a091a2 + b8d7266 commit 221927f
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 64 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ providers:
username: <your-account-username>
password: <your-account-password>
- name: Pingdom
apiKey: <your-api-key>
apiToken: <your-api-token>
apiURL: https://api.pingdom.com
username: <your-account-username>
password: <your-account-password>
accountEmail: <multi-auth-account-email>
alertIntegrations: "91166-10924"
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"
enableMonitorDeletion: true
monitorNameTemplate: "{{.Name}}-{{.Namespace}}"
```
2 changes: 1 addition & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {
os.Exit(1)
}
if len(namespace) == 0 {
log.Info("Warning: WATCH_NAMESPACE is set to empty string, will monitor ingresses in all namespaces.")
log.Info("Warning: WATCH_NAMESPACE is set to empty string, will check EndpointMonitors in all namespaces.")
} else {
log.Info("Watching Namespace: " + namespace)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ spec:
description: Comma separated set of tags to apply to check (e.g.
"testing,aws")
type: string
teamAlertContacts:
description: '`-` separated team id''s (e.g. "1234567_8_9-9876543_2_1")'
type: string
type: object
providers:
description: Comma separated list of providers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
apiVersion: operators.coreos.com/v1alpha1
kind: ClusterServiceVersion
metadata:
annotations:
alm-examples: '[]'
capabilities: Basic Install
name: ingressmonitorcontroller.v2.0.5
namespace: placeholder
spec:
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: EndpointMonitor is the Schema for the endpointmonitors API
kind: EndpointMonitor
name: endpointmonitors.endpointmonitor.stakater.com
version: v1alpha1
description: Placeholder description
displayName: Ingress Monitor Controller
install:
spec:
clusterPermissions:
- rules:
- apiGroups:
- ""
- extensions
- route.openshift.io
resources:
- ingresses
- routes
- secrets
verbs:
- list
- get
- apiGroups:
- ""
resources:
- events
- services
- configmaps
- services/finalizers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
- deployments
- daemonsets
- replicasets
- statefulsets
verbs:
- '*'
- apiGroups:
- monitoring.coreos.com
resources:
- servicemonitors
verbs:
- get
- create
- list
- apiGroups:
- apps
resourceNames:
- ingressmonitorcontroller
resources:
- deployments/finalizers
verbs:
- update
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- endpointmonitor.stakater.com
resources:
- '*'
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
serviceAccountName: ingressmonitorcontroller
deployments:
- name: ingressmonitorcontroller
spec:
replicas: 1
selector:
matchLabels:
name: ingressmonitorcontroller
strategy: {}
template:
metadata:
labels:
name: ingressmonitorcontroller
spec:
containers:
- command:
- IngressMonitorController
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.annotations['olm.targetNamespaces']
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: ingressmonitorcontroller
- name: CONFIG_SECRET_NAME
value: imc-config
- name: LOG_LEVEL
value: info
- name: LOG_FORMAT
value: text
image: stakater/ingressmonitorcontroller:v2.0.5
imagePullPolicy: Always
name: ingressmonitorcontroller
resources: {}
serviceAccountName: ingressmonitorcontroller
strategy: deployment
installModes:
- supported: true
type: OwnNamespace
- supported: true
type: SingleNamespace
- supported: false
type: MultiNamespace
- supported: true
type: AllNamespaces
maturity: alpha
provider: {}
replaces: ingressmonitorcontroller.v0.0.0
version: 2.0.5
2 changes: 1 addition & 1 deletion deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
serviceAccountName: ingressmonitorcontroller
containers:
- name: ingressmonitorcontroller
image: stakater/ingressmonitorcontroller:v2.0.4
image: stakater/ingressmonitorcontroller:v2.0.5
command:
- IngressMonitorController
imagePullPolicy: Always
Expand Down
16 changes: 8 additions & 8 deletions docs/pingdom-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ in the [Configuration section of the README](../README.md#configuration):

| Key | Description |
|----------|--------------------------------------------------|
| username | Account username for authentication with Pingdom |
| password | Account password for authentication with Pingdom |
| apiToken | Pingdom API Token generated inside My Pingdom |

## Optional
The following optional property can be included for Pingdom accounts which require multi-user authentication.
More information can be found [Here](https://www.pingdom.com/api/2.1/#multi-user+authentication)
The following optional properties can be included if you want to declare some default options, without re-declaring them for each EndpointMonitor.
You are able to override any of them via EndpointMonitor specific options.

| Key | Description |
|-------------------|----------------------------------------------------------|
| accountEmail | Email account for multi-user authentication with Pingdom |
| alertIntegrations | Comma separated list of integration ids |

| alertIntegrations | `-` separated list of integration ids |
| teamAlertContacts | `-` separated list of teams ids |
| alertContacts | `-` separated list of alert contacts ids |
## Advanced

Currently additional pingdom configurations can be added through these fields:
Expand All @@ -37,7 +36,7 @@ Currently additional pingdom configurations can be added through these fields:
| Tags | Comma separated set of tags to apply to check (e.g. "testing,aws") |
| AlertIntegrations | `-` separated set list of integrations ids (e.g. "91166-12168") |
| AlertContacts | `-` separated contact id's (e.g. "1234567_8_9-9876543_2_1") to override the [default alertContacts](https://github.com/stakater/IngressMonitorController/blob/master/README.md#usage)|

| TeamAlertContacts | Teams to alert. `-` separated set list of teams ids (e.g. "1234567_8_9-9876543_2_1)|

### Basic Auth checks

Expand Down Expand Up @@ -67,4 +66,5 @@ spec:
tags: "testing,aws"
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"
```
12 changes: 5 additions & 7 deletions examples/configs/test-config-pingdom.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
providers:
- name: PingdomMulti
apiURL: "https://api.pingdom.com/v2/"
apiKey: "657a68d9ashdyasjdklkskuasd"
username: "[email protected]"
password: "SuperSecret"
accountEmail: "[email protected]"
- name: Pingdom
apiURL: "https://api.pingdom.com/api/3.1"
apiToken: "657a68d9ashdyasjdklkskuasd"
alertContacts: "0544483_0_0-2628365_0_0-2633263_0_0"
alertIntegrations: "91166,10924"
teamAlertContacts: "1234567_0_0-2628365_0_0-2633263_0_0"
alertIntegrations: "91166-10924"
enableMonitorDeletion: true
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/openshift/api v0.0.0-20200526144822-34f54f12813a
github.com/operator-framework/operator-sdk v0.19.0
github.com/russellcardullo/go-pingdom v1.0.0
github.com/russellcardullo/go-pingdom v1.3.0
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.5.1
google.golang.org/api v0.14.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rubenv/sql-migrate v0.0.0-20200212082348-64f95ea68aa3/go.mod h1:rtQlpHw+eR6UrqaS3kX1VYeaCxzCVdimDS7g5Ln4pPc=
github.com/russellcardullo/go-pingdom v1.0.0 h1:onhnHzECEQI1r1Oel6F9piZ2hI8L339IDBKAQdbUAO4=
github.com/russellcardullo/go-pingdom v1.0.0/go.mod h1:MbP0xrebNTkKp7dUsxfOJF+MvJ6eNmvj5y6gqXFbOaw=
github.com/russellcardullo/go-pingdom v1.3.0/go.mod h1:y9hd/6P97iuRFi6VPGgLxsRQaJQll298jZ/qPQPfcXw=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/endpointmonitor/v1alpha1/endpointmonitor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ type PingdomConfig struct {
// `-` 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
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ func (c *Config) UnmarshalYAML(data []byte) error {
type Provider struct {
Name string `yaml:"name"`
ApiKey string `yaml:"apiKey"`
ApiToken string `yaml:"apiToken"`
ApiURL string `yaml:"apiURL"`
AlertContacts string `yaml:"alertContacts"`
AlertIntegrations string `yaml:"alertIntegrations"`
TeamAlertContacts string `yaml:"teamAlertContacts"`
Username string `yaml:"username"`
Password string `yaml:"password"`
AccountEmail string `yaml:"accountEmail"`
Expand Down
26 changes: 11 additions & 15 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ const (
correctTestEnableMonitorDeletion = true

configFilePathPingdom = "../../examples/configs/test-config-pingdom.yaml"
correctTestPingdomConfigMulti = "PingdomMulti"
correctTestPingdomUsername = "[email protected]"
correctTestPingdomAPIURL = "https://api.pingdom.com/v2/"
correctTestPingdomPassword = "SuperSecret"
correctTestPingdomAccountEmail = "[email protected]"
correctTestPingdomConfigMulti = "Pingdom"
correctTestPingdomAPIURL = "https://api.pingdom.com/api/3.1"
correctTestPingdomAlertContacts = "0544483_0_0-2628365_0_0-2633263_0_0"
correctTestPingdomAlertIntegrations = "91166,10924"
correctTestPingdomAPIKey = "657a68d9ashdyasjdklkskuasd"
correctTestPingdomAlertIntegrations = "91166-10924"
correctTestPingdomAPIToken = "657a68d9ashdyasjdklkskuasd"
correctTestPingdomTeamAlertContacts = "1234567_0_0-2628365_0_0-2633263_0_0"

configFilePathUptime = "../../examples/configs/test-config-uptime.yaml"
correctTestUptimeConfigName = "Uptime"
Expand All @@ -34,9 +32,8 @@ const (
)

func TestConfigWithCorrectValues(t *testing.T) {
correctConfig := Config{Providers: []Provider{{Name: correctTestPingdomConfigMulti, ApiKey: correctTestPingdomAPIKey, ApiURL: correctTestPingdomAPIURL,
AlertContacts: correctTestPingdomAlertContacts, AlertIntegrations: correctTestPingdomAlertIntegrations,
Username: correctTestPingdomUsername, Password: correctTestPingdomPassword, AccountEmail: correctTestPingdomAccountEmail}},
correctConfig := Config{Providers: []Provider{{Name: correctTestPingdomConfigMulti, ApiToken: correctTestPingdomAPIToken, ApiURL: correctTestPingdomAPIURL,
AlertContacts: correctTestPingdomAlertContacts, AlertIntegrations: correctTestPingdomAlertIntegrations, TeamAlertContacts: correctTestPingdomTeamAlertContacts}},
EnableMonitorDeletion: correctTestEnableMonitorDeletion, ResyncPeriod: 0}

config := ReadConfig(configFilePathPingdom)
Expand Down Expand Up @@ -73,18 +70,17 @@ func TestConfigWithoutProvider(t *testing.T) {
}

func TestConfigWithoutEnabledFlag(t *testing.T) {
incorrectConfig := Config{Providers: []Provider{{Name: correctTestConfigName, ApiKey: correctTestAPIKey, ApiURL: correctTestAPIURL, AlertContacts: correctTestAlertContacts}}}
incorrectConfig := Config{Providers: []Provider{{Name: correctTestConfigName, ApiKey: correctTestAPIKey, ApiURL: correctTestAPIURL, TeamAlertContacts: correctTestPingdomTeamAlertContacts, AlertContacts: correctTestAlertContacts}}}
config := ReadConfig(configFilePath)

if reflect.DeepEqual(config, incorrectConfig) {
t.Error("Marshalled config and incorrect config match, should not match")
}
}

func TestConfigWithPingdomMultiAuthEnabledFlag(t *testing.T) {
correctConfig := Config{Providers: []Provider{{Name: correctTestPingdomConfigMulti, ApiKey: correctTestPingdomAPIKey, ApiURL: correctTestPingdomAPIURL,
AlertContacts: correctTestPingdomAlertContacts, AlertIntegrations: correctTestPingdomAlertIntegrations,
Username: correctTestPingdomUsername, Password: correctTestPingdomPassword, AccountEmail: correctTestPingdomAccountEmail}},
func TestConfigWithPingdom(t *testing.T) {
correctConfig := Config{Providers: []Provider{{Name: correctTestPingdomConfigMulti, ApiToken: correctTestPingdomAPIToken, ApiURL: correctTestPingdomAPIURL,
AlertContacts: correctTestPingdomAlertContacts, AlertIntegrations: correctTestPingdomAlertIntegrations, TeamAlertContacts: correctTestPingdomTeamAlertContacts}},
EnableMonitorDeletion: correctTestEnableMonitorDeletion}
config := ReadConfig(configFilePathPingdom)
if !reflect.DeepEqual(config, correctConfig) {
Expand Down
Loading

0 comments on commit 221927f

Please sign in to comment.