You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

598 lines
15 KiB

  1. # API Reference
  2. SITE_NAME REST API supports listing, creating, updating, pausing and deleting
  3. checks in user's account.
  4. ## API Endpoints
  5. Endpoint Name | Endpoint Address
  6. ------------------------------------------------------|-------
  7. [Get a list of existing checks](#list-checks) | `GET SITE_ROOT/api/v1/checks/`
  8. [Create a new check](#create-check) | `POST SITE_ROOT/api/v1/checks/`
  9. [Update an existing check](#update-check) | `POST SITE_ROOT/api/v1/checks/<uuid>`
  10. [Pause monitoring of a check](#pause-check) | `POST SITE_ROOT/api/v1/checks/<uuid>/pause`
  11. [Delete check](#delete-check) | `DELETE SITE_ROOT/api/v1/checks/<uuid>`
  12. [Get a list of existing integrations](#list-channels) | `GET SITE_ROOT/api/v1/channels/`
  13. ## Authentication
  14. Your requests to SITE_NAME REST API must authenticate using an
  15. API key. Each project in your SITE_NAME account has separate API keys.
  16. There are no account-wide API keys. By default, a project on SITE_NAME doesn't have
  17. an API key. You can create read-write and read-only API keys in the
  18. **Project Settings** page.
  19. Key Type | Description
  20. -------------------|------------
  21. Regular API key | Have full access to all documented API endpoints.
  22. Read-only API key | Only work with the [Get a list of existing checks](#list-checks) endpoint. Some fields are omitted from the API responses.
  23. The client can authenticate itself by sending an appropriate HTTP
  24. request header. The header's name should be `X-Api-Key` and
  25. its value should be your API key.
  26. Alternatively, for POST requests with a JSON request body,
  27. the client can include an `api_key` field in the JSON document.
  28. See below the "Create a check" section for an example.
  29. ## API Requests
  30. For POST requests, the SITE_NAME API expects request body to be
  31. a JSON document (*not* a `multipart/form-data` encoded form data).
  32. ## API Responses
  33. SITE_NAME uses HTTP status codes wherever possible.
  34. In general, 2xx class indicates success, 4xx indicates an client error,
  35. and 5xx indicates a server error.
  36. The response may contain a JSON document with additional data.
  37. ## Get a List of Existing Checks {: #list-checks .rule }
  38. `GET SITE_ROOT/api/v1/checks/`
  39. Returns a list of checks belonging to the user, optionally filtered by
  40. one or more tags.
  41. ### Query String Parameters
  42. tag=&lt;value&gt;
  43. : Filters the checks, and returns only the checks that are tagged with the
  44. specified value.
  45. This parameter can be repeated multiple times.
  46. Example:
  47. `SITE_ROOT/api/v1/checks/?tag=foo&tag=bar`
  48. ### Response Codes
  49. 200 OK
  50. : The request succeeded.
  51. 401 Unauthorized
  52. : The API key is either missing or invalid.
  53. ### Example Request
  54. ```bash
  55. curl --header "X-Api-Key: your-api-key" SITE_ROOT/api/v1/checks/
  56. ```
  57. ### Example Response
  58. ```json
  59. {
  60. "checks": [
  61. {
  62. "channels": "4ec5a071-2d08-4baa-898a-eb4eb3cd6941,746a083e-f542-4554-be1a-707ce16d3acc",
  63. "desc": "Longer free-form description goes here",
  64. "grace": 900,
  65. "last_ping": "2017-01-04T13:24:39.903464+00:00",
  66. "n_pings": 1,
  67. "name": "Api test 1",
  68. "next_ping": "2017-01-04T14:24:39.903464+00:00",
  69. "pause_url": "SITE_ROOT/api/v1/checks/662ebe36-ecab-48db-afe3-e20029cb71e6/pause",
  70. "ping_url": "PING_ENDPOINT662ebe36-ecab-48db-afe3-e20029cb71e6",
  71. "status": "up",
  72. "tags": "foo",
  73. "timeout": 3600,
  74. "update_url": "SITE_ROOT/api/v1/checks/662ebe36-ecab-48db-afe3-e20029cb71e6"
  75. },
  76. {
  77. "channels": "",
  78. "desc": "",
  79. "grace": 3600,
  80. "last_ping": null,
  81. "n_pings": 0,
  82. "name": "Api test 2",
  83. "next_ping": null,
  84. "pause_url": "SITE_ROOT/api/v1/checks/9d17c61f-5c4f-4cab-b517-11e6b2679ced/pause",
  85. "ping_url": "PING_ENDPOINT9d17c61f-5c4f-4cab-b517-11e6b2679ced",
  86. "schedule": "0/10 * * * *",
  87. "status": "new",
  88. "tags": "bar baz",
  89. "tz": "UTC",
  90. "update_url": "SITE_ROOT/api/v1/checks/9d17c61f-5c4f-4cab-b517-11e6b2679ced"
  91. }
  92. ]
  93. }
  94. ```
  95. When using the read-only API key, the following fields are omitted:
  96. `ping_url`, `update_url`, `pause_url`, `channels`. An extra `unique_key` field
  97. is added. This identifier is stable across API calls. Example:
  98. ```json
  99. {
  100. "checks": [
  101. {
  102. "desc": "Longer free-form description goes here",
  103. "grace": 900,
  104. "last_ping": "2017-01-04T13:24:39.903464+00:00",
  105. "n_pings": 1,
  106. "name": "Api test 1",
  107. "status": "up",
  108. "tags": "foo",
  109. "timeout": 3600,
  110. "unique_key": "2872190d95224bad120f41d3c06aab94b8175bb6"
  111. },
  112. {
  113. "desc": "",
  114. "grace": 3600,
  115. "last_ping": null,
  116. "n_pings": 0,
  117. "name": "Api test 2",
  118. "next_ping": null,
  119. "schedule": "0/10 * * * *",
  120. "status": "new",
  121. "tags": "bar baz",
  122. "tz": "UTC",
  123. "unique_key": "9b5fc29129560ff2c5c1803803a7415e4f80cf7e"
  124. }
  125. ]
  126. }
  127. ```
  128. ## Create a Check {: #create-check .rule }
  129. `POST SITE_ROOT/api/v1/checks/`
  130. Creates a new check and returns its ping URL.
  131. All request parameters are optional and will use their default
  132. values if omitted.
  133. This API call can be used to create both "simple" and "cron" checks.
  134. To create a "simple" check, specify the "timeout" parameter.
  135. To create a "cron" check, specify the "schedule" and "tz" parameters.
  136. ### Request Parameters
  137. name
  138. : string, optional, default value: ""
  139. Name for the new check.
  140. tags
  141. : string, optional, default value: ""
  142. A space-delimited list of tags for the new check.
  143. Example:
  144. <pre>{"tags": "reports staging"}</pre>
  145. desc
  146. : string, optional.
  147. Description for the check.
  148. timeout
  149. : number, optional, default value: {{ default_timeout }}.
  150. A number of seconds, the expected period of this check.
  151. Minimum: 60 (one minute), maximum: 2592000 (30 days).
  152. Example for 5 minute timeout:
  153. <pre>{"kind": "simple", "timeout": 300}</pre>
  154. grace
  155. : number, optional, default value: {{ default_grace }}.
  156. A number of seconds, the grace period for this check.
  157. Minimum: 60 (one minute), maximum: 2592000 (30 days).
  158. schedule
  159. : string, optional, default value: "* * * * *".
  160. A cron expression defining this check's schedule.
  161. If you specify both "timeout" and "schedule" parameters, "timeout" will be
  162. ignored and "schedule" will be used.
  163. Example for a check running every half-hour:
  164. <pre>{"schedule": "0,30 * * * *"}</pre>
  165. tz
  166. : string, optional, default value: "UTC".
  167. Server's timezone. This setting only has effect in combination with the
  168. "schedule" paremeter.
  169. Example:
  170. <pre>{"tz": "Europe/Riga"}</pre>
  171. channels
  172. : string, optional
  173. By default, if a check is created through API, no notification channels
  174. (integrations) are assigned to it. So, when the check goes up or down, no
  175. notifications will get sent.
  176. Set this field to a special value "*" to automatically assign all existing
  177. integrations.
  178. To assign specific integrations, use a comma-separated list of integration
  179. identifiers. Use the [Get a List of Existing Integrations](#list-channels) call to
  180. look up integration identifiers.
  181. unique
  182. : array of string values, optional, default value: [].
  183. Before creating a check, look for existing checks, filtered by fields listed
  184. in `unique`. If a matching check is found, return it with HTTP status code 200.
  185. If no matching check is found, proceed as normal: create a check and return it
  186. with HTTP status code 201.
  187. The accepted values are: `name`, `tags`, `timeout` and `grace`.
  188. Example:
  189. <pre>{"name": "Backups", unique: ["name"]}</pre>
  190. In this example, if a check named "Backups" exists, it will be returned.
  191. Otherwise, a new check will be created and returned.
  192. ### Response Codes
  193. 201 Created
  194. : The check was successfully created.
  195. 200 OK
  196. : The `unique` parameter was used and an existing check was matched.
  197. 400 Bad Request
  198. : The request is not well-formed, violates schema, or uses invalid
  199. field values.
  200. 401 Unauthorized
  201. : The API key is either missing or invalid.
  202. 403 Forbidden
  203. : The account's check limit has been reached. For free accounts,
  204. the limit is 20 checks per account.
  205. ### Example Request
  206. ```bash
  207. curl SITE_ROOT/api/v1/checks/ \
  208. --header "X-Api-Key: your-api-key" \
  209. --data '{"name": "Backups", "tags": "prod www", "timeout": 3600, "grace": 60}'
  210. ```
  211. Or, alternatively:
  212. ```bash
  213. curl SITE_ROOT/api/v1/checks/ \
  214. --data '{"api_key": "your-api-key", "name": "Backups", "tags": "prod www", "timeout": 3600, "grace": 60}'
  215. ```
  216. ### Example Response
  217. ```json
  218. {
  219. "channels": "",
  220. "desc": "",
  221. "grace": 60,
  222. "last_ping": null,
  223. "n_pings": 0,
  224. "name": "Backups",
  225. "next_ping": null,
  226. "pause_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/pause",
  227. "ping_url": "PING_ENDPOINTf618072a-7bde-4eee-af63-71a77c5723bc",
  228. "status": "new",
  229. "tags": "prod www",
  230. "timeout": 3600,
  231. "update_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc",
  232. }
  233. ```
  234. ## Update an Existing Check {: #update-check .rule }
  235. `POST SITE_ROOT/api/v1/checks/<uuid>`
  236. Updates an existing check. All request parameters are optional. The check is
  237. updated only with the supplied request parameters. If any parameter is omitted,
  238. its value is left unchanged.
  239. ### Request Parameters
  240. name
  241. : string, optional.
  242. Name for the check.
  243. tags
  244. : string, optional.
  245. A space-delimited list of tags for the check.
  246. Example:
  247. <pre>{"tags": "reports staging"}</pre>
  248. desc
  249. : string, optional.
  250. Description for the check.
  251. timeout
  252. : number, optional.
  253. A number of seconds, the expected period of this check.
  254. Minimum: 60 (one minute), maximum: 2592000 (30 days).
  255. Example for 5 minute timeout:
  256. <pre>{"kind": "simple", "timeout": 300}</pre>
  257. grace
  258. : number, optional.
  259. A number of seconds, the grace period for this check.
  260. Minimum: 60 (one minute), maximum: 2592000 (30 days).
  261. schedule
  262. : string, optional.
  263. A cron expression defining this check's schedule.
  264. If you specify both "timeout" and "schedule" parameters, "timeout" will be
  265. ignored and "schedule" will be used.
  266. Example for a check running every half-hour:
  267. <pre>{"schedule": "0,30 * * * *"}</pre>
  268. tz
  269. : string, optional.
  270. Server's timezone. This setting only has effect in combination with the
  271. "schedule" paremeter.
  272. Example:
  273. <pre>{"tz": "Europe/Riga"}</pre>
  274. channels
  275. : string, optional.
  276. Set this field to a special value "*" to automatically assign all existing
  277. notification channels.
  278. Set this field to a special value "" (empty string) to automatically *unassign*
  279. all notification channels.
  280. Set this field to a comma-separated list of channel identifiers to assign
  281. specific notification channels.
  282. Example:
  283. <pre>{"channels": "4ec5a071-2d08-4baa-898a-eb4eb3cd6941,746a083e-f542-4554-be1a-707ce16d3acc"}</pre>
  284. ### Response Codes
  285. 200 OK
  286. : The check was successfully updated.
  287. 400 Bad Request
  288. : The request is not well-formed, violates schema, or uses invalid
  289. field values.
  290. 401 Unauthorized
  291. : The API key is either missing or invalid.
  292. 403 Forbidden
  293. : Access denied, wrong API key.
  294. 404 Not Found
  295. : The specified check does not exist.
  296. ### Example Request
  297. ```bash
  298. curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc \
  299. --header "X-Api-Key: your-api-key" \
  300. --data '{"name": "Backups", "tags": "prod www", "timeout": 3600, "grace": 60}'
  301. ```
  302. Or, alternatively:
  303. ```bash
  304. curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc \
  305. --data '{"api_key": "your-api-key", "name": "Backups", "tags": "prod www", "timeout": 3600, "grace": 60}'
  306. ```
  307. ### Example Response
  308. ```json
  309. {
  310. "channels": "",
  311. "desc": "",
  312. "grace": 60,
  313. "last_ping": null,
  314. "n_pings": 0,
  315. "name": "Backups",
  316. "next_ping": null,
  317. "pause_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/pause",
  318. "ping_url": "PING_ENDPOINTf618072a-7bde-4eee-af63-71a77c5723bc",
  319. "status": "new",
  320. "tags": "prod www",
  321. "timeout": 3600,
  322. "update_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc",
  323. }
  324. ```
  325. ## Pause Monitoring of a Check {: #pause-check .rule }
  326. `POST SITE_ROOT/api/v1/checks/<uuid>/pause`
  327. Disables monitoring for a check, without removing it. The check goes into a "paused"
  328. state. You can resume monitoring of the check by pinging it.
  329. This API call has no request parameters.
  330. ### Response Codes
  331. 200 OK
  332. : The check was successfully paused.
  333. 401 Unauthorized
  334. : The API key is either missing or invalid.
  335. 403 Forbidden
  336. : Access denied, wrong API key.
  337. 404 Not Found
  338. : The specified check does not exist.
  339. ### Example Request
  340. ```bash
  341. curl SITE_ROOT/api/v1/checks/0c8983c9-9d73-446f-adb5-0641fdacc9d4/pause \
  342. --request POST --header "X-Api-Key: your-api-key" --data ""
  343. ```
  344. Note: the `--data ""` argument forces curl to send a `Content-Length` request header
  345. even though the request body is empty. For HTTP POST requests, the `Content-Length`
  346. header is sometimes required by some network proxies and web servers.
  347. ### Example Response
  348. ```json
  349. {
  350. "channels": "",
  351. "desc": "",
  352. "grace": 60,
  353. "last_ping": null,
  354. "n_pings": 0,
  355. "name": "Backups",
  356. "next_ping": null,
  357. "pause_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/pause",
  358. "ping_url": "PING_ENDPOINTf618072a-7bde-4eee-af63-71a77c5723bc",
  359. "status": "paused",
  360. "tags": "prod www",
  361. "timeout": 3600,
  362. "update_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc"
  363. }
  364. ```
  365. ## Delete Check {: #delete-check .rule }
  366. `DELETE SITE_ROOT/api/v1/checks/<uuid>`
  367. Permanently deletes the check from user's account. Returns JSON representation of the
  368. check that was just deleted.
  369. This API call has no request parameters.
  370. ### Response Codes
  371. 200 OK
  372. : The check was successfully deleted.
  373. 401 Unauthorized
  374. : The API key is either missing or invalid.
  375. 403 Forbidden
  376. : Access denied, wrong API key.
  377. 404 Not Found
  378. : The specified check does not exist.
  379. ### Example Request
  380. ```bash
  381. curl SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc \
  382. --request DELETE --header "X-Api-Key: your-api-key"
  383. ```
  384. ### Example Response
  385. ```json
  386. {
  387. "channels": "",
  388. "desc": "",
  389. "grace": 60,
  390. "last_ping": null,
  391. "n_pings": 0,
  392. "name": "Backups",
  393. "next_ping": null,
  394. "pause_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc/pause",
  395. "ping_url": "PING_ENDPOINTf618072a-7bde-4eee-af63-71a77c5723bc",
  396. "status": "new",
  397. "tags": "prod www",
  398. "timeout": 3600,
  399. "update_url": "SITE_ROOT/api/v1/checks/f618072a-7bde-4eee-af63-71a77c5723bc",
  400. }
  401. ```
  402. ## Get a List of Existing Integrations {: #list-channels .rule }
  403. `GET SITE_ROOT/api/v1/channels/`
  404. Returns a list of integrations belonging to the user.
  405. ### Response Codes
  406. 200 OK
  407. : The request succeeded.
  408. 401 Unauthorized
  409. : The API key is either missing or invalid.
  410. ### Example Request
  411. ```bash
  412. curl --header "X-Api-Key: your-api-key" SITE_ROOT/api/v1/channels/
  413. ```
  414. ### Example Response
  415. ```json
  416. {
  417. "channels": [
  418. {
  419. "id": "4ec5a071-2d08-4baa-898a-eb4eb3cd6941",
  420. "name": "My Work Email",
  421. "kind": "email"
  422. },
  423. {
  424. "id": "746a083e-f542-4554-be1a-707ce16d3acc",
  425. "name": "My Phone",
  426. "kind": "sms"
  427. }
  428. ]
  429. }
  430. ```