Skip to content

Commit

Permalink
Update to use pingdom API v3
Browse files Browse the repository at this point in the history
  • Loading branch information
namm2 committed Oct 16, 2020
1 parent d063490 commit 3cd6104
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
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
59 changes: 28 additions & 31 deletions pkg/monitors/pingdom/pingdom-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,25 @@ 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())
}
}

func (service *PingdomMonitorService) GetByName(name string) (*models.Monitor, 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 3cd6104

Please sign in to comment.