Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft allocate checks owner #158174595 #31

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions hc/api/migrations/0051_check_check_owner.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
16 changes: 16 additions & 0 deletions hc/api/migrations/0052_merge_20180719_0757.py
Original file line number Diff line number Diff line change
@@ -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 = [
]
6 changes: 5 additions & 1 deletion hc/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand Down
15 changes: 10 additions & 5 deletions hc/api/tests/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion hc/api/tests/test_sendalerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions hc/api/tests/test_sendalerts_to_owner.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions hc/front/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions templates/front/my_checks_desktop.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@
Usage Examples
</a>
</li>
<li>
<a
href="#"
class="usage-examples"
data-url="{% url 'hc-check-owner' check.code %}">
Update owner
</a>
</li>
<li role="separator" class="divider"></li>
<li>
<a href="#" class="check-menu-remove"
Expand Down