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.

210 lines
8.3 KiB

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