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
18 KiB

3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <h1>Pinging API</h1>
  2. <p>With the Pinging API, you can signal <strong>success</strong>, <strong>start</strong>, and <strong>failure</strong> events from
  3. your systems.</p>
  4. <h2>General Notes</h2>
  5. <p>All ping endpoints support:</p>
  6. <ul>
  7. <li>HTTP and HTTPS</li>
  8. <li>HTTP 1.0, HTTP 1.1 and HTTP 2</li>
  9. <li>IPv4 and IPv6</li>
  10. <li>HEAD, GET, and POST requests methods. The HTTP POST requests
  11. can optionally include diagnostic information in the request body.
  12. If the request body looks like a UTF-8 string, SITE_NAME stores the request body
  13. (limited to the first 10KB for each received ping).</li>
  14. </ul>
  15. <p>Successful responses will have the "200 OK" HTTP response status code and a short
  16. "OK" string in the response body.</p>
  17. <h2>UUIDs and Slugs</h2>
  18. <p>Each Pinging API request needs to uniquely identify a check.
  19. SITE_NAME supports two ways of identifying a check: by check's UUID,
  20. or by a combination of project's Ping Key and check's slug.</p>
  21. <p><strong>Check's UUID</strong> is automatically assigned when the check is created. It is
  22. immutable. You cannot replace the automatically assigned UUID with a manually
  23. chosen one. When you delete a check, you also lose its UUID and cannot get it back.</p>
  24. <p>You can look up UUIDs of your checks in web UI or via <a href="../api/">Management API</a> calls.</p>
  25. <p><strong>Check's slug</strong> is derived from check's name using Django's
  26. <a href="https://docs.djangoproject.com/en/3.2/ref/utils/#django.utils.text.slugify">slugify</a>
  27. function. It applies the following transformations:</p>
  28. <ul>
  29. <li>Convert to ASCII.</li>
  30. <li>Convert to lowercase.</li>
  31. <li>Remove characters that aren't alphanumerics, underscores, hyphens, or whitespace.</li>
  32. <li>Replace any whitespace or repeated hyphens with single hyphens.</li>
  33. <li>Remove leading and trailing whitespace, hyphens, and underscores.</li>
  34. </ul>
  35. <p>For example, if check's name is "Database Backup", its slug is <code>database-backup</code>.</p>
  36. <p>Check's slug <strong>can change</strong>. SITE_NAME updates check's slug whenever its name changes.</p>
  37. <p>Check's slug is <strong>not guaranteed to be unique</strong>. If multiple checks in the project
  38. have the same name, they also have the same slug. If you make a Pinging API
  39. request using a non-unique slug, SITE_NAME will return the "409 Conflict" HTTP status
  40. code and ignore the request.</p>
  41. <h2>Endpoints</h2>
  42. <table>
  43. <thead>
  44. <tr>
  45. <th>Endpoint Name</th>
  46. <th>Endpoint Address</th>
  47. </tr>
  48. </thead>
  49. <tbody>
  50. <tr>
  51. <td><a href="#success-uuid">Success (UUID)</a></td>
  52. <td><code>PING_ENDPOINT&lt;uuid&gt;</code></td>
  53. </tr>
  54. <tr>
  55. <td><a href="#start-uuid">Start (UUID)</a></td>
  56. <td><code>PING_ENDPOINT&lt;uuid&gt;/start</code></td>
  57. </tr>
  58. <tr>
  59. <td><a href="#fail-uuid">Failure (UUID)</a></td>
  60. <td><code>PING_ENDPOINT&lt;uuid&gt;/fail</code></td>
  61. </tr>
  62. <tr>
  63. <td><a href="#exitcode-uuid">Report script's exit status (UUID)</a></td>
  64. <td><code>PING_ENDPOINT&lt;uuid&gt;/&lt;exit-status&gt;</code></td>
  65. </tr>
  66. <tr>
  67. <td><a href="#success-slug">Success (slug)</a></td>
  68. <td><code>PING_ENDPOINT&lt;ping-key&gt;/&lt;slug&gt;</code></td>
  69. </tr>
  70. <tr>
  71. <td><a href="#start-slug">Start (slug)</a></td>
  72. <td><code>PING_ENDPOINT&lt;ping-key&gt;/&lt;slug&gt;/start</code></td>
  73. </tr>
  74. <tr>
  75. <td><a href="#fail-slug">Failure (slug)</a></td>
  76. <td><code>PING_ENDPOINT&lt;ping-key&gt;/&lt;slug&gt;/fail</code></td>
  77. </tr>
  78. <tr>
  79. <td><a href="#exitcode-slug">Report script's exit status (slug)</a></td>
  80. <td><code>PING_ENDPOINT&lt;ping-key&gt;/&lt;slug&gt;/&lt;exit-status&gt;</code></td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. <h2 class="rule" id="success-uuid">Send a "success" Signal Using UUID</h2>
  85. <div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT&lt;uuid&gt;
  86. </code></pre></div>
  87. <p>Signals to SITE_NAME that the job has completed successfully (or,
  88. a continuously running process is still running and healthy).</p>
  89. <p>SITE_NAME identifies the check by the UUID value included in the URL.</p>
  90. <h3>Response Codes</h3>
  91. <dl>
  92. <dt>200 OK</dt>
  93. <dd>The request succeeded.</dd>
  94. <dt>404 not found</dt>
  95. <dd>Could not find a check with the specified UUID.</dd>
  96. </dl>
  97. <p><strong>Example</strong></p>
  98. <div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
  99. <span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
  100. </code></pre></div>
  101. <div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
  102. <span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
  103. <span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
  104. <span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
  105. <span class="na">Content-Length</span><span class="o">:</span> <span class="l">2</span>
  106. <span class="na">Connection</span><span class="o">:</span> <span class="l">close</span>
  107. <span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
  108. OK
  109. </code></pre></div>
  110. <h2 class="rule" id="start-uuid">Send a "start" Signal Using UUID</h2>
  111. <div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT&lt;uuid&gt;/start
  112. </code></pre></div>
  113. <p>Sends a "job has started!" message to SITE_NAME. Sending a "start" signal is optional,
  114. but it enables a few extra features:</p>
  115. <ul>
  116. <li>SITE_NAME will measure and display job execution times</li>
  117. <li>SITE_NAME will detect if the job runs longer than its configured grace time</li>
  118. </ul>
  119. <p>SITE_NAME identifies the check by the UUID value included in the URL.</p>
  120. <h3>Response Codes</h3>
  121. <dl>
  122. <dt>200 OK</dt>
  123. <dd>The request succeeded.</dd>
  124. <dt>404 not found</dt>
  125. <dd>Could not find a check with the specified UUID.</dd>
  126. </dl>
  127. <p><strong>Example</strong></p>
  128. <div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278/start</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
  129. <span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
  130. </code></pre></div>
  131. <div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
  132. <span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
  133. <span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
  134. <span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
  135. <span class="na">Content-Length</span><span class="o">:</span> <span class="l">2</span>
  136. <span class="na">Connection</span><span class="o">:</span> <span class="l">close</span>
  137. <span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
  138. OK
  139. </code></pre></div>
  140. <h2 class="rule" id="fail-uuid">Send a "failure" Signal Using UUID</h2>
  141. <div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT&lt;uuid&gt;/fail
  142. </code></pre></div>
  143. <p>Signals to SITE_NAME that the job has failed. Actively signaling a failure
  144. minimizes the delay from your monitored service failing to you receiving an alert.</p>
  145. <p>SITE_NAME identifies the check by the UUID value included in the URL.</p>
  146. <h3>Response Codes</h3>
  147. <dl>
  148. <dt>200 OK</dt>
  149. <dd>The request succeeded.</dd>
  150. <dt>404 not found</dt>
  151. <dd>Could not find a check with the specified UUID.</dd>
  152. </dl>
  153. <p><strong>Example</strong></p>
  154. <div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278/fail</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
  155. <span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
  156. </code></pre></div>
  157. <div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
  158. <span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
  159. <span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
  160. <span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
  161. <span class="na">Content-Length</span><span class="o">:</span> <span class="l">2</span>
  162. <span class="na">Connection</span><span class="o">:</span> <span class="l">close</span>
  163. <span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
  164. OK
  165. </code></pre></div>
  166. <h2 class="rule" id="exitcode-uuid">Report Script's Exit Status (Using UUID)</h2>
  167. <div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT&lt;uuid&gt;/&lt;exit-status&gt;
  168. </code></pre></div>
  169. <p>Sends a success or failure signal depending on the exit status
  170. included in the URL. The exit status is a 0-255 integer. SITE_NAME
  171. interprets 0 as success and all other values as failure.</p>
  172. <p>SITE_NAME identifies the check by the UUID value included in the URL.</p>
  173. <h3>Response Codes</h3>
  174. <dl>
  175. <dt>200 OK</dt>
  176. <dd>The request succeeded.</dd>
  177. <dt>400 invalid url format</dt>
  178. <dd>The URL does not match the expected format.</dd>
  179. <dt>404 not found</dt>
  180. <dd>Could not find a check with the specified UUID.</dd>
  181. </dl>
  182. <p><strong>Example</strong></p>
  183. <div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/5bf66975-d4c7-4bf5-bcc8-b8d8a82ea278/1</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
  184. <span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
  185. </code></pre></div>
  186. <div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
  187. <span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
  188. <span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
  189. <span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
  190. <span class="na">Content-Length</span><span class="o">:</span> <span class="l">2</span>
  191. <span class="na">Connection</span><span class="o">:</span> <span class="l">close</span>
  192. <span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
  193. OK
  194. </code></pre></div>
  195. <h2 class="rule" id="success-slug">Send a "success" Signal (Using Slug)</h2>
  196. <div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT&lt;ping-key&gt;/&lt;slug&gt;
  197. </code></pre></div>
  198. <p>Signals to SITE_NAME that the job has completed successfully (or,
  199. a continuously running process is still running and healthy).</p>
  200. <p>SITE_NAME identifies the check by project's ping key and check's slug
  201. included in the URL.</p>
  202. <h3>Response Codes</h3>
  203. <dl>
  204. <dt>200 OK</dt>
  205. <dd>The request succeeded.</dd>
  206. <dt>404 not found</dt>
  207. <dd>Could not find a check with the specified ping key and slug combination.</dd>
  208. <dt>409 ambiguous slug</dt>
  209. <dd>Ambiguous, the slug matched multiple checks.</dd>
  210. </dl>
  211. <p><strong>Example</strong></p>
  212. <div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/fqOOd6-F4MMNuCEnzTU01w/database-backup</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
  213. <span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
  214. </code></pre></div>
  215. <div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
  216. <span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
  217. <span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
  218. <span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
  219. <span class="na">Content-Length</span><span class="o">:</span> <span class="l">2</span>
  220. <span class="na">Connection</span><span class="o">:</span> <span class="l">close</span>
  221. <span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
  222. OK
  223. </code></pre></div>
  224. <h2 class="rule" id="start-slug">Send a "start" Signal (Using Slug)</h2>
  225. <div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT&lt;ping-key&gt;/&lt;slug&gt;/start
  226. </code></pre></div>
  227. <p>Sends a "job has started!" message to SITE_NAME. Sending a "start" signal is
  228. optional, but it enables a few extra features:</p>
  229. <ul>
  230. <li>SITE_NAME will measure and display job execution times</li>
  231. <li>SITE_NAME will detect if the job runs longer than its configured grace time</li>
  232. </ul>
  233. <p>SITE_NAME identifies the check by project's ping key and check's slug
  234. included in the URL.</p>
  235. <h3>Response Codes</h3>
  236. <dl>
  237. <dt>200 OK</dt>
  238. <dd>The request succeeded.</dd>
  239. <dt>404 not found</dt>
  240. <dd>Could not find a check with the specified ping key and slug combination.</dd>
  241. <dt>409 ambiguous slug</dt>
  242. <dd>Ambiguous, the slug matched multiple checks.</dd>
  243. </dl>
  244. <p><strong>Example</strong></p>
  245. <div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/fqOOd6-F4MMNuCEnzTU01w/database-backup/start</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
  246. <span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
  247. </code></pre></div>
  248. <div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
  249. <span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
  250. <span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
  251. <span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
  252. <span class="na">Content-Length</span><span class="o">:</span> <span class="l">2</span>
  253. <span class="na">Connection</span><span class="o">:</span> <span class="l">close</span>
  254. <span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
  255. OK
  256. </code></pre></div>
  257. <h2 class="rule" id="fail-slug">Send a "failure" Signal (Using slug)</h2>
  258. <div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT&lt;ping-key/&lt;slug&gt;/fail
  259. </code></pre></div>
  260. <p>Signals to SITE_NAME that the job has failed. Actively signaling a failure
  261. minimizes the delay from your monitored service failing to you receiving an alert.</p>
  262. <p>SITE_NAME identifies the check by project's ping key and check's slug
  263. included in the URL.</p>
  264. <h3>Response Codes</h3>
  265. <dl>
  266. <dt>200 OK</dt>
  267. <dd>The request succeeded.</dd>
  268. <dt>404 not found</dt>
  269. <dd>Could not find a check with the specified ping key and slug combination.</dd>
  270. <dt>409 ambiguous slug</dt>
  271. <dd>Ambiguous, the slug matched multiple checks.</dd>
  272. </dl>
  273. <p><strong>Example</strong></p>
  274. <div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/fqOOd6-F4MMNuCEnzTU01w/database-backup/fail</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
  275. <span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
  276. </code></pre></div>
  277. <div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
  278. <span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
  279. <span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
  280. <span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
  281. <span class="na">Content-Length</span><span class="o">:</span> <span class="l">2</span>
  282. <span class="na">Connection</span><span class="o">:</span> <span class="l">close</span>
  283. <span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
  284. OK
  285. </code></pre></div>
  286. <h2 class="rule" id="exitcode-slug">Report Script's Exit Status (Using Slug)</h2>
  287. <div class="highlight"><pre><span></span><code>HEAD|GET|POST PING_ENDPOINT&lt;ping-key&gt;/&lt;slug&gt;/&lt;exit-status&gt;
  288. </code></pre></div>
  289. <p>Sends a success or failure signal depending on the exit status
  290. included in the URL. The exit status is a 0-255 integer. SITE_NAME
  291. interprets 0 as success and all other values as failure.</p>
  292. <p>SITE_NAME identifies the check by project's ping key and check's slug
  293. included in the URL.</p>
  294. <h3>Response Codes</h3>
  295. <dl>
  296. <dt>200 OK</dt>
  297. <dd>The request succeeded.</dd>
  298. <dt>400 invalid url format</dt>
  299. <dd>The URL does not match the expected format.</dd>
  300. <dt>404 not found</dt>
  301. <dd>Could not find a check with the specified ping key and slug combination.</dd>
  302. <dt>409 ambiguous slug</dt>
  303. <dd>Ambiguous, the slug matched multiple checks.</dd>
  304. </dl>
  305. <p><strong>Example</strong></p>
  306. <div class="highlight"><pre><span></span><code><span class="nf">GET</span> <span class="nn">/fqOOd6-F4MMNuCEnzTU01w/database-backup/1</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.0</span>
  307. <span class="na">Host</span><span class="o">:</span> <span class="l">hc-ping.com</span>
  308. </code></pre></div>
  309. <div class="highlight"><pre><span></span><code><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">200</span> <span class="ne">OK</span>
  310. <span class="na">Server</span><span class="o">:</span> <span class="l">nginx</span>
  311. <span class="na">Date</span><span class="o">:</span> <span class="l">Wed, 29 Jan 2020 09:58:23 GMT</span>
  312. <span class="na">Content-Type</span><span class="o">:</span> <span class="l">text/plain; charset=utf-8</span>
  313. <span class="na">Content-Length</span><span class="o">:</span> <span class="l">2</span>
  314. <span class="na">Connection</span><span class="o">:</span> <span class="l">close</span>
  315. <span class="na">Access-Control-Allow-Origin</span><span class="o">:</span> <span class="l">*</span>
  316. OK
  317. </code></pre></div>