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.

423 lines
13 KiB

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