Skip to content

Commit 3bce738

Browse files
committed
[Components] uptimerobot - new action components
1 parent a437fcb commit 3bce738

File tree

10 files changed

+778
-32
lines changed

10 files changed

+778
-32
lines changed

components/uptimerobot/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import constants from "../../common/constants.mjs";
2+
import app from "../../uptimerobot.app.mjs";
3+
4+
export default {
5+
key: "uptimerobot-create-alert-contact",
6+
name: "Create Alert Contact",
7+
description: "Create a new alert contact. [See the documentation](https://uptimerobot.com/api/).",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
app,
12+
type: {
13+
type: "string",
14+
label: "Alert Contact Type",
15+
description: "The type of the alert contact.",
16+
options: Object.values(constants.ALERT_CONTACT_TYPE),
17+
default: constants.ALERT_CONTACT_TYPE.EMAIL.value,
18+
},
19+
friendlyName: {
20+
description: "A friendly name for the alert contact.",
21+
propDefinition: [
22+
app,
23+
"friendlyName",
24+
],
25+
},
26+
value: {
27+
type: "string",
28+
label: "Value",
29+
description: "Alert contact's email address Eg. `[email protected]`, phone Eg. `12345678910` (with country code), username, url Eg. `https://example.com/webhook/` or api key Eg. `dXB0aW1lcm9ib3Q=` depending on the alert contact type.",
30+
},
31+
},
32+
methods: {
33+
createAlertContact(args = {}) {
34+
return this.app.post({
35+
path: "/newAlertContact",
36+
...args,
37+
});
38+
},
39+
},
40+
async run({ $ }) {
41+
const {
42+
createAlertContact,
43+
type,
44+
friendlyName,
45+
value,
46+
} = this;
47+
48+
const response = await createAlertContact({
49+
$,
50+
data: {
51+
type,
52+
friendly_name: friendlyName,
53+
value,
54+
},
55+
});
56+
57+
$.export("$summary", "Successfully created the alert contact.");
58+
return response;
59+
},
60+
};
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
import constants from "../../common/constants.mjs";
2+
import app from "../../uptimerobot.app.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
key: "uptimerobot-create-monitor",
7+
name: "Create Monitor",
8+
description: "Create a new monitor. [See the documentation](https://uptimerobot.com/api/).",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
type: {
14+
type: "string",
15+
label: "Monitor Type",
16+
description: "The type of the monitor.",
17+
reloadProps: true,
18+
default: constants.MONITOR_TYPE.PING.value,
19+
options: Object.values(constants.MONITOR_TYPE),
20+
},
21+
friendlyName: {
22+
description: "A friendly name for the monitor.",
23+
propDefinition: [
24+
app,
25+
"friendlyName",
26+
],
27+
},
28+
url: {
29+
type: "string",
30+
label: "URL, IP Or Host",
31+
description: "The URL, IP address or Host to monitor.",
32+
},
33+
interval: {
34+
type: "string",
35+
label: "Monitor Interval",
36+
description: "The interval for the monitoring check in seconds. It is recommended to use at least 1-minute checks [available in paid plans](https://app.uptimerobot.com/billing/pricing).",
37+
default: String(5 * 60),
38+
options: [
39+
{
40+
label: "5 Minutes",
41+
value: String(5 * 60),
42+
},
43+
{
44+
label: "30 Minutes",
45+
value: String(30 * 60),
46+
},
47+
{
48+
label: "1 Hour",
49+
value: String(60 * 60),
50+
},
51+
{
52+
label: "12 Hours",
53+
value: String(12 * 60 * 60),
54+
},
55+
{
56+
label: "1 Day",
57+
value: String(24 * 60 * 60),
58+
},
59+
],
60+
},
61+
alertContacts: {
62+
type: "string[]",
63+
label: "Alert Contacts",
64+
propDefinition: [
65+
app,
66+
"alertContact",
67+
],
68+
},
69+
},
70+
additionalProps() {
71+
const {
72+
type: monitorType,
73+
subType,
74+
} = this;
75+
76+
const timeout = {
77+
type: "string",
78+
label: "Request Timeout",
79+
description: "The request timeout. The shorter the timeout the earlier we mark website as down.",
80+
default: "30",
81+
options: [
82+
{
83+
label: "1 Second",
84+
value: "1",
85+
},
86+
{
87+
label: "15 Seconds",
88+
value: "15",
89+
},
90+
{
91+
label: "30 Seconds",
92+
value: "30",
93+
},
94+
{
95+
label: "45 Seconds",
96+
value: "45",
97+
},
98+
{
99+
label: "1 Minute",
100+
value: "60",
101+
},
102+
],
103+
};
104+
105+
const authProps = {
106+
httpAuthType: {
107+
type: "string",
108+
label: "HTTP Auth Type",
109+
description: "The HTTP auth type for the monitor.",
110+
optional: true,
111+
options: [
112+
{
113+
label: "HTTP Basic",
114+
value: "1",
115+
},
116+
{
117+
label: "Digest",
118+
value: "2",
119+
},
120+
],
121+
},
122+
httpUsername: {
123+
type: "string",
124+
label: "HTTP Username",
125+
description: "The HTTP username for the monitor.",
126+
optional: true,
127+
},
128+
httpPassword: {
129+
type: "string",
130+
label: "HTTP Password",
131+
description: "The HTTP password for the monitor.",
132+
optional: true,
133+
},
134+
};
135+
136+
if (monitorType === constants.MONITOR_TYPE.PORT.value) {
137+
return {
138+
timeout,
139+
subType: {
140+
type: "string",
141+
label: "Port Type",
142+
description: "The type of the port.",
143+
options: Object.values(constants.PORT_TYPE),
144+
default: constants.PORT_TYPE.HTTP.value,
145+
reloadProps: true,
146+
},
147+
...(subType === constants.PORT_TYPE.CUSTOM.value && {
148+
port: {
149+
type: "string",
150+
label: "Port",
151+
description: "The port number to monitor.",
152+
},
153+
}),
154+
};
155+
}
156+
157+
if (monitorType === constants.MONITOR_TYPE.KEYWORD.value) {
158+
return {
159+
keywordValue: {
160+
type: "string",
161+
label: "Keyword Value",
162+
description: "The keyword must be present in the response HTML source. You can use HTML markup, too. Eg. `apple` or `<span id=\"availability\">Out of stock</span>`.",
163+
},
164+
keywordType: {
165+
type: "string",
166+
label: "Keyword Type",
167+
description: "The keyword type of the monitor.",
168+
default: "1",
169+
options: [
170+
{
171+
label: "Start incident when keyword exists",
172+
value: "1",
173+
},
174+
{
175+
label: "Start incident when keyword does not exist",
176+
value: "2",
177+
},
178+
],
179+
},
180+
keywordCaseType: {
181+
type: "string",
182+
label: "Keyword Case Type",
183+
description: "The keyword case type of the monitor.",
184+
default: "1",
185+
options: [
186+
{
187+
label: "Case Sensitive",
188+
value: "0",
189+
},
190+
{
191+
label: "Case Insensitive",
192+
value: "1",
193+
},
194+
],
195+
},
196+
...authProps,
197+
};
198+
}
199+
200+
if (monitorType === constants.MONITOR_TYPE.HTTPS.value) {
201+
return {
202+
timeout,
203+
...authProps,
204+
};
205+
}
206+
207+
return {};
208+
},
209+
methods: {
210+
formatAlertContacts(alertContacts, useDefaultThresholdAndRecurrence = true) {
211+
const threshold = 0;
212+
const recurrence = 0;
213+
return utils.parseArray(alertContacts)
214+
?.map((value) => useDefaultThresholdAndRecurrence
215+
? `${value}_${threshold}_${recurrence}`
216+
: value)
217+
.join("-");
218+
},
219+
createMonitor(args = {}) {
220+
return this.app.post({
221+
path: "/newMonitor",
222+
...args,
223+
});
224+
},
225+
},
226+
async run({ $ }) {
227+
const {
228+
createMonitor,
229+
formatAlertContacts,
230+
type,
231+
friendlyName,
232+
url,
233+
interval,
234+
alertContacts,
235+
timeout,
236+
subType,
237+
port,
238+
keywordType,
239+
keywordValue,
240+
keywordCaseType,
241+
httpUsername,
242+
httpPassword,
243+
httpAuthType,
244+
} = this;
245+
246+
const response = await createMonitor({
247+
$,
248+
data: {
249+
friendly_name: friendlyName,
250+
url,
251+
type,
252+
interval,
253+
alert_contacts: formatAlertContacts(alertContacts),
254+
timeout,
255+
sub_type: subType,
256+
port,
257+
keyword_type: keywordType,
258+
keyword_value: keywordValue,
259+
keyword_case_type: keywordCaseType,
260+
http_username: httpUsername,
261+
http_password: httpPassword,
262+
http_auth_type: httpAuthType,
263+
},
264+
});
265+
266+
$.export("$summary", `Successfully created monitor with ID \`${response.monitor.id}\`.`);
267+
return response;
268+
},
269+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import app from "../../uptimerobot.app.mjs";
2+
3+
export default {
4+
key: "uptimerobot-update-monitor-status",
5+
name: "Update Monitor Status",
6+
description: "Update an existing monitor's status to pause or resume monitoring. [See the documentation](https://uptimerobot.com/api/).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
monitorId: {
12+
propDefinition: [
13+
app,
14+
"monitorId",
15+
],
16+
},
17+
status: {
18+
propDefinition: [
19+
app,
20+
"status",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const {
26+
app,
27+
monitorId,
28+
status,
29+
} = this;
30+
31+
const response = await app.updateMonitor({
32+
$,
33+
data: {
34+
id: monitorId,
35+
status,
36+
},
37+
});
38+
$.export("$summary", "Successfully updated the monitor status.");
39+
return response;
40+
},
41+
};

components/uptimerobot/app/uptimerobot.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)