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