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.

438 lines
14 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. {% extends "front/base_docs.html" %}
  2. {% load compress static hc_extras %}
  3. {% block title %}API Reference - {% site_name %}{% endblock %}
  4. {% block description %}
  5. <meta name="description" content="Build advanced integrations and custom dashboards using {% site_name %} REST API calls.">
  6. {% endblock %}
  7. {% block docs_content %}
  8. <h2>API Reference</h2>
  9. <p>{% site_name %} REST API supports listing, creating,
  10. updating, pausing and deleting checks in user's account.
  11. </p>
  12. <h2>API Endpoints</h2>
  13. <table class="table table-bordered">
  14. <tr>
  15. <td><a href="#list-checks">Get list of existing checks</a></td>
  16. <td>
  17. <code>GET {{ SITE_ROOT }}/api/v1/checks/</code>
  18. </td>
  19. </tr>
  20. <tr>
  21. <td><a href="#create-check">Create a new check</a></td>
  22. <td>
  23. <code>POST {{ SITE_ROOT }}/api/v1/checks/</code>
  24. </td>
  25. </tr>
  26. <tr>
  27. <td><a href="#update-check">Update an existing check</a></td>
  28. <td>
  29. <code>POST {{ SITE_ROOT }}/api/v1/checks/&lt;code&gt;</code>
  30. </td>
  31. </tr>
  32. <tr>
  33. <td><a href="#pause-check">Pause monitoring of a check</a></td>
  34. <td>
  35. <code>POST {{ SITE_ROOT }}/api/v1/checks/&lt;code&gt;/pause</code>
  36. </td>
  37. </tr>
  38. <tr>
  39. <td><a href="#delete-check">Delete check</a></td>
  40. <td>
  41. <code>DELETE {{ SITE_ROOT }}/api/v1/checks/&lt;code&gt;</code>
  42. </td>
  43. </tr>
  44. </table>
  45. <h2>Authentication</h2>
  46. <p>Your requests to {% site_name %} REST API must authenticate using an
  47. API key. By default, an user account on {% site_name %} doesn't have
  48. an API key. You can create one in the
  49. {% if request.user.is_authenticated %}
  50. <a href="{% url 'hc-profile' %}">Account Settings</a>
  51. {% else %}<b>Account Settings</b>{% endif %} page.
  52. </p>
  53. <p>The client can authenticate itself by sending an appropriate HTTP
  54. request header. The header's name should be <code>X-Api-Key</code> and
  55. its value should be your API key.
  56. </p>
  57. <p> Alternatively, for POST requests with a JSON request body,
  58. the client can include an <code>api_key</code> field in the JSON document.
  59. See below the "Create a check" section for an example.
  60. </p>
  61. <h2>API Requests</h2>
  62. <p>
  63. For POST requests, the {% site_name %} API expects request body to be
  64. a JSON document (<em>not</em> a <code>multipart/form-data</code> encoded
  65. form data).
  66. </p>
  67. <h2>API Responses</h2>
  68. <p>
  69. {% site_name %} uses HTTP status codes wherever possible.
  70. In general, 2xx class indicates success, 4xx indicates an client error,
  71. and 5xx indicates a server error.
  72. </p>
  73. <p>
  74. The response may contain a JSON document with additional data.
  75. </p>
  76. <!-- ********************************************************************** /-->
  77. <a class="section" name="list-checks">
  78. <h2 class="rule">Get List of Existing Checks</h2>
  79. </a>
  80. <div class="api-path">GET {{ SITE_ROOT }}/api/v1/checks/</div>
  81. <p>Returns a list of checks belonging to the user, optionally filtered by
  82. one or more tags.</p>
  83. <h3 class="api-section">Query String Parameters</h3>
  84. <table class="table">
  85. <tr>
  86. <th>tag=&lt;value&gt;</th>
  87. <td>
  88. <p>
  89. Filters the checks, and returns only the checks that
  90. are tagged with the specified value.
  91. </p>
  92. <p>
  93. This parameter can be repeated multiple times.
  94. </p>
  95. <p>Example:</p>
  96. <pre>{{ SITE_ROOT }}/api/v1/checks/?tag=foo&amp;tag=bar</pre>
  97. </td>
  98. </tr>
  99. </table>
  100. <h3 class="api-section">Example Request</h3>
  101. {% include "front/snippets/list_checks_request.html" %}
  102. <h3 class="api-section">Example Response</h3>
  103. {% include "front/snippets/list_checks_response.html" %}
  104. <!-- ********************************************************************** /-->
  105. <a class="section" name="create-check">
  106. <h2 class="rule">Create a Check</h2>
  107. </a>
  108. <div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/</div>
  109. <strong></strong>
  110. <p>
  111. Creates a new check and returns its ping URL.
  112. All request parameters are optional and will use their default
  113. values if omitted.
  114. </p>
  115. <p>This API call can be used to create both "simple" and "cron" checks.
  116. To create a "simple" check, specify the "timeout" parameter.
  117. To create a "cron" check, specify the "schedule" and "tz" parameters.
  118. </p>
  119. <h3 class="api-section">Request Parameters</h3>
  120. <table class="table">
  121. <tr>
  122. <th>name</th>
  123. <td>
  124. <p>string, optional, default value: ""</p>
  125. <p>Name for the new check.</p>
  126. </td>
  127. </tr>
  128. <tr>
  129. <th>tags</th>
  130. <td>
  131. <p>string, optional, default value: ""</p>
  132. <p>A space-delimited list of tags for the new check.</p>
  133. <p>Example:</p>
  134. <pre>{"tags": "reports staging"}</pre>
  135. </td>
  136. </tr>
  137. <tr>
  138. <th>timeout</th>
  139. <td>
  140. <p>number, optional, default value: {{ default_timeout }}.</p>
  141. <p>A number of seconds, the expected period of this check.</p>
  142. <p>Minimum: 60 (one minute), maximum: 2592000 (30 days).</p>
  143. <p>Example for 5 minute timeout:</p>
  144. <pre>{"kind": "simple", "timeout": 300}</pre>
  145. </td>
  146. </tr>
  147. <tr>
  148. <th>grace</th>
  149. <td>
  150. <p>number, optional, default value: {{ default_grace }}.</p>
  151. <p>A number of seconds, the grace period for this check.</p>
  152. <p>Minimum: 60 (one minute), maximum: 2592000 (30 days).</p>
  153. </td>
  154. </tr>
  155. <tr>
  156. <th>schedule</th>
  157. <td>
  158. <p>string, optional, default value: "* * * * *".</p>
  159. <p>A cron expression defining this check's schedule.</p>
  160. <p>If you specify both "timeout" and "schedule" parameters,
  161. "timeout" will be ignored and "schedule" will be used.</p>
  162. <p>Example for a check running every half-hour:</p>
  163. <pre>{"schedule": "0,30 * * * *"}</pre>
  164. </td>
  165. </tr>
  166. <tr>
  167. <th>tz</th>
  168. <td>
  169. <p>string, optional, default value: "UTC".</p>
  170. <p>Server's timezone. This setting only has effect in combination
  171. with the "schedule" paremeter.</p>
  172. <p>Example:</p>
  173. <pre>{"tz": "Europe/Riga"}</pre>
  174. </td>
  175. </tr>
  176. <tr>
  177. <th>channels</th>
  178. <td>
  179. <p>string, optional</p>
  180. <p>By default, if a check is created through API, no notification
  181. channels are assigned to it. So, when the check goes up or down,
  182. no notifications will get sent.</p>
  183. <p>Set this field to a special value "*"
  184. to automatically assign all existing notification channels.</p>
  185. <p>To assign specific notification channels, use a comma-separated
  186. list of channel identifiers.</p>
  187. </td>
  188. </tr>
  189. <tr>
  190. <th>unique</th>
  191. <td>
  192. <p>array of string values, optional, default value: [].</p>
  193. <p>Before creating a check, look for existing checks, filtered
  194. by fields listed in <code>unique</code>. If a matching check is
  195. found, return it with HTTP status code 200. If no matching check is
  196. found, proceed as normal: create a check and return it
  197. with HTTP status code 201.</p>
  198. <p>The accepted values are: <code>name</code>,
  199. <code>tags</code>, <code>timeout</code> and <code>grace</code>.</p>
  200. <p>Example:</p>
  201. <pre>{"name": "Backups", unique: ["name"]}</pre>
  202. <p>In this example, if a check named "Backups" exists, it will
  203. be returned. Otherwise, a new check will be created and
  204. returned.</p>
  205. </td>
  206. </tr>
  207. </table>
  208. <h3 class="api-section">Response Codes</h3>
  209. <table class="table">
  210. <tr>
  211. <th>201 Created</th>
  212. <td>Returned if the check was successfully created.</td>
  213. </tr>
  214. <tr>
  215. <th>200 OK</th>
  216. <td>Returned if the <code>unique</code> parameter was used and an
  217. existing check was matched.</td>
  218. </tr>
  219. <tr>
  220. <th>403 Forbidden</th>
  221. <td>Returned if the account's check limit has been reached.
  222. For free accounts, the limit is 20 checks per account.</td>
  223. </tr>
  224. </table>
  225. <h3 class="api-section">Example Request</h3>
  226. {% include "front/snippets/create_check_request_a.html" %}
  227. <br>
  228. <p>Or, alternatively:</p>
  229. {% include "front/snippets/create_check_request_b.html" %}
  230. <h3 class="api-section">Example Response</h3>
  231. {% include "front/snippets/create_check_response.html" %}
  232. <!-- ********************************************************************** /-->
  233. <a class="section" name="update-check">
  234. <h2 class="rule">Update an Existing Check</h2>
  235. </a>
  236. <div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/&lt;code&gt;</div>
  237. <strong></strong>
  238. <p>
  239. Updates an existing check. All request parameters are optional. The
  240. check is updated only with the supplied request parameters.
  241. If any parameter is omitted, its value is left unchanged.
  242. </p>
  243. <h3 class="api-section">Request Parameters</h3>
  244. <table class="table">
  245. <tr>
  246. <th>name</th>
  247. <td>
  248. <p>string, optional.</p>
  249. <p>Name for the check.</p>
  250. </td>
  251. </tr>
  252. <tr>
  253. <th>tags</th>
  254. <td>
  255. <p>string, optional.</p>
  256. <p>A space-delimited list of tags for the check.</p>
  257. <p>Example:</p>
  258. <pre>{"tags": "reports staging"}</pre>
  259. </td>
  260. </tr>
  261. <tr>
  262. <th>timeout</th>
  263. <td>
  264. <p>number, optional.</p>
  265. <p>A number of seconds, the expected period of this check.</p>
  266. <p>Minimum: 60 (one minute), maximum: 2592000 (30 days).</p>
  267. <p>Example for 5 minute timeout:</p>
  268. <pre>{"kind": "simple", "timeout": 300}</pre>
  269. </td>
  270. </tr>
  271. <tr>
  272. <th>grace</th>
  273. <td>
  274. <p>number, optional.</p>
  275. <p>A number of seconds, the grace period for this check.</p>
  276. <p>Minimum: 60 (one minute), maximum: 2592000 (30 days).</p>
  277. </td>
  278. </tr>
  279. <tr>
  280. <th>schedule</th>
  281. <td>
  282. <p>string, optional.</p>
  283. <p>A cron expression defining this check's schedule.</p>
  284. <p>If you specify both "timeout" and "schedule" parameters,
  285. "timeout" will be ignored and "schedule" will be used.</p>
  286. <p>Example for a check running every half-hour:</p>
  287. <pre>{"schedule": "0,30 * * * *"}</pre>
  288. </td>
  289. </tr>
  290. <tr>
  291. <th>tz</th>
  292. <td>
  293. <p>string, optional.</p>
  294. <p>Server's timezone. This setting only has effect in combination
  295. with the "schedule" paremeter.</p>
  296. <p>Example:</p>
  297. <pre>{"tz": "Europe/Riga"}</pre>
  298. </td>
  299. </tr>
  300. <tr>
  301. <th>channels</th>
  302. <td>
  303. <p>string, optional.</p>
  304. <p>Set this field to a special value "*"
  305. to automatically assign all existing notification channels.
  306. </p>
  307. <p>Set this field to a special value "" (empty string)
  308. to automatically <em>unassign</em> all notification channels.
  309. </p>
  310. <p>Set this field to a comma-separated list of channel identifiers
  311. to assign specific notification channels.
  312. </p>
  313. <p>Example:</p>
  314. <pre>{"channels": "4ec5a071-2d08-4baa-898a-eb4eb3cd6941,746a083e-f542-4554-be1a-707ce16d3acc"}</pre>
  315. </td>
  316. </tr>
  317. </table>
  318. <h3 class="api-section">Response Codes</h3>
  319. <table class="table">
  320. <tr>
  321. <th>200 OK</th>
  322. <td>Returned if the check was successfully updated.</td>
  323. </tr>
  324. </table>
  325. <h3 class="api-section">Example Request</h3>
  326. {% include "front/snippets/update_check_request_a.html" %}
  327. <br>
  328. <p>Or, alternatively:</p>
  329. {% include "front/snippets/update_check_request_b.html" %}
  330. <h3 class="api-section">Example Response</h3>
  331. {% include "front/snippets/create_check_response.html" %}
  332. <!-- ********************************************************************** /-->
  333. <a class="section" name="pause-check">
  334. <h2 class="rule">Pause Monitoring of a Check</h2>
  335. </a>
  336. <div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/&lt;uuid&gt;/pause</div>
  337. <p>
  338. Disables monitoring for a check, without removing it. The check goes
  339. into a "paused" state. You can resume monitoring of the check by pinging
  340. it.
  341. </p>
  342. <p>
  343. This API call has no request parameters.
  344. </p>
  345. <h3 class="api-section">Example Request</h3>
  346. {% include "front/snippets/pause_check_request.html" %}
  347. <p>Note: the <code>--data ""</code> argument forces curl to send a
  348. <code>Content-Length</code> request header even though the request body
  349. is empty. For HTTP POST requests, the <code>Content-Length</code> header
  350. is sometimes required by some network proxies and web servers.
  351. </p>
  352. <h3 class="api-section">Example Response</h3>
  353. {% include "front/snippets/pause_check_response.html" %}
  354. <!-- ********************************************************************** /-->
  355. <a class="section" name="delete-check">
  356. <h2 class="rule">Delete Check</h2>
  357. </a>
  358. <div class="api-path">DELETE {{ SITE_ROOT }}/api/v1/checks/&lt;uuid&gt;</div>
  359. <p>
  360. Permanently deletes the check from user's account. Returns JSON
  361. representation of the check that was just deleted.
  362. </p>
  363. <p>
  364. This API call has no request parameters.
  365. </p>
  366. <h3 class="api-section">Example Request</h3>
  367. {% include "front/snippets/delete_check_request.html" %}
  368. <h3 class="api-section">Example Response</h3>
  369. {% include "front/snippets/create_check_response.html" %}
  370. {% endblock %}
  371. {% block scripts %}
  372. {% compress js %}
  373. <script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
  374. <script src="{% static 'js/bootstrap.min.js' %}"></script>
  375. <script src="{% static 'js/clipboard.min.js' %}"></script>
  376. <script src="{% static 'js/snippet-copy.js' %}"></script>
  377. {% endcompress %}
  378. {% endblock %}