Created
October 8, 2018 13:32
-
-
Save rk295/45b3408bdd7508ebe42405e0d5fabfdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- -- `core` is a static class provided by haproxy containing all | |
-- -- the haproxy methods we can use. | |
-- -- `register_init` registers a function to be executed after | |
-- -- configuration parsing. | |
-- core.register_init(function () | |
-- core.log(core.info, "script loaded: case-200-ok") | |
-- end) | |
-- `register_service` registers a lua function to be executed | |
-- as a service. Once it's been properly registered, the service | |
-- can be referenced in the haproxy configuration as `lua.<svc_name>`. | |
-- | |
-- Depending on the mode (tcp or http), the applet is either an | |
-- AppletHTTP or AppletTCP class instance. | |
core.register_service("tcp_healthcheck", "http", function (applet) | |
local backend_name = "simple-ad" | |
local r = "" | |
backend = core.proxies[backend_name] | |
servers = backend["servers"] | |
local any_up = false | |
for k, v in pairs(servers) do | |
status = v.get_stats(v)["status"] | |
-- If _any_ of the servers are up, we will return OK | |
if (status == "UP") then | |
any_up = true | |
end | |
end | |
if ( any_up ) then | |
core.log(core.info, "Found some servers up") | |
applet:set_status(200) | |
r = "OK" | |
else | |
core.log(core.info, "Found NO servers up") | |
applet:set_status(500) | |
r = "FAILED" | |
end | |
applet:start_response() | |
applet:send(r) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment