betterstackmanager 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/docs/classes/Client.md +18 -2
- package/docs/classes/Error.md +2 -2
- package/docs/classes/IncidentComment.md +26 -0
- package/docs/classes/Incidents.md +32 -15
- package/docs/classes/Monitor.md +115 -0
- package/docs/etc/Util.md +29 -0
- package/docs/objects/IncidentComment.md +6 -6
- package/docs/objects/Monitor.md +130 -0
- package/docs/readme.md +14 -2
- package/docs/upstream/Pagination.md +12 -0
- package/examples/acknowledgeIncident.js +1 -1
- package/examples/createIncident.js +1 -1
- package/examples/createIncidentComment.js +1 -1
- package/examples/getSingleIncident.js +1 -1
- package/examples/readme.md +7 -2
- package/examples/resolveIncident.js +1 -1
- package/package.json +1 -1
- package/src/client/index.js +2 -0
- package/src/client/utils.js +63 -0
- package/src/etc/Incident.js +49 -1
- package/src/etc/IncidentComment.js +35 -2
- package/src/etc/Monitor.js +153 -0
- package/src/index.js +5 -0
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@ There is a required node version, and it is `>= 6.0.0`.
|
|
|
9
9
|
You must clone this repository (or, at least, the `src` directory) and require the Client object.
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
|
-
const BSM = require('
|
|
13
|
-
const client = new BSM();
|
|
12
|
+
const BSM = require('betterstackmanager');
|
|
13
|
+
const client = new BSM.Client();
|
|
14
14
|
const config = require('./config.json');
|
|
15
15
|
|
|
16
16
|
client.login(config.token);
|
|
@@ -31,10 +31,15 @@ The documentation for this project is contained within the `docs` directory.
|
|
|
31
31
|
## Links
|
|
32
32
|
|
|
33
33
|
- [Documentation](https://codeberg.org/Cyanic76/BSM.js/src/branch/main/docs)
|
|
34
|
-
- [
|
|
34
|
+
- [Source Code](https://codeberg.org/Cyanic76/BSM.js/)
|
|
35
|
+
- [Discord server](https://cyanic.me/discord)
|
|
36
|
+
|
|
37
|
+
Get the package on
|
|
38
|
+
[Codeberg](https://codeberg.org/Cyanic76/-/packages/npm/betterstackmanager/) or on
|
|
39
|
+
[NPM](https://www.npmjs.com/package/betterstackmanager).
|
|
35
40
|
|
|
36
41
|
## Contributing & Help
|
|
37
42
|
|
|
38
43
|
As always, if you're in need of help, don't hesitate to create a new issue or to [join my Discord server](https://cyanic.me/discord).
|
|
39
44
|
|
|
40
|
-
This project abides by the CCoC.
|
|
45
|
+
This project abides by the [CCoC](https://codeberg.org/Cyanic76/pages/src/branch/pages/CODE_OF_CONDUCT.md).
|
package/docs/classes/Client.md
CHANGED
|
@@ -6,7 +6,15 @@ The `Client` interface is the main entry point to interact with BetterStack.
|
|
|
6
6
|
|
|
7
7
|
## `client`
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
This function defines your BetterStack API client.
|
|
10
|
+
|
|
11
|
+
`new Client()`
|
|
12
|
+
|
|
13
|
+
## client.login(token)
|
|
14
|
+
|
|
15
|
+
`client.login(token)`
|
|
16
|
+
|
|
17
|
+
This function is the point where your token is first used.
|
|
10
18
|
|
|
11
19
|
| Value | Type | Required | About |
|
|
12
20
|
|-|-|-|-|
|
|
@@ -14,4 +22,12 @@ The `Client` interface is the main entry point to interact with BetterStack.
|
|
|
14
22
|
|
|
15
23
|
## Classes
|
|
16
24
|
|
|
17
|
-
The Client constructor includes the
|
|
25
|
+
The Client constructor includes the following classes.
|
|
26
|
+
|
|
27
|
+
- `incidentComments`
|
|
28
|
+
- `incidents`,
|
|
29
|
+
- `monitors`
|
|
30
|
+
|
|
31
|
+
## Event listeners
|
|
32
|
+
|
|
33
|
+
The Client constructor does not currently listen to any upstream event.
|
package/docs/classes/Error.md
CHANGED
|
@@ -14,14 +14,14 @@ The errors generated via this module fall in 3 categories:
|
|
|
14
14
|
| status | HTTP Response code (usually 4XX or 5XX) |
|
|
15
15
|
| data | The error data. |
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
## NetworkError
|
|
18
18
|
|
|
19
19
|
| Value | Type |
|
|
20
20
|
|-|-|
|
|
21
21
|
| name | `NetworkError` |
|
|
22
22
|
| message | The error message. |
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
## RequestError
|
|
25
25
|
|
|
26
26
|
| Value | Type |
|
|
27
27
|
|-|-|
|
|
@@ -6,6 +6,8 @@ This is the point from which all incident comments can be managed.
|
|
|
6
6
|
|
|
7
7
|
> **Markdown is supported within comments.**
|
|
8
8
|
|
|
9
|
+
Methods: `create`, `get`, `getAll`, `update`.
|
|
10
|
+
|
|
9
11
|
## create(incidentId, incidentCommentText)
|
|
10
12
|
|
|
11
13
|
Add a comment to an existing incident.
|
|
@@ -33,6 +35,30 @@ This can return:
|
|
|
33
35
|
- HTTP 200 with the comment object if it was successful.
|
|
34
36
|
- HTTP 404 if the given comment or incident doesn't exist.
|
|
35
37
|
|
|
38
|
+
## getAll(incidentId)
|
|
39
|
+
|
|
40
|
+
Fetch all comments from an incident.
|
|
41
|
+
|
|
42
|
+
| Value | Type | Required | About |
|
|
43
|
+
|-|-|-|-|
|
|
44
|
+
| `incidentId` | Number | true | Specify the ID of the incident. |
|
|
45
|
+
|
|
46
|
+
This can return:
|
|
47
|
+
- HTTP 200 with an array of incident comments if it was successful.
|
|
48
|
+
- HTTP 404 if the given incident doesn't exist.
|
|
49
|
+
|
|
50
|
+
## remove(incidentId, incidentCommentId)
|
|
51
|
+
|
|
52
|
+
Delete a comment from an incident.
|
|
53
|
+
|
|
54
|
+
| Value | Type | Required | About |
|
|
55
|
+
|-|-|-|-|
|
|
56
|
+
| `incidentId` | Number | true | Specify the ID of the incident. |
|
|
57
|
+
| `incidentCommentId` | Number | true | Specify the ID of the incident comment. |
|
|
58
|
+
|
|
59
|
+
This can return:
|
|
60
|
+
- HTTP 204 if it was successful.
|
|
61
|
+
|
|
36
62
|
## update(incidentId, incidentCommentId, incidentCommentText)
|
|
37
63
|
|
|
38
64
|
Edit an existing comment on an incident.
|
|
@@ -6,6 +6,8 @@ This is the point from which all incidents can be managed.
|
|
|
6
6
|
|
|
7
7
|
Status updates can't be managed from here.
|
|
8
8
|
|
|
9
|
+
Methods: `acknowledge`, `create`, `escalate`, `get`, `remove`, `resolve`.
|
|
10
|
+
|
|
9
11
|
## `acknowledge`
|
|
10
12
|
|
|
11
13
|
`acknowledge(incidentId)`
|
|
@@ -17,9 +19,8 @@ Acknowledge an existing incident.
|
|
|
17
19
|
| `incidentId` | Number | true | Specify the ID of the incident. |
|
|
18
20
|
|
|
19
21
|
This can return:
|
|
20
|
-
|
|
21
|
-
- HTTP
|
|
22
|
-
- HTTP 409 if that incident was already acknowledged.
|
|
22
|
+
- If successful: HTTP 200 with the incident data,
|
|
23
|
+
- If already acknowledged: HTTP 409 with the error message.
|
|
23
24
|
|
|
24
25
|
## `create`
|
|
25
26
|
|
|
@@ -41,9 +42,7 @@ Create a new incident. `incidentData` is an object with the following properties
|
|
|
41
42
|
| `policy_id` | String | false | Policy escalation ID with which the incident should be escalated. |
|
|
42
43
|
|
|
43
44
|
This can return:
|
|
44
|
-
|
|
45
|
-
- HTTP 201 if the incident was successfully created,
|
|
46
|
-
- HTTP 404 if the token was not provided.
|
|
45
|
+
- If successful: HTTP 201 and the Incident object containing its data.
|
|
47
46
|
|
|
48
47
|
Most optional options can also be found in the [upstream](https://betterstack.com/docs/uptime/api/create-a-new-incident/) documentation.
|
|
49
48
|
|
|
@@ -72,9 +71,8 @@ Some properties in the `escalationData` value are only required depending on wha
|
|
|
72
71
|
Other properties of this value can be found in the [upstream](https://betterstack.com/docs/uptime/api/escalate-an-ongoing-incident/) documentation, though they're not required.
|
|
73
72
|
|
|
74
73
|
This can return:
|
|
75
|
-
|
|
76
|
-
- HTTP
|
|
77
|
-
- HTTP 409 if the incident was already resolved.
|
|
74
|
+
- If successful: HTTP 200 with the incident data,
|
|
75
|
+
- If already escalated: HTTP 409 with the error message.
|
|
78
76
|
|
|
79
77
|
## `get`
|
|
80
78
|
|
|
@@ -85,8 +83,7 @@ Fetch an existing incident.
|
|
|
85
83
|
| `incidentId` | Number | true | Specify the ID of the incident. |
|
|
86
84
|
|
|
87
85
|
This can return:
|
|
88
|
-
|
|
89
|
-
- HTTP 200 with the incident data as an Object if it was successful.
|
|
86
|
+
- If successful: HTTP 200 with the incident data.
|
|
90
87
|
|
|
91
88
|
## `remove`
|
|
92
89
|
|
|
@@ -99,8 +96,7 @@ Delete an existing incident.
|
|
|
99
96
|
| `incidentId` | Number | true | Specify the ID of the incident. |
|
|
100
97
|
|
|
101
98
|
This can return:
|
|
102
|
-
|
|
103
|
-
- HTTP 204 if it was successful.
|
|
99
|
+
- If successful: HTTP 204 and an empty body.
|
|
104
100
|
|
|
105
101
|
## `resolve`
|
|
106
102
|
|
|
@@ -113,6 +109,27 @@ Resolve and close an existing incident.
|
|
|
113
109
|
| `incidentId` | Number | true | Specify the ID of the incident. |
|
|
114
110
|
|
|
115
111
|
This can return:
|
|
112
|
+
- If successful: HTTP 200 with the incident data.
|
|
113
|
+
- If already resolved: HTTP 409 with the error message.
|
|
114
|
+
|
|
115
|
+
## `search`
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
`search(perPage, page, from, to, monitorId, heartbeatId, resolved, acknowledged, metadata)`
|
|
118
|
+
|
|
119
|
+
> Each value must be set, either as the required corresponding type, as `null` or `undefined`.
|
|
120
|
+
|
|
121
|
+
> This method supports **pagination**!
|
|
122
|
+
|
|
123
|
+
| Value | Type | Required | About |
|
|
124
|
+
|-|-|-|-|
|
|
125
|
+
| `perPage` | Number | true | Number of results to show. Maximum is 250. |
|
|
126
|
+
| `page` | Number | true | Page of results to show. |
|
|
127
|
+
| `from` | String | false | Specify the start date. |
|
|
128
|
+
| `to` | String | false | Specify the end date. |
|
|
129
|
+
| `monitorId` | Number | false | Specify the monitor ID. |
|
|
130
|
+
| `heartbeatId` | Number | false | Specify the heartbeat ID. |
|
|
131
|
+
| `resolved` | Boolean | false | Whether to query only resolved or unresolved incidents. |
|
|
132
|
+
| `acknowledged` | Boolean | false | Whether to query only incidents that are acknowledged or not. |
|
|
133
|
+
|
|
134
|
+
This can return:
|
|
135
|
+
- If successful: HTTP 200 with a list of Incidents objects.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Monitors
|
|
2
|
+
|
|
3
|
+
Class: `client.monitors`
|
|
4
|
+
|
|
5
|
+
This is the point from which all monitors can be managed.
|
|
6
|
+
|
|
7
|
+
Methods: `create`, `edit`, `get`, `getAll`, `getHistory`, `getSLA`, `remove`.
|
|
8
|
+
|
|
9
|
+
## `create`
|
|
10
|
+
|
|
11
|
+
`create(monitorData)`
|
|
12
|
+
|
|
13
|
+
Create a new monitor.
|
|
14
|
+
|
|
15
|
+
> You should refer to [upstream documentation](https://betterstack.com/docs/uptime/api/create-a-new-monitor/) to learn more about this call.
|
|
16
|
+
|
|
17
|
+
| Value | Type | Required | About |
|
|
18
|
+
|-|-|-|-|
|
|
19
|
+
| `monitorData` | Object | true | The monitor data. |
|
|
20
|
+
| `monitorData.team_name` | String | true | The team which owns the monitor. |
|
|
21
|
+
|
|
22
|
+
This can return:
|
|
23
|
+
- If successful: HTTP 201 and the Monitor object containing the data.
|
|
24
|
+
- If it fails: HTTP 422 with the error message.
|
|
25
|
+
|
|
26
|
+
> Once you've created a monitor, you should expect its ID in the `data.id` value as a String.
|
|
27
|
+
|
|
28
|
+
## `edit`
|
|
29
|
+
|
|
30
|
+
`edit(id, monitorData)`
|
|
31
|
+
|
|
32
|
+
Edit an existing monitor.
|
|
33
|
+
|
|
34
|
+
> You should refer to [upstream documentation](https://betterstack.com/docs/uptime/api/update-an-existing-monitor/) to learn more about this call.
|
|
35
|
+
|
|
36
|
+
| Value | Type | Required | About |
|
|
37
|
+
|-|-|-|-|
|
|
38
|
+
| `id` | Number | true | The monitor ID. |
|
|
39
|
+
| `monitorData` | Object | true | The monitor data. |
|
|
40
|
+
|
|
41
|
+
This can return:
|
|
42
|
+
- If successful: HTTP 200 and the Monitor object containing the new data.
|
|
43
|
+
- If it fails: HTTP 422 with the error message.
|
|
44
|
+
|
|
45
|
+
## `get`
|
|
46
|
+
|
|
47
|
+
`get(id)`
|
|
48
|
+
|
|
49
|
+
Get a single monitor.
|
|
50
|
+
|
|
51
|
+
| Value | Type | Required | About |
|
|
52
|
+
|-|-|-|-|
|
|
53
|
+
| `id` | Number | true | The monitor ID. |
|
|
54
|
+
|
|
55
|
+
This can return:
|
|
56
|
+
- If successful: HTTP 200 and the Monitor object containing the data.
|
|
57
|
+
|
|
58
|
+
## `getAll`
|
|
59
|
+
|
|
60
|
+
`getAll(perPage, page, name, url)`
|
|
61
|
+
|
|
62
|
+
Query bulk monitors.
|
|
63
|
+
|
|
64
|
+
| Value | Type | Required | About |
|
|
65
|
+
|-|-|-|-|
|
|
66
|
+
| `perPage` | Number | false | Amount of monitors per page. Default value is 50. |
|
|
67
|
+
| `page` | Number | false | Results page number. Default value is 1. |
|
|
68
|
+
| `name` | String | false | Pronounceable name of monitors. |
|
|
69
|
+
| `url` | String | false | URL of monitors. |
|
|
70
|
+
|
|
71
|
+
> This method supports **pagination**!
|
|
72
|
+
|
|
73
|
+
This can return:
|
|
74
|
+
- If successful: HTTP 200 and a list of Monitors.
|
|
75
|
+
|
|
76
|
+
## `getHistory`
|
|
77
|
+
|
|
78
|
+
`getHistory(monitorId)`
|
|
79
|
+
|
|
80
|
+
Get the response time history of an existing monitor.
|
|
81
|
+
|
|
82
|
+
| Value | Type | Required | About |
|
|
83
|
+
|-|-|-|-|
|
|
84
|
+
| `monitorId` | Number | true | Specify the ID of the monitor. |
|
|
85
|
+
|
|
86
|
+
This can return:
|
|
87
|
+
- If successful: HTTP 200 and a Monitor Response Time History object.
|
|
88
|
+
|
|
89
|
+
## `getSLA`
|
|
90
|
+
|
|
91
|
+
`getSLA(monitorId, from, to)`
|
|
92
|
+
|
|
93
|
+
Get the availability summary of an existing monitor.
|
|
94
|
+
|
|
95
|
+
| Value | Type | Required | About |
|
|
96
|
+
|-|-|-|-|
|
|
97
|
+
| `monitorId` | Number | true | Specify the ID of the monitor. |
|
|
98
|
+
| `from` | String `YYYY-MM-DD` | false | Start date. |
|
|
99
|
+
| `to` | String `YYYY-MM-DD` | false | End date. |
|
|
100
|
+
|
|
101
|
+
This can return:
|
|
102
|
+
- If successful: HTTP 200 and a [Monitor Availability](//codeberg.org/Cyanic76/BSM.js/src/branch/main/docs/objects/Monitor.md#availability) object containing the data.
|
|
103
|
+
|
|
104
|
+
## `remove`
|
|
105
|
+
|
|
106
|
+
`remove(monitorId)`
|
|
107
|
+
|
|
108
|
+
Delete an existing monitor.
|
|
109
|
+
|
|
110
|
+
| Value | Type | Required | About |
|
|
111
|
+
|-|-|-|-|
|
|
112
|
+
| `monitorId` | Number | true | Specify the ID of the monitor. |
|
|
113
|
+
|
|
114
|
+
This can return:
|
|
115
|
+
- If successful: HTTP 204 and an empty body.
|
package/docs/etc/Util.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Utils
|
|
2
|
+
|
|
3
|
+
This group of functions is never exported.
|
|
4
|
+
|
|
5
|
+
Functions: `checkDateFormat`, `validateMonitorData`.
|
|
6
|
+
|
|
7
|
+
## `checkDateFormat(date)`
|
|
8
|
+
|
|
9
|
+
Test a date string against the `YYYY-MM-DD` format.
|
|
10
|
+
|
|
11
|
+
| Value | Type | Required | About |
|
|
12
|
+
|-|-|-|-|
|
|
13
|
+
| `date` | String | true | Date string. |
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
- `true` if the check succeeds.
|
|
17
|
+
- `false` if the check fails.
|
|
18
|
+
|
|
19
|
+
## `validateMonitorData(data)`
|
|
20
|
+
|
|
21
|
+
Check for most values of a Monitor.
|
|
22
|
+
|
|
23
|
+
| Value | Type | Required | About |
|
|
24
|
+
|-|-|-|-|
|
|
25
|
+
| `data` | Object | true | Monitor object. |
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
- `true` if the check succeeds.
|
|
29
|
+
- An Error and its reason if the check fails.
|
|
@@ -17,12 +17,12 @@ The `data` property has many sub-properties, including the following:
|
|
|
17
17
|
|
|
18
18
|
| Property | Type | Description |
|
|
19
19
|
|-|-|-|
|
|
20
|
-
| `id` | String | The ID of the incident comment. |
|
|
21
|
-
| `comment` | String | The comment. |
|
|
22
|
-
| `user_id` | Number | The ID of the author. |
|
|
23
|
-
| `user_email` | String | The email address of the author. |
|
|
24
|
-
| `created_at` | String | The ISO-formatted timestamp at which the incident comment was created. |
|
|
25
|
-
| `updated_at` | String | The ISO-formatted timestamp at which the incident comment was last edited. |
|
|
20
|
+
| `attributes.id` | String | The ID of the incident comment. |
|
|
21
|
+
| `attributes.comment` | String | The comment. |
|
|
22
|
+
| `attributes.user_id` | Number | The ID of the author. |
|
|
23
|
+
| `attributes.user_email` | String | The email address of the author. |
|
|
24
|
+
| `attributes.created_at` | String | The ISO-formatted timestamp at which the incident comment was created. |
|
|
25
|
+
| `attributes.updated_at` | String | The ISO-formatted timestamp at which the incident comment was last edited. |
|
|
26
26
|
|
|
27
27
|
## Example
|
|
28
28
|
|
package/docs/objects/Monitor.md
CHANGED
|
@@ -5,3 +5,133 @@ A Monitor object has the following properties.
|
|
|
5
5
|
> The namespace is `data`.
|
|
6
6
|
|
|
7
7
|
Get the attributes on the [upstream documentation](https://betterstack.com/docs/uptime/api/monitors-api-response-params/).
|
|
8
|
+
|
|
9
|
+
## List
|
|
10
|
+
|
|
11
|
+
An Array of monitors.
|
|
12
|
+
|
|
13
|
+
You should refer to the [upstream documentation](https://betterstack.com/docs/uptime/api/list-all-existing-monitors/).
|
|
14
|
+
|
|
15
|
+
## Availability
|
|
16
|
+
|
|
17
|
+
### attributes
|
|
18
|
+
|
|
19
|
+
The following depend whether you're looking for data since the monitor was created or for data within a given date range.
|
|
20
|
+
|
|
21
|
+
| Property | Type | Description |
|
|
22
|
+
|-|-|-|
|
|
23
|
+
| `attributes.availability` | Number | Percentage of uptime. |
|
|
24
|
+
| `attributes.total_downtime` | Number | Number of seconds of downtime. |
|
|
25
|
+
| `attributes.number_of_incidents` | Number | Number of incidents. |
|
|
26
|
+
| `attributes.longest_incident` | Number | Duration of the longest incident in seconds. |
|
|
27
|
+
| `attributes.average_incident` | Number | Duration of the average incident in seconds. |
|
|
28
|
+
|
|
29
|
+
### Example
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"data": {
|
|
34
|
+
"id": "1",
|
|
35
|
+
"type": "monitor_sla",
|
|
36
|
+
"attributes": {
|
|
37
|
+
"availability": 99.98,
|
|
38
|
+
"total_downtime": 600, // => 10 min
|
|
39
|
+
"number_of_incidents": 3,
|
|
40
|
+
"longest_incident": 300, // => 5 min
|
|
41
|
+
"average_incident": 200, // => 3 min 20 seconds
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Response Time
|
|
48
|
+
|
|
49
|
+
### attributes
|
|
50
|
+
|
|
51
|
+
| Property | Type | Description |
|
|
52
|
+
|-|-|-|
|
|
53
|
+
| `id` | String | Monitor ID. |
|
|
54
|
+
| `type` | String | "monitor_response_times". |
|
|
55
|
+
| `attributes.regions` | Array | List of times by regions. |
|
|
56
|
+
| `attributes.regions.region` | String | Region. |
|
|
57
|
+
| `attributes.regions.response_times` | Array | List of times. |
|
|
58
|
+
| `attributes.regions.response_times[item]` | Object | Response data. |
|
|
59
|
+
| `attributes.regions.response_times[item].at` | String | Timestamp of the response. |
|
|
60
|
+
| `attributes.regions.response_times[item].response_time` | Number | Time of the response in seconds. |
|
|
61
|
+
| `attributes.regions.response_times[item].name_lookup_time` | Number | Time of the DNS lookup in seconds. |
|
|
62
|
+
| `attributes.regions.response_times[item].connection_time` | Number | Time of the connection in seconds. |
|
|
63
|
+
| `attributes.regions.response_times[item].tls_handshake_time` | Number | Time of the TLS handshake in seconds. |
|
|
64
|
+
| `attributes.regions.response_times[item].data_transfer_time` | Number | Time of the data transfer in seconds. |
|
|
65
|
+
|
|
66
|
+
### Example
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"data": {
|
|
71
|
+
"id": "270985",
|
|
72
|
+
"type": "monitor_response_times",
|
|
73
|
+
"attributes": {
|
|
74
|
+
"regions": [
|
|
75
|
+
{
|
|
76
|
+
"region": "us",
|
|
77
|
+
"response_times": [
|
|
78
|
+
{
|
|
79
|
+
"at": "2025-04-03T11:00:57.000Z",
|
|
80
|
+
"response_time": 0.47273,
|
|
81
|
+
"name_lookup_time": 0.00002,
|
|
82
|
+
"connection_time": 0.14187,
|
|
83
|
+
"tls_handshake_time": 0.19929,
|
|
84
|
+
"data_transfer_time": 0.13154
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"at": "2025-04-03T11:01:27.000Z",
|
|
88
|
+
"response_time": 0.41211,
|
|
89
|
+
"name_lookup_time": 0.00002,
|
|
90
|
+
"connection_time": 0.13058,
|
|
91
|
+
"tls_handshake_time": 0.17109,
|
|
92
|
+
"data_transfer_time": 0.11042
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"at": "2025-04-03T11:04:27.000Z",
|
|
96
|
+
"response_time": 0.41943,
|
|
97
|
+
"name_lookup_time": 0.00002,
|
|
98
|
+
"connection_time": 0.10908,
|
|
99
|
+
"tls_handshake_time": 0.19844,
|
|
100
|
+
"data_transfer_time": 0.11188
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"region": "eu",
|
|
106
|
+
"response_times": [
|
|
107
|
+
{
|
|
108
|
+
"at": "2025-04-03T11:13:27.000Z",
|
|
109
|
+
"response_time": 0.60383,
|
|
110
|
+
"name_lookup_time": 0.00002,
|
|
111
|
+
"connection_time": 0.15449,
|
|
112
|
+
"tls_handshake_time": 0.31218,
|
|
113
|
+
"data_transfer_time": 0.13714
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"at": "2025-04-03T11:13:57.000Z",
|
|
117
|
+
"response_time": 0.36093,
|
|
118
|
+
"name_lookup_time": 0.00002,
|
|
119
|
+
"connection_time": 0.12147,
|
|
120
|
+
"tls_handshake_time": 0.12925,
|
|
121
|
+
"data_transfer_time": 0.11019
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"at": "2025-04-03T11:17:27.000Z",
|
|
125
|
+
"response_time": 0.34252,
|
|
126
|
+
"name_lookup_time": 0.00002,
|
|
127
|
+
"connection_time": 0.10989,
|
|
128
|
+
"tls_handshake_time": 0.1224,
|
|
129
|
+
"data_transfer_time": 0.11021
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
package/docs/readme.md
CHANGED
|
@@ -4,7 +4,19 @@ Manage your Better Stack incidents & more using the API with this library.
|
|
|
4
4
|
|
|
5
5
|
You're in the **user-facing documentation**.
|
|
6
6
|
|
|
7
|
+
## Directories
|
|
8
|
+
|
|
9
|
+
- `classes/`
|
|
10
|
+
- `etc/`
|
|
11
|
+
- `objects/`
|
|
12
|
+
- `upstream/`
|
|
13
|
+
|
|
7
14
|
## Links
|
|
8
15
|
|
|
9
|
-
- [
|
|
10
|
-
- [
|
|
16
|
+
- [Documentation](https://codeberg.org/Cyanic76/BSM.js/src/branch/main/docs)
|
|
17
|
+
- [Source Code](https://codeberg.org/Cyanic76/BSM.js/)
|
|
18
|
+
- [Discord server](https://cyanic.me/discord)
|
|
19
|
+
|
|
20
|
+
Get the package on
|
|
21
|
+
[Codeberg](https://codeberg.org/Cyanic76/-/packages/npm/betterstackmanager/) or on
|
|
22
|
+
[NPM](https://www.npmjs.com/package/betterstackmanager).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Pagination
|
|
2
|
+
|
|
3
|
+
When getting a result from an method that support pagination, you may check the following properties.
|
|
4
|
+
|
|
5
|
+
| Property | Type | Description |
|
|
6
|
+
|-|-|-|
|
|
7
|
+
| `pagination.first` | String | URL to the first page of results. |
|
|
8
|
+
| `pagination.last` | String | URL to the last page of results. |
|
|
9
|
+
| `pagination.prev` | String/null | URL to the previous page of results. If you're on the first page, you'll get `null`. |
|
|
10
|
+
| `pagination.next` | String/null | URL to the next page of results. If you're on the last page, you'll get `null`. |
|
|
11
|
+
|
|
12
|
+
You may as well refer to the [upstream documentation](https://betterstack.com/docs/uptime/api/pagination).
|
package/examples/readme.md
CHANGED
|
@@ -32,5 +32,10 @@ This example resolves an existing incident with the given ID.
|
|
|
32
32
|
|
|
33
33
|
## Links
|
|
34
34
|
|
|
35
|
-
- [
|
|
36
|
-
- [
|
|
35
|
+
- [Documentation](https://codeberg.org/Cyanic76/BSM.js/src/branch/main/docs)
|
|
36
|
+
- [Source Code](https://codeberg.org/Cyanic76/BSM.js/)
|
|
37
|
+
- [Discord server](https://cyanic.me/discord)
|
|
38
|
+
|
|
39
|
+
Get the package on
|
|
40
|
+
[Codeberg](https://codeberg.org/Cyanic76/-/packages/npm/betterstackmanager/) or on
|
|
41
|
+
[NPM](https://www.npmjs.com/package/betterstackmanager).
|
package/package.json
CHANGED
package/src/client/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const axios = require('axios');
|
|
|
2
2
|
|
|
3
3
|
const Incidents = require('../etc/Incident');
|
|
4
4
|
const IncidentComments = require('../etc/IncidentComment');
|
|
5
|
+
const Monitors = require('../etc/Monitor');
|
|
5
6
|
|
|
6
7
|
const { handleError } = require('../errors/Error');
|
|
7
8
|
|
|
@@ -21,6 +22,7 @@ class Client {
|
|
|
21
22
|
// Get the right classes as found in the folder.
|
|
22
23
|
this.incidents = new Incidents(this);
|
|
23
24
|
this.incidentComments = new IncidentComments(this);
|
|
25
|
+
this.monitors = new Monitors(this);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
async delete (endpoint) {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function used to validate date formatting.
|
|
3
|
+
* @param {String} date
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
function checkDateFormat(date) {
|
|
7
|
+
const dateRegex = new RegExp(/^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/);
|
|
8
|
+
return date.match(dateRegex);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Function used to validate monitor data.
|
|
13
|
+
* @param {Object} data
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function validateMonitorData(data) {
|
|
17
|
+
|
|
18
|
+
// Validate common properties first
|
|
19
|
+
if(data.monitor_type && typeof(data.monitor_type) != "string") throw new Error("monitor_type must be a String.");
|
|
20
|
+
if(data.url && typeof(data.url) != "string") throw new Error("monitor_url must be a String.");
|
|
21
|
+
if(data.pronounceable_name && typeof(data.pronounceable_name) != "string") throw new Error("pronounceable_name must be a String.");
|
|
22
|
+
if(data.email && typeof(data.email) != "boolean") throw new Error("email must be a Boolean.");
|
|
23
|
+
if(data.sms && typeof(data.sms) != "boolean") throw new Error("sms must be a Boolean.");
|
|
24
|
+
if(data.call && typeof(data.call) != "boolean") throw new Error("call must be a Boolean.");
|
|
25
|
+
if(data.critical_alert && typeof(data.critical_alert) != "boolean") throw new Error("critical_alert must be a Boolean.");
|
|
26
|
+
if(data.check_frequency && isNaN(data.check_frequency)) throw new Error("check_frequency must be a Number.");
|
|
27
|
+
if(data.domain_expiration && isNaN(data.domain_expiration)) throw new Error("domain_expiration must be a Number.");
|
|
28
|
+
if(data.ssl_expiration && isNaN(data.ssl_expiration)) throw new Error("ssl_expiration must be a Number.");
|
|
29
|
+
if(data.expiration_policy_id && isNaN(data.expiration_policy_id)) throw new Error("expiration_policy_id must be a Number.");
|
|
30
|
+
if(data.follow_redirects && typeof(data.follow_redirects) != "boolean") throw new Error("follow_redirects must be a Boolean.");
|
|
31
|
+
if(data.team_wait && isNaN(data.team_wait)) throw new Error("team_wait must be a Number.");
|
|
32
|
+
if(data.paused && typeof(data.paused) != "boolean") throw new Error("paused must be a Boolean.");
|
|
33
|
+
if(data.recovery_period && isNaN(data.recovery_period)) throw new Error("recovery_period must be a Number.");
|
|
34
|
+
if(data.verify_ssl && typeof(data.verify_ssl) != "boolean") throw new Error("verify_ssl must be a Boolean.");
|
|
35
|
+
if(data.confirmation_period && isNaN(data.confirmation_period)) throw new Error("confirmation_period must be a Number.");
|
|
36
|
+
if(data.request_timeout && isNaN(data.request_timeout)) throw new Error("request_timeout must be a Number.");
|
|
37
|
+
if(data.remember_cookies && typeof(data.remember_cookies) != "boolean") throw new Error("remember_cookies must be a Boolean.");
|
|
38
|
+
|
|
39
|
+
// Validate HTTP method
|
|
40
|
+
if(data.http_method){
|
|
41
|
+
const allowedMethods = ["GET", "HEAD", "PATCH", "POST", "PUT"];
|
|
42
|
+
if(!allowedMethods.includes(data.http_method)) throw new Error("http_method must be GET, HEAD, PATCH, POST or PUT (case-sensitive).");
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Validate headers
|
|
46
|
+
if(data.request_headers && typeof(data.request_headers) != "object") throw new Error("request_headers must be an Array of Object.");
|
|
47
|
+
|
|
48
|
+
// Validate status codes
|
|
49
|
+
if(data.expected_status_codes){
|
|
50
|
+
if(typeof(data.expected_status_codes) != "object") throw new Error("expected_status_codes must be an Array of Numbers.");
|
|
51
|
+
data.expected_status_codes.forEach(i => {
|
|
52
|
+
if(isNaN(i)) throw new Error(`expected_status_codes: All values must be Numbers. ${i} is not a Number.`);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Here, we send "true" in any case. Or else, we'd get errors.
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
checkDateFormat,
|
|
62
|
+
validateMonitorData
|
|
63
|
+
};
|
package/src/etc/Incident.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const util = require('../client/utils');
|
|
2
|
+
|
|
1
3
|
class Incidents {
|
|
2
4
|
/**
|
|
3
5
|
* @param {string} token
|
|
@@ -68,6 +70,52 @@ class Incidents {
|
|
|
68
70
|
}
|
|
69
71
|
};
|
|
70
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Query bulk incidents.
|
|
75
|
+
* @param {Number} perPage
|
|
76
|
+
* @param {Number} page
|
|
77
|
+
* @param {String} from
|
|
78
|
+
* @param {String} to
|
|
79
|
+
* @param {Number} monitorId
|
|
80
|
+
* @param {Number} heartbeatId
|
|
81
|
+
* @param {Boolean} resolved
|
|
82
|
+
* @param {Boolean} acknowledged
|
|
83
|
+
* @param {Object} metadata
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
async search(perPage, page, from, to, monitorId, heartbeatId, resolved, acknowledged, metadata) {
|
|
87
|
+
|
|
88
|
+
// Test both timestamps against the YYYY-MM-DD format.
|
|
89
|
+
if(from != null && from != undefined && !util.checkDateFormat(from) ||
|
|
90
|
+
to != null && to != undefined && !util.checkDateFormat(to)) throw new Error("Incident search: Both timestamps must be formatted as YYYY-MM-DD.");
|
|
91
|
+
|
|
92
|
+
// Both following values are only boolean values.
|
|
93
|
+
if(monitorId != null && monitorId != undefined && isNaN(monitorId)) throw new Error("Incident search: Monitor ID must be a number.");
|
|
94
|
+
if(heartbeatId != null && heartbeatId != undefined && heartbeatId(monitorId)) throw new Error("Incident search: Monitor ID must be a number.");
|
|
95
|
+
|
|
96
|
+
// Both following values are only numbers.
|
|
97
|
+
if(perPage != null && perPage != undefined && isNaN(perPage) || page != null && page != null && isNaN(page)) throw new Error("Incident search: Page number and results must both be numbers.");
|
|
98
|
+
if(perPage != null && perPage != undefined && perPage < 1 || perPage != null && perPage != undefined && perPage > 250) throw new Error("Incident search: Can only get between 1 and 250 results.");
|
|
99
|
+
if(page != null && page != undefined && perPage < 1) throw new Error("Incident search: Page number must be a number.");
|
|
100
|
+
|
|
101
|
+
// Build our query with the params by only passing provided params.
|
|
102
|
+
const query = new URLSearchParams();
|
|
103
|
+
if(from != null && from != undefined) query.append('from', from);
|
|
104
|
+
if(to != null && to != undefined) query.append('to', to);
|
|
105
|
+
if(monitorId != null && monitorId != undefined) query.append('monitor_id', monitorId);
|
|
106
|
+
if(heartbeatId != null && heartbeatId != undefined) query.append('heartbeat_id', heartbeatId);
|
|
107
|
+
if(resolved == false || resolved == true) query.append('resolved', resolved);
|
|
108
|
+
if(acknowledged == false || acknowledged == true) query.append('acknowledged', acknowledged);
|
|
109
|
+
if(metadata != null && metadata != undefined) query.append('metadata', metadata);
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
return await this.client.get(`/v3/incidents/?${query}`);
|
|
113
|
+
} catch(error) {
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
71
119
|
/**
|
|
72
120
|
* Resolve an existing incident.
|
|
73
121
|
* @param {Number} incidentId
|
|
@@ -134,7 +182,7 @@ class Incidents {
|
|
|
134
182
|
if(isNaN(incidentId)) throw new Error("Incident acknowledgement: incidentId is not a Number.");
|
|
135
183
|
|
|
136
184
|
try {
|
|
137
|
-
return await this.client.
|
|
185
|
+
return await this.client.delete(`/v3/incidents/${incidentId}`);
|
|
138
186
|
} catch(error) {
|
|
139
187
|
throw error;
|
|
140
188
|
}
|
|
@@ -16,7 +16,7 @@ class IncidentComments {
|
|
|
16
16
|
async create(incidentId, incidentCommentText) {
|
|
17
17
|
|
|
18
18
|
if(!incidentId || !incidentCommentText) throw new Error("Incident comment creation: incidentId and incidentCommentText are required options.");
|
|
19
|
-
if(isNaN(incidentId)) throw new Error("Incident comment creation: incidentId must be a Number.");
|
|
19
|
+
if(isNaN(incidentId) || incidentId < 1) throw new Error("Incident comment creation: incidentId must be a Number greater than 0.");
|
|
20
20
|
|
|
21
21
|
try {
|
|
22
22
|
return await this.client.post(`/v2/incidents/${incidentId}/comments`, {
|
|
@@ -35,8 +35,9 @@ class IncidentComments {
|
|
|
35
35
|
*/
|
|
36
36
|
async get(incidentId, incidentCommentId) {
|
|
37
37
|
|
|
38
|
-
if(!incidentId || !incidentCommentId) throw new Error("Incident comment fetch: incidentId
|
|
38
|
+
if(!incidentId || !incidentCommentId) throw new Error("Incident comment fetch: incidentId and incidentCommentId are required options.");
|
|
39
39
|
if(isNaN(incidentId) || isNaN(incidentCommentId)) throw new Error("Incident comment fetch: incidentId and incidentCommentId must both be Numbers.");
|
|
40
|
+
if(incidentId < 1 || incidentCommentId < 1) throw new Error("Incident comment fetch: incidentId and incidentCommentId must be greater than 0.");
|
|
40
41
|
|
|
41
42
|
try {
|
|
42
43
|
return await this.client.get(`/v2/incidents/${incidentId}/comments/${incidentCommentId}`);
|
|
@@ -46,6 +47,37 @@ class IncidentComments {
|
|
|
46
47
|
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Get all comments on an incident.
|
|
52
|
+
* @param {Number} incidentId
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
async getAll(incidentId) {
|
|
56
|
+
|
|
57
|
+
if(!incidentId) throw new Error("Incident comment fetch: incidentId is a required options.");
|
|
58
|
+
if(isNaN(incidentId) || incidentId < 1) throw new Error("Incident comment fetch: incidentId must be a Number greater than 0.");
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
return await this.client.get(`/v2/incidents/${incidentId}/comments`);
|
|
62
|
+
} catch(error) {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async remove(incidentId, incidentCommentId) {
|
|
69
|
+
|
|
70
|
+
if(!incidentId || !incidentCommentId || incidentId && isNaN(incidentId) || incidentCommentId && isNaN(incidentCommentId)) throw new Error("Incident comment removal: incidentId and incidentCommentId must be Numbers.");
|
|
71
|
+
if(incidentId < 1 || incidentCommentId < 1) throw new Error("Incident comment removal: incidentId and incidentCommentId must be greater than 0.");
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
return await this.client.delete(`/v2/incidents/${incidentId}/comments/${incidentCommentId}`);
|
|
75
|
+
} catch(error) {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
49
81
|
/**
|
|
50
82
|
* Edit an existing incident comment.
|
|
51
83
|
* @param {Number} incidentId
|
|
@@ -57,6 +89,7 @@ class IncidentComments {
|
|
|
57
89
|
|
|
58
90
|
if(!incidentId || !incidentCommentId || !incidentCommentText ) throw new Error("Incident comment update: incidentId, incidentCommentId, incidentCommentText are required options.");
|
|
59
91
|
if(isNaN(incidentId) || isNaN(incidentCommentId)) throw new Error("Incident comment update: incidentId and incidentCommentId must both be Numbers.");
|
|
92
|
+
if(incidentId < 1 || incidentCommentId < 1) throw new Error("Incident comment update: incidentId and incidentCommentId must be greater than 0.");
|
|
60
93
|
|
|
61
94
|
try {
|
|
62
95
|
return await this.client.patch(`/v2/incidents/${incidentId}/comments/${incidentCommentId}`, {
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
const util = require('../client/utils');
|
|
2
|
+
|
|
3
|
+
class Monitor {
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} token
|
|
6
|
+
* @param {string} baseURL
|
|
7
|
+
*/
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a monitor.
|
|
14
|
+
* @param {String} teamName
|
|
15
|
+
* @param {Object} monitorData
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
async create(monitorData) {
|
|
19
|
+
if(!monitorData) throw new Error("Monitor creation: data must be passed as an Object.");
|
|
20
|
+
if(!monitorData.team_name) throw new Error("Monitor creation: data.team_name must be passed as a String.");
|
|
21
|
+
|
|
22
|
+
// Validate our new monitor first.
|
|
23
|
+
try {
|
|
24
|
+
util.validateMonitorData(monitorData);
|
|
25
|
+
} catch(error) {
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
return await this.client.post('/v2/monitors/', monitorData);
|
|
31
|
+
} catch(error) {
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async edit(id, monitorData) {
|
|
37
|
+
if(!id || id && isNaN(id)) throw new Error("Monitor update: id must be a Number.");
|
|
38
|
+
if(id < 0) throw new Error("Monitor update: id must be greater than 0.");
|
|
39
|
+
|
|
40
|
+
// Validate our new monitor first.
|
|
41
|
+
try {
|
|
42
|
+
util.validateMonitorData(monitorData);
|
|
43
|
+
} catch(error) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
return await this.client.patch(`/v2/monitors/${id}`, monitorData);
|
|
49
|
+
} catch(error) {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get a monitor.
|
|
56
|
+
* @param {Number} id
|
|
57
|
+
*/
|
|
58
|
+
async get(id) {
|
|
59
|
+
if(!id || id && isNaN(id)) throw new Error("Monitor: id must be a Number.");
|
|
60
|
+
if(id < 0) throw new Error("Monitor: id must be greater than 0.")
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
return await this.client.get(`/v2/monitors/${id}`);
|
|
64
|
+
} catch(error) {
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get all the monitors.
|
|
71
|
+
* @param {Number} perPage
|
|
72
|
+
* @param {Number} page
|
|
73
|
+
* @param {String} name
|
|
74
|
+
* @param {String} url
|
|
75
|
+
*/
|
|
76
|
+
async getAll(perPage, page, name, url){
|
|
77
|
+
if(page && isNaN(page) || page && !isNaN(page) && page < 1) throw new Error("Monitor List: pageId must be a number greater than or equal to 0.");
|
|
78
|
+
if(perPage && isNaN(perPage) || perPage && perPage > 250 || perPage && perPage < 1) throw new Error("Monitor List: perPage must be a number between 1 and 250.");
|
|
79
|
+
|
|
80
|
+
let endpoint = '/v2/monitors?';
|
|
81
|
+
|
|
82
|
+
// Build query from passed parameters
|
|
83
|
+
let parameters = {
|
|
84
|
+
"perPage": perPage ? perPage : 50,
|
|
85
|
+
"page": page ? page : 1,
|
|
86
|
+
"name": name ? name : null,
|
|
87
|
+
"url": url ? url : null
|
|
88
|
+
}
|
|
89
|
+
for (let key in parameters) {
|
|
90
|
+
let value = parameters[key];
|
|
91
|
+
if(value != null) endpoint += `${key}=${value}&`;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
return await this.client.get(endpoint);
|
|
96
|
+
} catch(error) {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async getResponseHistory(monitorId) {
|
|
102
|
+
if(!monitorId || monitorId && isNaN(monitorId)) throw new Error("Monitor History: monitorId must be a Number.");
|
|
103
|
+
if(monitorId < 0) throw new Error("Monitor History: monitorId must be greater than 0.")
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
return await this.client.get(`/v2/monitors/${monitorId}/response-times`);
|
|
107
|
+
} catch(error) {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get the availability summary of the monitor.
|
|
114
|
+
* @param {Number} monitorId
|
|
115
|
+
* @param {String} from
|
|
116
|
+
* @param {String} to
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
119
|
+
async getSLA(monitorId, from, to){
|
|
120
|
+
if(!monitorId || monitorId && isNaN(monitorId)) throw new Error("Monitor SLA: monitorId must be a Number.");
|
|
121
|
+
if(monitorId < 0) throw new Error("Monitor SLA: monitorId must be greater than 0.")
|
|
122
|
+
|
|
123
|
+
if(!util.checkDateFormat(from) || !util.checkDateFormat(to)) throw new Error("Monitor SLA: Bad date format.");
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
return await this.client.get(`/v2/monitors/${monitorId}/sla`, {
|
|
127
|
+
from: from,
|
|
128
|
+
to: to
|
|
129
|
+
});
|
|
130
|
+
} catch(error) {
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Delete an existing monitor.
|
|
137
|
+
* @param {Number} monitorId
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
async remove(monitorId) {
|
|
141
|
+
if(!monitorId || monitorId && isNaN(monitorId)) throw new Error("Monitor deletion: monitorId must be a Number.");
|
|
142
|
+
if(monitorId < 0) throw new Error("Monitor deletion: monitorId must be greater than 0.");
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
return await this.client.delete(`/v3/monitors/${monitorId}`);
|
|
146
|
+
} catch(error) {
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = { Monitor };
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
const { Client } = require('./client');
|
|
2
2
|
const { Incidents } = require('./etc/Incident');
|
|
3
|
+
const { IncidentComments } = require('./etc/IncidentComment');
|
|
4
|
+
const { Monitor } = require('./etc/Monitor');
|
|
3
5
|
|
|
4
6
|
module.exports = {
|
|
5
7
|
Client,
|
|
6
8
|
|
|
7
9
|
Incidents,
|
|
10
|
+
IncidentComments,
|
|
11
|
+
|
|
12
|
+
Monitor
|
|
8
13
|
};
|