Skip to content

Commit d355222

Browse files
committed
Requested changes done
1 parent 8acf020 commit d355222

File tree

5 files changed

+203
-3
lines changed

5 files changed

+203
-3
lines changed

components/opsgenie/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import app from "../../opsgenie.app.mjs";
2+
3+
export default {
4+
key: "opsgenie-create-alert",
5+
name: "Create Alert",
6+
description: "Send a new Alert for processing. [See the documentation](https://www.postman.com/api-evangelist/opsgenie/request/zuj17nj/create-alert)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
user: {
12+
propDefinition: [
13+
app,
14+
"user",
15+
],
16+
},
17+
message: {
18+
propDefinition: [
19+
app,
20+
"message",
21+
],
22+
},
23+
note: {
24+
propDefinition: [
25+
app,
26+
"note",
27+
],
28+
},
29+
description: {
30+
propDefinition: [
31+
app,
32+
"description",
33+
],
34+
},
35+
tags: {
36+
propDefinition: [
37+
app,
38+
"tags",
39+
],
40+
},
41+
priority: {
42+
propDefinition: [
43+
app,
44+
"priority",
45+
],
46+
},
47+
},
48+
async run({ $ }) {
49+
const response = await this.app.createAlert({
50+
$,
51+
data: {
52+
message: this.message,
53+
user: this.user,
54+
note: this.note,
55+
description: this.description,
56+
tags: this.tags,
57+
priority: this.priority,
58+
},
59+
});
60+
61+
$.export("$summary", `Successfully sent a new alert for processing. The alert ID can be used to check the request status: '${response.requestId}'`);
62+
63+
return response;
64+
},
65+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import app from "../../opsgenie.app.mjs";
2+
3+
export default {
4+
key: "opsgenie-get-alert-status",
5+
name: "Get Alert Status",
6+
description: "Get the status of the alert with the specified ID. [See the documentation](https://www.postman.com/api-evangelist/opsgenie/request/03tcghu/get-request-status-of-alert)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
requestId: {
12+
propDefinition: [
13+
app,
14+
"requestId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.getAlertStatus({
20+
$,
21+
requestId: this.requestId,
22+
});
23+
24+
$.export("$summary", `Request processing status: '${response.data.status}'`);
25+
26+
return response;
27+
},
28+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
PRIORITY_OPTIONS: [
3+
"P1",
4+
"P2",
5+
"P3",
6+
"P4",
7+
"P5",
8+
],
9+
};
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
4+
export default {
5+
type: "app",
6+
app: "opsgenie",
7+
propDefinitions: {
8+
user: {
9+
type: "string",
10+
label: "User ID",
11+
description: "ID of the User",
12+
async options() {
13+
const response = await this.listUsers();
14+
const usersIds = response.data;
15+
return usersIds.map(({
16+
id, fullName,
17+
}) => ({
18+
value: id,
19+
label: fullName,
20+
}));
21+
},
22+
},
23+
message: {
24+
type: "string",
25+
label: "message",
26+
description: "The message of the alert",
27+
},
28+
note: {
29+
type: "string",
30+
label: "Note",
31+
description: "Note of the alert",
32+
},
33+
description: {
34+
type: "string",
35+
label: "Description",
36+
description: "Description of the alert",
37+
},
38+
tags: {
39+
type: "string[]",
40+
label: "Tags",
41+
description: "Tags of the alert",
42+
},
43+
priority: {
44+
type: "string",
45+
label: "Priority",
46+
description: "Priority of the alert",
47+
options: constants.PRIORITY_OPTIONS,
48+
},
49+
requestId: {
50+
type: "string",
51+
label: "Request ID",
52+
description: "ID of the alert request to be checked",
53+
},
54+
},
55+
methods: {
56+
_baseUrl() {
57+
return `https://${this.$auth.instance_region}.opsgenie.com/v2`;
58+
},
59+
async _makeRequest(opts = {}) {
60+
const {
61+
$ = this,
62+
path,
63+
headers,
64+
APIKey,
65+
...otherOpts
66+
} = opts;
67+
return axios($, {
68+
...otherOpts,
69+
url: this._baseUrl() + path,
70+
headers: {
71+
...headers,
72+
Authorization: `GenieKey ${APIKey}`,
73+
},
74+
});
75+
},
76+
async createAlert(args = {}) {
77+
return this._makeRequest({
78+
method: "post",
79+
path: "/alerts",
80+
APIKey: this.$auth.team_api_key,
81+
...args,
82+
});
83+
},
84+
async getAlertStatus({
85+
requestId, ...args
86+
}) {
87+
return this._makeRequest({
88+
path: `/alerts/requests/${requestId}`,
89+
APIKey: this.$auth.team_api_key,
90+
...args,
91+
});
92+
},
93+
async listUsers(args = {}) {
94+
return this._makeRequest({
95+
path: "/users",
96+
APIKey: this.$auth.api_key,
97+
...args,
98+
});
99+
},
100+
},
101+
};

0 commit comments

Comments
 (0)