90 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			90 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
const moment = require("moment/moment");
 | 
						|
const zulip = require("zulip-js");
 | 
						|
const { exec } = require('child_process');
 | 
						|
 | 
						|
const sendNotification = async () => {
 | 
						|
 | 
						|
  try {
 | 
						|
    const config = {
 | 
						|
      username: "networktool-bot@zulip.ipsupply.com.au",
 | 
						|
      apiKey: "0jMAmOuhfLvBqKJikv5oAkyNM4RIEoAM",
 | 
						|
      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:";
 | 
						|
 | 
						|
      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
 | 
						|
        }
 | 
						|
 | 
						|
      });
 | 
						|
 | 
						|
      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
 | 
						|
        }
 | 
						|
 | 
						|
      });
 | 
						|
 | 
						|
      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
 | 
						|
        }
 | 
						|
 | 
						|
      });
 | 
						|
 | 
						|
 | 
						|
      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,
 | 
						|
    // };
 | 
						|
 | 
						|
    // await client.messages.send(params);
 | 
						|
  } catch (error) {
 | 
						|
    console.log(error);
 | 
						|
  }
 | 
						|
};
 | 
						|
 | 
						|
sendNotification();
 |