From bb8f38c6ecbb19cb9a5a7194b2a6f236d1049ea0 Mon Sep 17 00:00:00 2001 From: joseph le Date: Wed, 11 Oct 2023 15:10:44 +0700 Subject: [PATCH] Create function check status for other system --- app/utils/sendStatusOtherSystem.js | 1488 ++++++++++++++++------------ 1 file changed, 855 insertions(+), 633 deletions(-) diff --git a/app/utils/sendStatusOtherSystem.js b/app/utils/sendStatusOtherSystem.js index 19a8168..986b3a7 100644 --- a/app/utils/sendStatusOtherSystem.js +++ b/app/utils/sendStatusOtherSystem.js @@ -2,6 +2,7 @@ const axios = require("axios"); const crypto = require("crypto"); const moment = require("moment"); const zulip = require("zulip-js"); +const { exec } = require("child_process"); const config = { username: "networktool-bot@zulip.ipsupply.com.au", @@ -27,495 +28,814 @@ const checkMultipleRequest = async () => { let content = "||Server| System time| Status \n|---|:---|:---|:---:\n"; // Tạo tiêu đề const requests = [ + //Ebay Systems + // { + // url: "https://disti.danielvu.com/api/eBayNewItemLog", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Accept: "application/json", + // loginid: null, + // Code: code, + // AccessToken: accessToken, + // }, + // data: {}, + // name: "New item", + // group: "Ebay Systems", + // }, + // { + // url: "https://disti.danielvu.com/api/eBayChatLog", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Accept: "application/json", + // loginid: null, + // Code: code, + // AccessToken: accessToken, + // }, + // data: {}, + // name: "Ebay message", + // group: "Ebay Systems", + // }, + // { + // 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", + // group: "Ebay Systems" + // }, + // { + // 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", + // group: "Ebay Systems" + // }, + // //ERP Systems + // { + // 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: "Log SN to ERP", + // group: "ERP Systems" + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferGetData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/stock-model-serial/check-sn-cisco", + // filter: {}, + // }, + // name: "SN Cisco to ERP", + // group: "ERP Systems", + // }, + // { + // 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", + // group: "ERP Systems", + // }, + // { + // 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", + // group: "ERP Systems", + // }, + // { + // 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", + // group: "ERP Systems", + // }, + // { + // 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", + // group: "ERP Systems", + // }, + // { + // 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", + // group: "ERP Systems", + // }, + // { + // 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", + // group: "ERP Systems", + // }, + // { + // 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", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "782568904960", + // type: "Fedex", + // }, + // }, + // name: "Tracking Fedex", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "210865775", + // type: "TNT", + // }, + // }, + // name: "Tracking TNT", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "1Z94VTP30308384260", + // type: "UPS", + // }, + // }, + // name: "Tracking UPS", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "33FJV771376901000930306", + // type: "Auspost", + // }, + // }, + // name: "Tracking Auspost", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "9400111206203073428144", + // type: "USPS", + // }, + // }, + // name: "Tracking USPS", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "CVAZ00633255", + // type: "StarTrack", + // }, + // }, + // name: "Tracking StarTrack", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "S92C5DS", + // type: "Sendle", + // }, + // }, + // name: "Tracking Sendle", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "2334909695 ", + // type: "DHL", + // }, + // }, + // name: "Tracking DHL", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/logistics/check-tracking", + // data: { + // trackingNumber: "60508912001", + // type: "CouriersPlease", + // }, + // }, + // name: "Tracking CouriersPlease", + // group: "ERP Systems", + // }, + // { + // url: "https://int.ipsupply.com.au/api/transferPostData", + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer " + tokenInt, + // }, + // data: { + // urlAPI: "/api/stock-model-serial/check-sn-list-cisco", + // data: { + // serialNumbers: ["FGL1716W349"], + // }, + // }, + // name: "Check SN Cisco", + // group: "Other Systems", + // }, { - url: "https://disti.danielvu.com/api/sendSellerOrderToERP", - method: "POST", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - loginid: null, - Code: code, - AccessToken: accessToken, - }, + url: "ssh danielvu-gold@172.16.6.2 cat /home/danielvu-gold/htdocs/gold.danielvu.com/check_file.json", + method: "SSH", + headers: {}, 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", + name: "Perthmint", + group: "Other Systems", }, ]; + const logicCheck = async (req, response) => { + try { + if (Array.isArray(response.data) === false) { + if ( + (response.data.data !== undefined && + response.data.data.length > 0) || + (response.data !== undefined && response.data?.success) + ) { + report.push({ + group: req.group, + name: req.name, + status: ":check:", + code: response.status, + lengthOrData: response.data?.data?.length | response.data, + }); + } else { + if (Array.isArray(response.data.data) === false) { + const data = JSON.stringify( + response.data?.data + )?.toLocaleLowerCase(); + if ( + data?.includes("error") || + data?.includes("invalid") || + response.data.data === undefined + ) { + report.push({ + group: req.group, + name: req.name, + status: ":red_circle:", + code: response.status, + lengthOrData: JSON.stringify(response.data?.data), + }); + } else { + report.push({ + group: req.group, + name: req.name, + status: ":check:", + code: response.status, + lengthOrData: response.data?.data?.length, + }); + } + } else { + if ( + response.data?.data !== undefined && + response.data?.data?.length > 0 + ) { + report.push({ + group: req.group, + name: req.name, + status: ":check:", + code: response.status, + lengthOrData: response.data?.data?.length, + }); + } else { + report.push({ + group: req.group, + name: req.name, + status: ":red_circle:", + code: response.status, + lengthOrData: JSON.stringify(response.data?.data), + }); + } + } + } + } else { + if (response.data.length > 0) { + report.push({ + group: req.group, + name: req.name, + status: ":check:", + code: response.status, + lengthOrData: response.data.length, + }); + } else { + report.push({ + group: req.group, + name: req.name, + status: ":red_circle:", + code: response.status, + lengthOrData: response.data, + }); + } + } + } catch (error) { + console.log("logic check: ", error); + } + }; + const promises = requests.map(async (req, index) => { if (req.method === "POST") { await axios @@ -523,78 +843,18 @@ const checkMultipleRequest = async () => { headers: req.headers, }) .then((response) => { - // console.log(response.data); + 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, - }); - } - } + + logicCheck(req, 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, @@ -610,74 +870,13 @@ const checkMultipleRequest = async () => { // 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, - }); - } - } + logicCheck(req, response); }) .catch((error) => { // Xử lý lỗi ở đây console.log("Error:", error); report.push({ + group: req.group, name: req.name, status: ":red_circle:", code: error.status, @@ -685,38 +884,61 @@ const checkMultipleRequest = async () => { }); }); } + + if(req.method === "SSH"){ + exec(req.url, (error, stdout, stderr) => { + if (error) { + // console.error(`Error executing command: ${error.message}`); + return; + } + + if (stdout !== "") { + console.log(stdout) + } else { + console.log(stderr) + } + }); + } }); await Promise.all(promises); - report.map((u, index) => { - content += - "|" + - (index + 1) + - "|**" + - u.name + - "**|**" + - time + - "**|" + - u.status + - "|\n"; - }); + let groupName = report?.sort((a, b) => a.group.localeCompare(b.group))[0] + ?.group; + let no = 0; + content += "||**" + groupName + "**|||\n"; + report + .sort((a, b) => a.group.localeCompare(b.group)) + ?.map((u, index) => { + no += 1; + if (u.group === groupName) { + content += + "|" + no + "|" + u.name + "|**" + time + "**|" + u.status + "|\n"; + } else { + no = 1; + groupName = u.group; + content += "||**" + groupName + "**|||\n"; + content += + "|" + no + "|" + u.name + "|**" + time + "**|" + u.status + "|\n"; + } + }); let params = { type: "stream", - to: "networkToolBot", - topic: "System Logs", - content: JSON.stringify(report, null, 2), + to: "Result test - auto.nswteam.net", + topic: "AU-dev", + content: content, + // content: JSON.stringify(report, null, 2), }; let params1 = { - type: "stream", - to: "System Logs", - topic: "stream events", - content: content, - }; + type: "stream", + to: "System Logs", + topic: "stream events", + content: content, + }; client.messages.send(params); - client.messages.send(params1); - console.log(report); + // client.messages.send(params1); + console.log(report.sort((a, b) => a.group.localeCompare(b.group))); } catch (error) { console.log(error); if (