From d73684115a0018be8651e31e23e0c0734753afce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Fo=C5=A1n=C3=A1r?= Date: Mon, 15 Jan 2024 17:18:09 +0100 Subject: [PATCH 1/5] fix #4369 - treat unhealthy docker container as down --- server/model/monitor.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 2dc77fbd3..2356b9c91 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -770,7 +770,10 @@ class Monitor extends BeanModel { let res = await axios.request(options); if (res.data.State.Running) { - if (res.data.State.Health && res.data.State.Health.Status !== "healthy") { + if (res.data.State.Health && res.data.State.Health.Status === "unhealthy") { + bean.status = DOWN; + bean.msg = res.data.State.Health.Status; + } else if (res.data.State.Health && res.data.State.Health.Status !== "healthy") { bean.status = PENDING; bean.msg = res.data.State.Health.Status; } else { From 7f5dfcc05106724e410372303da6bd7c4657e47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Fo=C5=A1n=C3=A1r?= Date: Mon, 15 Jan 2024 19:12:16 +0100 Subject: [PATCH 2/5] fix #3767 by @nougad - treat empty healthcheck reported by podman as up --- server/model/monitor.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 2356b9c91..b6c393e44 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -770,12 +770,12 @@ class Monitor extends BeanModel { let res = await axios.request(options); if (res.data.State.Running) { - if (res.data.State.Health && res.data.State.Health.Status === "unhealthy") { - bean.status = DOWN; - bean.msg = res.data.State.Health.Status; - } else if (res.data.State.Health && res.data.State.Health.Status !== "healthy") { + if (res.data.State.Health && ![ "healthy", "unhealthy", "" ].includes(res.data.State.Health.Status)) { bean.status = PENDING; bean.msg = res.data.State.Health.Status; + } else if (res.data.State.Health && res.data.State.Health.Status === "unhealthy") { + bean.status = DOWN; + bean.msg = res.data.State.Health.Status; } else { bean.status = UP; bean.msg = res.data.State.Health ? res.data.State.Health.Status : res.data.State.Status; From 0b478404cf1c5596be47663c214d459a521be318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Fo=C5=A1n=C3=A1r?= Date: Mon, 15 Jan 2024 20:36:22 +0100 Subject: [PATCH 3/5] make DOWN the default fallback for docker container healthcheck --- server/model/monitor.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index b6c393e44..483f5266d 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -770,15 +770,20 @@ class Monitor extends BeanModel { let res = await axios.request(options); if (res.data.State.Running) { - if (res.data.State.Health && ![ "healthy", "unhealthy", "" ].includes(res.data.State.Health.Status)) { - bean.status = PENDING; - bean.msg = res.data.State.Health.Status; - } else if (res.data.State.Health && res.data.State.Health.Status === "unhealthy") { - bean.status = DOWN; - bean.msg = res.data.State.Health.Status; + if (res.data.State.Health) { + if ([ "", "healthy" ].includes(res.data.State.Health.Status)) { + bean.status = UP; + bean.msg = res.data.State.Health.Status; + } else if (res.data.State.Health.Status === "starting") { + bean.status = PENDING; + bean.msg = res.data.State.Health.Status; + } else { + bean.status = DOWN; + bean.msg = res.data.State.Health.Status; + } } else { - bean.status = UP; - bean.msg = res.data.State.Health ? res.data.State.Health.Status : res.data.State.Status; + bean.status = DOWN; + bean.msg = res.data.State.Status; } } else { throw Error("Container State is " + res.data.State.Status); From 0b0f081a1340a93c95f663b77e76a388f383bc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Fo=C5=A1n=C3=A1r?= Date: Wed, 17 Jan 2024 16:32:42 +0100 Subject: [PATCH 4/5] treat the starting state of a docker container as DOWN --- server/model/monitor.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 483f5266d..5aef8b144 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -774,9 +774,6 @@ class Monitor extends BeanModel { if ([ "", "healthy" ].includes(res.data.State.Health.Status)) { bean.status = UP; bean.msg = res.data.State.Health.Status; - } else if (res.data.State.Health.Status === "starting") { - bean.status = PENDING; - bean.msg = res.data.State.Health.Status; } else { bean.status = DOWN; bean.msg = res.data.State.Health.Status; From 2ba933734236c2368295cf225b2d703a56ecdda0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Fo=C5=A1n=C3=A1r?= Date: Thu, 18 Jan 2024 09:45:32 +0100 Subject: [PATCH 5/5] Apply suggestions for docker compose healthcheck Co-authored-by: Frank Elsinga --- server/model/monitor.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 5aef8b144..d036e3002 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -771,13 +771,10 @@ class Monitor extends BeanModel { if (res.data.State.Running) { if (res.data.State.Health) { - if ([ "", "healthy" ].includes(res.data.State.Health.Status)) { - bean.status = UP; - bean.msg = res.data.State.Health.Status; - } else { - bean.status = DOWN; - bean.msg = res.data.State.Health.Status; - } + // treat empty Status as healthy to support podman: https://github.com/louislam/uptime-kuma/issues/3767 + const containerIsHealthy = [ "", "healthy" ].includes(res.data.State.Health.Status); + bean.status = containerIsHealthy ? UP : DOWN; + bean.msg = res.data.State.Health.Status; } else { bean.status = DOWN; bean.msg = res.data.State.Status;