Created
January 23, 2019 16:46
-
-
Save homeyjd/3fdd4e1247978a264e0a77f4c71367b0 to your computer and use it in GitHub Desktop.
Replacement for src/parsers/batch-events.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const _ = require("lodash") | |
, SNSParser = require("./sns") | |
, Slack = require("../slack"); | |
class BatchParser extends SNSParser { | |
handleMessage(message) { | |
if (_.get(message, "source") !== "aws.batch") { | |
return false; | |
} | |
const time = new Date(_.get(message, "time")); | |
const status = _.get(message, "detail.status"); | |
const reason = _.get(message, "detail.statusReason"); | |
const jobName = _.get(message, "detail.jobName"); | |
const logStream = _.get(message, "detail.attempts[0].container.logStreamName"); | |
const logsUrl = `https://console.aws.amazon.com/cloudwatch/home?region=${message.region}#logEventViewer:group=/aws/batch/job;stream=${logStream};`; | |
const fields = []; | |
let color = Slack.COLORS.neutral; | |
const baseTitle = `Batch Job Event ${jobName}`; | |
let title = baseTitle; | |
if (status === "SUCCESS") { | |
title = `${jobName} succeeded`; | |
color = Slack.COLORS.ok; | |
} | |
else if (status === "FAILED") { | |
title = `${jobName} failed`; | |
color = Slack.COLORS.critical; | |
} | |
fields.push({ | |
title: "Status", | |
value: status, | |
short: true | |
}); | |
fields.push({ | |
title: "Reason", | |
value: `${reason}`, | |
short: true | |
}); | |
fields.push({ | |
title: "Logs", | |
value: `<${logsUrl}|View Logs>`, | |
short: true | |
}); | |
return { | |
attachments: [{ | |
author_name: "AWS Batch Notification", | |
fallback: `${baseTitle} ${status}`, | |
color: color, | |
title: title, | |
fields: fields, | |
mrkdwn_in: [ "title", "text" ], | |
ts: Slack.toEpochTime(time) | |
}] | |
}; | |
} | |
} | |
module.exports = BatchParser; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment