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",
 | 
				
			||||||
| 
						 | 
					@ -1004,7 +1005,7 @@ const checkMultipleRequest = async () => {
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }else{
 | 
					          } else {
 | 
				
			||||||
            console.log("Error:", response);
 | 
					            console.log("Error:", response);
 | 
				
			||||||
            report.push({
 | 
					            report.push({
 | 
				
			||||||
              group: req.group,
 | 
					              group: req.group,
 | 
				
			||||||
| 
						 | 
					@ -1078,7 +1079,7 @@ const checkMultipleRequest = async () => {
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }else{
 | 
					          } else {
 | 
				
			||||||
            console.log("Error:", response);
 | 
					            console.log("Error:", response);
 | 
				
			||||||
            report.push({
 | 
					            report.push({
 | 
				
			||||||
              group: req.group,
 | 
					              group: req.group,
 | 
				
			||||||
| 
						 | 
					@ -1145,7 +1146,7 @@ const checkMultipleRequest = async () => {
 | 
				
			||||||
          name: req.name,
 | 
					          name: req.name,
 | 
				
			||||||
          status: ":red_circle:",
 | 
					          status: ":red_circle:",
 | 
				
			||||||
          code: "bad",
 | 
					          code: "bad",
 | 
				
			||||||
            lengthOrData: "Error: " + JSON.stringify(error, null, 2)
 | 
					          lengthOrData: "Error: " + JSON.stringify(error, null, 2),
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
| 
						 | 
					@ -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