Skip to content

Commit

Permalink
feat(summary): add url to grafana dashboard in summary email content
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentinTh committed Apr 15, 2022
1 parent dde2bf4 commit b4f6269
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export TO='jane.doe@gmail.com'
export SUMMARY_DAY='SUNDAY'
export SUMMARY_HOUR='16'

# URL to your Grafana dashboard
export GRAFANA_URL='https://my.grafana.com'

# go to https://ipinfo.io/ for more details
export IP_INFOS_TOKEN='00000000000000'

Expand Down
12 changes: 6 additions & 6 deletions src/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { Config } from './utils/Config.js';
import DateHelper from './helpers/DateHelper.js';
import Database from './utils/Database.js';
import SpamController from './controllers/SpamController.js';
import Mailer from './Mailer.js';
import Mailer from './utils/Mailer.js';
import { ConsoleHelper, EOL, Tags } from './helpers/ConsoleHelper.js';

class Summary {
async sendSummary() {
const config = Config.getConfig();
const todayDay = dayjs().day();

if (DateHelper.getDayNumber(config.summary.DAY) === todayDay) {
if (DateHelper.getDayNumber(config.summary.day) === todayDay) {
const currentHour = dayjs().hour();

if (config.summary.HOUR === currentHour) {
if (config.summary.hour === currentHour) {
const database = new Database();
const client = await database.connect({ sshTunnel: true });

Expand All @@ -28,12 +28,12 @@ class Summary {

const mailer = new Mailer();
await mailer.sendMail({
from: config.email.FROM,
to: config.email.TO,
from: config.email.from,
to: config.email.to,
subject: `Weekly Summary Report`,
html: `<div style="font-size: 16px;font-family: 'Arial';">
<p>This week, <strong>${total} spam email${plural}</strong> have been successfully deleted.</p>
<p>Complete and detailed logs are available if you need more insight on spam addresses that have been removed.</p>
<p>Complete and detailed data are available in the <a href='${config.summary.grafana_url}'>Grafana dashboard</a> if you need more insight.</p>
</div>`
});

Expand Down
10 changes: 6 additions & 4 deletions src/utils/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const defaultValidationSchema = joi
]
}),
SUMMARY_HOUR: joi.number().integer().required().min(0).max(23),
GRAFANA_URL: joi.string().trim().uri().optional(),
IP_INFOS_TOKEN: joi.string().trim().required(),
DB_USER: joi.string().trim().required(),
DB_PASSWORD: joi.string().trim().required(),
Expand Down Expand Up @@ -69,12 +70,13 @@ export class Config {
return {
account: env.ACCOUNT,
email: {
FROM: env.FROM,
TO: env.TO
from: env.FROM,
to: env.TO
},
summary: {
DAY: env.SUMMARY_DAY.toLowerCase(),
HOUR: env.SUMMARY_HOUR
day: env.SUMMARY_DAY.toLowerCase(),
hour: env.SUMMARY_HOUR,
grafana_url: env.GRAFANA_URL
},
ip_infos: {
token: env.IP_INFOS_TOKEN
Expand Down

0 comments on commit b4f6269

Please sign in to comment.