create function sendNotification
This commit is contained in:
parent
8318b0598f
commit
d2843a0013
|
|
@ -1,9 +1,8 @@
|
|||
const moment = require("moment/moment");
|
||||
const zulip = require("zulip-js");
|
||||
const { exec } = require('child_process');
|
||||
const { exec } = require("child_process");
|
||||
|
||||
const sendNotification = async () => {
|
||||
|
||||
try {
|
||||
const config = {
|
||||
username: "networktool-bot@zulip.ipsupply.com.au",
|
||||
|
|
@ -11,76 +10,77 @@ const sendNotification = async () => {
|
|||
realm: "https://zulip.ipsupply.com.au",
|
||||
};
|
||||
const client = await zulip(config);
|
||||
let auto1 = ""
|
||||
let auto2 = ""
|
||||
let log = ""
|
||||
// let autoStatus = process.argv[2].includes("succeeded") && process.argv[3].includes("succeeded")
|
||||
// ? ":check:"
|
||||
// : ":red_circle:";
|
||||
// let logStatus = process.argv[4].includes("succeeded")
|
||||
// ? ":check:"
|
||||
// : ":red_circle:";
|
||||
let auto1 = "";
|
||||
let auto2 = "";
|
||||
let log = "";
|
||||
|
||||
exec("nc -zv 172.16.7.13 8002", (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
exec("nc -zv 172.16.7.13 8002", (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
// console.error(`Error executing command: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if(stdout !== ""){
|
||||
auto1 += stdout
|
||||
}else{
|
||||
auto1 += stderr
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
if (stdout !== "") {
|
||||
auto1 += stdout;
|
||||
} else {
|
||||
auto1 += stderr;
|
||||
}
|
||||
});
|
||||
|
||||
exec("nc -zv 172.16.7.13 5000", (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
exec("nc -zv 172.16.7.13 5000", (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
// console.error(`Error executing command: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if(stdout !== ""){
|
||||
auto2 += stdout
|
||||
}else{
|
||||
auto2 += stderr
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
if (stdout !== "") {
|
||||
auto2 += stdout;
|
||||
} else {
|
||||
auto2 += stderr;
|
||||
}
|
||||
});
|
||||
|
||||
exec("nc -zv 172.16.6.23 3333", (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
exec("nc -zv 172.16.6.23 3333", (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
// console.error(`Error executing command: ${error.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if(stdout !== ""){
|
||||
log += stdout
|
||||
}else{
|
||||
log += stderr
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
if (stdout !== "") {
|
||||
log += stdout;
|
||||
} else {
|
||||
log += stderr;
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
console.log({ auto1: auto1, auto2: auto2, log: log });
|
||||
let autoStatus =
|
||||
auto1?.includes("succeeded") && auto2?.includes("succeeded")
|
||||
? ":check:"
|
||||
: ":red_circle:";
|
||||
let logStatus = log?.includes("succeeded") ? ":check:" : ":red_circle:";
|
||||
|
||||
setTimeout(() => {
|
||||
console.log({auto1:auto1, auto2: auto2, log:log})
|
||||
}, 3000);
|
||||
let time = moment(Date.now()).format("HH:mm - DD/MM");
|
||||
let content =
|
||||
"| |Server| System time| Status \n|---|:---:|:---|:---:\n|1|auto.danielvu.com|**" +
|
||||
time +
|
||||
"**|" +
|
||||
autoStatus +
|
||||
"|\n|2|logs.danielvu.com|**" +
|
||||
time +
|
||||
"**|" +
|
||||
logStatus +
|
||||
"|";
|
||||
let params = {
|
||||
type: "stream",
|
||||
to: "Result test - auto.nswteam.net",
|
||||
topic: "test",
|
||||
content: content,
|
||||
};
|
||||
|
||||
// let time = moment(Date.now()).format("HH:mm - DD/MM")
|
||||
// let content =
|
||||
// "| |Server| System time| Status \n|---|:---:|:---|:---:\n|1|auto.danielvu.com|**"+time+"**|" +
|
||||
// autoStatus +
|
||||
// "|\n|2|logs.danielvu.com|**"+time+"**|"+logStatus+"|";
|
||||
// let params = {
|
||||
// type: "stream",
|
||||
// to: "Result test - auto.nswteam.net",
|
||||
// topic: "test",
|
||||
// content: content,
|
||||
// };
|
||||
|
||||
// await client.messages.send(params);
|
||||
await client.messages.send(params);
|
||||
}, 3000);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue