1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-08-31 21:38:12 +02:00

internal/api: rename eosio_*.go to antelope_*.go

This commit is contained in:
Henrik Hautakoski 2022-12-22 14:17:22 +01:00
parent 1fc8c927aa
commit 86e87d8245
No known key found for this signature in database
GPG key ID: 217490840C18A5D9
4 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,71 @@
package api
import (
"fmt"
"github.com/eosswedenorg-go/haproxy/agentcheck"
"github.com/eosswedenorg-go/leapapi"
"github.com/eosswedenorg/antelope-api-healthcheck/internal/utils"
)
type AntelopeV1 struct {
utils.Time
client leapapi.Client
block_time float64
}
func AntelopeV1Factory(args ApiArguments) ApiInterface {
return NewAntelopeV1(args.Url, args.Host, float64(args.NumBlocks/2))
}
func NewAntelopeV1(url string, host string, block_time float64) AntelopeV1 {
api := AntelopeV1{
client: *leapapi.New(url),
block_time: block_time,
}
api.client.Host = host
return api
}
func (e AntelopeV1) LogInfo() LogParams {
p := LogParams{
"type", "antelope-v1",
"url", e.client.Url,
}
if len(e.client.Host) > 0 {
p.Add("host", e.client.Host)
}
p.Add("block_time", e.block_time)
return p
}
func (e AntelopeV1) Call() (agentcheck.Response, string) {
info, err := e.client.GetInfo()
if err != nil {
resp := agentcheck.NewStatusMessageResponse(agentcheck.Fail, "")
return resp, err.Error()
}
// Validate head block.
diff := e.GetTime().Sub(info.HeadBlockTime).Seconds()
if diff > e.block_time {
resp := agentcheck.NewStatusMessageResponse(agentcheck.Down, "")
msg := "Taking offline because head block is lagging %.0f seconds"
return resp, fmt.Sprintf(msg, diff)
} else if diff < -e.block_time {
resp := agentcheck.NewStatusMessageResponse(agentcheck.Down, "")
msg := "Taking offline because head block is %.0f seconds into the future"
return resp, fmt.Sprintf(msg, diff)
}
return agentcheck.NewStatusResponse(agentcheck.Up), "OK"
}