crowdsec/pkg/apiserver/controllers/v1/heartbeat.go
Thibault "bui" Koechlin fe09737d80
Add support for machine heartbeat (#1541)
* add the last_heartbeat field

* add heartbeat controller

* add endpoint of heartbeat

* heartbeat integration

* add last_heartbeat to cscli machines list
2022-05-19 15:47:27 +02:00

22 lines
442 B
Go

package v1
import (
"net/http"
jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
)
func (c *Controller) HeartBeat(gctx *gin.Context) {
claims := jwt.ExtractClaims(gctx)
/*TBD : use defines rather than hardcoded key to find back owner*/
machineID := claims["id"].(string)
if err := c.DBClient.UpdateMachineLastHeartBeat(machineID); err != nil {
c.HandleDBErrors(gctx, err)
return
}
gctx.Status(http.StatusOK)
}