Browse Source

Add more views

pull/229/head
Michal Bryc 6 years ago
parent
commit
6f1ade98e2
10 changed files with 66 additions and 2 deletions
  1. +1
    -1
      hc/api/migrations/0058_auto_20190312_1716.py
  2. +3
    -0
      hc/api/models.py
  3. +12
    -0
      hc/api/tests/test_notify.py
  4. +18
    -0
      hc/api/transports.py
  5. +1
    -0
      hc/front/urls.py
  6. +17
    -0
      hc/front/views.py
  7. +2
    -0
      templates/front/channels.html
  8. +3
    -1
      templates/front/details_events.html
  9. +2
    -0
      templates/front/log.html
  10. +7
    -0
      templates/front/welcome.html

+ 1
- 1
hc/api/migrations/0058_auto_20190312_1716.py View File

@ -13,6 +13,6 @@ class Migration(migrations.Migration):
migrations.AlterField( migrations.AlterField(
model_name='channel', model_name='channel',
name='kind', name='kind',
field=models.CharField(choices=[('email', 'Email'), ('webhook', 'Webhook'), ('hipchat', 'HipChat'), ('slack', 'Slack'), ('pd', 'PagerDuty'), ('pagertree', 'PagerTree'), ('po', 'Pushover'), ('pushbullet', 'Pushbullet'), ('opsgenie', 'OpsGenie'), ('victorops', 'VictorOps'), ('discord', 'Discord'), ('telegram', 'Telegram'), ('sms', 'SMS'), ('zendesk', 'Zendesk'), ('trello', 'Trello'), ('matrix', 'Matrix')], max_length=20),
field=models.CharField(choices=[('email', 'Email'), ('webhook', 'Webhook'), ('hipchat', 'HipChat'), ('slack', 'Slack'), ('pd', 'PagerDuty'), ('pagertree', 'PagerTree'), ('pagerteam', 'PagerTeam') ('po', 'Pushover'), ('pushbullet', 'Pushbullet'), ('opsgenie', 'OpsGenie'), ('victorops', 'VictorOps'), ('discord', 'Discord'), ('telegram', 'Telegram'), ('sms', 'SMS'), ('zendesk', 'Zendesk'), ('trello', 'Trello'), ('matrix', 'Matrix')], max_length=20),
), ),
] ]

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

