Skip to content

Commit

Permalink
Fixed email notification, logs attachment was missing on backup error
Browse files Browse the repository at this point in the history
  • Loading branch information
ulver2812 committed Mar 7, 2019
1 parent 7add0a5 commit 74a766d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 59 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
### Changelog
All notable changes to this project will be documented in this file.

## [1.4.1] - 2019-03-07
### Fixed
- Email notification: logs attachment was missing on backup error

## [1.4.0] - 2019-03-06
### Fixed
- With multiple folders in the backup job the S3 paths were wrong
Expand Down
67 changes: 16 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-s3-backup",
"version": "1.4.0",
"version": "1.4.1",
"description": "AWS S3 backup system",
"homepage": "https://github.com/ulver2812/aws-s3-backup",
"author": {
Expand Down
4 changes: 2 additions & 2 deletions src/app/providers/aws.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class AwsService {
this.jobService.save(job);
this.logService.printLog(LogType.ERROR, 'Can\'t run job ' + job.name + ' because of: \r\n' + err);
this.notification.sendNotification('Problem with job: ' + job.name, 'The job ' + job.name +
' has just stopped because of ' + err + '. <br/> - AWS S3 Backup', 'email');
' has just stopped because of ' + err + '. <br/> - AWS S3 Backup', 'email', true);
if (err) {
return callback(err);
}
Expand All @@ -178,7 +178,7 @@ export class AwsService {
this.jobService.save(job);
this.logService.printLog(LogType.ERROR, 'Error with job ' + job.name + ' because of: \r\n' + err);
this.notification.sendNotification('Problem with job: ' + job.name, 'The job ' + job.name +
' has just throw an error because of ' + err + '. <br/> - AWS S3 Backup', 'email');
' has just throw an error because of ' + err + '. <br/> - AWS S3 Backup', 'email', true);
});

} else {
Expand Down
4 changes: 4 additions & 0 deletions src/app/providers/log.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ export class LogService {
fs.ensureFileSync(this.logFile);
return fs.readFileSync(this.logFile, {encoding: 'utf8'});
}

getLogsFile() {
return this.logFile;
}
}
22 changes: 17 additions & 5 deletions src/app/providers/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,39 @@ export class NotificationsService {
}

// subject = await this.translate.get('NOTIFICATIONS.SUBJECT-START').toPromise();
sendNotification(subject: string, message: string, channel: string) {
sendNotification(subject: string, message: string, channel: string, logAttachment: boolean = false) {
const settings = this.settingsService.getSettings();
if (settings.allowNotifications === false) {
return;
}

if (channel === 'email') {
const transporter = this.getEmailTransporter();
transporter.sendMail(this.getMailOptions(subject, message), (err: Error, res: Response) => {
transporter.sendMail(this.getMailOptions(subject, message, logAttachment), (err: Error, res: Response) => {
this.log.printLog(LogType.ERROR, 'Email - ' + err.message);
});
}
}

getMailOptions(subject: string, message: string) {
getMailOptions(subject: string, message: string, logAttachment: boolean = false) {
const settings = this.settingsService.getSettings();
return {

const options = {
from: settings.emailSender, // sender address
to: settings.emailReceivers, // list of receivers
subject: subject, // Subject line
html: message // html body
html: message, // html body
};

if (logAttachment) {
options['attachments'] = [
{
filename: 'log-activities.txt',
path: this.log.getLogsFile() // stream this file
}
];
}

return options;
}
}

0 comments on commit 74a766d

Please sign in to comment.