Skip to content

Commit

Permalink
Merge pull request #286 from namm2/pingdom-api-v3
Browse files Browse the repository at this point in the history
Update IMC v1 to be compatible with Pingdom API v3
  • Loading branch information
ahmedwaleedmalik committed Oct 20, 2020
2 parents d063490 + e2f68bf commit f7f3453
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 50 deletions.
6 changes: 1 addition & 5 deletions configs/testConfigs/test-config-pingdom.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
providers:
- name: PingdomMulti
apiURL: "https://api.pingdom.com/v2/"
apiKey: "657a68d9ashdyasjdklkskuasd"
username: "user@test.com"
password: "SuperSecret"
accountEmail: "multi@test.com"
apiToken: "657a68d9ashdyasjdklkskuasd"
alertContacts: "0544483_0_0-2628365_0_0-2633263_0_0"
alertIntegrations: "91166,10924"
enableMonitorDeletion: true
5 changes: 2 additions & 3 deletions docs/pingdom-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ 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 | Your generated Pingdom API Token |

## 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)

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

## Advanced
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/openshift/api v0.0.0-20200526144822-34f54f12813a
github.com/openshift/client-go v0.0.0-20200521150516-05eb9880269c
github.com/pkg/errors v0.9.1
github.com/russellcardullo/go-pingdom v1.0.0
github.com/russellcardullo/go-pingdom v1.2.0
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.4.0
google.golang.org/api v0.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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.2.0 h1:2Ow0DAxEzzuZ2hW5uX/guA/j0UChAP43OaUPsEVqNJ8=
github.com/russellcardullo/go-pingdom v1.2.0/go.mod h1:NT3vtTnQ6SX9/FeDcf+QOb9GHZ7jDUdmY7wFVfxRxok=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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"`
Expand Down
16 changes: 5 additions & 11 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ const (

configFilePathPingdom = "../../configs/testConfigs/test-config-pingdom.yaml"
correctTestPingdomConfigMulti = "PingdomMulti"
correctTestPingdomUsername = "user@test.com"
correctTestPingdomAPIURL = "https://api.pingdom.com/v2/"
correctTestPingdomPassword = "SuperSecret"
correctTestPingdomAccountEmail = "multi@test.com"
correctTestPingdomAPIToken = "657a68d9ashdyasjdklkskuasd"
correctTestPingdomAlertContacts = "0544483_0_0-2628365_0_0-2633263_0_0"
correctTestPingdomAlertIntegrations = "91166,10924"
correctTestPingdomAPIKey = "657a68d9ashdyasjdklkskuasd"

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

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

config := ReadConfig(configFilePathPingdom)
Expand Down Expand Up @@ -82,9 +77,8 @@ func TestConfigWithoutEnabledFlag(t *testing.T) {
}

func TestConfigWithPingdomMultiAuthEnabledFlag(t *testing.T) {
correctConfig := Config{Providers: []Provider{Provider{Name: correctTestPingdomConfigMulti, ApiKey: correctTestPingdomAPIKey, ApiURL: correctTestPingdomAPIURL,
AlertContacts: correctTestPingdomAlertContacts, AlertIntegrations: correctTestPingdomAlertIntegrations,
Username: correctTestPingdomUsername, Password: correctTestPingdomPassword, AccountEmail: correctTestPingdomAccountEmail}},
correctConfig := Config{Providers: []Provider{Provider{Name: correctTestPingdomConfigMulti, ApiToken: correctTestPingdomAPIToken,
AlertContacts: correctTestPingdomAlertContacts, AlertIntegrations: correctTestPingdomAlertIntegrations}},
EnableMonitorDeletion: correctTestEnableMonitorDeletion}
config := ReadConfig(configFilePathPingdom)
if !reflect.DeepEqual(config, correctConfig) {
Expand Down
57 changes: 27 additions & 30 deletions pkg/monitors/pingdom/pingdom-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,24 @@ const (

// PingdomMonitorService interfaces with MonitorService
type PingdomMonitorService struct {
apiKey string
apiToken string
url string
alertContacts string
alertIntegrations string
username string
password string
accountEmail string
client *pingdom.Client
}

func (service *PingdomMonitorService) Setup(p config.Provider) {
service.apiKey = p.ApiKey
service.url = p.ApiURL
service.apiToken = p.ApiToken
service.alertContacts = p.AlertContacts
service.alertIntegrations = p.AlertIntegrations
service.username = p.Username
service.password = p.Password

// Check if config file defines a multi-user config
if p.AccountEmail != "" {
service.accountEmail = p.AccountEmail
service.client = pingdom.NewMultiUserClient(service.username, service.password, service.apiKey, service.accountEmail)
} else {
service.client = pingdom.NewClient(service.username, service.password, service.apiKey)
var err error
service.client, err = pingdom.NewClientWithConfig(pingdom.ClientConfig{
APIToken: service.apiToken,
})
if err != nil {
log.Println("Failed to authenticate with error: ", err.Error())
}
}

Expand Down Expand Up @@ -141,22 +135,25 @@ func (service *PingdomMonitorService) createHttpCheck(monitor models.Monitor) pi
httpCheck.Url = url.Path
httpCheck.Name = monitor.Name

userIdsStringArray := strings.Split(service.alertContacts, "-")

if userIds, err := util.SliceAtoi(userIdsStringArray); err != nil {
log.Println(err.Error())
} else {
httpCheck.UserIds = userIds
}

integrationIdsStringArray := strings.Split(service.alertIntegrations, "-")

if integrationIds, err := util.SliceAtoi(integrationIdsStringArray); err != nil {
log.Println(err.Error())
} else {
httpCheck.IntegrationIds = integrationIds
}

if service.alertContacts != "" {
userIdsStringArray := strings.Split(service.alertContacts, "-")

if userIds, err := util.SliceAtoi(userIdsStringArray); err != nil {
log.Println(err.Error())
} else {
httpCheck.UserIds = userIds
}
}

if service.alertIntegrations != "" {
integrationIdsStringArray := strings.Split(service.alertIntegrations, "-")

if integrationIds, err := util.SliceAtoi(integrationIdsStringArray); err != nil {
log.Println(err.Error())
} else {
httpCheck.IntegrationIds = integrationIds
}
}
service.addAnnotationConfigToHttpCheck(&httpCheck, monitor.Annotations)

return httpCheck
Expand Down

0 comments on commit f7f3453

Please sign in to comment.