-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[updown-supprot-in-imc] implemented two method Setup and GetAll metho…
…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
1 parent
5e09602
commit 02b3855
Showing
5 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.