reworked container data fetching
Currently it would log "container not found" even if the container was found
This commit is contained in:
parent
d8b2a3bb46
commit
6014189be3
1 changed files with 28 additions and 21 deletions
|
@ -107,32 +107,39 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
|
|||
}
|
||||
// Type Docker
|
||||
else if (entry.type === ServiceType.docker) {
|
||||
for (let i = 0; i < containers.length; i++) {
|
||||
const container = containers[i];
|
||||
// Docker API returns container names with / prepended
|
||||
if (containers[i].Names.includes("/" + entry.docker_container_name)) {
|
||||
// so far only "running" is properly implemented, mroe cases to follow as needed
|
||||
switch (container.State) {
|
||||
case "running":
|
||||
entry.status = ServiceStatus.online;
|
||||
break;
|
||||
default:
|
||||
console.log("Container Status " + container.State + " has no case implemented");
|
||||
entry.status = ServiceStatus.offline;
|
||||
if (entry.name !== null) {
|
||||
let found = false;
|
||||
for (let i = 0; i < containers.length; i++) {
|
||||
const container = containers[i];
|
||||
// Docker API returns container names with / prepended
|
||||
if (containers[i].Names.includes("/" + entry.docker_container_name)) {
|
||||
// so far only "running" is properly implemented, mroe cases to follow as needed
|
||||
switch (container.State) {
|
||||
case "running":
|
||||
entry.status = ServiceStatus.online;
|
||||
break;
|
||||
default:
|
||||
console.log("Container Status " + container.State + " has no case implemented");
|
||||
entry.status = ServiceStatus.offline;
|
||||
}
|
||||
found = true;
|
||||
// cancel the for
|
||||
break;
|
||||
}
|
||||
// If container name is not missing the container is set to offline
|
||||
else {
|
||||
entry.status = ServiceStatus.offline;
|
||||
}
|
||||
// cancel the for
|
||||
break;
|
||||
}
|
||||
// If container name is not missing the container is set to offline
|
||||
else if (entry.docker_container_name !== null) {
|
||||
if (!found) {
|
||||
console.warn("Container for " + entry.name + " could not be found");
|
||||
entry.status = ServiceStatus.offline;
|
||||
}
|
||||
else {
|
||||
console.error("Container Name not specified");
|
||||
entry.status = ServiceStatus.error;
|
||||
}
|
||||
}
|
||||
// if name is null do not enter for loop
|
||||
else {
|
||||
console.error("Container Name not specified");
|
||||
entry.status = ServiceStatus.error;
|
||||
}
|
||||
}
|
||||
// If no Type matches
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue