update write for functions
This commit is contained in:
		
							parent
							
								
									d06d5c7586
								
							
						
					
					
						commit
						1ea8092676
					
				| 
						 | 
					@ -0,0 +1,34 @@
 | 
				
			||||||
 | 
					import fs from "fs";
 | 
				
			||||||
 | 
					import moment from "moment";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const addLogFunction = async (fileName, data, functionName) => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    fs.exists(fileName, async (exists) => {
 | 
				
			||||||
 | 
					      if (exists) {
 | 
				
			||||||
 | 
					        let old_data = await fs.readFileSync(fileName, "utf8");
 | 
				
			||||||
 | 
					        fs.writeFileSync(
 | 
				
			||||||
 | 
					          fileName,
 | 
				
			||||||
 | 
					          old_data +
 | 
				
			||||||
 | 
					            "\n\n[" +
 | 
				
			||||||
 | 
					            moment(Date.now()).format("D/M/YY-HH:mm:ss") +
 | 
				
			||||||
 | 
					            "] - " +
 | 
				
			||||||
 | 
					            functionName +
 | 
				
			||||||
 | 
					            "\n" +
 | 
				
			||||||
 | 
					            data +
 | 
				
			||||||
 | 
					            "\n\n======================================================================"
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        fs.writeFileSync(
 | 
				
			||||||
 | 
					          fileName,
 | 
				
			||||||
 | 
					          "\n\n[" +
 | 
				
			||||||
 | 
					            moment(Date.now()).format("D/M/YY-HH:mm:ss") +
 | 
				
			||||||
 | 
					            "] - System Logs" +
 | 
				
			||||||
 | 
					            data +
 | 
				
			||||||
 | 
					            "\n\n======================================================================"
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.log(error);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,34 @@
 | 
				
			||||||
 | 
					import fs from "fs";
 | 
				
			||||||
 | 
					import moment from "moment";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const addLogFunction = async (fileName, data, functionName) => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    fs.exists(fileName, async (exists) => {
 | 
				
			||||||
 | 
					      if (exists) {
 | 
				
			||||||
 | 
					        let old_data = await fs.readFileSync(fileName, "utf8");
 | 
				
			||||||
 | 
					        fs.writeFileSync(
 | 
				
			||||||
 | 
					          fileName,
 | 
				
			||||||
 | 
					          old_data +
 | 
				
			||||||
 | 
					            "\n\n[" +
 | 
				
			||||||
 | 
					            moment(Date.now()).format("D/M/YY-HH:mm:ss") +
 | 
				
			||||||
 | 
					            "] - " +
 | 
				
			||||||
 | 
					            functionName +
 | 
				
			||||||
 | 
					            "\n" +
 | 
				
			||||||
 | 
					            data +
 | 
				
			||||||
 | 
					            "\n\n======================================================================"
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        fs.writeFileSync(
 | 
				
			||||||
 | 
					          fileName,
 | 
				
			||||||
 | 
					          "\n\n[" +
 | 
				
			||||||
 | 
					            moment(Date.now()).format("D/M/YY-HH:mm:ss") +
 | 
				
			||||||
 | 
					            "] - System Logs" +
 | 
				
			||||||
 | 
					            data +
 | 
				
			||||||
 | 
					            "\n\n======================================================================"
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.log(error);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,8 @@ import Env from "@ioc:Adonis/Core/Env";
 | 
				
			||||||
// import fs from "fs";
 | 
					// import fs from "fs";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import axios from "axios";
 | 
					import axios from "axios";
 | 
				
			||||||
 | 
					import { addLogFunction } from "./addLogFunction";
 | 
				
			||||||
 | 
					import moment from "moment";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const checkIndexSN = async (content, beginLine, nameF) => {
 | 
					export const checkIndexSN = async (content, beginLine, nameF) => {
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
| 
						 | 
					@ -195,6 +197,11 @@ export const checkIndexSN = async (content, beginLine, nameF) => {
 | 
				
			||||||
          );
 | 
					          );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          console.log(nameF + " response\n", response_int.data);
 | 
					          console.log(nameF + " response\n", response_int.data);
 | 
				
			||||||
 | 
					          const fileName =
 | 
				
			||||||
 | 
					            "./app/store/logsAPI/" +
 | 
				
			||||||
 | 
					            moment(Date.now()).format("DD_MM_YYYY").toString() +
 | 
				
			||||||
 | 
					            ".log";
 | 
				
			||||||
 | 
					          addLogFunction(fileName, "URL: https://int.ipsupply.com.au/api/transferPostData\n"+ response_int.data, "Update SN index to int.ipsupply.com.au");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
const puppeteer = require("puppeteer");
 | 
					const puppeteer = require("puppeteer");
 | 
				
			||||||
const zulip = require("zulip-js");
 | 
					const zulip = require("zulip-js");
 | 
				
			||||||
 | 
					const { addLogFunction } = require("./addLogFunction");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(async () => {
 | 
					(async () => {
 | 
				
			||||||
  // Launch a headless browser
 | 
					  // Launch a headless browser
 | 
				
			||||||
| 
						 | 
					@ -72,4 +73,9 @@ const zulip = require("zulip-js");
 | 
				
			||||||
      client.messages.send(params);
 | 
					      client.messages.send(params);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }, 5000);
 | 
					  }, 5000);
 | 
				
			||||||
 | 
					  const fileName =
 | 
				
			||||||
 | 
					      "./app/store/logsAPI/" +
 | 
				
			||||||
 | 
					      moment(Date.now()).format("DD_MM_YYYY").toString() +
 | 
				
			||||||
 | 
					      ".log";
 | 
				
			||||||
 | 
					  addLogFunction(fileName, JSON.stringify(params, null, 2), "powerSchedule")
 | 
				
			||||||
})();
 | 
					})();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 304 KiB  | 
| 
						 | 
					@ -5,6 +5,7 @@ import nodeMailer from "nodemailer";
 | 
				
			||||||
import LogDetectFile from "App/Models/LogDetectFile";
 | 
					import LogDetectFile from "App/Models/LogDetectFile";
 | 
				
			||||||
import InfoDevice from "App/Models/InfoDevice";
 | 
					import InfoDevice from "App/Models/InfoDevice";
 | 
				
			||||||
import KeyValue from "App/Models/KeyValue";
 | 
					import KeyValue from "App/Models/KeyValue";
 | 
				
			||||||
 | 
					import { addLogFunction } from "./addLogFunction";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const sendDeviceInfora = async () => {
 | 
					export const sendDeviceInfora = async () => {
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
| 
						 | 
					@ -333,8 +334,19 @@ export const sendDeviceInfora = async () => {
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
      transporter.sendMail(options);
 | 
					      transporter.sendMail(options);
 | 
				
			||||||
      await InfoDevice.createMany(listInformation);
 | 
					      await InfoDevice.createMany(listInformation);
 | 
				
			||||||
    }else{
 | 
					      const fileName =
 | 
				
			||||||
      console.log("listInformation", listInformation)
 | 
					        "./app/store/logsAPI/" +
 | 
				
			||||||
 | 
					        moment(Date.now()).format("DD_MM_YYYY").toString() +
 | 
				
			||||||
 | 
					        ".log";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      addLogFunction(
 | 
				
			||||||
 | 
					        fileName,
 | 
				
			||||||
 | 
					        JSON.stringify(listInformation[0], null, 2),
 | 
				
			||||||
 | 
					        "Get-Send devices info"
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      console.log("listInformation", listInformation);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } catch (error) {
 | 
					  } catch (error) {
 | 
				
			||||||
    console.log(error);
 | 
					    console.log(error);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ const moment = require("moment");
 | 
				
			||||||
const zulip = require("zulip-js");
 | 
					const zulip = require("zulip-js");
 | 
				
			||||||
const { exec } = require("child_process");
 | 
					const { exec } = require("child_process");
 | 
				
			||||||
const fs = require("fs");
 | 
					const fs = require("fs");
 | 
				
			||||||
 | 
					const { addLogFunction } = require("./addLogFunction");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const config = {
 | 
					const config = {
 | 
				
			||||||
  username: "networktool-bot@zulip.ipsupply.com.au",
 | 
					  username: "networktool-bot@zulip.ipsupply.com.au",
 | 
				
			||||||
| 
						 | 
					@ -955,149 +956,168 @@ const checkMultipleRequest = async () => {
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const promises = requests.map(async (req, index) => {
 | 
					    const promises = requests.map(async (req, index) => {
 | 
				
			||||||
     try {
 | 
					      try {
 | 
				
			||||||
      if (req.method === "POST") {
 | 
					        if (req.method === "POST") {
 | 
				
			||||||
        let response = await axios.post(req.url, req.data, {
 | 
					          let response = await axios.post(req.url, req.data, {
 | 
				
			||||||
          headers: req.headers,
 | 
					            headers: req.headers,
 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let responseDataString = JSON.stringify(response.data, null, 2);
 | 
					 | 
				
			||||||
        allResponse += `${req.name}\n${responseDataString}\n\n`;
 | 
					 | 
				
			||||||
        console.log(response.data);
 | 
					 | 
				
			||||||
        // Xử lý response ở đây
 | 
					 | 
				
			||||||
        // console.log("Response:", response.data.length);
 | 
					 | 
				
			||||||
        // console.log("Status:", response.status);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (response.data !== "" && response.data !== undefined) {
 | 
					 | 
				
			||||||
          if (req.name !== "Auto import Disti") {
 | 
					 | 
				
			||||||
            logicCheck(req, response);
 | 
					 | 
				
			||||||
          } else {
 | 
					 | 
				
			||||||
            console.log(response.data?.data?.length);
 | 
					 | 
				
			||||||
            if (response.data?.data?.length > 0) {
 | 
					 | 
				
			||||||
              response.data?.data?.map((u) => {
 | 
					 | 
				
			||||||
                let name = req.name + " from " + u.data_name;
 | 
					 | 
				
			||||||
                if (u.status === true) {
 | 
					 | 
				
			||||||
                  report.push({
 | 
					 | 
				
			||||||
                    group: req.group,
 | 
					 | 
				
			||||||
                    name: name,
 | 
					 | 
				
			||||||
                    status: ":check:",
 | 
					 | 
				
			||||||
                    code: "good",
 | 
					 | 
				
			||||||
                    lengthOrData: response.data?.data,
 | 
					 | 
				
			||||||
                  });
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                  report.push({
 | 
					 | 
				
			||||||
                    group: req.group,
 | 
					 | 
				
			||||||
                    name: name,
 | 
					 | 
				
			||||||
                    status: ":red_circle:",
 | 
					 | 
				
			||||||
                    code: "fail",
 | 
					 | 
				
			||||||
                    lengthOrData: response.data?.data,
 | 
					 | 
				
			||||||
                  });
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
              });
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
              report.push({
 | 
					 | 
				
			||||||
                group: req.group,
 | 
					 | 
				
			||||||
                name: req.name,
 | 
					 | 
				
			||||||
                status: ":red_circle:",
 | 
					 | 
				
			||||||
                code: "fail",
 | 
					 | 
				
			||||||
                lengthOrData: response.data?.data,
 | 
					 | 
				
			||||||
              });
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        }else{
 | 
					 | 
				
			||||||
          console.log("Error:", response);
 | 
					 | 
				
			||||||
          report.push({
 | 
					 | 
				
			||||||
            group: req.group,
 | 
					 | 
				
			||||||
            name: req.name,
 | 
					 | 
				
			||||||
            status: ":red_circle:",
 | 
					 | 
				
			||||||
            code: response.status,
 | 
					 | 
				
			||||||
            lengthOrData: "Error: " + JSON.stringify(response, null, 2),
 | 
					 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        // .then((response) => {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // })
 | 
					          let responseDataString = JSON.stringify(response.data, null, 2);
 | 
				
			||||||
        // .catch((error) => {
 | 
					 | 
				
			||||||
        //   // Xử lý lỗi ở đây
 | 
					 | 
				
			||||||
        //   console.log("Error:", error);
 | 
					 | 
				
			||||||
        //   report.push({
 | 
					 | 
				
			||||||
        //     group: req.group,
 | 
					 | 
				
			||||||
        //     name: req.name,
 | 
					 | 
				
			||||||
        //     status: ":red_circle:",
 | 
					 | 
				
			||||||
        //     code: response.status,
 | 
					 | 
				
			||||||
        //     lengthOrData: "Error: " + error,
 | 
					 | 
				
			||||||
        //   });
 | 
					 | 
				
			||||||
        // });
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (req.method === "GET") {
 | 
					 | 
				
			||||||
        let response = await axios.get(req.url, req.data, {
 | 
					 | 
				
			||||||
          headers: req.headers,
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let responseDataString = JSON.stringify(response.data, null, 2);
 | 
					 | 
				
			||||||
        allResponse += `${req.name}\n${responseDataString}\n\n`;
 | 
					 | 
				
			||||||
        console.log(response.data);
 | 
					 | 
				
			||||||
        // Xử lý response ở đây
 | 
					 | 
				
			||||||
        // console.log("Response:", response.data.length);
 | 
					 | 
				
			||||||
        // console.log("Status:", response.status);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (response.data !== "" && response.data !== undefined) {
 | 
					 | 
				
			||||||
          if (req.name !== "Auto import Disti") {
 | 
					 | 
				
			||||||
            logicCheck(req, response);
 | 
					 | 
				
			||||||
          } else {
 | 
					 | 
				
			||||||
            console.log(response.data?.data?.length);
 | 
					 | 
				
			||||||
            if (response.data?.data?.length > 0) {
 | 
					 | 
				
			||||||
              response.data?.data?.map((u) => {
 | 
					 | 
				
			||||||
                let name = req.name + " from " + u.data_name;
 | 
					 | 
				
			||||||
                if (u.status === true) {
 | 
					 | 
				
			||||||
                  report.push({
 | 
					 | 
				
			||||||
                    group: req.group,
 | 
					 | 
				
			||||||
                    name: name,
 | 
					 | 
				
			||||||
                    status: ":check:",
 | 
					 | 
				
			||||||
                    code: "good",
 | 
					 | 
				
			||||||
                    lengthOrData: response.data?.data,
 | 
					 | 
				
			||||||
                  });
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                  report.push({
 | 
					 | 
				
			||||||
                    group: req.group,
 | 
					 | 
				
			||||||
                    name: name,
 | 
					 | 
				
			||||||
                    status: ":red_circle:",
 | 
					 | 
				
			||||||
                    code: "fail",
 | 
					 | 
				
			||||||
                    lengthOrData: response.data?.data,
 | 
					 | 
				
			||||||
                  });
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
              });
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
              report.push({
 | 
					 | 
				
			||||||
                group: req.group,
 | 
					 | 
				
			||||||
                name: req.name,
 | 
					 | 
				
			||||||
                status: ":red_circle:",
 | 
					 | 
				
			||||||
                code: "fail",
 | 
					 | 
				
			||||||
                lengthOrData: response.data?.data,
 | 
					 | 
				
			||||||
              });
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        }else{
 | 
					 | 
				
			||||||
          console.log("Error:", response);
 | 
					 | 
				
			||||||
          report.push({
 | 
					 | 
				
			||||||
            group: req.group,
 | 
					 | 
				
			||||||
            name: req.name,
 | 
					 | 
				
			||||||
            status: ":red_circle:",
 | 
					 | 
				
			||||||
            code: response.status,
 | 
					 | 
				
			||||||
            lengthOrData: "Error: " + JSON.stringify(response, null, 2),
 | 
					 | 
				
			||||||
          });
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (req.method === "EXEC") {
 | 
					 | 
				
			||||||
        const stdout = await runExec(req.url, req.group);
 | 
					 | 
				
			||||||
        if (stdout !== "") {
 | 
					 | 
				
			||||||
          let responseDataString = JSON.stringify(stdout, null, 2);
 | 
					 | 
				
			||||||
          allResponse += `${req.name}\n${responseDataString}\n\n`;
 | 
					          allResponse += `${req.name}\n${responseDataString}\n\n`;
 | 
				
			||||||
 | 
					          console.log(response.data);
 | 
				
			||||||
 | 
					          // Xử lý response ở đây
 | 
				
			||||||
 | 
					          // console.log("Response:", response.data.length);
 | 
				
			||||||
 | 
					          // console.log("Status:", response.status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (req.name === "Perthmint") {
 | 
					          if (response.data !== "" && response.data !== undefined) {
 | 
				
			||||||
            if (stdout.toString().split("true").length - 1 > 1) {
 | 
					            if (req.name !== "Auto import Disti") {
 | 
				
			||||||
 | 
					              logicCheck(req, response);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              console.log(response.data?.data?.length);
 | 
				
			||||||
 | 
					              if (response.data?.data?.length > 0) {
 | 
				
			||||||
 | 
					                response.data?.data?.map((u) => {
 | 
				
			||||||
 | 
					                  let name = req.name + " from " + u.data_name;
 | 
				
			||||||
 | 
					                  if (u.status === true) {
 | 
				
			||||||
 | 
					                    report.push({
 | 
				
			||||||
 | 
					                      group: req.group,
 | 
				
			||||||
 | 
					                      name: name,
 | 
				
			||||||
 | 
					                      status: ":check:",
 | 
				
			||||||
 | 
					                      code: "good",
 | 
				
			||||||
 | 
					                      lengthOrData: response.data?.data,
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                  } else {
 | 
				
			||||||
 | 
					                    report.push({
 | 
				
			||||||
 | 
					                      group: req.group,
 | 
				
			||||||
 | 
					                      name: name,
 | 
				
			||||||
 | 
					                      status: ":red_circle:",
 | 
				
			||||||
 | 
					                      code: "fail",
 | 
				
			||||||
 | 
					                      lengthOrData: response.data?.data,
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					              } else {
 | 
				
			||||||
 | 
					                report.push({
 | 
				
			||||||
 | 
					                  group: req.group,
 | 
				
			||||||
 | 
					                  name: req.name,
 | 
				
			||||||
 | 
					                  status: ":red_circle:",
 | 
				
			||||||
 | 
					                  code: "fail",
 | 
				
			||||||
 | 
					                  lengthOrData: response.data?.data,
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            console.log("Error:", response);
 | 
				
			||||||
 | 
					            report.push({
 | 
				
			||||||
 | 
					              group: req.group,
 | 
				
			||||||
 | 
					              name: req.name,
 | 
				
			||||||
 | 
					              status: ":red_circle:",
 | 
				
			||||||
 | 
					              code: response.status,
 | 
				
			||||||
 | 
					              lengthOrData: "Error: " + JSON.stringify(response, null, 2),
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          // .then((response) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          // })
 | 
				
			||||||
 | 
					          // .catch((error) => {
 | 
				
			||||||
 | 
					          //   // Xử lý lỗi ở đây
 | 
				
			||||||
 | 
					          //   console.log("Error:", error);
 | 
				
			||||||
 | 
					          //   report.push({
 | 
				
			||||||
 | 
					          //     group: req.group,
 | 
				
			||||||
 | 
					          //     name: req.name,
 | 
				
			||||||
 | 
					          //     status: ":red_circle:",
 | 
				
			||||||
 | 
					          //     code: response.status,
 | 
				
			||||||
 | 
					          //     lengthOrData: "Error: " + error,
 | 
				
			||||||
 | 
					          //   });
 | 
				
			||||||
 | 
					          // });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (req.method === "GET") {
 | 
				
			||||||
 | 
					          let response = await axios.get(req.url, req.data, {
 | 
				
			||||||
 | 
					            headers: req.headers,
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          let responseDataString = JSON.stringify(response.data, null, 2);
 | 
				
			||||||
 | 
					          allResponse += `${req.name}\n${responseDataString}\n\n`;
 | 
				
			||||||
 | 
					          console.log(response.data);
 | 
				
			||||||
 | 
					          // Xử lý response ở đây
 | 
				
			||||||
 | 
					          // console.log("Response:", response.data.length);
 | 
				
			||||||
 | 
					          // console.log("Status:", response.status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          if (response.data !== "" && response.data !== undefined) {
 | 
				
			||||||
 | 
					            if (req.name !== "Auto import Disti") {
 | 
				
			||||||
 | 
					              logicCheck(req, response);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              console.log(response.data?.data?.length);
 | 
				
			||||||
 | 
					              if (response.data?.data?.length > 0) {
 | 
				
			||||||
 | 
					                response.data?.data?.map((u) => {
 | 
				
			||||||
 | 
					                  let name = req.name + " from " + u.data_name;
 | 
				
			||||||
 | 
					                  if (u.status === true) {
 | 
				
			||||||
 | 
					                    report.push({
 | 
				
			||||||
 | 
					                      group: req.group,
 | 
				
			||||||
 | 
					                      name: name,
 | 
				
			||||||
 | 
					                      status: ":check:",
 | 
				
			||||||
 | 
					                      code: "good",
 | 
				
			||||||
 | 
					                      lengthOrData: response.data?.data,
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                  } else {
 | 
				
			||||||
 | 
					                    report.push({
 | 
				
			||||||
 | 
					                      group: req.group,
 | 
				
			||||||
 | 
					                      name: name,
 | 
				
			||||||
 | 
					                      status: ":red_circle:",
 | 
				
			||||||
 | 
					                      code: "fail",
 | 
				
			||||||
 | 
					                      lengthOrData: response.data?.data,
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					              } else {
 | 
				
			||||||
 | 
					                report.push({
 | 
				
			||||||
 | 
					                  group: req.group,
 | 
				
			||||||
 | 
					                  name: req.name,
 | 
				
			||||||
 | 
					                  status: ":red_circle:",
 | 
				
			||||||
 | 
					                  code: "fail",
 | 
				
			||||||
 | 
					                  lengthOrData: response.data?.data,
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            console.log("Error:", response);
 | 
				
			||||||
 | 
					            report.push({
 | 
				
			||||||
 | 
					              group: req.group,
 | 
				
			||||||
 | 
					              name: req.name,
 | 
				
			||||||
 | 
					              status: ":red_circle:",
 | 
				
			||||||
 | 
					              code: response.status,
 | 
				
			||||||
 | 
					              lengthOrData: "Error: " + JSON.stringify(response, null, 2),
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (req.method === "EXEC") {
 | 
				
			||||||
 | 
					          const stdout = await runExec(req.url, req.group);
 | 
				
			||||||
 | 
					          if (stdout !== "") {
 | 
				
			||||||
 | 
					            let responseDataString = JSON.stringify(stdout, null, 2);
 | 
				
			||||||
 | 
					            allResponse += `${req.name}\n${responseDataString}\n\n`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            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,
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (req.group === "Test Log System") {
 | 
				
			||||||
              report.push({
 | 
					              report.push({
 | 
				
			||||||
                group: req.group,
 | 
					                group: req.group,
 | 
				
			||||||
                name: req.name,
 | 
					                name: req.name,
 | 
				
			||||||
| 
						 | 
					@ -1105,49 +1125,30 @@ const checkMultipleRequest = async () => {
 | 
				
			||||||
                code: "good",
 | 
					                code: "good",
 | 
				
			||||||
                lengthOrData: stdout,
 | 
					                lengthOrData: stdout,
 | 
				
			||||||
              });
 | 
					              });
 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
              report.push({
 | 
					 | 
				
			||||||
                group: req.group,
 | 
					 | 
				
			||||||
                name: req.name,
 | 
					 | 
				
			||||||
                status: ":red_circle:",
 | 
					 | 
				
			||||||
                code: "fail",
 | 
					 | 
				
			||||||
                lengthOrData: stdout,
 | 
					 | 
				
			||||||
              });
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          }
 | 
					          } else {
 | 
				
			||||||
 | 
					            console.log(stdout);
 | 
				
			||||||
          if (req.group === "Test Log System") {
 | 
					            let responseDataString = JSON.stringify(stdout, null, 2);
 | 
				
			||||||
 | 
					            allResponse += `${req.name}\n${responseDataString}\n\n`;
 | 
				
			||||||
            report.push({
 | 
					            report.push({
 | 
				
			||||||
              group: req.group,
 | 
					              group: req.group,
 | 
				
			||||||
              name: req.name,
 | 
					              name: req.name,
 | 
				
			||||||
              status: ":check:",
 | 
					              status: ":red_circle:",
 | 
				
			||||||
              code: "good",
 | 
					              code: "fail",
 | 
				
			||||||
              lengthOrData: stdout,
 | 
					              lengthOrData: stdout,
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
          console.log(stdout);
 | 
					 | 
				
			||||||
          let responseDataString = JSON.stringify(stdout, null, 2);
 | 
					 | 
				
			||||||
          allResponse += `${req.name}\n${responseDataString}\n\n`;
 | 
					 | 
				
			||||||
          report.push({
 | 
					 | 
				
			||||||
            group: req.group,
 | 
					 | 
				
			||||||
            name: req.name,
 | 
					 | 
				
			||||||
            status: ":red_circle:",
 | 
					 | 
				
			||||||
            code: "fail",
 | 
					 | 
				
			||||||
            lengthOrData: stdout,
 | 
					 | 
				
			||||||
          });
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					      } catch (error) {
 | 
				
			||||||
 | 
					        console.log("Error:", error);
 | 
				
			||||||
 | 
					        report.push({
 | 
				
			||||||
 | 
					          group: req.group,
 | 
				
			||||||
 | 
					          name: req.name,
 | 
				
			||||||
 | 
					          status: ":red_circle:",
 | 
				
			||||||
 | 
					          code: "bad",
 | 
				
			||||||
 | 
					          lengthOrData: "Error: " + JSON.stringify(error, null, 2),
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
     } catch (error) {
 | 
					 | 
				
			||||||
      console.log("Error:", error);
 | 
					 | 
				
			||||||
          report.push({
 | 
					 | 
				
			||||||
            group: req.group,
 | 
					 | 
				
			||||||
            name: req.name,
 | 
					 | 
				
			||||||
            status: ":red_circle:",
 | 
					 | 
				
			||||||
            code: "bad",
 | 
					 | 
				
			||||||
            lengthOrData: "Error: " + JSON.stringify(error, null, 2)
 | 
					 | 
				
			||||||
          });
 | 
					 | 
				
			||||||
     }
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await Promise.all(promises);
 | 
					    await Promise.all(promises);
 | 
				
			||||||
| 
						 | 
					@ -1189,8 +1190,14 @@ const checkMultipleRequest = async () => {
 | 
				
			||||||
    report.map((r) => {
 | 
					    report.map((r) => {
 | 
				
			||||||
      allResponse += JSON.stringify(r, null, 2);
 | 
					      allResponse += JSON.stringify(r, null, 2);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					    const fileName =
 | 
				
			||||||
 | 
					      "./app/store/logsAPI/" +
 | 
				
			||||||
 | 
					      moment(Date.now()).format("DD_MM_YYYY").toString() +
 | 
				
			||||||
 | 
					      ".log";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fs.writeFileSync("/home/logs/logSystems.txt", allResponse);
 | 
					    addLogFunction(fileName, allResponse, "System Logs")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // fs.writeFileSync("/home/logs/logSystems.txt", allResponse);
 | 
				
			||||||
    console.log(sortArray(report));
 | 
					    console.log(sortArray(report));
 | 
				
			||||||
  } catch (error) {
 | 
					  } catch (error) {
 | 
				
			||||||
    console.log(error);
 | 
					    console.log(error);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue