reworked container data fetching

Currently it would log "container not found" even if the container was found
This commit is contained in:
Neshura 2022-12-11 17:24:03 +01:00
parent d8b2a3bb46
commit 6014189be3
No known key found for this signature in database
GPG key ID: ACDF5B6EBECF6B0A

View file

@ -107,6 +107,8 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
}
// Type Docker
else if (entry.type === ServiceType.docker) {
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
@ -120,20 +122,25 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[])
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 if (entry.docker_container_name !== null) {
console.warn("Container for " + entry.name + " could not be found");
else {
entry.status = ServiceStatus.offline;
}
}
if (!found) {
console.warn("Container for " + entry.name + " could not be found");
}
}
// 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 {
console.warn("Service Type for Service " + entry.name + " not specified or invalid");