Create function check status for other system
This commit is contained in:
		
							parent
							
								
									c944e29c51
								
							
						
					
					
						commit
						300bd5651f
					
				| 
						 | 
					@ -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) => {
 | 
					    const promises = requests.map(async (req, index) => {
 | 
				
			||||||
      if (req.method === "POST") {
 | 
					      if (req.method === "POST") {
 | 
				
			||||||
        await axios
 | 
					        await axios
 | 
				
			||||||
| 
						 | 
					@ -915,57 +927,46 @@ const checkMultipleRequest = async () => {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (req.method === "SSH") {
 | 
					      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,
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          if (stdout !== "") {
 | 
					 | 
				
			||||||
            allResponse+=JSON.stringify(req.name+"\n"+stdout)
 | 
					 | 
				
			||||||
            console.log("stdout ", stdout)
 | 
					 | 
				
			||||||
            console.log(typeof stdout)
 | 
					 | 
				
			||||||
            console.log("req.name ", req.name)
 | 
					 | 
				
			||||||
            console.log(req.name==="Perthmint")
 | 
					 | 
				
			||||||
            console.log((stdout.toString().split("true").length-1)>1)
 | 
					 | 
				
			||||||
            if(req.name==="Perthmint"){
 | 
					 | 
				
			||||||
              if((stdout.toString().split("true").length-1)>1){
 | 
					 | 
				
			||||||
                report.push({
 | 
					 | 
				
			||||||
                  group: req.group,
 | 
					 | 
				
			||||||
                  name: req.name,
 | 
					 | 
				
			||||||
                  status: ":check:",
 | 
					 | 
				
			||||||
                  code: "good",
 | 
					 | 
				
			||||||
                  lengthOrData: stdout,
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
              }else{
 | 
					 | 
				
			||||||
                report.push({
 | 
					 | 
				
			||||||
                  group: req.group,
 | 
					 | 
				
			||||||
                  name: req.name,
 | 
					 | 
				
			||||||
                  status: ":red_circle:",
 | 
					 | 
				
			||||||
                  code: "fail",
 | 
					 | 
				
			||||||
                  lengthOrData: stdout,
 | 
					 | 
				
			||||||
                });
 | 
					 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const stdout = await runExec(req.url);
 | 
				
			||||||
 | 
					        if (stdout !== "") {
 | 
				
			||||||
 | 
					          allResponse+=JSON.stringify(req.name+"\n"+stdout)
 | 
				
			||||||
 | 
					          console.log("stdout ", stdout)
 | 
				
			||||||
 | 
					          console.log(typeof stdout)
 | 
				
			||||||
 | 
					          console.log("req.name ", req.name)
 | 
				
			||||||
 | 
					          console.log(req.name==="Perthmint")
 | 
				
			||||||
 | 
					          console.log((stdout.toString().split("true").length-1)>1)
 | 
				
			||||||
 | 
					          if(req.name==="Perthmint"){
 | 
				
			||||||
 | 
					            if((stdout.toString().split("true").length-1)>1){
 | 
				
			||||||
 | 
					              report.push({
 | 
				
			||||||
 | 
					                group: req.group,
 | 
				
			||||||
 | 
					                name: req.name,
 | 
				
			||||||
 | 
					                status: ":check:",
 | 
				
			||||||
 | 
					                code: "good",
 | 
				
			||||||
 | 
					                lengthOrData: stdout,
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
 | 
					            }else{
 | 
				
			||||||
 | 
					              report.push({
 | 
				
			||||||
 | 
					                group: req.group,
 | 
				
			||||||
 | 
					                name: req.name,
 | 
				
			||||||
 | 
					                status: ":red_circle:",
 | 
				
			||||||
 | 
					                code: "fail",
 | 
				
			||||||
 | 
					                lengthOrData: stdout,
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          } else {
 | 
					            
 | 
				
			||||||
            console.log(stderr)
 | 
					 | 
				
			||||||
            allResponse+=JSON.stringify(req.name+"\n"+stderr)
 | 
					 | 
				
			||||||
            report.push({
 | 
					 | 
				
			||||||
              group: req.group,
 | 
					 | 
				
			||||||
              name: req.name,
 | 
					 | 
				
			||||||
              status: ":red_circle:",
 | 
					 | 
				
			||||||
              code: "fail",
 | 
					 | 
				
			||||||
              lengthOrData: stderr,
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        });
 | 
					        } else {
 | 
				
			||||||
 | 
					          console.log(stderr)
 | 
				
			||||||
 | 
					          allResponse+=JSON.stringify(req.name+"\n"+stderr)
 | 
				
			||||||
 | 
					          report.push({
 | 
				
			||||||
 | 
					            group: req.group,
 | 
				
			||||||
 | 
					            name: req.name,
 | 
				
			||||||
 | 
					            status: ":red_circle:",
 | 
				
			||||||
 | 
					            code: "fail",
 | 
				
			||||||
 | 
					            lengthOrData: stderr,
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue