From f6aabb7ed87b2ab7dcb324091852e659a7a1c890 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 21 Feb 2022 13:25:28 +0100 Subject: [PATCH] Change order of request parameters: api field moved from position 3 to 1 and are now required. --- README.md | 6 +++--- src/server.go | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 48904cf..bf45078 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ first to last below: | # | Name | Required | Description | | - | ---------- | ----------------------- | -------------------------------------------------------------- | -| 1 | url | Yes (port default `80`) | http url to the api. `http(s)://(:)` | -| 2 | num_blocks | No (default `10`) | Number of blocks the api can drift before reported `down` | -| 3 | api | No (default `v1`) | Type of API to check against, `v1` = standard, `v2` = Hyperion | +| 1 | api | Yes | Type of API to check against, `v1` = standard, `v2` = Hyperion | +| 2 | url | Yes (port default `80`) | http url to the api. `http(s)://(:)` | +| 3 | num_blocks | No (default `10`) | Number of blocks the api can drift before reported `down` | | 4 | host | No (default from `url`) | Value to send in the `HTTP Host Header` to the API | ### Response diff --git a/src/server.go b/src/server.go index f518181..8884650 100644 --- a/src/server.go +++ b/src/server.go @@ -20,6 +20,8 @@ type arguments struct { func createApi(a *arguments) api.ApiInterface { switch a.api { + case "contract": + return api.NewEosioContract(a.url, float64(a.block_time)) case "v2": return api.NewEosioV2(eosapi.ReqParams{Url: a.url, Host: a.host}, int64(a.block_time / 2)) } @@ -45,22 +47,29 @@ func onTcpMessage(c *tcp_server.Client, args string) { // ------------------- split := strings.Split(strings.TrimSpace(args), "|") - // 1. url (scheme + ip/domain + port) - a.url = split[0] + if len(split) < 2 { + msg := "Invalid number of parameters in agent request" - // 2. Block time. + logger.Warn("Agent request error", "message", msg, "args", split) + c.WriteString(fmt.Sprintf("%s#%s\n", haproxy.HealthCheckFailed, msg)) + c.Close() + return + } + + // 1. Api + a.api = split[0] + + // 2. url (scheme + ip/domain + port) + a.url = split[1] + + // 3. Block time. if len(split) > 1 { - num, err := strconv.ParseInt(split[1], 10, 32) + num, err := strconv.ParseInt(split[2], 10, 32) if err == nil { a.block_time = int(num) } } - // 3. Api - if len(split) > 2 { - a.api = split[2] - } - // 4. Host if len(split) > 3 { a.host = split[3]