diff --git a/hc/api/migrations/0051_check_check_owner.py b/hc/api/migrations/0051_check_check_owner.py new file mode 100644 index 00000000..92eab4f0 --- /dev/null +++ b/hc/api/migrations/0051_check_check_owner.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2018-07-17 11:52 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0050_merge_20180716_0922'), + ] + + operations = [ + migrations.AddField( + model_name='check', + name='check_owner', + field=models.CharField(blank=True, max_length=100, null=True), + ), + ] diff --git a/hc/api/migrations/0052_merge_20180719_0757.py b/hc/api/migrations/0052_merge_20180719_0757.py new file mode 100644 index 00000000..03e68f65 --- /dev/null +++ b/hc/api/migrations/0052_merge_20180719_0757.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2018-07-19 07:57 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0051_check_check_owner'), + ('api', '0051_merge_20180716_1254'), + ] + + operations = [ + ] diff --git a/hc/api/models.py b/hc/api/models.py index 85f2f5f9..e23b7e70 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -66,6 +66,7 @@ class Meta: escalate = models.BooleanField(default=False) twilio_number = models.TextField(default="+00000000000", null=True, blank=True) + check_owner = models.CharField(max_length=100, blank=True, null=True) def name_then_code(self): if self.name: @@ -111,7 +112,10 @@ def send_alert(self): errors.append((channel, error)) else: - for channel in self.channel_set.all(): + # use email check user + user = User.objects.get(email=self.check_owner) + channels = Channel.objects.filter(user=user) + for channel in channels: error = channel.notify(self) if error not in ("", "no-op"): errors.append((channel, error)) diff --git a/hc/api/tests/test_protocols.py b/hc/api/tests/test_protocols.py index 541af39a..8e6e689a 100644 --- a/hc/api/tests/test_protocols.py +++ b/hc/api/tests/test_protocols.py @@ -26,7 +26,8 @@ def test_it_handles_protocol_list(self): channel = Channel(user=self.bob, kind="email", value="bob@example.com") channel.save() - check = Check(user=self.alice, status="down") + check = Check(user=self.alice, status="down", + check_owner="bob@example.org") check.last_ping = timezone.now() - timedelta(minutes=300) check.number_of_nags = 5 check.priority = 3 @@ -41,11 +42,15 @@ def test_it_handles_many_checks_protocol_list(self): """ test it escalates """ - channel = Channel(user=self.bob, kind="email", value="bob@example.com") + channel = Channel(user=self.bob, kind="email", + value="bob@example.com") channel.save() - check = Check(user=self.alice, status="down") - check1 = Check(user=self.alice, status="down") - check2 = Check(user=self.alice, status="down") + check = Check(user=self.alice, status="down", + check_owner="bob@example.org") + check1 = Check(user=self.alice, status="down", + check_owner="bob@example.org") + check2 = Check(user=self.alice, status="down", + check_owner="bob@example.org") check.last_ping = timezone.now() - timedelta(minutes=300) check1.last_ping = timezone.now() - timedelta(minutes=300) check2.last_ping = timezone.now() - timedelta(minutes=300) diff --git a/hc/api/tests/test_sendalerts.py b/hc/api/tests/test_sendalerts.py index 97458baa..3fca3a62 100644 --- a/hc/api/tests/test_sendalerts.py +++ b/hc/api/tests/test_sendalerts.py @@ -33,7 +33,8 @@ def test_it_handles_few(self, mock): @patch("hc.api.management.commands.sendalerts.Command.handle_many") def test_it_handles_grace_period(self, mock): - check = Check(user=self.alice, status="up") + check = Check(user=self.alice, status="up", + check_owner="bob@example.org") # 1 day 30 minutes after ping the check is in grace period: check.last_ping = timezone.now() - timedelta(days=1, minutes=30) diff --git a/hc/api/tests/test_sendalerts_to_owner.py b/hc/api/tests/test_sendalerts_to_owner.py new file mode 100644 index 00000000..3a388753 --- /dev/null +++ b/hc/api/tests/test_sendalerts_to_owner.py @@ -0,0 +1,38 @@ +from datetime import timedelta + +from django.utils import timezone +from hc.api.models import Check, Channel +from hc.test import BaseTestCase +from mock import patch +from django.contrib.auth.hashers import make_password + + +def fake_twilio_notify(): + pass + + +class SendOwnerAlertsTestCase(BaseTestCase): + + def setUp(self): + super(SendOwnerAlertsTestCase, self).setUp() + self.profile.token = make_password("secret-token") + self.profile.save() + + @patch("hc.api.transports.TwilioSms.notify", fake_twilio_notify()) + def test_it_handles_check_owner(self): + """ + test it sends notifications to assigned owner + """ + channel = Channel(user=self.bob, kind="email", + value="bob@example.org") + channel.save() + check = Check(user=self.alice, status="down", + check_owner="bob@example.org") + check.last_ping = timezone.now() - timedelta(minutes=30) + check.number_of_nags = 2 + check.priority = 3 + check.save() + check.send_alert() + + self.assertFalse(check.escalate) + assert check.number_of_nags == 3 diff --git a/hc/front/views.py b/hc/front/views.py index 8ae49288..59080b72 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -55,11 +55,13 @@ def my_checks(request): grace_tags.add(tag) state = {1: "low", 2: "medium", 3: "high"} + # list of all team members #members = ctx = { "page": "checks", "checks": checks, "state": state, + # "team_members":members, "now": timezone.now(), "tags": counter.most_common(), "down_tags": down_tags, diff --git a/templates/front/my_checks_desktop.html b/templates/front/my_checks_desktop.html index 16ed3fea..2552e267 100644 --- a/templates/front/my_checks_desktop.html +++ b/templates/front/my_checks_desktop.html @@ -170,6 +170,14 @@ Usage Examples +
  • + + Update owner + +