Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const parse = require('url').parse;
- const { WebClient } = require('@slack/client');
- const chat = new WebClient(process.env.SLACK_OAUTH_TOKEN).chat;
- const request = require('../src/request');
- const formatPing = ping => {
- return `\`\`\`${JSON.stringify(ping, null, 2)}\`\`\``;
- };
- /**
- * @param {array} urls
- */
- module.exports = async urls => {
- const pings = await Promise.all(
- urls.map(url => {
- return request(parse(url));
- })
- );
- pings.forEach(ping => {
- if (ping.statusCode < 200 || ping.statusCode > 299) {
- chat.postMessage({
- channel: process.env.SLACK_CHANNEL_ID,
- attachments: [
- {
- text: `Failed to reach ${url}\n${formatPing(ping)}`,
- color: 'danger'
- }
- ]
- });
- }
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement