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.

173 lines
6.1 KiB

9 years ago
  1. {% extends "base.html" %}
  2. {% load compress humanize staticfiles 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>Runs a HTTP GET or HTTP POST to your specified URL when a check
  9. goes up or down. Uses GET by default, and uses POST if you specify
  10. any POST data.</p>
  11. <p>You can use the following variables in webhook URLs:</p>
  12. <table class="table webhook-variables">
  13. <tr>
  14. <th class="variable-column">Variable</th>
  15. <td>Will be replaced with…</td>
  16. </tr>
  17. <tr>
  18. <th><code>$CODE</code></th>
  19. <td>The UUID code of the check</td>
  20. </tr>
  21. <tr>
  22. <th><code>$NAME</code></th>
  23. <td>Name of the check</td>
  24. </tr>
  25. <tr>
  26. <th><code>$NOW</code></th>
  27. <td>
  28. Current UTC time in ISO8601 format.
  29. Example: "{{ now }}"
  30. </td>
  31. </tr>
  32. <tr>
  33. <th><code>$STATUS</code></th>
  34. <td>Check's current status ("up" or "down")</td>
  35. </tr>
  36. <tr>
  37. <th><code>$TAG1, $TAG2, …</code></th>
  38. <td>Value of the first tag, the second tag, …</td>
  39. </tr>
  40. </table>
  41. <p>For example, a callback URL using variables might look like so:
  42. <pre>http://requestb.in/1hhct291?message=<strong>$NAME</strong>:<strong>$STATUS</strong></pre>
  43. <p>
  44. After encoding and replacing the variables, {% site_name %} would then call:
  45. </p>
  46. <pre>http://requestb.in/1hhct291?message=<strong>My%20Check</strong>:<strong>down</strong></pre>
  47. <h2>Integration Settings</h2>
  48. <form method="post" class="form-horizontal">
  49. {% csrf_token %}
  50. <input type="hidden" name="kind" value="webhook" />
  51. <div class="form-group {{ form.url_down.css_classes }}">
  52. <label class="col-sm-2 control-label">URL for "down" events</label>
  53. <div class="col-sm-10">
  54. <input
  55. type="text"
  56. class="form-control"
  57. name="url_down"
  58. placeholder="http://..."
  59. value="{{ form.url_down.value|default:"" }}">
  60. {% if form.url_down.errors %}
  61. <div class="help-block">
  62. {{ form.url_down.errors|join:"" }}
  63. </div>
  64. {% endif %}
  65. </div>
  66. </div>
  67. <div class="form-group {{ form.url_up.css_classes }}">
  68. <label class="col-sm-2 control-label">URL for "up" events</label>
  69. <div class="col-sm-10">
  70. <input
  71. type="text"
  72. class="form-control"
  73. name="url_up"
  74. placeholder="http://..."
  75. value="{{ form.url_up.value|default:"" }}">
  76. {% if form.url_up.errors %}
  77. <div class="help-block">
  78. {{ form.url_up.errors|join:"" }}
  79. </div>
  80. {% endif %}
  81. </div>
  82. </div>
  83. <div class="form-group {{ form.post_data.css_classes }}">
  84. <label class="col-sm-2 control-label">POST data</label>
  85. <div class="col-sm-10">
  86. <input
  87. type="text"
  88. class="form-control"
  89. name="post_data"
  90. placeholder='{"status": "$STATUS"}'
  91. value="{{ form.post_data.value|default:"" }}">
  92. {% if form.post_data.errors %}
  93. <div class="help-block">
  94. {{ form.post_data.errors|join:"" }}
  95. </div>
  96. {% endif %}
  97. </div>
  98. </div>
  99. <div class="form-group">
  100. <label class="col-sm-2 control-label">Request Headers</label>
  101. <div class="col-xs-12 col-sm-10">
  102. <div id="webhook-headers">
  103. {% for k, v in form.headers.items %}
  104. <div class="form-inline webhook-header">
  105. <input
  106. type="text"
  107. class="form-control key {% if k in form.invalid_header_names %}error{% endif %}"
  108. name="header_key[]"
  109. placeholder="Content-Type"
  110. value="{{ k }}" />
  111. <input
  112. type="text"
  113. class="form-control value"
  114. name="header_value[]"
  115. placeholder="application/json"
  116. value="{{ v }}" />
  117. <button class="btn btn-default" type="button">
  118. <span class="icon-delete"></span>
  119. </button>
  120. </div>
  121. {% endfor %}
  122. </div>
  123. {% if form.invalid_header_names %}
  124. <div class="text-danger">
  125. Please use valid HTTP header names.
  126. </div>
  127. {% endif %}
  128. </div>
  129. </div>
  130. <div class="form-group">
  131. <div class="col-sm-offset-2 col-sm-10">
  132. <button type="submit" class="btn btn-primary">Save Integration</button>
  133. </div>
  134. </div>
  135. </form>
  136. </div>
  137. </div>
  138. <div id="header-template" class="hide">
  139. <div class="form-inline webhook-header">
  140. <input
  141. type="text"
  142. class="form-control key"
  143. name="header_key[]"
  144. placeholder="Content-Type" />
  145. <input
  146. type="text"
  147. class="form-control value"
  148. name="header_value[]"
  149. placeholder="application/json" />
  150. <button class="btn btn-default" type="button">
  151. <span class="icon-delete"></span>
  152. </button>
  153. </div>
  154. </div>
  155. {% endblock %}
  156. {% block scripts %}
  157. {% compress js %}
  158. <script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
  159. <script src="{% static 'js/bootstrap.min.js' %}"></script>
  160. <script src="{% static 'js/webhook.js' %}"></script>
  161. {% endcompress %}
  162. {% endblock %}