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.

234 lines
9.0 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. <div class="form-group" class="clearfix">
  143. <br>
  144. <br>
  145. <div class="text-right">
  146. <button type="submit" class="btn btn-primary">
  147. {% if channel %}
  148. Save Changes
  149. {% else %}
  150. Save Integration
  151. {% endif %}
  152. </button>
  153. </div>
  154. </div>
  155. </form>
  156. </div>
  157. </div>
  158. <div id="reference-modal" class="modal">
  159. <div class="modal-dialog">
  160. <div class="modal-content">
  161. <div class="modal-header">
  162. <h4>Supported Placeholders</h4>
  163. </div>
  164. <div class="modal-body">
  165. <p>
  166. You can use the below placeholders in webhook URL, request body
  167. and header values. {% site_name %} will replace the placeholders
  168. with the correct values.
  169. </p>
  170. <table id="webhook-variables" class="table modal-body">
  171. <tr>
  172. <th><code>$CODE</code></th>
  173. <td>The UUID code of the check</td>
  174. </tr>
  175. <tr>
  176. <th><code>$NAME</code></th>
  177. <td>Name of the check</td>
  178. </tr>
  179. <tr>
  180. <th><code>$NOW</code></th>
  181. <td>
  182. Current UTC time in ISO8601 format.<br />
  183. Example: "{% now_isoformat %}"
  184. </td>
  185. </tr>
  186. <tr>
  187. <th><code>$STATUS</code></th>
  188. <td>Check's current status ("up" or "down")</td>
  189. </tr>
  190. <tr>
  191. <th><code>$TAGS</code></th>
  192. <td>Check's tags, separated by spaces</td>
  193. </tr>
  194. <tr>
  195. <th><code>$TAG1, $TAG2, …</code></th>
  196. <td>Value of the first tag, the second tag, …</td>
  197. </tr>
  198. </table>
  199. </div>
  200. <div class="modal-footer">
  201. <button type="button" class="btn btn-default" data-dismiss="modal">Got It!</button>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. {% endblock %}
  207. {% block scripts %}
  208. {% compress js %}
  209. <script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
  210. <script src="{% static 'js/bootstrap.min.js' %}"></script>
  211. <script src="{% static 'js/bootstrap-select.min.js' %}"></script>
  212. <script src="{% static 'js/webhook.js' %}"></script>
  213. {% endcompress %}
  214. {% endblock %}