parent
8cfe5cdefe
commit
0f4c72a32f
|
@ -2,7 +2,8 @@
|
|||
"options": {
|
||||
"parallel_nodes": 2,
|
||||
"parallel_node_tasks": 5,
|
||||
"separate_into_tables": false
|
||||
"separate_into_tables": false,
|
||||
"mysql_dump_settings": "--no-comments"
|
||||
},
|
||||
|
||||
"smtp": {
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
|
||||
import { SystemControl } from "./models/SystemController";
|
||||
|
||||
(global as any).logger = new SystemControl();
|
||||
|
||||
/**
|
||||
* The main function to run the program with
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* A Collection of settings
|
||||
*/
|
||||
interface ConfigOptions {
|
||||
export interface ConfigOptions {
|
||||
/**
|
||||
* The number of nodes that will be ran in parallel,
|
||||
* if the number of nodes is smaller than the parallels,
|
||||
|
@ -20,12 +20,17 @@ interface ConfigOptions {
|
|||
* to only export tables.
|
||||
*/
|
||||
separate_into_tables: boolean,
|
||||
|
||||
/**
|
||||
* A string of CLI options for the mysql dump command
|
||||
*/
|
||||
mysql_dump_settings: string,
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic configuration interface for the mailer
|
||||
*/
|
||||
interface SMTPConfig {
|
||||
export interface SMTPConfig {
|
||||
/**
|
||||
* The email address to globally use for sending
|
||||
* out email from.
|
||||
|
@ -46,14 +51,14 @@ interface SMTPConfig {
|
|||
/**
|
||||
* The port to send to, common ports are 465 ( ssl ), 587 for TLS
|
||||
*/
|
||||
port : string,
|
||||
port : number,
|
||||
/**
|
||||
* Secure Connection
|
||||
*/
|
||||
ssl : boolean,
|
||||
}
|
||||
|
||||
interface NodeConnectionMail {
|
||||
export interface NodeConnectionMail {
|
||||
/**
|
||||
* Enable or disable email sending
|
||||
*/
|
||||
|
@ -68,7 +73,7 @@ interface NodeConnectionMail {
|
|||
email_cc: Array<string>,
|
||||
}
|
||||
|
||||
interface DatabaseFilter {
|
||||
export interface DatabaseFilter {
|
||||
/**
|
||||
* A filter where anything inside of it is going to be ignored
|
||||
*/
|
||||
|
@ -82,7 +87,7 @@ interface DatabaseFilter {
|
|||
/**
|
||||
* A Node Connection for the database backup
|
||||
*/
|
||||
interface NodeConnection {
|
||||
export interface NodeConnection {
|
||||
/**
|
||||
* The name for the connection to be identified by
|
||||
*/
|
||||
|
@ -117,7 +122,7 @@ interface NodeConnection {
|
|||
databases?: DatabaseFilter
|
||||
}
|
||||
|
||||
interface ConfigObject {
|
||||
export interface ConfigObject {
|
||||
/**
|
||||
* A list of global settings for the behaviour
|
||||
* of the exporter
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {getConfig} from "../helper/config";
|
||||
import {getConfig, NodeConnectionMail} from "../helper/config";
|
||||
import nodemailer from "nodemailer";
|
||||
|
||||
const config = getConfig();
|
||||
|
@ -12,6 +12,8 @@ function getTransporter() : nodemailer.Transporter {
|
|||
// Generate the transporter
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: config?.smtp.host,
|
||||
port: config?.smtp.port,
|
||||
secure: config?.smtp.ssl,
|
||||
auth: {
|
||||
user: config?.smtp.username,
|
||||
pass: config?.smtp.password,
|
||||
|
@ -22,15 +24,24 @@ function getTransporter() : nodemailer.Transporter {
|
|||
return transporter;
|
||||
}
|
||||
|
||||
export async function sendMail(mailContent: string, toAddress: string, ccAddresses?: Array<string>) {
|
||||
/**
|
||||
* Send out an email with the config details.
|
||||
*/
|
||||
export async function sendMail(mailContent: string, toAddress: string, nodeConfig: NodeConnectionMail, ccAddresses?: Array<string>) {
|
||||
|
||||
// Get the transporter
|
||||
const transporter = getTransporter();
|
||||
|
||||
// Generate the mail options
|
||||
const mailOptions : nodemailer.SendMailOptions = {
|
||||
from: config?.smtp.email_from,
|
||||
to: nodeConfig.email_to,
|
||||
cc: nodeConfig.email_cc,
|
||||
html: mailContent,
|
||||
}
|
||||
|
||||
await new Promise((_r, _e) => {
|
||||
transporter.sendMail({
|
||||
|
||||
}, (err, info) => {
|
||||
transporter.sendMail(mailOptions, (err, info) => {
|
||||
|
||||
})
|
||||
})
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
function formatDate(d : Date) : string {
|
||||
|
||||
let day = (String(d.getDate() + 1)).padStart(2, "0")
|
||||
let month = (String(d.getMonth())).padStart(2, "0");
|
||||
let year = (String(d.getFullYear()));
|
||||
|
||||
let hour = (String(d.getHours())).padStart(2, "0");
|
||||
let minute = (String(d.getMinutes())).padStart(2, "0");
|
||||
|
||||
// Return the formatted datye
|
||||
return `${day}/${month}/${year} ${hour}:${minute}`;
|
||||
}
|
||||
|
||||
|
||||
class logMessage {
|
||||
|
||||
ts: Date;
|
||||
origin: string;
|
||||
message: string;
|
||||
|
||||
constructor( message: string, origin: string = "Unknown", ts?: Date ) {
|
||||
|
||||
// Initialize the date as the current date
|
||||
if ( !ts ) ts = new Date();
|
||||
|
||||
// Initialize the log message's data
|
||||
this.ts = ts;
|
||||
this.origin = origin;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the log as a string
|
||||
* @returns A string representation fo the log message
|
||||
*/
|
||||
toString() : string {
|
||||
// Get the formatted date
|
||||
let dateFormatted = formatDate(this.ts);
|
||||
|
||||
// return the formatted message
|
||||
return `[${dateFormatted}][${this.origin}]: ${this.message}`;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Logger {
|
||||
|
||||
// An array of logs to represent in an email
|
||||
logData : Array<logMessage>;
|
||||
|
||||
constructor() {
|
||||
// Initialize an array of logs
|
||||
this.logData = [];
|
||||
}
|
||||
|
||||
sendEmailLog() : void{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class SystemControl {
|
||||
// The main logger of the system
|
||||
log: Logger;
|
||||
|
||||
constructor() {
|
||||
// Create an instance of the logger
|
||||
this.log = new Logger();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Send out a panic message and end the process
|
||||
* @param message The panic message
|
||||
*/
|
||||
async panic(message: string) : Promise<void> {
|
||||
// Send out the error message
|
||||
console.error(message);
|
||||
|
||||
// End the process
|
||||
this.endProcess();
|
||||
}
|
||||
|
||||
async endProcess(exitCode : number = 100): Promise<void> {
|
||||
|
||||
|
||||
// Exit the process
|
||||
process.exit(exitCode);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue