Browse Source

Mattermost integration WIP cc: #276

pull/287/head
Pēteris Caune 5 years ago
parent
commit
862bafc331
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
16 changed files with 166 additions and 12 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +3
    -2
      hc/api/models.py
  3. +23
    -0
      hc/front/tests/test_add_mattermost.py
  4. +1
    -0
      hc/front/urls.py
  5. +20
    -5
      hc/front/views.py
  6. +9
    -5
      static/css/icomoon.css
  7. BIN
      static/fonts/icomoon.eot
  8. +1
    -0
      static/fonts/icomoon.svg
  9. BIN
      static/fonts/icomoon.ttf
  10. BIN
      static/fonts/icomoon.woff
  11. BIN
      static/img/integrations/mattermost.png
  12. BIN
      static/img/integrations/setup_mattermost_1.png
  13. BIN
      static/img/integrations/setup_mattermost_2.png
  14. BIN
      static/img/integrations/setup_mattermost_3.png
  15. +11
    -0
      templates/front/channels.html
  16. +97
    -0
      templates/integrations/add_mattermost.html

+ 1
- 0
CHANGELOG.md View File

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- Show the number of downtimes and total downtime minutes in monthly reports (#104)
- Show the number of downtimes and total downtime minutes in "Check Details" page
- Add the `pruneflips` management command
- Add Mattermost integration (#276)
## Bug Fixes
- Fix javascript code to construct correct URLs when running from a subdirectory (#273)


+ 3
- 2
hc/api/models.py View File

@ -42,6 +42,7 @@ CHANNEL_KINDS = (
("matrix", "Matrix"),
("whatsapp", "WhatsApp"),
("apprise", "Apprise"),
("mattermost", "Mattermost"),
)
PO_PRIORITIES = {-2: "lowest", -1: "low", 0: "normal", 1: "high", 2: "emergency"}
@ -363,7 +364,7 @@ class Channel(models.Model):
return transports.Email(self)
elif self.kind == "webhook":
return transports.Webhook(self)
elif self.kind == "slack":
elif self.kind in ("slack", "mattermost"):
return transports.Slack(self)
elif self.kind == "hipchat":
return transports.HipChat(self)
@ -504,7 +505,7 @@ class Channel(models.Model):
@property
def slack_webhook_url(self):
assert self.kind == "slack"
assert self.kind in ("slack", "mattermost")
if not self.value.startswith("{"):
return self.value


+ 23
- 0
hc/front/tests/test_add_mattermost.py View File

@ -0,0 +1,23 @@
from django.test.utils import override_settings
from hc.api.models import Channel
from hc.test import BaseTestCase
class AddMattermostTestCase(BaseTestCase):
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get("/integrations/add_mattermost/")
self.assertContains(r, "Integration Settings", status_code=200)
def test_it_works(self):
form = {"value": "http://example.org"}
self.client.login(username="[email protected]", password="password")
r = self.client.post("/integrations/add_mattermost/", form)
self.assertRedirects(r, "/integrations/")
c = Channel.objects.get()
self.assertEqual(c.kind, "mattermost")
self.assertEqual(c.value, "http://example.org")
self.assertEqual(c.project, self.project)

+ 1
- 0
hc/front/urls.py View File

@ -30,6 +30,7 @@ channel_urls = [
path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"),
path("add_pagerteam/", views.add_pagerteam, name="hc-add-pagerteam"),
path("add_slack/", views.add_slack, name="hc-add-slack"),
path("add_mattermost/", views.add_mattermost, name="hc-add-mattermost"),
path("add_slack_btn/", views.add_slack_btn, name="hc-add-slack-btn"),
path("add_pushbullet/", views.add_pushbullet, name="hc-add-pushbullet"),
path("add_discord/", views.add_discord, name="hc-add-discord"),


+ 20
- 5
hc/front/views.py View File

@ -902,6 +902,25 @@ def add_slack(request):
return render(request, "integrations/add_slack.html", ctx)
@login_required
def add_mattermost(request):
if request.method == "POST":
form = AddUrlForm(request.POST)
if form.is_valid():
channel = Channel(project=request.project, kind="mattermost")
channel.value = form.cleaned_data["value"]
channel.save()
channel.assign_all_checks()
return redirect("hc-channels")
else:
form = AddUrlForm()
ctx = {"page": "channels", "form": form, "project": request.project}
return render(request, "integrations/add_mattermost.html", ctx)
@login_required
def add_slack_btn(request):
code = _get_validated_code(request, "slack")
@ -1346,11 +1365,7 @@ def add_apprise(request):
else:
form = AddAppriseForm()
ctx = {
"page": "channels",
"project": request.project,
"form": form,
}
ctx = {"page": "channels", "project": request.project, "form": form}
return render(request, "integrations/add_apprise.html", ctx)


+ 9
- 5
static/css/icomoon.css View File

@ -1,10 +1,10 @@
@font-face {
font-family: 'icomoon';
src: url('../fonts/icomoon.eot?iewxyq');
src: url('../fonts/icomoon.eot?iewxyq#iefix') format('embedded-opentype'),
url('../fonts/icomoon.ttf?iewxyq') format('truetype'),
url('../fonts/icomoon.woff?iewxyq') format('woff'),
url('../fonts/icomoon.svg?iewxyq#icomoon') format('svg');
src: url('../fonts/icomoon.eot?smade2');
src: url('../fonts/icomoon.eot?smade2#iefix') format('embedded-opentype'),
url('../fonts/icomoon.ttf?smade2') format('truetype'),
url('../fonts/icomoon.woff?smade2') format('woff'),
url('../fonts/icomoon.svg?smade2#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
@ -24,6 +24,10 @@
-moz-osx-font-smoothing: grayscale;
}
.icon-mattermost:before {
content: "\e907";
color: #045acc;
}
.icon-pagerteam:before {
content: "\e914";
color: #cd2a00;


BIN
static/fonts/icomoon.eot View File


+ 1
- 0
static/fonts/icomoon.svg View File

@ -25,6 +25,7 @@
<glyph unicode="&#xe904;" glyph-name="sms" d="M142.769 871.774c-73.5 0-133.644-60.149-133.644-133.65v-398.151c0-73.5 60.143-133.644 133.644-133.644h56.045v-215.2l195.357 215.2 489.426 0.265c68.005 8.811 129.663 59.708 129.663 133.379v398.151c0 73.501-60.144 133.644-133.644 133.644l-736.847 0.006zM263.737 675.43c16.811-0.371 31.771-4.079 44.873-11.124 13.103-6.922 23.111-16.626 30.033-29.11 6.922-12.361 10.137-26.517 9.643-42.463l-45.608 0.188c0.865 14.091-2.291 25.033-9.46 32.82-7.046 7.787-17.735 11.865-32.073 12.236-14.462 0.247-26.7-3.155-36.712-10.201-9.889-7.046-15.697-16.561-17.427-28.551-2.472-15.698 8.035-28.059 31.521-37.083l13.905-5.004c28.306-10.136 48.083-22.069 59.331-35.789 11.248-13.597 16.194-29.724 14.834-48.389-1.236-15.204-6.246-28.492-15.022-39.864-8.776-11.248-20.95-19.966-36.524-26.147-15.451-6.18-32.511-9.143-51.176-8.896-17.676 0.124-33.745 3.831-48.207 11.124-14.339 7.293-25.339 17.366-33.002 30.221-7.664 12.979-11.184 27.687-10.566 44.127l45.796-0.182c-0.989-15.327 2.778-27.131 11.307-35.413s20.767-12.547 36.712-12.794c14.833-0.247 27.194 2.903 37.083 9.454 10.012 6.551 16.008 15.885 17.986 27.999 2.719 17.8-6.984 31.023-29.11 39.676l-15.017 5.562c-27.936 9.765-47.777 21.322-59.519 34.672s-17.058 28.867-15.946 46.543c0.989 15.327 6.181 28.797 15.575 40.417 9.518 11.743 22.002 20.766 37.453 27.070s31.89 9.273 49.318 8.902zM811.818 675.43c16.811-0.371 31.771-4.079 44.873-11.124 13.103-6.922 23.111-16.626 30.033-29.11 6.922-12.361 10.137-26.517 9.643-42.463l-45.608 0.188c0.865 14.091-2.291 25.033-9.46 32.82-7.046 7.787-17.735 11.865-32.073 12.236-14.462 0.247-26.7-3.155-36.712-10.201-9.889-7.046-15.697-16.561-17.427-28.551-2.472-15.698 8.029-28.059 31.515-37.083l13.911-5.004c28.306-10.136 48.083-22.069 59.331-35.789 11.248-13.597 16.194-29.724 14.834-48.389-1.236-15.204-6.246-28.492-15.022-39.864-8.776-11.248-20.95-19.966-36.524-26.147-15.451-6.18-32.511-9.143-51.176-8.896-17.676 0.124-33.745 3.831-48.207 11.124-14.339 7.293-25.339 17.366-33.002 30.221-7.664 12.979-11.184 27.687-10.566 44.127l45.796-0.182c-0.989-15.327 2.778-27.131 11.307-35.413s20.767-12.547 36.712-12.794c14.833-0.247 27.194 2.903 37.083 9.454 10.012 6.551 16.008 15.885 17.986 27.999 2.719 17.8-6.984 31.023-29.11 39.676l-15.017 5.562c-27.936 9.765-47.777 21.322-59.519 34.672s-17.058 28.867-15.946 46.543c0.989 15.327 6.181 28.797 15.575 40.417 9.518 11.743 22.002 20.766 37.453 27.070s31.889 9.273 49.318 8.902zM402.614 671.72h58.22l39.493-206.551 111.060 206.551h60.072l-46.72-269.963h-45.614l15.763 91.411 23.912 112.548-111.243-203.958h-33.008l-41.346 210.073-16.875-123.484-15.017-86.589h-45.608l46.908 269.963z" />
<glyph unicode="&#xe905;" glyph-name="slack" d="M421.504 469.547l44.16-131.627 136.747 45.824-44.16 131.157-136.747-46.080v0.725zM803.157 338.987l-66.347-22.229 23.040-68.693c9.301-27.733-5.76-57.813-33.536-67.157-6.4-1.92-12.16-2.859-18.56-2.688-21.803 0.64-41.643 14.421-49.28 36.224l-23.040 68.565-136.96-45.781 22.997-68.608c9.003-27.819-5.76-57.941-33.877-67.2-6.4-2.048-12.16-2.859-18.56-2.731-21.76 0.64-41.643 14.507-49.323 36.267l-22.997 69.077-66.603-22.357c-6.4-1.92-12.16-2.603-18.56-2.603-21.803 0.683-41.643 14.72-49.28 36.48-9.6 28.16 5.76 58.197 33.28 67.2l66.56 22.4-42.112 131.755-66.176-22.4c-6.016-2.048-12.16-2.816-18.261-2.731-21.12 0.683-41.6 14.421-48.683 36.181-8.917 27.733 5.76 57.771 33.963 67.157l66.56 22.187-23.040 68.48c-8.96 27.904 5.803 57.984 33.963 67.2 28.117 9.387 58.155-5.803 67.157-33.408l22.997-68.608 136.32 45.824-23.040 68.48c-8.917 27.52 5.76 57.6 33.664 67.157 27.819 9.003 57.984-5.76 67.2-33.749l23.040-69.163 66.347 21.76c27.776 9.344 57.856-5.76 67.2-33.237 9.301-27.904-5.76-57.984-33.451-67.2l-66.432-22.357 44.16-131.669 66.176 22.016c27.819 9.003 57.941-5.76 67.2-33.92 9.387-28.16-5.76-58.24-33.237-67.157l-0.469 1.237zM981.12 567.51c-105.6 351.701-258.091 433.92-609.963 328.277-351.701-105.557-433.92-257.963-328.277-609.963 105.6-351.787 257.963-433.92 609.963-328.277 351.787 105.6 433.92 257.963 328.277 609.963z" />
<glyph unicode="&#xe906;" glyph-name="telegram" d="M385.195 49.622c-30.464 0-25.301 11.563-35.797 40.491l-89.728 295.253 690.219 409.515zM385.195 49.622c23.552 0 33.92 10.752 47.147 23.595l125.483 121.899-156.629 94.464zM401.195 289.579l379.307-280.235c43.307-23.893 74.581-11.563 85.333 40.192l154.453 727.595c15.872 63.445-24.064 92.117-65.451 73.387l-906.837-349.739c-61.867-24.832-61.568-59.392-11.264-74.795l232.747-72.533 538.624 339.755c25.387 15.36 48.768 7.125 29.611-9.899z" />
<glyph unicode="&#xe907;" glyph-name="mattermost" d="M812.886 862.286l5.388-108.675c88.107-97.331 122.88-235.174 79.024-364.727-65.466-193.39-281.341-295.051-482.17-227.064-200.829 67.985-310.561 279.871-245.094 473.263 44.003 129.983 155.955 218.524 285.614 241.97l70.053 82.77c-218.559 5.917-424.758-129.745-498.535-347.68-90.647-267.771 52.94-558.326 320.711-648.975 267.771-90.646 558.329 52.94 648.975 320.711 73.658 217.588-7.346 450.217-183.967 578.408zM687.37 541.618l-3.711 151.926-2.976 87.421-2.013 75.737c0 0 0.422 36.521-0.854 45.102-0.268 1.806-0.838 3.275-1.511 4.559l-0.258 0.537-0.291 0.469c-1.401 2.411-3.603 4.368-6.451 5.333-2.914 0.987-5.927 0.743-8.546-0.387l-0.162-0.061c-0.311-0.141-0.608-0.299-0.907-0.463-1.241-0.604-2.503-1.387-3.738-2.585-6.226-6.042-28.077-35.308-28.077-35.308l-47.603-58.941-55.467-67.637-95.232-118.43c0 0-43.701-54.541-34.045-121.676s59.567-99.84 98.288-112.949c38.72-13.107 98.236-17.445 146.687 30.020 48.451 47.463 46.867 117.334 46.867 117.334z" />
<glyph unicode="&#xe908;" glyph-name="webhook" horiz-adv-x="1097" d="M512.168 508.059c-45.458-76.418-89.010-150.42-133.47-223.865-11.418-18.856-17.069-34.216-7.948-58.183 25.184-66.213-10.343-130.647-77.112-148.136-62.969-16.5-124.319 24.884-136.812 92.301-11.071 59.67 35.236 118.166 101.028 127.494 5.51 0.788 11.14 0.878 20.403 1.572l100.077 167.815c-62.943 62.588-100.407 135.746-92.117 226.405 5.861 64.083 31.063 119.464 77.121 164.854 88.218 86.924 222.802 100.998 326.675 34.28 99.76-64.087 145.45-188.92 106.504-295.763-29.366 7.961-58.937 15.99-91.444 24.807 12.228 59.404 3.183 112.746-36.881 158.445-26.47 30.171-60.437 45.985-99.057 51.812-77.429 11.697-153.449-38.046-176.007-114.045-25.604-86.247 13.149-156.705 119.040-209.799zM641.992 598.432c32.027-56.5 64.546-113.852 96.774-170.677 162.896 50.398 285.716-39.777 329.777-136.32 53.222-116.62 16.838-254.743-87.682-326.692-107.284-73.856-242.961-61.238-338.012 33.638 24.225 20.278 48.569 40.647 74.58 62.408 93.882-60.805 175.994-57.943 236.954 14.062 51.984 61.427 50.857 153.016-2.635 213.153-61.731 69.396-144.417 71.512-244.366 4.897-41.461 73.556-83.642 146.525-123.792 220.613-13.539 24.97-28.483 39.46-58.997 44.743-50.955 8.835-83.852 52.592-85.827 101.615-1.941 48.483 26.624 92.309 71.268 109.383 44.225 16.919 96.123 3.265 125.87-34.336 24.31-30.72 32.035-65.296 19.242-103.183-3.556-10.566-8.162-20.788-13.153-33.308zM718.539 136.564h-196.101c-18.796-77.309-59.396-139.726-129.349-179.417-54.383-30.848-112.995-41.307-175.377-31.234-114.859 18.522-208.775 121.919-217.044 238.346-9.357 131.894 81.298 249.13 202.134 275.463 8.342-30.296 16.774-60.883 25.116-91.105-110.865-56.564-149.237-127.832-118.209-216.949 27.314-78.423 104.901-121.41 189.147-104.786 86.033 16.975 129.409 88.475 124.113 203.222 81.56 0 163.188 0.844 244.756-0.416 31.851-0.501 56.44 2.802 80.433 30.883 39.503 46.204 112.215 42.035 154.76-1.602 43.479-44.597 41.397-116.354-4.614-159.070-44.392-41.217-114.524-39.015-156.058 5.398-8.535 9.152-15.261 20.021-23.706 31.268z" />
<glyph unicode="&#xe909;" glyph-name="pushbullet" d="M512 938.667c-282.768 0-512-229.232-512-512s229.232-512 512-512c282.768 0 512 229.232 512 512s-229.232 512-512 512zM308 681.599h13.336c66.932 0 66.932 0 66.932-66.932v-367.468c0-66.932 0-66.932-66.932-66.932h-13.336c-66.932 0-66.932 0-66.932 66.932v367.468c0 66.932 0 66.932 66.932 66.932zM484.164 681.599h150.148c128.712 0 210.512-129.092 210.512-252.1s-82.512-249.232-210.512-249.232h-150.148c-22.796 0-34.032 11.236-34.032 34.032v433.272c0 22.792 11.236 34.028 34.032 34.028z" />
<glyph unicode="&#xe90a;" glyph-name="email" d="M512.021 938.667c-0.002 0-0.005 0-0.008 0-282.777 0-512.013-229.236-512.013-512.013 0-0.003 0-0.006 0-0.008v0c0.020-282.762 229.248-511.979 512.013-511.979 0.003 0 0.006 0 0.008 0v0c0.002 0 0.005 0 0.008 0 282.765 0 511.993 229.216 512.013 511.977v0.002c0 0.002 0 0.005 0 0.008 0 282.777-229.236 512.013-512.013 512.013-0.003 0-0.006 0-0.008 0v0zM515.875 776.257c172.986 0 324.563-149.864 344.259-323.278 1.285-11.133 1.712-21.837 1.712-31.685 0-89.062-50.526-177.268-145.154-177.268-41.962 0-75.788 17.555-99.767 48.385-29.116-25.691-68.509-45.387-115.609-45.387-103.62 0-182.406 82.639-182.406 186.26 0 92.916 81.783 178.98 173.842 178.98 38.108 0 72.363-9.848 101.051-28.26 5.994 17.127 21.837 29.117 40.249 29.117 23.55 0 42.818-19.268 42.818-42.818v-209.81c0-14.986 18.84-29.545 39.821-29.545 39.821 0 58.661 44.959 58.661 89.919 0 146.438-126.742 266.33-259.479 266.33-155.431 0-268.471-124.601-268.471-258.622 0-142.157 105.333-264.189 255.197-264.189 30.401 0 61.23 5.995 93.772 17.127 10.276 3.425 19.268 5.994 27.832 5.994 22.694 0 34.255-17.127 34.255-39.821 0-22.266-11.989-39.393-32.542-47.1-41.534-15.843-82.639-23.55-123.317-23.55-197.821 0-340.405 164.85-340.405 350.254 0 174.271 146.010 348.969 353.679 348.969zM497.891 525.77c-50.954 0-93.344-44.103-93.344-95.913 0-51.382 37.68-96.769 93.344-96.769 53.951 0 93.772 41.962 94.628 95.485-0.427 53.951-41.962 97.197-94.628 97.197z" />


BIN
static/fonts/icomoon.ttf View File


BIN
static/fonts/icomoon.woff View File


BIN
static/img/integrations/mattermost.png View File

Before After
Width: 96  |  Height: 96  |  Size: 3.1 KiB

BIN
static/img/integrations/setup_mattermost_1.png View File

Before After
Width: 523  |  Height: 401  |  Size: 37 KiB

BIN
static/img/integrations/setup_mattermost_2.png View File

Before After
Width: 959  |  Height: 747  |  Size: 46 KiB

BIN
static/img/integrations/setup_mattermost_3.png View File

Before After
Width: 965  |  Height: 443  |  Size: 32 KiB

+ 11
- 0
templates/front/channels.html View File

@ -100,6 +100,8 @@
{% if ch.whatsapp_notify_up and not ch.whatsapp_notify_down %}
(up only)
{% endif %}
{% elif ch.kind == "mattermost" %}
Mattermost
{% else %}
{{ ch.kind }}
{% endif %}
@ -348,6 +350,15 @@
<a href="{% url 'hc-add-whatsapp' %}" class="btn btn-primary">Add Integration</a>
</li>
{% endif %}
<li>
<img src="{% static 'img/integrations/mattermost.png' %}"
class="icon" alt="Mattermost icon" />
<h2>Mattermost</h2>
<p>High Trust Messaging for the Enterprise.</p>
<a href="{% url 'hc-add-mattermost' %}" class="btn btn-primary">Add Integration</a>
</li>
<li class="link-to-github">
<img src="{% static 'img/integrations/missing.png' %}"
class="icon" alt="Suggest New Integration" />


+ 97
- 0
templates/integrations/add_mattermost.html View File

@ -0,0 +1,97 @@
{% extends "base.html" %}
{% load humanize static hc_extras %}
{% block title %}Add Mattermost - {% site_name %}{% endblock %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<h1>Mattermost</h1>
<p>If your team uses <a href="https://mattermost.com/">Mattermost</a>, you can set
up {% site_name %} to post status updates directly to an appropriate
Mattermost channel.</p>
<h2>Setup Guide</h2>
<div class="row ai-step">
<div class="col-sm-6">
<span class="step-no">1</span>
Log into your Mattermost account and
select <strong>Integrations</strong> in the
hamburger menu.
</div>
<div class="col-sm-6">
<img
class="ai-guide-screenshot"
alt="Screenshot"
src="{% static 'img/integrations/setup_mattermost_1.png' %}">
</div>
</div>
<div class="row ai-step">
<div class="col-sm-6">
<span class="step-no">2</span>
<p>
In the "Integrations" screen, select <strong>Incoming Webhook</strong>
and then <strong>Add Incoming Webhook</strong>.
</p>
<p>Fill in the form and hit "Save".</p>
</div>
<div class="col-sm-6">
<img
class="ai-guide-screenshot"
alt="Screenshot"
src="{% static 'img/integrations/setup_mattermost_2.png' %}">
</div>
</div>
<div class="row ai-step">
<div class="col-sm-6">
<span class="step-no">3</span>
<p>Copy the displayed <strong>URL</strong> and paste it down below.</p>
<p>Save the integration, and it's done!</p>
</div>
<div class="col-sm-6">
<img
class="ai-guide-screenshot"
alt="Screenshot"
src="{% static 'img/integrations/setup_mattermost_3.png' %}">
</div>
</div>
<h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-mattermost' %}">
{% csrf_token %}
<div class="form-group {{ form.value.css_classes }}">
<label for="callback-url" class="col-sm-2 control-label">
Webhook URL
</label>
<div class="col-sm-10">
<input
id="callback-url"
type="text"
class="form-control"
name="value"
placeholder="https://"
value="{{ form.value.value|default:"" }}">
{% if form.value.errors %}
<div class="help-block">
{{ form.value.errors|join:"" }}
</div>
{% endif %}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Save Integration</button>
</div>
</div>
</form>
</div>
</div>
{% endblock %}

Loading…
Cancel
Save