Create function check status for other system

This commit is contained in:
joseph le 2023-10-11 15:58:18 +07:00
parent c944e29c51
commit 300bd5651f
1 changed files with 49 additions and 48 deletions

View File

@ -862,6 +862,18 @@ const checkMultipleRequest = async () => {
}
};
const runExec = (command) => {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
} else {
resolve(stdout);
}
});
});
}
const promises = requests.map(async (req, index) => {
if (req.method === "POST") {
await axios
@ -915,18 +927,8 @@ const checkMultipleRequest = async () => {
}
if (req.method === "SSH") {
await exec(req.url, (error, stdout, stderr) => {
if (error) {
allResponse+=JSON.stringify(req.name+"\n"+error)
report.push({
group: req.group,
name: req.name,
status: ":red_circle:",
code: error.status,
lengthOrData: "Error: " + error,
});
}
const stdout = await runExec(req.url);
if (stdout !== "") {
allResponse+=JSON.stringify(req.name+"\n"+stdout)
console.log("stdout ", stdout)
@ -965,7 +967,6 @@ const checkMultipleRequest = async () => {
lengthOrData: stderr,
});
}
});
}
});