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 axios from "axios";
|
||||
import { addLogFunction } from "./addLogFunction";
|
||||
import moment from "moment";
|
||||
|
||||
export const checkIndexSN = async (content, beginLine, nameF) => {
|
||||
try {
|
||||
|
|
@ -195,6 +197,11 @@ export const checkIndexSN = async (content, beginLine, nameF) => {
|
|||
);
|
||||
|
||||
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 zulip = require("zulip-js");
|
||||
const { addLogFunction } = require("./addLogFunction");
|
||||
|
||||
(async () => {
|
||||
// Launch a headless browser
|
||||
|
|
@ -72,4 +73,9 @@ const zulip = require("zulip-js");
|
|||
client.messages.send(params);
|
||||
}
|
||||
}, 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 InfoDevice from "App/Models/InfoDevice";
|
||||
import KeyValue from "App/Models/KeyValue";
|
||||
import { addLogFunction } from "./addLogFunction";
|
||||
|
||||
export const sendDeviceInfora = async () => {
|
||||
try {
|
||||
|
|
@ -333,8 +334,19 @@ export const sendDeviceInfora = async () => {
|
|||
};
|
||||
transporter.sendMail(options);
|
||||
await InfoDevice.createMany(listInformation);
|
||||
}else{
|
||||
console.log("listInformation", listInformation)
|
||||
const fileName =
|
||||
"./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) {
|
||||
console.log(error);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ const moment = require("moment");
|
|||
const zulip = require("zulip-js");
|
||||
const { exec } = require("child_process");
|
||||
const fs = require("fs");
|
||||
const { addLogFunction } = require("./addLogFunction");
|
||||
|
||||
const config = {
|
||||
username: "networktool-bot@zulip.ipsupply.com.au",
|
||||
|
|
@ -955,149 +956,168 @@ const checkMultipleRequest = async () => {
|
|||
};
|
||||
|
||||
const promises = requests.map(async (req, index) => {
|
||||
try {
|
||||
if (req.method === "POST") {
|
||||
let response = await axios.post(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),
|
||||
try {
|
||||
if (req.method === "POST") {
|
||||
let response = await axios.post(req.url, req.data, {
|
||||
headers: req.headers,
|
||||
});
|
||||
}
|
||||
// .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);
|
||||
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 (req.name === "Perthmint") {
|
||||
if (stdout.toString().split("true").length - 1 > 1) {
|
||||
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) => {
|
||||
|
||||
// })
|
||||
// .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({
|
||||
group: req.group,
|
||||
name: req.name,
|
||||
|
|
@ -1105,49 +1125,30 @@ const checkMultipleRequest = async () => {
|
|||
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") {
|
||||
} 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: ":check:",
|
||||
code: "good",
|
||||
status: ":red_circle:",
|
||||
code: "fail",
|
||||
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);
|
||||
|
|
@ -1189,8 +1190,14 @@ const checkMultipleRequest = async () => {
|
|||
report.map((r) => {
|
||||
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));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
|
|
|||
Loading…
Reference in New Issue