Skip to content

Commit

Permalink
Add an AWS SES based Notifier to Tilloo (#185)
Browse files Browse the repository at this point in the history
* Add new SES notifier

* Update README
  • Loading branch information
lekhacminhphuong authored May 14, 2024
1 parent d8e51c1 commit ae5a269
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ __Settings__

## Notifications

There are notifiers included that can notify of job failures via Mandrill or AWS SNS. Notifiers are easily added for other destinations. If you add one please submit a pull request and share it.
There are notifiers included that can notify of job failures via Mandrill, AWS SNS, or AWS SES. Notifiers are easily added for other destinations. If you add one please submit a pull request and share it.

## Resources
* Running tilloo on Raspberry PI/k3s - [tilloo-k3s] (https://github.com/chriskinsman/tilloo-k3s)
Expand Down
68 changes: 68 additions & 0 deletions lib/notifiers/ses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const AWS = require('aws-sdk');
const debug = require('debug')('tilloo:notifier:ses');

let ses;

function SES(pluginConfig, generalConfig) {
this.pluginConfig = pluginConfig;
this.generalConfig = generalConfig;

const awsConfig = {};
if (this.pluginConfig.accessKeyId) {
awsConfig.accessKeyId = this.pluginConfig.accessKeyId;
}

if (this.pluginConfig.secretAccessKey) {
awsConfig.secretAccessKey = this.pluginConfig.secretAccessKey;
}

if (this.pluginConfig.region) {
awsConfig.region = this.pluginConfig.region;
}

ses = new AWS.SES(awsConfig);
}

SES.prototype.notify = async function notify(message, lastErrorTime, failureCount, job) {
if (!message.manualStop) {
const jobId = message.jobId;
const runId = message.runId;
const toEmail = job?.alternateFailureEmail && job?.alternateFailureEmail?.length > 0 ? job.alternateFailureEmail : this.pluginConfig.to_email;

let html;
if (job && job.name) {
html = `<b>${message.statusDescription}.</b> View job: <a href="http://${this.pluginConfig.web_host}/run/${runId}">${job.name}.</a>`;
}
else {
html = `<b>${message.statusDescription}.</b> <a href="http://${this.pluginConfig.web_host}/run/${runId}">Click here to view job.</a>`;
}

const params = {
Destination: {
ToAddresses: [toEmail],
},
Message: {
Subject: {
Data: message.statusDescription,
},
Body: {
Html: {
Data: html,
},
},
},
Source: this.pluginConfig.from_email,
};

try {
debug(`Sending message body: ${params}`);
await ses.sendEmail(params);
debug(`Sent message to: ${toEmail}, jobId: ${jobId}, statusDescription: ${message.statusDescription}`);
} catch (err) {
debug('Error sending message err: %O', err);
console.error('SES error: ', err);
}
}
};

module.exports = SES;

0 comments on commit ae5a269

Please sign in to comment.