diff --git a/config.yaml b/config.yaml index 30b601e..90f60e9 100644 --- a/config.yaml +++ b/config.yaml @@ -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 diff --git a/controllers/dashboard.go b/controllers/dashboard.go index 3915a23..6cdadfd 100644 --- a/controllers/dashboard.go +++ b/controllers/dashboard.go @@ -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) { diff --git a/controllers/webhooks.go b/controllers/webhooks.go index 62f26fb..48b2fe5 100644 --- a/controllers/webhooks.go +++ b/controllers/webhooks.go @@ -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, }) diff --git a/main.go b/main.go index 7e5ba15..b0a99bd 100644 --- a/main.go +++ b/main.go @@ -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() diff --git a/models/configuration.go b/models/configuration.go index dcad603..b5cbb0e 100644 --- a/models/configuration.go +++ b/models/configuration.go @@ -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 { diff --git a/models/webhook.go b/models/webhook.go index bf635f3..4b821b8 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -7,4 +7,5 @@ type WebHookData struct { Type string `json:"type"` Title string `json:"title"` Body string `json:"body"` + Name string `json:"name"` } diff --git a/requests/webhook.go b/requests/webhook.go index 5b26aca..bccd032 100644 --- a/requests/webhook.go +++ b/requests/webhook.go @@ -3,4 +3,5 @@ package requests type WebhookRequest struct { Title string `json:"title"` Body string `json:"body"` + Type string `json:"type"` } diff --git a/workers/http_endpoints.go b/workers/http_endpoints.go index 83f134e..c88ffa2 100644 --- a/workers/http_endpoints.go +++ b/workers/http_endpoints.go @@ -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,