Merge branch 'main' of https://gitea.nswteam.net/joseph/Log_service
This commit is contained in:
commit
1ef8097aa7
|
|
@ -0,0 +1,732 @@
|
||||||
|
const axios = require("axios");
|
||||||
|
const crypto = require("crypto");
|
||||||
|
const moment = require("moment");
|
||||||
|
const zulip = require("zulip-js");
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
username: "networktool-bot@zulip.ipsupply.com.au",
|
||||||
|
apiKey: "0jMAmOuhfLvBqKJikv5oAkyNM4RIEoAM",
|
||||||
|
realm: "https://zulip.ipsupply.com.au",
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkMultipleRequest = async () => {
|
||||||
|
try {
|
||||||
|
let report = [];
|
||||||
|
let time = moment(Date.now()).format("HH:mm - DD/MM");
|
||||||
|
const client = await zulip(config);
|
||||||
|
|
||||||
|
const code = Math.random().toString(36).substring(2, 12);
|
||||||
|
const secretString =
|
||||||
|
code + "24feca0508b52d34b51db4b40964e7fff12edf71208a4607126f75cb5d504f7f";
|
||||||
|
const accessToken = crypto
|
||||||
|
.createHash("md5")
|
||||||
|
.update(secretString)
|
||||||
|
.digest("hex");
|
||||||
|
const tokenInt =
|
||||||
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2ludC5pcHN1cHBseS5jb20uYXUvYXBpL2xvZ2luIiwiaWF0IjoxNjg5ODYyNjAxLCJleHAiOjE3MjEzOTg2MDEsIm5iZiI6MTY4OTg2MjYwMSwianRpIjoiUElZVjNBM3ZPQVlMQ081SyIsInN1YiI6MSwicHJ2IjoiYzhlZTFmYzg5ZTc3NWVjNGM3Mzg2NjdlNWJlMTdhNTkwYjZkNDBmYyJ9.UcybIKMBjTAY9i0PfIDQMtqHyN72Ul0jC03ZDGLGpMI";
|
||||||
|
let content = "||Server| System time| Status \n|---|:---|:---|:---:\n";
|
||||||
|
// Tạo tiêu đề
|
||||||
|
const requests = [
|
||||||
|
{
|
||||||
|
url: "https://disti.danielvu.com/api/sendSellerOrderToERP",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
loginid: null,
|
||||||
|
Code: code,
|
||||||
|
AccessToken: accessToken,
|
||||||
|
},
|
||||||
|
data: {},
|
||||||
|
name: "Erp Sync Order Ebay",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://disti.danielvu.com/api/sendBuyerOrderToERP",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
loginid: null,
|
||||||
|
Code: code,
|
||||||
|
AccessToken: accessToken,
|
||||||
|
},
|
||||||
|
data: {},
|
||||||
|
name: "Erp Sync PO Ebay",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://int.ipsupply.com.au/api/transferGetData",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + tokenInt,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
urlAPI: "/api/test-log-serial-number/sync-data",
|
||||||
|
filter: {},
|
||||||
|
},
|
||||||
|
name: "Erp Sync Auto Test Log",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://int.ipsupply.com.au/api/transferPostData",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + tokenInt,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
urlAPI: "/api/logistics/check-shipping-rates",
|
||||||
|
data: {
|
||||||
|
courierName: "Fedex",
|
||||||
|
packageInfo: {
|
||||||
|
from: {
|
||||||
|
streetLines: ["8/4A Bachell Ave"],
|
||||||
|
city: "Lidcombe",
|
||||||
|
stateOrProvinceCode: "",
|
||||||
|
postalCode: "2141",
|
||||||
|
countryCode: "AU",
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
streetLines: ["600 Terminal Dr"],
|
||||||
|
city: "Louisville",
|
||||||
|
stateOrProvinceCode: "KY",
|
||||||
|
postalCode: "40209",
|
||||||
|
countryCode: "US",
|
||||||
|
},
|
||||||
|
requestedPackageLineItems: [
|
||||||
|
{
|
||||||
|
weight: {
|
||||||
|
value: 10,
|
||||||
|
units: "KG",
|
||||||
|
},
|
||||||
|
dimensions: {
|
||||||
|
length: 2,
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
units: "CM",
|
||||||
|
},
|
||||||
|
groupPackageCount: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
commodities: [
|
||||||
|
{
|
||||||
|
description: "G6",
|
||||||
|
quantity: 2,
|
||||||
|
quantityUnits: "PCS",
|
||||||
|
unitPrice: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
customsValue: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
inforCreateFedex: {
|
||||||
|
pickupType: "CONTACT_FEDEX_TO_SCHEDULE",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Shipping rate Fedex",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://int.ipsupply.com.au/api/transferPostData",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + tokenInt,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
urlAPI: "/api/logistics/check-shipping-rates",
|
||||||
|
data: {
|
||||||
|
courierName: "DHL",
|
||||||
|
packageInfo: {
|
||||||
|
from: {
|
||||||
|
streetLines: ["8/4A Bachell Ave"],
|
||||||
|
city: "Lidcombe",
|
||||||
|
stateOrProvinceCode: "",
|
||||||
|
postalCode: "2141",
|
||||||
|
countryCode: "AU",
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
streetLines: ["600 Terminal Dr"],
|
||||||
|
city: "Louisville",
|
||||||
|
stateOrProvinceCode: "KY",
|
||||||
|
postalCode: "40209",
|
||||||
|
countryCode: "US",
|
||||||
|
},
|
||||||
|
requestedPackageLineItems: [
|
||||||
|
{
|
||||||
|
weight: {
|
||||||
|
value: 10,
|
||||||
|
units: "KG",
|
||||||
|
},
|
||||||
|
dimensions: {
|
||||||
|
length: 2,
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
units: "CM",
|
||||||
|
},
|
||||||
|
groupPackageCount: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
commodities: [
|
||||||
|
{
|
||||||
|
description: "G6",
|
||||||
|
quantity: 2,
|
||||||
|
quantityUnits: "PCS",
|
||||||
|
unitPrice: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
customsValue: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
inforCreateFedex: {
|
||||||
|
pickupType: "CONTACT_FEDEX_TO_SCHEDULE",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Shipping rate DHL",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://int.ipsupply.com.au/api/transferPostData",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + tokenInt,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
urlAPI: "/api/logistics/check-shipping-rates",
|
||||||
|
data: {
|
||||||
|
courierName: "Transdirect",
|
||||||
|
packageInfo: {
|
||||||
|
from: {
|
||||||
|
streetLines: ["8/4A Bachell Ave"],
|
||||||
|
city: "Lidcombe",
|
||||||
|
stateOrProvinceCode: "",
|
||||||
|
postalCode: "2141",
|
||||||
|
countryCode: "AU",
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
streetLines: ["600 Terminal Dr"],
|
||||||
|
city: "Louisville",
|
||||||
|
stateOrProvinceCode: "KY",
|
||||||
|
postalCode: "40209",
|
||||||
|
countryCode: "US",
|
||||||
|
},
|
||||||
|
requestedPackageLineItems: [
|
||||||
|
{
|
||||||
|
weight: {
|
||||||
|
value: 10,
|
||||||
|
units: "KG",
|
||||||
|
},
|
||||||
|
dimensions: {
|
||||||
|
length: 2,
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
units: "CM",
|
||||||
|
},
|
||||||
|
groupPackageCount: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
commodities: [
|
||||||
|
{
|
||||||
|
description: "G6",
|
||||||
|
quantity: 2,
|
||||||
|
quantityUnits: "PCS",
|
||||||
|
unitPrice: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
customsValue: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
inforCreateFedex: {
|
||||||
|
pickupType: "CONTACT_FEDEX_TO_SCHEDULE",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Shipping rate Transdirect",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://int.ipsupply.com.au/api/transferPostData",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + tokenInt,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
urlAPI: "/api/logistics/check-shipping-rates",
|
||||||
|
data: {
|
||||||
|
courierName: "Courier Please",
|
||||||
|
packageInfo: {
|
||||||
|
from: {
|
||||||
|
streetLines: ["8/4A Bachell Ave"],
|
||||||
|
city: "Lidcombe",
|
||||||
|
stateOrProvinceCode: "",
|
||||||
|
postalCode: "2141",
|
||||||
|
countryCode: "AU",
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
streetLines: ["600 Terminal Dr"],
|
||||||
|
city: "Louisville",
|
||||||
|
stateOrProvinceCode: "KY",
|
||||||
|
postalCode: "40209",
|
||||||
|
countryCode: "US",
|
||||||
|
},
|
||||||
|
requestedPackageLineItems: [
|
||||||
|
{
|
||||||
|
weight: {
|
||||||
|
value: 10,
|
||||||
|
units: "KG",
|
||||||
|
},
|
||||||
|
dimensions: {
|
||||||
|
length: 2,
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
units: "CM",
|
||||||
|
},
|
||||||
|
groupPackageCount: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
commodities: [
|
||||||
|
{
|
||||||
|
description: "G6",
|
||||||
|
quantity: 2,
|
||||||
|
quantityUnits: "PCS",
|
||||||
|
unitPrice: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
customsValue: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
inforCreateFedex: {
|
||||||
|
pickupType: "CONTACT_FEDEX_TO_SCHEDULE",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Shipping rate Courier Please",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://int.ipsupply.com.au/api/transferPostData",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + tokenInt,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
urlAPI: "/api/logistics/check-shipping-rates",
|
||||||
|
data: {
|
||||||
|
courierName: "Auspost",
|
||||||
|
packageInfo: {
|
||||||
|
from: {
|
||||||
|
streetLines: ["8/4A Bachell Ave"],
|
||||||
|
city: "Lidcombe",
|
||||||
|
stateOrProvinceCode: "",
|
||||||
|
postalCode: "2141",
|
||||||
|
countryCode: "AU",
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
streetLines: ["600 Terminal Dr"],
|
||||||
|
city: "Louisville",
|
||||||
|
stateOrProvinceCode: "KY",
|
||||||
|
postalCode: "40209",
|
||||||
|
countryCode: "US",
|
||||||
|
},
|
||||||
|
requestedPackageLineItems: [
|
||||||
|
{
|
||||||
|
weight: {
|
||||||
|
value: 10,
|
||||||
|
units: "KG",
|
||||||
|
},
|
||||||
|
dimensions: {
|
||||||
|
length: 2,
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
units: "CM",
|
||||||
|
},
|
||||||
|
groupPackageCount: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
commodities: [
|
||||||
|
{
|
||||||
|
description: "G6",
|
||||||
|
quantity: 2,
|
||||||
|
quantityUnits: "PCS",
|
||||||
|
unitPrice: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
customsValue: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
inforCreateFedex: {
|
||||||
|
pickupType: "CONTACT_FEDEX_TO_SCHEDULE",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Shipping rate Auspost",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://int.ipsupply.com.au/api/transferPostData",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + tokenInt,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
urlAPI: "/api/logistics/check-shipping-rates",
|
||||||
|
data: {
|
||||||
|
courierName: "FRF",
|
||||||
|
packageInfo: {
|
||||||
|
from: {
|
||||||
|
streetLines: ["8/4A Bachell Ave"],
|
||||||
|
city: "Lidcombe",
|
||||||
|
stateOrProvinceCode: "",
|
||||||
|
postalCode: "2141",
|
||||||
|
countryCode: "AU",
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
streetLines: ["600 Terminal Dr"],
|
||||||
|
city: "Louisville",
|
||||||
|
stateOrProvinceCode: "KY",
|
||||||
|
postalCode: "40209",
|
||||||
|
countryCode: "US",
|
||||||
|
},
|
||||||
|
requestedPackageLineItems: [
|
||||||
|
{
|
||||||
|
weight: {
|
||||||
|
value: 10,
|
||||||
|
units: "KG",
|
||||||
|
},
|
||||||
|
dimensions: {
|
||||||
|
length: 2,
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
units: "CM",
|
||||||
|
},
|
||||||
|
groupPackageCount: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
commodities: [
|
||||||
|
{
|
||||||
|
description: "G6",
|
||||||
|
quantity: 2,
|
||||||
|
quantityUnits: "PCS",
|
||||||
|
unitPrice: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
customsValue: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
inforCreateFedex: {
|
||||||
|
pickupType: "CONTACT_FEDEX_TO_SCHEDULE",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Shipping rate FRF",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://int.ipsupply.com.au/api/transferPostData",
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + tokenInt,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
urlAPI: "/api/logistics/check-shipping-rates",
|
||||||
|
data: {
|
||||||
|
courierName: "Sendle",
|
||||||
|
packageInfo: {
|
||||||
|
from: {
|
||||||
|
streetLines: ["8/4A Bachell Ave"],
|
||||||
|
city: "Lidcombe",
|
||||||
|
stateOrProvinceCode: "",
|
||||||
|
postalCode: "2141",
|
||||||
|
countryCode: "AU",
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
streetLines: ["600 Terminal Dr"],
|
||||||
|
city: "Louisville",
|
||||||
|
stateOrProvinceCode: "KY",
|
||||||
|
postalCode: "40209",
|
||||||
|
countryCode: "US",
|
||||||
|
},
|
||||||
|
requestedPackageLineItems: [
|
||||||
|
{
|
||||||
|
weight: {
|
||||||
|
value: 10,
|
||||||
|
units: "KG",
|
||||||
|
},
|
||||||
|
dimensions: {
|
||||||
|
length: 2,
|
||||||
|
width: 3,
|
||||||
|
height: 4,
|
||||||
|
units: "CM",
|
||||||
|
},
|
||||||
|
groupPackageCount: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
commodities: [
|
||||||
|
{
|
||||||
|
description: "G6",
|
||||||
|
quantity: 2,
|
||||||
|
quantityUnits: "PCS",
|
||||||
|
unitPrice: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
customsValue: {
|
||||||
|
amount: 10000,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
inforCreateFedex: {
|
||||||
|
pickupType: "CONTACT_FEDEX_TO_SCHEDULE",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
name: "Shipping rate Sendle",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const promises = requests.map(async (req, index) => {
|
||||||
|
if (req.method === "POST") {
|
||||||
|
await axios
|
||||||
|
.post(req.url, req.data, {
|
||||||
|
headers: req.headers,
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
// console.log(response.data);
|
||||||
|
// Xử lý response ở đây
|
||||||
|
// console.log("Response:", response.data.length);
|
||||||
|
// console.log("Status:", response.status);
|
||||||
|
if (Array.isArray(response.data) === false) {
|
||||||
|
if (response.data.data.length > 0) {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":check:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data.data.length,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (Array.isArray(response.data.data) === false) {
|
||||||
|
const data = JSON.stringify(
|
||||||
|
response.data.data
|
||||||
|
).toLocaleLowerCase();
|
||||||
|
if (data.includes("error") || data.includes("invalid")) {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":red_circle:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: JSON.stringify(response.data.data),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":check:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data.data.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (response.data.data.length > 0) {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":check:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data.data.length,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":red_circle:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: JSON.stringify(response.data.data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (response.data.length > 0) {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":check:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data.length,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":red_circle:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// Xử lý lỗi ở đây
|
||||||
|
console.log("Error:", error);
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":red_circle:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: "Error: " + error,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await axios
|
||||||
|
.get(req.url, req.data, {
|
||||||
|
headers: req.headers,
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
// Xử lý response ở đây
|
||||||
|
// console.log("Response:", response.data.length);
|
||||||
|
// console.log("Status:", response.status);
|
||||||
|
if (Array.isArray(response.data) === false) {
|
||||||
|
if (response.data.data.length > 0) {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":check:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data.data.length,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (Array.isArray(response.data.data) === false) {
|
||||||
|
const data = JSON.stringify(
|
||||||
|
response.data.data
|
||||||
|
).toLocaleLowerCase();
|
||||||
|
if (data.includes("error") || data.includes("invalid")) {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":red_circle:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: JSON.stringify(response.data.data),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":check:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data.data.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (response.data.data.length > 0) {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":check:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data.data.length,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":red_circle:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: JSON.stringify(response.data.data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (response.data.length > 0) {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":check:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data.length,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":red_circle:",
|
||||||
|
code: response.status,
|
||||||
|
lengthOrData: response.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
// Xử lý lỗi ở đây
|
||||||
|
console.log("Error:", error);
|
||||||
|
report.push({
|
||||||
|
name: req.name,
|
||||||
|
status: ":red_circle:",
|
||||||
|
code: error.status,
|
||||||
|
lengthOrData: "Error: " + error,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(promises);
|
||||||
|
report.map((u, index) => {
|
||||||
|
content +=
|
||||||
|
"|" +
|
||||||
|
(index + 1) +
|
||||||
|
"|**" +
|
||||||
|
u.name +
|
||||||
|
"**|**" +
|
||||||
|
time +
|
||||||
|
"**|" +
|
||||||
|
u.status +
|
||||||
|
"|\n";
|
||||||
|
});
|
||||||
|
let params = {
|
||||||
|
type: "stream",
|
||||||
|
to: "networkToolBot",
|
||||||
|
topic: "System Logs",
|
||||||
|
content: JSON.stringify(report, null, 2),
|
||||||
|
};
|
||||||
|
|
||||||
|
let params1 = {
|
||||||
|
type: "stream",
|
||||||
|
to: "System Logs",
|
||||||
|
topic: "stream events",
|
||||||
|
content: content,
|
||||||
|
};
|
||||||
|
|
||||||
|
client.messages.send(params);
|
||||||
|
client.messages.send(params1);
|
||||||
|
console.log(report);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
if (
|
||||||
|
JSON.stringify(error).includes(
|
||||||
|
"https://zulip.ipsupply.com.au/api/v1/messages failed"
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
checkMultipleRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
checkMultipleRequest();
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"child_process": "^1.0.2",
|
"child_process": "^1.0.2",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"helpers": "^0.0.6",
|
"helpers": "^0.0.6",
|
||||||
|
|
@ -2860,6 +2861,12 @@
|
||||||
"node": "*"
|
"node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/crypto": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==",
|
||||||
|
"deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in."
|
||||||
|
},
|
||||||
"node_modules/cuid": {
|
"node_modules/cuid": {
|
||||||
"version": "2.1.8",
|
"version": "2.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/cuid/-/cuid-2.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/cuid/-/cuid-2.1.8.tgz",
|
||||||
|
|
@ -11520,6 +11527,11 @@
|
||||||
"integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==",
|
"integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"crypto": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig=="
|
||||||
|
},
|
||||||
"cuid": {
|
"cuid": {
|
||||||
"version": "2.1.8",
|
"version": "2.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/cuid/-/cuid-2.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/cuid/-/cuid-2.1.8.tgz",
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"child_process": "^1.0.2",
|
"child_process": "^1.0.2",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
|
"crypto": "^1.0.1",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"helpers": "^0.0.6",
|
"helpers": "^0.0.6",
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,39 @@
|
||||||
const regex = /(\d+)K/g;
|
const axios = require('axios');
|
||||||
|
const md5 = require('md5');
|
||||||
|
|
||||||
console.log(
|
// Tạo dữ liệu JSON bạn muốn gửi đi
|
||||||
"1000944K bytes of ATA System CompactFlash 0 (Read/Write) "
|
const dataToSend = {
|
||||||
.match(regex)
|
// Đặt dữ liệu của bạn ở đây
|
||||||
.map((obj) => (parseInt(obj.replace("K", ""))/1024/1024).toFixed(2)+"G")
|
};
|
||||||
);
|
|
||||||
|
// Tạo tiêu đề
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'loginid': null,
|
||||||
|
'Code': 'chuoi ngau nhiên',
|
||||||
|
'AccessToken': md5(Code + '24feca0508b52d34b51db4b40964e7fff12edf71208a4607126f75cb5d504f7f')
|
||||||
|
};
|
||||||
|
|
||||||
|
// Gửi POST request bằng Axios
|
||||||
|
axios.post('https://disti.danielvu.com/api/sendBuyerOrderToERP', dataToSend, { headers })
|
||||||
|
.then(response => {
|
||||||
|
// Xử lý response ở đây
|
||||||
|
console.log('Response:', response.data);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
// Xử lý lỗi ở đây
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// const regex = /(\d+)K/g;
|
||||||
|
|
||||||
|
// console.log(
|
||||||
|
// "1000944K bytes of ATA System CompactFlash 0 (Read/Write) "
|
||||||
|
// .match(regex)
|
||||||
|
// .map((obj) => (parseInt(obj.replace("K", ""))/1024/1024).toFixed(2)+"G")
|
||||||
|
// );
|
||||||
|
|
||||||
// let a = [1,2,3]
|
// let a = [1,2,3]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue