feat: Add PagerDuty Integration (#565)

Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
Jingsi Zhu
2020-10-22 20:48:37 -04:00
committed by GitHub
parent ac37f87793
commit 11ee0bf1a3
8 changed files with 3236 additions and 2 deletions
+32
View File
@@ -0,0 +1,32 @@
import {Link, Store} from '../store/model';
import {Print, logger} from '../logger';
import PDClient from 'node-pagerduty';
import {config} from '../config';
const pd = new PDClient('');
export function sendPagerDutyNotification(link: Link, store: Store) {
if (config.notifications.pagerduty.integrationKey) {
logger.debug('↗ sending pagerduty message');
const links = [
{href: link.url, text: 'Visit Store'}
];
if (link.cartUrl) {
links.push({
href: link.cartUrl, text: 'Add to Cart'
});
}
pd.events.sendEvent({
dedup_key: link.url,
event_action: 'trigger',
payload: {
links,
severity: config.notifications.pagerduty.severity,
source: store.name,
summary: Print.inStock(link, store)
},
routing_key: config.notifications.pagerduty.integrationKey
});
}
}