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.

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