Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue that alarm info part shows undefined when alarm is base… #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,26 @@ var handleCloudWatch = function(event, context) {
var region = event.Records[0].EventSubscriptionArn.split(":")[3];
var subject = "AWS CloudWatch Notification";
var alarmName = message.AlarmName;
var metricName = message.Trigger.MetricName;
var oldState = message.OldStateValue;
var newState = message.NewStateValue;
var alarmDescription = message.AlarmDescription;
var alarmReason = message.NewStateReason;
var trigger = message.Trigger;
var color = "warning";
var alarmConfigInfo;

if (message.NewStateValue === "ALARM") {
color = "danger";
} else if (message.NewStateValue === "OK") {
color = "good";
}

if (Array.isArray(trigger.Metrics) && trigger.Metrics.length > 0) {
alarmConfigInfo = "Expression based alarm";
} else {
alarmConfigInfo = trigger.Statistic + " " + trigger.MetricName;
}

var slackMessage = {
text: "*" + subject + "*",
attachments: [
Expand All @@ -257,8 +263,7 @@ var handleCloudWatch = function(event, context) {
{ "title": "Alarm Description", "value": alarmDescription, "short": false},
{
"title": "Trigger",
"value": trigger.Statistic + " "
+ metricName + " "
"value": alarmConfigInfo + " "
+ trigger.ComparisonOperator + " "
+ trigger.Threshold + " for "
+ trigger.EvaluationPeriods + " period(s) of "
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lambda-cloudwatch-slack",
"version": "0.3.0",
"description": "Better Slack notifications for AWS CloudWatch",
"authors": [
"authors": [
"Christopher Reichert <[email protected]>",
"Cody Reichert <[email protected]>",
"Alexandr Promakh <[email protected]>"
Expand Down