Add some dashboard api

This commit is contained in:
2018-03-15 09:22:43 +11:00
parent b805a9d367
commit 3a64ca5659
8 changed files with 28 additions and 10 deletions
+4 -5
View File
@@ -1,5 +1,5 @@
name: dex-prod
frequency: 10
frequency: 5
db:
url: "host=localhost port=5432 user=postgres dbname=next_dashboard password=postgres sslmode=disable"
type: postgres
@@ -9,7 +9,6 @@ db:
table: http_healths
field: url
value: https://docs.dev.dexdev.greensync.xyz/health
- name: two
table: http_healths
@@ -18,10 +17,10 @@ http:
- url: https://api.dev.dexdev.greensync.xyz/health/contracts
name: contracts
- url: https://docs.dev.dexdev.greensync.xyz/health
name: docs
- url: http://app.dev.dexdev.greensync.xyz/health
name: docs-fake
- url: http://app.dev.dexdev.greensync.xyz/health1
name: app
event:
checks:
- name: 'contracts'
- name: contracts
+14
View File
@@ -13,7 +13,21 @@ type DashboardController struct {
}
func (controller *DashboardController) Database(c *gin.Context) {
var records []*models.DBSummary
controller.DB.Limit(20).Order("created_at desc").Where("name = ?", c.Param("name")).Find(&records)
c.JSON(http.StatusOK, records)
}
func (controller *DashboardController) HTTPEndpoint(c *gin.Context) {
var records []*models.HTTPHealth
controller.DB.Limit(20).Order("created_at desc").Where("name = ?", c.Param("name")).Find(&records)
c.JSON(http.StatusOK, records)
}
func (controller *DashboardController) Event(c *gin.Context) {
var records []*models.WebHookData
controller.DB.Limit(20).Order("created_at desc").Where("name = ?", c.Param("name")).Find(&records)
c.JSON(http.StatusOK, records)
}
func (controller *DashboardController) Show(c *gin.Context) {
+2 -1
View File
@@ -31,7 +31,8 @@ func (controller *WebHookController) PostData(c *gin.Context) {
}
controller.DB.Create(&models.WebHookData{
Type: c.Param("name"),
Name: c.Param("name"),
Type: requestBody.Type,
Body: requestBody.Body,
Title: requestBody.Title,
})
+3 -1
View File
@@ -60,7 +60,9 @@ func main() {
server := gin.Default()
server.Use(setupCORS())
server.POST("/webhooks/:name", webhookController.PostData)
server.GET("/dashboard/db", dashboardController.Database)
server.GET("/dashboard/db/:name", dashboardController.Database)
server.GET("/dashboard/http/:name", dashboardController.HTTPEndpoint)
server.GET("/dashboard/event/:name", dashboardController.Event)
server.GET("/dashboard", dashboardController.Show)
server.Run()
+1 -1
View File
@@ -27,7 +27,7 @@ type DBCheck struct {
Value string `json:"value"`
}
type HTTPConfig struct {
Checks []*HTTPCheck `json:"check"`
Checks []*HTTPCheck `json:"checks"`
}
type HTTPCheck struct {
+1
View File
@@ -7,4 +7,5 @@ type WebHookData struct {
Type string `json:"type"`
Title string `json:"title"`
Body string `json:"body"`
Name string `json:"name"`
}
+1
View File
@@ -3,4 +3,5 @@ package requests
type WebhookRequest struct {
Title string `json:"title"`
Body string `json:"body"`
Type string `json:"type"`
}
+2 -2
View File
@@ -26,9 +26,9 @@ DoRequest:
}
func doHTTPChecks(db *gorm.DB, check *models.HTTPCheck) {
logrus.Info("Request URL:" + check.URL)
// logrus.Info("Request URL:" + check.URL)
resp, err := resty.R().Get(check.URL)
logrus.Debugf("Request of URL: %s Status code is: %d, response time is: %f s", check.URL, resp.StatusCode(), resp.Time().Seconds())
logrus.Infof("Request of URL: %s Status code is: %d, response time is: %f s", check.URL, resp.StatusCode(), resp.Time().Seconds())
db.Create(&models.HTTPHealth{
URL: check.URL,
Name: check.Name,