Skip to content

Commit 4e158b8

Browse files
committed
[Components] uptimerobot - new action components
1 parent a437fcb commit 4e158b8

File tree

10 files changed

+780
-32
lines changed

10 files changed

+780
-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: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
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+
console.log("subType!!!", subType);
138+
return {
139+
timeout,
140+
subType: {
141+
type: "string",
142+
label: "Port Type",
143+
description: "The type of the port.",
144+
options: Object.values(constants.PORT_TYPE),
145+
default: constants.PORT_TYPE.HTTP.value,
146+
reloadProps: true,
147+
},
148+
...(subType === constants.PORT_TYPE.CUSTOM.value && {
149+
port: {
150+
type: "string",
151+
label: "Port",
152+
description: "The port number to monitor.",
153+
},
154+
}),
155+
};
156+
}
157+
158+
if (monitorType === constants.MONITOR_TYPE.KEYWORKD.value) {
159+
return {
160+
keywordValue: {
161+
type: "string",
162+
label: "Keyword Value",
163+
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>`.",
164+
},
165+
keywordType: {
166+
type: "string",
167+
label: "Keyword Type",
168+
description: "The keyword type of the monitor.",
169+
default: "1",
170+
options: [
171+
{
172+
label: "Start incident when keyword exists",
173+
value: "1",
174+
},
175+
{
176+
label: "Start incident when keyword does not exist",
177+
value: "2",
178+
},
179+
],
180+
},
181+
keywordCaseType: {
182+
type: "string",
183+
label: "Keyword Case Type",
184+
description: "The keyword case type of the monitor.",
185+
default: "1",
186+
options: [
187+
{
188+
label: "Case Sensitive",
189+
value: "0",
190+
},
191+
{
192+
label: "Case Insensitive",
193+
value: "1",
194+
},
195+
],
196+
},
197+
...authProps,
198+
};
199+
}
200+
201+
if (monitorType === constants.MONITOR_TYPE.HTTPS.value) {
202+
return {
203+
timeout,
204+
...authProps,
205+
};
206+
}
207+
208+
return {};
209+
},
210+
methods: {
211+
formatAlertContacts(alertContacts, useDefaultThresholdAndRecurrence = true) {
212+
const threshold = 0;
213+
const recurrence = 0;
214+
return utils.parseArray(alertContacts)
215+
?.map((value) => useDefaultThresholdAndRecurrence
216+
? `${value}_${threshold}_${recurrence}`
217+
: value)
218+
.join("-");
219+
},
220+
createMonitor(args = {}) {
221+
return this.app.post({
222+
path: "/newMonitor",
223+
...args,
224+
});
225+
},
226+
},
227+
async run({ $ }) {
228+
const {
229+
createMonitor,
230+
formatAlertContacts,
231+
type,
232+
friendlyName,
233+
url,
234+
interval,
235+
alertContacts,
236+
timeout,
237+
subType,
238+
port,
239+
keywordType,
240+
keywordValue,
241+
keywordCaseType,
242+
httpUsername,
243+
httpPassword,
244+
httpAuthType,
245+
} = this;
246+
247+
const response = await createMonitor({
248+
$,
249+
data: {
250+
friendly_name: friendlyName,
251+
url,
252+
type,
253+
interval,
254+
alert_contacts: formatAlertContacts(alertContacts),
255+
timeout,
256+
sub_type: subType,
257+
port,
258+
keyword_type: keywordType,
259+
keyword_value: keywordValue,
260+
keyword_case_type: keywordCaseType,
261+
http_username: httpUsername,
262+
http_password: httpPassword,
263+
http_auth_type: httpAuthType,
264+
},
265+
});
266+
267+
$.export("$summary", `Successfully created monitor with ID \`${response.monitor.id}\`.`);
268+
return response;
269+
},
270+
};
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)