Skip to content

Commit

Permalink
[updown-supprot-in-imc] implemented two method Setup and GetAll metho…
Browse files Browse the repository at this point in the history
…d of updown monitor, added httpStatusCodesMap file that contains a map of status codes, delete test file for now and fixed typo in pingdom monior
  • Loading branch information
aliartiza75 committed Apr 8, 2019
1 parent 5e09602 commit 02b3855
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
4 changes: 3 additions & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ import:
- package: github.com/pkg/errors
version: v0.8.0
- package: github.com/openshift/client-go
version: v3.9.0
version: v3.9.0
- package: github.com/antoineaugusti/updown
version: v0.3
8 changes: 8 additions & 0 deletions pkg/constants/httpStatusCodesMap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// httpStatusCodesMap contains basic http response codes
package constants

var HTTPStatusCodesMap = map[string]int{
"OK": 200,
"NOT_FOUND": 404,
"UN_AUTHORISED": 401,
"BAD_REQUEST": 400}
2 changes: 1 addition & 1 deletion pkg/monitors/pingdom/pingdom-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (service *PingdomMonitorService) GetAll() []models.Monitor {

checks, err := service.client.Checks.List()
if err != nil {
log.Println("Error recevied while listing checks: ", err.Error())
log.Println("Error received while listing checks: ", err.Error())
return nil
}
for _, mon := range checks {
Expand Down
57 changes: 57 additions & 0 deletions pkg/monitors/updown/updown-monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Package UpdownMonitor adds updown website monitoring tool's support in IngressMonitorController
package updown

import (
"log"
"net/http"

"github.com/antoineaugusti/updown"
"github.com/stakater/IngressMonitorController/pkg/config"
"github.com/stakater/IngressMonitorController/pkg/constants"
"github.com/stakater/IngressMonitorController/pkg/models"
)

// UpdownMonitorService struct contains parameters required by updown go client
type UpdownMonitorService struct {
apiKey string
url string
alertContacts string
client *updown.Client
statusCodes constants.HTTPStatusCodesMap
}

// Setup function will create a updown's go client object by using the configuration parameters
func (updownService *UpdownMonitorService) Setup(confProvider config.Provider) {
// configuration parameters for creating a updown client
updownService.apiKey = confProvider.ApiKey
updownService.alertContacts = confProvider.AlertContacts
// creating updown go client
httpDefaultClient := http.DefaultClient
updownService.client = updown.NewClient(updownService.apiKey, http.DefaultClient)
}

// GetAll function will return all checks object in an array
func (updownService *UpdownMonitorService) GetAll() []models.Monitor {

var monitors []models.Monitor

// getting all checks list
updownChecks, httpResponse, err := updownService.client.Check.List()

if (httpResponse.StatusCode == updownService.statusCodes.OK) && (err == nil) {

// populating a monitors array using the updownChecks objects given in updownChecks slice
for _, updownCheck := range updownChecks {
newMonitor := models.Monitor{
URL: updownCheck.URL,
NAME: updownCheck.Alias,
TOKEN: updownCheck.Token,
}
monitors = append(monitors, newMonitor)
}
return monitors
} else {
log.Println("Unable to get updown provider checks")
}

}
Empty file.

0 comments on commit 02b3855

Please sign in to comment.