Skip to content

Instantly share code, notes, and snippets.

@kstolte
Created January 29, 2018 19:06
Show Gist options
  • Save kstolte/3d80e0d2c073977e31a5b27af7f71e1c to your computer and use it in GitHub Desktop.
Save kstolte/3d80e0d2c073977e31a5b27af7f71e1c to your computer and use it in GitHub Desktop.
Webtask to have an Azure Alert be sent to a Slack Channel
var request = require('request');
module.exports = function (context, done) {
var recBody = context.body;
var rContext = recBody.context;
var rCondition = rContext.condition;
var icon = recBody.status === 'Activated' ? ':open_mouth:': ':party_parrot:';
var outText = `${rContext.resourceName} - ${rContext.name} - ${recBody.status} <${rContext.portalLink}|Click Here>
Condition: ${rCondition.metricName} ${rCondition.operator} ${rCondition.threshold} (${rCondition.metricUnit}) in the last ${rCondition.windowSize} minutes
Raw Value: ${rCondition.metricName} @ ${rCondition.metricValue} (${rCondition.metricUnit})`;
request({
url: "{YourSlackChannelURL}",
method: 'POST',
json: true,
body: {
text: `${outText}`,
icon_emoji: `${icon}`
}
});
done(null, {
text: `${outText}`,
icon_emoji: `${icon}`
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment