Skip to content
Snippets Groups Projects
Commit f9ed3880 authored by kuzdogan's avatar kuzdogan
Browse files

Test send email.

Currently gets the validators that are checked for uptime and sends an
email. The email is plaintext formatted but dynamically gets contact
info. The contact info is not dnamic but uses a dummy contact. This will
be replaced by a mapping from the contacts exported from Cobra at first.
Later throgh automatic access to Cobra DB.
parent 73693e81
No related branches found
No related tags found
No related merge requests found
SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASS=
\ No newline at end of file
config.js config.js
node_modules/ node_modules/
\ No newline at end of file .env
\ No newline at end of file
...@@ -11,6 +11,8 @@ Install the dependencies ...@@ -11,6 +11,8 @@ Install the dependencies
npm install npm install
``` ```
Copy the file `.env-template` to a new file called `.env`. Add the SMTP credentials for each variable. You can use a service like [Mailtap](https://mailtrap.io/) to test emails.
Run the script with Run the script with
``` ```
node index.js node index.js
......
email.js 0 → 100644
/**
* @module email
*/
const nodemailer = require('nodemailer');
const moment = require('moment');
require('dotenv').config();
const transport = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PASS,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
});
/**
* @function to send a notice email to the validator input.
*
* @param {Object} validatorObj returned Object from module:validators.getValidatorArray
*
*/
function sendNoticeMail(validatorObj) {
let { instituteName, address, lastOnline } = validatorObj; // TODO: Get the institute name from Cobra, not the validators contract.
let { title, name, surname, email } = getContactInfo(address);
let lastOfflineDateString = moment(lastOnline).format('MMMM Do YYYY, hh:mm a [Germany time]')
console.log('Sending email to: ' + email)
const message = {
from: `bloxberg <monitoring@bloxberg.org>`,
to: `${email}`,
subject: 'bloxberg Validator Inactive',
text: `Dear ${title} ${name} ${surname},\n\n
It seems your bloxberg validator node at ${instituteName} has been offline since ${lastOfflineDateString}.\n\n
Could you please check if there is a problem with the validator? Also, please make sure the bootnodes.txt of your validator is up to date with the most recent one here. If you need technical assistance contact us at info@bloxberg.org.\n\n
You can check the last time your node validated blocks from here: https://blockexplorer.bloxberg.org/address/${address}/validations\n\n
Best\n
bloxberg\n
`
};
return transport.sendMail(message);
}
/**
* @function to get the contact information of the validators from the validator address.
*
* Takes the validator address. Checks if there is a techie contact. If yes returns it, otherwise returns the main contact.
*
* @param {String} address - validator address
*/
function getContactInfo(address) {
return {
title: 'Mr.',
name: 'Max',
surname: 'Mustermann',
email: 'uzdogan@mpdl.mpg.de'
}
}
module.exports = {
sendNoticeMail
}
\ No newline at end of file
const {getValidatorArray} = require('./validators.js'); const {getValidatorArray} = require('./validators');
const { sendNoticeMail } = require('./email');
getValidatorArray() getValidatorArray()
.then(console.log); .then( validatorsArray => {
console.log("Got the online status for validators: ");
console.log(validatorsArray);
// for (let i=0; i<validatorsArray.length; i++) {
for (let i=0; i<1; i++) {
sendNoticeMail(validatorsArray[i])
}
});
...@@ -1550,6 +1550,11 @@ ...@@ -1550,6 +1550,11 @@
"resolved": "https://registry.npmjs.org/mock-fs/-/mock-fs-4.13.0.tgz", "resolved": "https://registry.npmjs.org/mock-fs/-/mock-fs-4.13.0.tgz",
"integrity": "sha512-DD0vOdofJdoaRNtnWcrXe6RQbpHkPPmtqGq14uRX0F8ZKJ5nv89CVTYl/BZdppDxBDaV0hl75htg3abpEWlPZA==" "integrity": "sha512-DD0vOdofJdoaRNtnWcrXe6RQbpHkPPmtqGq14uRX0F8ZKJ5nv89CVTYl/BZdppDxBDaV0hl75htg3abpEWlPZA=="
}, },
"moment": {
"version": "2.29.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz",
"integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ=="
},
"ms": { "ms": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"dependencies": { "dependencies": {
"axios": "^0.20.0", "axios": "^0.20.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"moment": "^2.29.1",
"nodemailer": "^6.4.16", "nodemailer": "^6.4.16",
"web3": "^1.2.11" "web3": "^1.2.11"
} }
......
const axios = require('axios'); const axios = require('axios');
/**
* @module validators
*/
const abi = require('./abis/RelaySet.abi.json'); const abi = require('./abis/RelaySet.abi.json');
const metaDataAbi = require('./abis/ValidatorMetadata.abi.json'); const metaDataAbi = require('./abis/ValidatorMetadata.abi.json');
const Web3 = require('web3'); const Web3 = require('web3');
...@@ -33,7 +36,7 @@ async function getValidatorArray() { ...@@ -33,7 +36,7 @@ async function getValidatorArray() {
console.log('------------------------------------------'); console.log('------------------------------------------');
// Check and print each institute // Check and print each institute
let resultArray = []; let resultArray = [];
for (let i = 0; i < 3; i++) { // Debug for (let i = 0; i < 2; i++) { // Debug
// for (let i = 0; i < validators.length; i++) { // for (let i = 0; i < validators.length; i++) {
let address = validators[i]; let address = validators[i];
validatorData = await getLastBlock(address); validatorData = await getLastBlock(address);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment