Enhance error handling for container state checks
This commit is contained in:
parent
65cadead3e
commit
5af0753415
@ -754,18 +754,32 @@ class Monitor extends BeanModel {
|
|||||||
log.debug("monitor", `[${this.name}] Axios Request`);
|
log.debug("monitor", `[${this.name}] Axios Request`);
|
||||||
let res = await axios.request(options);
|
let res = await axios.request(options);
|
||||||
|
|
||||||
if (res.data.State.Running) {
|
if (!res.data.State) {
|
||||||
|
throw Error("Container state is not available");
|
||||||
|
}
|
||||||
|
if (!res.data.State.Running) {
|
||||||
|
throw Error("Container State is " + res.data.State.Status);
|
||||||
|
}
|
||||||
|
if (res.data.State.Paused) {
|
||||||
|
throw Error("Container is paused");
|
||||||
|
}
|
||||||
|
if (res.data.State.Restarting) {
|
||||||
|
bean.status = PENDING;
|
||||||
|
bean.msg = "Container is reporting it is currently restarting";
|
||||||
|
} else if (res.data.State.Health && res.data.State.Health !== "none") {
|
||||||
|
// if healthchecks are disabled (?), Health MAY not be present
|
||||||
if (res.data.State.Health.Status === "healthy") {
|
if (res.data.State.Health.Status === "healthy") {
|
||||||
bean.status = UP;
|
bean.status = UP;
|
||||||
bean.msg = res.data.State.Health ? res.data.State.Health.Status : res.data.State.Status;
|
bean.msg = "healthy";
|
||||||
} else if (res.data.State.Health.Status === "unhealthy") {
|
} else if (res.data.State.Health.Status === "unhealthy") {
|
||||||
throw Error("Container State is unhealthy");
|
throw Error("Container State is unhealthy due according to its healthcheck");
|
||||||
} else {
|
} else {
|
||||||
bean.status = PENDING;
|
bean.status = PENDING;
|
||||||
bean.msg = res.data.State.Health.Status;
|
bean.msg = res.data.State.Health.Status;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw Error("Container State is " + res.data.State.Status);
|
bean.status = PENDING;
|
||||||
|
bean.msg = "Container has not reported its health and is currentlty " + res.data.State.Status;
|
||||||
}
|
}
|
||||||
} else if (this.type === "mysql") {
|
} else if (this.type === "mysql") {
|
||||||
let startTime = dayjs().valueOf();
|
let startTime = dayjs().valueOf();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user