mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 12:17:37 +00:00
feat: Add PagerDuty Integration (#565)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
@@ -147,6 +147,10 @@ const notifications = {
|
||||
topic: envOrString(process.env.MQTT_TOPIC, 'nvidia-snatcher/alert'),
|
||||
username: envOrString(process.env.MQTT_USERNAME)
|
||||
},
|
||||
pagerduty: {
|
||||
integrationKey: envOrString(process.env.PAGERDUTY_INTEGRATION_KEY),
|
||||
severity: envOrString(process.env.PAGERDUTY_SEVERITY, 'info')
|
||||
},
|
||||
phone: {
|
||||
availableCarriers: new Map([
|
||||
['att', 'txt.att.net'],
|
||||
|
||||
@@ -4,6 +4,7 @@ import {sendDesktopNotification} from './desktop';
|
||||
import {sendDiscordMessage} from './discord';
|
||||
import {sendEmail} from './email';
|
||||
import {sendMqttMessage} from './mqtt';
|
||||
import {sendPagerDutyNotification} from './pagerduty';
|
||||
import {sendPushbulletNotification} from './pushbullet';
|
||||
import {sendPushoverNotification} from './pushover';
|
||||
import {sendSlackMessage} from './slack';
|
||||
@@ -22,6 +23,7 @@ export function sendNotification(link: Link, store: Store) {
|
||||
// Non-priority
|
||||
sendDiscordMessage(link, store);
|
||||
sendMqttMessage(link, store);
|
||||
sendPagerDutyNotification(link, store);
|
||||
sendPushbulletNotification(link, store);
|
||||
sendPushoverNotification(link, store);
|
||||
sendSlackMessage(link, store);
|
||||
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
declare module 'node-pagerduty';
|
||||
Reference in New Issue
Block a user