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.

232 lines
8.9 KiB

9 years ago
  1. {% extends "base.html" %}
  2. {% load compress humanize static hc_extras %}
  3. {% block title %}
  4. {% if is_new %}
  5. Add Webhook Integration - {% site_name %}
  6. {% else %}
  7. Webhook Settings - {% site_name %}
  8. {% endif %}
  9. {% endblock %}
  10. {% block content %}
  11. <div class="row">
  12. <div class="col-sm-12">
  13. <h1>Webhook</h1>
  14. <p>
  15. Executes an HTTP request to your specified URL when a check
  16. goes up or down. You can use placeholders <strong>$NAME</strong>,
  17. <strong>$STATUS</strong> and others in webhook URLs, request body and
  18. header values
  19. <a href="#" data-toggle="modal" data-target="#reference-modal">(available placeholders)</a>.
  20. </p>
  21. <form id="add-webhook-form" method="post">
  22. {% csrf_token %}
  23. <div class="form-group {{ form.name.css_classes }}">
  24. <br>
  25. <label>Name</label>
  26. <input
  27. id="webhook-form-name"
  28. name="name"
  29. value="{{ form.name.value|default:"" }}"
  30. type="text"
  31. class="form-control" />
  32. <div class="help-block">Give this integration a descriptive name, so you can easily recognize it later. </div>
  33. </div>
  34. <div class="row">
  35. <div class="col-sm-6">
  36. <h2>Execute when a check goes <strong class="label-down">down</strong></h2>
  37. <br />
  38. <div class="form-group {{ form.url_down.css_classes }}">
  39. <label>URL</label>
  40. <div class="method-url-group">
  41. <select id="method-down" name="method_down" class="selectpicker">
  42. <option{% if form.method_down.value == "GET" %} selected{% endif %}>GET</option>
  43. <option{% if form.method_down.value == "POST" %} selected{% endif %}>POST</option>
  44. <option{% if form.method_down.value == "PUT" %} selected{% endif %}>PUT</option>
  45. </select>
  46. <input
  47. name="url_down"
  48. value="{{ form.url_down.value|default:"" }}"
  49. type="text"
  50. class="form-control"
  51. placeholder="https://..." />
  52. </div>
  53. {% if form.url_down.errors %}
  54. <div class="help-block">
  55. {{ form.url_down.errors|join:"" }}
  56. </div>
  57. {% endif %}
  58. </div>
  59. <div id="body-down-group" class="form-group {{ form.body_down.css_classes }}" style="display: none">
  60. <label class="control-label">Request Body</label>
  61. <textarea
  62. class="form-control"
  63. rows="3"
  64. name="body_down"
  65. placeholder='{"status": "$STATUS"}'>{{ form.body_down.value|default:"" }}</textarea>
  66. {% if form.body_down.errors %}
  67. <div class="help-block">
  68. {{ form.body_down.errors|join:"" }}
  69. </div>
  70. {% endif %}
  71. </div>
  72. <div class="form-group {{ form.headers_down.css_classes }}">
  73. <label class="control-label">Request Headers</label>
  74. <textarea
  75. class="form-control"
  76. rows="3"
  77. name="headers_down"
  78. placeholder="X-Sample-Header: $NAME has gone down">{{ form.headers_down.value|default:"" }}</textarea>
  79. <div class="help-block">
  80. {% if form.headers_down.errors %}
  81. {{ form.headers_down.errors|join:"" }}
  82. {% else %}
  83. Optional "Header-Name: value" pairs, one pair per line.
  84. {% endif %}
  85. </div>
  86. </div>
  87. </div>
  88. <div class="col-sm-6">
  89. <h2>Execute when a check goes <strong class="label-up">up</strong></h2>
  90. <br />
  91. <div class="form-group {{ form.url_up.css_classes }}">
  92. <label>URL</label>
  93. <div class="method-url-group">
  94. <select id="method-up" name="method_up" class="selectpicker">
  95. <option{% if form.method_up.value == "GET" %} selected{% endif %}>GET</option>
  96. <option{% if form.method_up.value == "POST" %} selected{% endif %}>POST</option>
  97. <option{% if form.method_up.value == "PUT" %} selected{% endif %}>PUT</option>
  98. </select>
  99. <input
  100. name="url_up"
  101. value="{{ form.url_up.value|default:"" }}"
  102. type="text"
  103. class="form-control"
  104. placeholder="https://..." />
  105. </div>
  106. {% if form.url_up.errors %}
  107. <div class="help-block">
  108. {{ form.url_up.errors|join:"" }}
  109. </div>
  110. {% endif %}
  111. </div>
  112. <div id="body-up-group" class="form-group {{ form.body_up.css_classes }}" style="display: none">
  113. <label class="control-label">Request Body</label>
  114. <textarea
  115. class="form-control"
  116. rows="3"
  117. name="body_up"
  118. placeholder='{"status": "$STATUS"}'>{{ form.body_up.value|default:"" }}</textarea>
  119. {% if form.post_data.errors %}
  120. <div class="help-block">
  121. {{ form.post_data.errors|join:"" }}
  122. </div>
  123. {% endif %}
  124. </div>
  125. <div class="form-group {{ form.headers_up.css_classes }}">
  126. <label class="control-label">Request Headers</label>
  127. <textarea
  128. class="form-control"
  129. rows="3"
  130. name="headers_up"
  131. placeholder="X-Sample-Header: $NAME is back up">{{ form.headers_up.value|default:"" }}</textarea>
  132. <div class="help-block">
  133. {% if form.headers_up.errors %}
  134. {{ form.headers_up.errors|join:"" }}
  135. {% else %}
  136. Optional "Header-Name: value" pairs, one pair per line.
  137. {% endif %}
  138. </div>
  139. </div>
  140. </div>
  141. </div>
  142. <br>
  143. <br>
  144. <div class="text-right">
  145. <button type="submit" class="btn btn-primary">
  146. {% if channel %}
  147. Save Changes
  148. {% else %}
  149. Save Integration
  150. {% endif %}
  151. </button>
  152. </div>
  153. </form>
  154. </div>
  155. </div>
  156. <div id="reference-modal" class="modal">
  157. <div class="modal-dialog">
  158. <div class="modal-content">
  159. <div class="modal-header">
  160. <h4>Supported Placeholders</h4>
  161. </div>
  162. <div class="modal-body">
  163. <p>
  164. You can use the below placeholders in webhook URL, request body
  165. and header values. {% site_name %} will replace the placeholders
  166. with the correct values.
  167. </p>
  168. <table id="webhook-variables" class="table modal-body">
  169. <tr>
  170. <th><code>$CODE</code></th>
  171. <td>The UUID code of the check</td>
  172. </tr>
  173. <tr>
  174. <th><code>$NAME</code></th>
  175. <td>Name of the check</td>
  176. </tr>
  177. <tr>
  178. <th><code>$NOW</code></th>
  179. <td>
  180. Current UTC time in ISO8601 format.<br />
  181. Example: "{% now_isoformat %}"
  182. </td>
  183. </tr>
  184. <tr>
  185. <th><code>$STATUS</code></th>
  186. <td>Check's current status ("up" or "down")</td>
  187. </tr>
  188. <tr>
  189. <th><code>$TAGS</code></th>
  190. <td>Check's tags, separated by spaces</td>
  191. </tr>
  192. <tr>
  193. <th><code>$TAG1, $TAG2, …</code></th>
  194. <td>Value of the first tag, the second tag, …</td>
  195. </tr>
  196. </table>
  197. </div>
  198. <div class="modal-footer">
  199. <button type="button" class="btn btn-default" data-dismiss="modal">Got It!</button>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. {% endblock %}
  205. {% block scripts %}
  206. {% compress js %}
  207. <script src="{% static 'js/jquery-3.6.0.min.js' %}"></script>
  208. <script src="{% static 'js/bootstrap.min.js' %}"></script>
  209. <script src="{% static 'js/bootstrap-select.min.js' %}"></script>
  210. <script src="{% static 'js/webhook.js' %}"></script>
  211. {% endcompress %}
  212. {% endblock %}