Skip to content

Commit 810b487

Browse files
bradh352Copilot
andcommitted
Update systemvm/debian/root/health_checks/haproxy_check.py
copilot suggestion Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent bac44ed commit 810b487

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

systemvm/debian/root/health_checks/haproxy_check.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,44 @@ def checkMaxconn(haproxyData, haCfgSections):
2929
return True
3030

3131
def checkIdletimeout(haproxyData, haCfgSections):
32-
if "idletimeout" in haproxyData:
33-
if "timeout client" not in haCfgSections["defaults"] or "timeout server" not in haCfgSections["defaults"]:
34-
print("defaults timeout client or timeout server missing")
32+
if "idletimeout" not in haproxyData:
33+
return True
3534

36-
if haproxyData["idletimeout"] != haCfgSections["defaults"]["timeout client"][0].strip() or haproxyData["idletimeout"] != haCfgSections["defaults"]["timeout server"][0].strip():
37-
print("defaults timeout client or timeout server mismatch occurred")
35+
# Normalize idletimeout value to string for comparison
36+
idle_value = str(haproxyData["idletimeout"]).strip()
37+
38+
# Safely get the defaults section and its timeout directives
39+
defaults_section = haCfgSections.get("defaults", {})
40+
timeout_lines = defaults_section.get("timeout", [])
41+
42+
# Extract client and server timeout values from the parsed "timeout" entries
43+
timeout_values = {}
44+
for tline in timeout_lines:
45+
tline = tline.strip()
46+
if not tline:
47+
continue
48+
parts = tline.split(None, 1)
49+
if len(parts) < 2:
50+
continue
51+
kind, value = parts[0].strip(), parts[1].strip()
52+
if kind in ("client", "server"):
53+
timeout_values[kind] = value
54+
55+
# Special handling for idletimeout == 0: there should be no client/server timeouts configured
56+
if idle_value == "0":
57+
if "client" in timeout_values or "server" in timeout_values:
58+
print("defaults timeout client or timeout server should be absent when idletimeout is 0")
3859
return False
60+
return True
61+
62+
# Non-zero idletimeout: both client and server timeouts must be present
63+
if "client" not in timeout_values or "server" not in timeout_values:
64+
print("defaults timeout client or timeout server missing")
65+
return False
3966

67+
if idle_value != timeout_values["client"] or idle_value != timeout_values["server"]:
68+
print("defaults timeout client or timeout server mismatch occurred")
69+
return False
4070
return True
4171

4272
def checkLoadBalance(haproxyData, haCfgSections):

0 commit comments

Comments
 (0)