mirror of
https://github.com/wahyd4/next-dashboard.git
synced 2026-08-09 04:26:06 +10:00
Add some dashboard api
This commit is contained in:
+4
-5
@@ -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
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -7,4 +7,5 @@ type WebHookData struct {
|
||||
Type string `json:"type"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@ package requests
|
||||
type WebhookRequest struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user