mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 05:17:35 +00:00
feat: Add PagerDuty Integration (#565)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
@@ -33,6 +33,8 @@ PAGE_BACKOFF_MAX=
|
|||||||
PAGE_SLEEP_MIN=
|
PAGE_SLEEP_MIN=
|
||||||
PAGE_SLEEP_MAX=
|
PAGE_SLEEP_MAX=
|
||||||
PAGE_TIMEOUT=
|
PAGE_TIMEOUT=
|
||||||
|
PAGERDUTY_INTEGRATION_KEY=
|
||||||
|
PAGERDUTY_SEVERITY=
|
||||||
PHONE_CARRIER=
|
PHONE_CARRIER=
|
||||||
PHONE_NUMBER=
|
PHONE_NUMBER=
|
||||||
PLAY_SOUND=
|
PLAY_SOUND=
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ Here is a list of variables that you can use to customize your newly copied `.en
|
|||||||
| `NVIDIA_ADD_TO_CART_ATTEMPTS` | The maximum number of times the `nvidia-api` add to cart feature will be attempted before failing | Default: `10` |
|
| `NVIDIA_ADD_TO_CART_ATTEMPTS` | The maximum number of times the `nvidia-api` add to cart feature will be attempted before failing | Default: `10` |
|
||||||
| `NVIDIA_SESSION_TTL` | The time in milliseconds to keep the cart active while using `nvidia-api` | Default: `60000` |
|
| `NVIDIA_SESSION_TTL` | The time in milliseconds to keep the cart active while using `nvidia-api` | Default: `60000` |
|
||||||
| `OPEN_BROWSER` | Toggle for whether or not the browser should open when item is found | Default: `true` |
|
| `OPEN_BROWSER` | Toggle for whether or not the browser should open when item is found | Default: `true` |
|
||||||
|
| `PAGERDUTY_INTEGRATION_KEY` | PagerDuty Events API v2 Integration Key. Obtain one in PagerDuty - <Service you want to use> - Integrations | |
|
||||||
|
| `PAGERDUTY_SEVERITY` | Severity of PagerDuty events | Default: `info` |
|
||||||
| `PAGE_BACKOFF_MIN` | Minimum backoff time between retrying requests for the same store when a forbidden response is received | Default: `10000` |
|
| `PAGE_BACKOFF_MIN` | Minimum backoff time between retrying requests for the same store when a forbidden response is received | Default: `10000` |
|
||||||
| `PAGE_BACKOFF_MAX` | Maximum backoff time between retrying requests for the same store when a forbidden response is received | Default: `3600000` |
|
| `PAGE_BACKOFF_MAX` | Maximum backoff time between retrying requests for the same store when a forbidden response is received | Default: `3600000` |
|
||||||
| `PAGE_SLEEP_MIN` | Minimum sleep time between queries of the same product page | In milliseconds, default: `5000` |
|
| `PAGE_SLEEP_MIN` | Minimum sleep time between queries of the same product page | In milliseconds, default: `5000` |
|
||||||
|
|||||||
Generated
+3192
-2
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,7 @@
|
|||||||
"messaging-api-telegram": "^1.0.1",
|
"messaging-api-telegram": "^1.0.1",
|
||||||
"mqtt": "^4.2.1",
|
"mqtt": "^4.2.1",
|
||||||
"node-notifier": "^8.0.0",
|
"node-notifier": "^8.0.0",
|
||||||
|
"node-pagerduty": "^1.3.4",
|
||||||
"nodemailer": "^6.4.14",
|
"nodemailer": "^6.4.14",
|
||||||
"open": "^7.3.0",
|
"open": "^7.3.0",
|
||||||
"play-sound": "^1.1.3",
|
"play-sound": "^1.1.3",
|
||||||
|
|||||||
@@ -147,6 +147,10 @@ const notifications = {
|
|||||||
topic: envOrString(process.env.MQTT_TOPIC, 'nvidia-snatcher/alert'),
|
topic: envOrString(process.env.MQTT_TOPIC, 'nvidia-snatcher/alert'),
|
||||||
username: envOrString(process.env.MQTT_USERNAME)
|
username: envOrString(process.env.MQTT_USERNAME)
|
||||||
},
|
},
|
||||||
|
pagerduty: {
|
||||||
|
integrationKey: envOrString(process.env.PAGERDUTY_INTEGRATION_KEY),
|
||||||
|
severity: envOrString(process.env.PAGERDUTY_SEVERITY, 'info')
|
||||||
|
},
|
||||||
phone: {
|
phone: {
|
||||||
availableCarriers: new Map([
|
availableCarriers: new Map([
|
||||||
['att', 'txt.att.net'],
|
['att', 'txt.att.net'],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {sendDesktopNotification} from './desktop';
|
|||||||
import {sendDiscordMessage} from './discord';
|
import {sendDiscordMessage} from './discord';
|
||||||
import {sendEmail} from './email';
|
import {sendEmail} from './email';
|
||||||
import {sendMqttMessage} from './mqtt';
|
import {sendMqttMessage} from './mqtt';
|
||||||
|
import {sendPagerDutyNotification} from './pagerduty';
|
||||||
import {sendPushbulletNotification} from './pushbullet';
|
import {sendPushbulletNotification} from './pushbullet';
|
||||||
import {sendPushoverNotification} from './pushover';
|
import {sendPushoverNotification} from './pushover';
|
||||||
import {sendSlackMessage} from './slack';
|
import {sendSlackMessage} from './slack';
|
||||||
@@ -22,6 +23,7 @@ export function sendNotification(link: Link, store: Store) {
|
|||||||
// Non-priority
|
// Non-priority
|
||||||
sendDiscordMessage(link, store);
|
sendDiscordMessage(link, store);
|
||||||
sendMqttMessage(link, store);
|
sendMqttMessage(link, store);
|
||||||
|
sendPagerDutyNotification(link, store);
|
||||||
sendPushbulletNotification(link, store);
|
sendPushbulletNotification(link, store);
|
||||||
sendPushoverNotification(link, store);
|
sendPushoverNotification(link, store);
|
||||||
sendSlackMessage(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