Skip to content

Commit 7e5a386

Browse files
feat: pagerduty template support (#72)
* chore: pagerduty template support --------- Signed-off-by: Divya-Singh1693 <[email protected]>
1 parent 067fdf9 commit 7e5a386

File tree

7 files changed

+260
-20
lines changed

7 files changed

+260
-20
lines changed

.secrets.baseline

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "package-lock.json|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2025-01-02T03:52:00Z",
6+
"generated_at": "2025-02-25T17:44:26Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -144,15 +144,15 @@
144144
"hashed_secret": "0cc20f91828bed53ddb6294968b7f9abd631a3ba",
145145
"is_secret": false,
146146
"is_verified": false,
147-
"line_number": 1357,
147+
"line_number": 1385,
148148
"type": "Secret Keyword",
149149
"verified_result": null
150150
},
151151
{
152152
"hashed_secret": "3235b7f8d626cde63611d2e9ec43473f4e844c67",
153153
"is_secret": false,
154154
"is_verified": false,
155-
"line_number": 2821,
155+
"line_number": 2880,
156156
"type": "Base64 High Entropy String",
157157
"verified_result": null
158158
}

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,30 @@ try {
637637
```
638638
For webhook template supported template type value: webhook.notification
639639

640+
#### Pagerduty Template
641+
```js
642+
const templateConfigModel = {
643+
params: {
644+
body: 'base 64 encoded json body',
645+
},
646+
};
647+
let createTemplateParams = {
648+
instanceId: <instance-id>,
649+
name: <template-name>,
650+
type: <template-type>,
651+
templateConfigModel,
652+
description: <template-description>,
653+
};
654+
let createTemplateResult;
655+
try {
656+
createTemplateResult = await eventNotificationsService.createTemplate(createTemplateParams);
657+
console.log(JSON.stringify(createTemplateResult.result, null, 2));
658+
} catch (err) {
659+
console.warn(err);
660+
}
661+
```
662+
For pagerduty template supported template type value: pagerduty.notification
663+
640664
### List Templates
641665
```js
642666
const params = {
@@ -740,6 +764,29 @@ try {
740764
```
741765
For webhook template supported template type value: webhook.notification
742766

767+
#### Update PagerDuty Template
768+
```js
769+
const templateConfigModel = {
770+
params: {
771+
body: 'base 64 encoded json body',
772+
},
773+
};
774+
let replaceTemplateParams = {
775+
instanceId: <instance-id>,
776+
name: <template-name>,
777+
type: <template-type>,
778+
templateConfigModel,
779+
description: <template-description>,s
780+
};
781+
let replaceTemplateResult;
782+
try {
783+
replaceTemplateResult = await eventNotificationsService.replaceTemplate(replaceTemplateParams);
784+
} catch (err) {
785+
console.warn(err);
786+
}
787+
```
788+
For pagerduty template supported template type value: pagerduty.notification
789+
743790
### Delete Template
744791
```js
745792
const params = {
@@ -1256,7 +1303,6 @@ try {
12561303
let mms = '{"content": "akajdklahl", "content_type": "image/png"}'
12571304

12581305
const notificationCreateModel = {
1259-
instanceId,
12601306
ibmenseverity: notificationSeverity,
12611307
id: notificationID,
12621308
source: notificationsSouce,

event-notifications/v1.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,6 +5050,13 @@ namespace EventNotificationsV1 {
50505050
from_name: string;
50515051
}
50525052

5053+
/** The attributes for a PagerDuty notification. */
5054+
export interface SubscriptionAttributesPagerDutyAttributesResponse
5055+
extends SubscriptionAttributes {
5056+
/** ID of Base64 converted JSON Pagerduty Blocks w/o Handlebars. */
5057+
template_id_notification?: string;
5058+
}
5059+
50535060
/** SMS attributes object. */
50545061
export interface SubscriptionAttributesSMSAttributesResponse extends SubscriptionAttributes {
50555062
/** The subscribed list. */
@@ -5140,6 +5147,13 @@ namespace EventNotificationsV1 {
51405147
/** The attributes for an FCM notification. */
51415148
export interface SubscriptionCreateAttributesFCMAttributes extends SubscriptionCreateAttributes {}
51425149

5150+
/** The attributes for a pagerduty notification. */
5151+
export interface SubscriptionCreateAttributesPagerDutyAttributes
5152+
extends SubscriptionCreateAttributes {
5153+
/** ID of Base64 converted JSON Slack Blocks w/o Handlebars. */
5154+
template_id_notification?: string;
5155+
}
5156+
51435157
/** The attributes for an sms notification. */
51445158
export interface SubscriptionCreateAttributesSMSAttributes extends SubscriptionCreateAttributes {
51455159
/** The sms id string. */
@@ -5237,6 +5251,13 @@ namespace EventNotificationsV1 {
52375251
unsubscribed?: UpdateAttributesUnsubscribed;
52385252
}
52395253

5254+
/** The attributes for a pagerduty notification. */
5255+
export interface SubscriptionUpdateAttributesPagerDutyAttributes
5256+
extends SubscriptionUpdateAttributes {
5257+
/** ID of Base64 converted JSON Slack Blocks w/o Handlebars. */
5258+
template_id_notification?: string;
5259+
}
5260+
52405261
/** SMS attributes object. */
52415262
export interface SubscriptionUpdateAttributesSMSUpdateAttributes
52425263
extends SubscriptionUpdateAttributes {
@@ -5292,6 +5313,12 @@ namespace EventNotificationsV1 {
52925313
subject?: string;
52935314
}
52945315

5316+
/** Payload describing a pagerduty template configuration. */
5317+
export interface TemplateConfigOneOfPagerdutyTemplateConfig extends TemplateConfigOneOf {
5318+
/** Template body(Base64 encoded). */
5319+
body: string;
5320+
}
5321+
52955322
/** Payload describing a slack template configuration. */
52965323
export interface TemplateConfigOneOfSlackTemplateConfig extends TemplateConfigOneOf {
52975324
/** Template body(Base64 encoded). */

examples/event-notifications.v1.test.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ let subscriptionId5 = '';
7676
let subscriptionId6 = '';
7777
let subscriptionId7 = '';
7878
let subscriptionId8 = '';
79+
let subscriptionId9 = '';
7980
let fcmServerKey = '';
8081
let fcmSenderId = '';
8182
let safariCertificatePath = '';
@@ -109,6 +110,8 @@ let slackDmToken = '';
109110
let slackChannelID = '';
110111
let webhookTemplateID = '';
111112
let webhookTemplateBody = '';
113+
let pagerdutyTemplateID = '';
114+
let pagerdutyTemplateBody = '';
112115

113116
// Save original console.log
114117
const originalLog = console.log;
@@ -148,6 +151,7 @@ describe('EventNotificationsV1', () => {
148151
slackDmToken = config.slackDmToken;
149152
slackChannelID = config.slackChannelId;
150153
webhookTemplateBody = config.webhookTemplateBody;
154+
pagerdutyTemplateBody = config.pagerdutyTemplateBody;
151155
let eventNotificationsService = EventNotificationsV1.newInstance({});
152156

153157
test('Initialize services', async () => {
@@ -1186,6 +1190,29 @@ describe('EventNotificationsV1', () => {
11861190
} catch (err) {
11871191
console.warn(err);
11881192
}
1193+
1194+
const pagerdutyTemplateConfigModel = {
1195+
body: pagerdutyTemplateBody,
1196+
};
1197+
1198+
name = 'pagerduty template name';
1199+
description = 'pagerduty template description';
1200+
type = 'pagerduty.notification';
1201+
createTemplateParams = {
1202+
instanceId,
1203+
name,
1204+
type,
1205+
params: pagerdutyTemplateConfigModel,
1206+
description,
1207+
};
1208+
1209+
try {
1210+
createTemplateResult = await eventNotificationsService.createTemplate(createTemplateParams);
1211+
console.log(JSON.stringify(createTemplateResult.result, null, 2));
1212+
pagerdutyTemplateID = createTemplateResult.result.id;
1213+
} catch (err) {
1214+
console.warn(err);
1215+
}
11891216
// end-create_template
11901217
});
11911218

@@ -1881,6 +1908,31 @@ describe('EventNotificationsV1', () => {
18811908
description,
18821909
};
18831910

1911+
try {
1912+
replaceTemplateResult =
1913+
await eventNotificationsService.replaceTemplate(replaceTemplateParams);
1914+
console.log(JSON.stringify(replaceTemplateResult.result, null, 2));
1915+
webhookTemplateID = replaceTemplateResult.result.id;
1916+
} catch (err) {
1917+
console.warn(err);
1918+
}
1919+
1920+
const pagerdutyTemplateConfigModel = {
1921+
body: pagerdutyTemplateBody,
1922+
};
1923+
1924+
name = 'pagerduty template name update';
1925+
description = 'pagerduty template description update';
1926+
type = 'pagerduty.notification';
1927+
replaceTemplateParams = {
1928+
instanceId,
1929+
id: pagerdutyTemplateID,
1930+
name,
1931+
type,
1932+
params: pagerdutyTemplateConfigModel,
1933+
description,
1934+
};
1935+
18841936
try {
18851937
replaceTemplateResult =
18861938
await eventNotificationsService.replaceTemplate(replaceTemplateParams);
@@ -2127,6 +2179,28 @@ describe('EventNotificationsV1', () => {
21272179
} catch (err) {
21282180
console.warn(err);
21292181
}
2182+
2183+
// PagerDuty
2184+
name = 'PagerDuty subscription';
2185+
description = 'Subscription for the PagerDuty';
2186+
params = {
2187+
instanceId,
2188+
name,
2189+
destinationId: destinationId10,
2190+
topicId,
2191+
description,
2192+
attributes: {
2193+
template_id_notification: pagerdutyTemplateID,
2194+
},
2195+
};
2196+
2197+
try {
2198+
res = await eventNotificationsService.createSubscription(params);
2199+
console.log(JSON.stringify(res.result, null, 2));
2200+
subscriptionId9 = res.result.id;
2201+
} catch (err) {
2202+
console.warn(err);
2203+
}
21302204
// end-create_subscription
21312205
});
21322206

@@ -2466,6 +2540,26 @@ describe('EventNotificationsV1', () => {
24662540
},
24672541
};
24682542

2543+
try {
2544+
res = await eventNotificationsService.updateSubscription(params);
2545+
console.log(JSON.stringify(res.result, null, 2));
2546+
} catch (err) {
2547+
console.warn(err);
2548+
}
2549+
2550+
// PagerDuty
2551+
name = 'Pager Duty subscription update';
2552+
description = 'Subscription for the Pager Duty update';
2553+
params = {
2554+
instanceId,
2555+
name,
2556+
id: subscriptionId9,
2557+
description,
2558+
attributes: {
2559+
template_id_notification: pagerdutyTemplateID,
2560+
},
2561+
};
2562+
24692563
try {
24702564
res = await eventNotificationsService.updateSubscription(params);
24712565
console.log(JSON.stringify(res.result, null, 2));

package-lock.json

Lines changed: 17 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@typescript-eslint/parser": "^7.8.0",
5050
"axios": "^1.6.8",
5151
"dotenv": "^16.4.5",
52-
"eslint": "^8.52.0",
52+
"eslint": "^8.57.1",
5353
"eslint-config-airbnb-base": "^15.0.0",
5454
"eslint-config-airbnb-typescript": "^18.0.0",
5555
"eslint-config-prettier": "^9.1.0",
@@ -75,5 +75,15 @@
7575
"<rootDir>/examples/"
7676
],
7777
"testEnvironment": "node"
78+
},
79+
"bugs": {
80+
"url": "https://github.com/IBM/event-notifications-node-admin-sdk/issues"
81+
},
82+
"homepage": "https://github.com/IBM/event-notifications-node-admin-sdk#readme",
83+
"main": ".eslintrc.js",
84+
"directories": {
85+
"example": "examples",
86+
"lib": "lib",
87+
"test": "test"
7888
}
79-
}
89+
}

0 commit comments

Comments
 (0)