@ -33,6 +33,7 @@ CHANNEL_KINDS = (("email", "Email"),
("slack", "Slack"), ("slack", "Slack"),
("pd", "PagerDuty"), ("pd", "PagerDuty"),
("pagertree", "PagerTree"), ("pagertree", "PagerTree"),
("pagerteam", "PagerTeam"),
("po", "Pushover"), ("po", "Pushover"),
("pushbullet", "Pushbullet"), ("pushbullet", "Pushbullet"),
("opsgenie", "OpsGenie"), ("opsgenie", "OpsGenie"),
@ -322,6 +323,8 @@ class Channel(models.Model):
return transports.PagerDuty(self) return transports.PagerDuty(self)
elif self.kind == "pagertree": elif self.kind == "pagertree":
return transports.PagerTree(self) return transports.PagerTree(self)
elif self.kind == "pagerteam":
return transports.PagerTeam(self)
elif self.kind == "victorops": elif self.kind == "victorops":
return transports.VictorOps(self) return transports.VictorOps(self)
elif self.kind == "pushbullet": elif self.kind == "pushbullet":


+ 12
- 0
hc/api/tests/test_notify.py View File

@ -294,6 +294,18 @@ class NotifyTestCase(BaseTestCase):
payload = kwargs["json"] payload = kwargs["json"]
self.assertEqual(payload["event_type"], "trigger") self.assertEqual(payload["event_type"], "trigger")
@patch("hc.api.transports.requests.request")
def test_pagerteam(self, mock_post):
self._setup_data("pagerteam", "123")
mock_post.return_value.status_code = 200
self.channel.notify(self.check)
assert Notification.objects.count() == 1
args, kwargs = mock_post.call_args
payload = kwargs["json"]
self.assertEqual(payload["event_type"], "trigger")
@patch("hc.api.transports.requests.request") @patch("hc.api.transports.requests.request")
def test_slack(self, mock_post): def test_slack(self, mock_post):
self._setup_data("slack", "123") self._setup_data("slack", "123")


+ 18
- 0
hc/api/transports.py View File

@ -269,6 +269,24 @@ class PagerTree(HttpTransport):
return self.post(url, json=payload, headers=headers) return self.post(url, json=payload, headers=headers)
class PagerTeam(HttpTransport):
def notify(self, check):
url = self.channel.value
headers = {
"Conent-Type": "application/json"
}
payload = {
"incident_key": str(check.code),
"event_type": "trigger" if check.status == "down" else "resolve",
"title": tmpl("pagerteam_title.html", check=check),
"description": tmpl("pagerteam_description.html", check=check),
"client": settings.SITE_NAME,
"client_url": settings.SITE_ROOT,
"tags": ",".join(check.tags_list())
}
return self.post(url, json=payload, headers=headers)
class Pushbullet(HttpTransport): class Pushbullet(HttpTransport):
def notify(self, check): def notify(self, check):


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

@ -24,6 +24,7 @@ channel_urls = [
path('add_pd/', views.add_pd, name="hc-add-pd"), path('add_pd/', views.add_pd, name="hc-add-pd"),
path('add_pd/<str:state>/', views.add_pd, name="hc-add-pd-state"), path('add_pd/<str:state>/', views.add_pd, name="hc-add-pd-state"),
path('add_pagertree/', views.add_pagertree, name="hc-add-pagertree"), 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_slack/', views.add_slack, name="hc-add-slack"),
path('add_slack_btn/', views.add_slack_btn, name="hc-add-slack-btn"), 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_pushbullet/', views.add_pushbullet, name="hc-add-pushbullet"),


+ 17
- 0
hc/front/views.py View File

@ -749,6 +749,23 @@ def add_pagertree(request):
ctx = {"page": "channels", "form": form} ctx = {"page": "channels", "form": form}
return render(request, "integrations/add_pagertree.html", ctx) return render(request, "integrations/add_pagertree.html", ctx)
@login_required
def add_pagerteam(request):
if request.method == "POST":
form = AddUrlForm(request.POST)
if form.is_valid():
channel = Channel(project=request.project, kind="pagerteam")
channel.value = form.cleaned_data["value"]
channel.save()
channel.assign_all_checks()
return redirect("hc-channels")
else:
form = AddUrlForm()
ctx = {"page": "channels", "form": form}
return render(request, "integrations/add_pagerteam.html", ctx)
def add_slack(request): def add_slack(request):
if not settings.SLACK_CLIENT_ID and not request.user.is_authenticated: if not settings.SLACK_CLIENT_ID and not request.user.is_authenticated:


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

@ -47,6 +47,8 @@
PagerDuty account <span>{{ ch.pd_account }}</span> PagerDuty account <span>{{ ch.pd_account }}</span>
{% elif ch.kind == "pagertree" %} {% elif ch.kind == "pagertree" %}
PagerTree PagerTree
{% elif ch.kind == "pagerteam" %}
PagerTeam
{% elif ch.kind == "opsgenie" %} {% elif ch.kind == "opsgenie" %}
OpsGenie OpsGenie
{% elif ch.kind == "victorops" %} {% elif ch.kind == "victorops" %}


+ 3
- 1
templates/front/details_events.html View File

@ -64,6 +64,8 @@
Sent alert to PagerDuty Sent alert to PagerDuty
{% elif event.channel.kind == "pagertree" %} {% elif event.channel.kind == "pagertree" %}
Sent alert to PagerTree Sent alert to PagerTree
{% elif event.channel.kind == "pagerteam" %}
Sent alert to Pager Team
{% elif event.channel.kind == "opsgenie" %} {% elif event.channel.kind == "opsgenie" %}
Sent alert to OpsGenie Sent alert to OpsGenie
{% elif event.channel.kind == "hipchat" %} {% elif event.channel.kind == "hipchat" %}
@ -92,4 +94,4 @@
{% endif %} {% endif %}
{% else %} {% else %}
<div class="alert alert-info">This check has not received any pings yet.</div> <div class="alert alert-info">This check has not received any pings yet.</div>
{% endif %}
{% endif %}

+ 2
- 0
templates/front/log.html View File

@ -107,6 +107,8 @@
Sent alert to PagerDuty Sent alert to PagerDuty
{% elif event.channel.kind == "pagertree" %} {% elif event.channel.kind == "pagertree" %}
Sent alert to PagerTree Sent alert to PagerTree
{% elif event.channel.kind == "pagerteam" %}
Sent alert to Pager Team
{% elif event.channel.kind == "opsgenie" %} {% elif event.channel.kind == "opsgenie" %}
Sent alert to OpsGenie Sent alert to OpsGenie
{% elif event.channel.kind == "hipchat" %} {% elif event.channel.kind == "hipchat" %}


+ 7
- 0
templates/front/welcome.html View File

@ -399,6 +399,13 @@
</div> </div>
</div> </div>
<div class="col-md-2 col-sm-4 col-xs-6">
<div class="integration">
<img src="{% static 'img/integrations/pagerteam.png' %}" class="icon" alt="Pager Team icon" />
<h3>Pager Team <br><small>On-call rotations without limits</small></h3>
</div>
</div>
{% if enable_trello %} {% if enable_trello %}
<div class="col-md-2 col-sm-4 col-xs-6"> <div class="col-md-2 col-sm-4 col-xs-6">
<div class="integration"> <div class="integration">


Loading…
Cancel
Save