From 44d2a9f33b6f46a704579c11a4468f2d245212f4 Mon Sep 17 00:00:00 2001 From: Divyansh Date: Tue, 7 Jul 2020 16:57:02 +0530 Subject: [PATCH] AddSpikeTestCase --- hc/api/transports.py | 5 +- hc/front/tests/test_add_spike.py | 30 ++ templates/front/channels.html | 2 +- templates/front/welcome.html | 563 +++++++++++++++---------------- 4 files changed, 313 insertions(+), 287 deletions(-) create mode 100644 hc/front/tests/test_add_spike.py diff --git a/hc/api/transports.py b/hc/api/transports.py index 05ef4ee7..884f3ce2 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -585,10 +585,9 @@ class Spike(HttpTransport): url = self.channel.value headers = {"Conent-Type": "application/json"} payload = { - "incident_key": str(check.code), "title": tmpl("spike_title.html", check=check), - "description": tmpl("spike_description.html", check=check), - "client": settings.SITE_NAME, + "message": tmpl("spike_description.html", check=check), + "status": check.status } return self.post(url, json=payload, headers=headers) diff --git a/hc/front/tests/test_add_spike.py b/hc/front/tests/test_add_spike.py new file mode 100644 index 00000000..bf7c9e72 --- /dev/null +++ b/hc/front/tests/test_add_spike.py @@ -0,0 +1,30 @@ +from hc.api.models import Channel +from hc.test import BaseTestCase + + +class AddSpikeTestCase(BaseTestCase): + url = "/integrations/add_spike/" + + def test_instructions_work(self): + self.client.login(username="alice@example.org", password="password") + r = self.client.get(self.url) + self.assertContains(r, "Spike") + + def test_it_works(self): + form = {"value": "http://example.org"} + + self.client.login(username="alice@example.org", password="password") + r = self.client.post(self.url, form) + self.assertRedirects(r, "/integrations/") + + c = Channel.objects.get() + self.assertEqual(c.kind, "spike") + self.assertEqual(c.value, "http://example.org") + self.assertEqual(c.project, self.project) + + def test_it_rejects_bad_url(self): + form = {"value": "not an URL"} + + self.client.login(username="alice@example.org", password="password") + r = self.client.post(self.url, form) + self.assertContains(r, "Enter a valid URL") \ No newline at end of file diff --git a/templates/front/channels.html b/templates/front/channels.html index caf600e5..7b5e7e34 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -361,7 +361,7 @@
  • Spike.sh icon -

    Spike

    +

    Spike.sh

    Incident Management - On-Call Schedules, Alerts, & Notifications

    Add Integration
  • diff --git a/templates/front/welcome.html b/templates/front/welcome.html index 38bdaa26..96119921 100644 --- a/templates/front/welcome.html +++ b/templates/front/welcome.html @@ -2,310 +2,299 @@ {% load compress hc_extras humanize static %} {% block description %} - + {% endblock %} {% block head %} - + {% endblock %} {% block containers %}
    -
    -
    -
    -

    - Monitoring for your nightly backups, - weekly reports, cron jobs and background tasks.

    -
    -
    - -
    -
    -

    - Make HTTP requests to the Ping URL at regular intervals. - - When the URL is not pinged on time, - {% site_name %} will send you an alert. - - - You can monitor any service that can make HTTP requests - or send emails. -

    -
    -
    -

    - For each of your periodic tasks, - {% site_name %} provides an unique URL like this one: -

    -
    - {{ ping_url }} +
    +
    +
    +

    + Monitoring for your nightly backups, + weekly reports, cron jobs and background tasks.

    +
    -
    -
    -
    -
    - -
    -
    - {% include "front/snippets/crontab.html" %} -
    -
    - {% include "front/snippets/bash_curl.html" %} - {% include "front/snippets/bash_wget.html" %} -
    -
    - {% include "front/snippets/python_urllib2.html" %} - {% include "front/snippets/python_requests.html" %} -
    -
    - {% include "front/snippets/ruby.html" %} -
    -
    - {% include "front/snippets/node.html" %} -
    -
    - {% include "front/snippets/go.html" %} -
    -
    - {% include "front/snippets/php.html" %} -
    -
    - {% include "front/snippets/cs.html" %} -
    -
    - {% include "front/snippets/browser.html" %} -
    -
    - {% include "front/snippets/powershell.html" %} - {% include "front/snippets/powershell_inline.html" %} +
    +
    +

    + Make HTTP requests to the Ping URL at regular intervals. + + When the URL is not pinged on time, + {% site_name %} will send you an alert. + + + You can monitor any service that can make HTTP requests + or send emails. +

    +
    +
    +

    + For each of your periodic tasks, + {% site_name %} provides an unique URL like this one: +

    +
    + {{ ping_url }}
    -
    -

    - As an alternative to HTTP and HTTPS requests, - you can "ping" this check by sending an - email message to - {{ check.email }} -

    +
    +
    + +
    +
    + +
    +
    + {% include "front/snippets/crontab.html" %} +
    +
    + {% include "front/snippets/bash_curl.html" %} + {% include "front/snippets/bash_wget.html" %} +
    +
    + {% include "front/snippets/python_urllib2.html" %} + {% include "front/snippets/python_requests.html" %} +
    +
    + {% include "front/snippets/ruby.html" %} +
    +
    + {% include "front/snippets/node.html" %} +
    +
    + {% include "front/snippets/go.html" %} +
    +
    + {% include "front/snippets/php.html" %} +
    +
    + {% include "front/snippets/cs.html" %} +
    +
    + {% include "front/snippets/browser.html" %} +
    +
    + {% include "front/snippets/powershell.html" %} + {% include "front/snippets/powershell_inline.html" %} +
    +
    +

    + As an alternative to HTTP and HTTPS requests, + you can "ping" this check by sending an + email message to + {{ check.email }} +

    +
    -
    {% if registration_open %}
    -
    -
    -
    -

    {% site_name %} monitors the heartbeat messages sent by your cron jobs, services and APIs. - Get immediate alerts when they don't arrive on schedule.

    - - Sign Up – It's Free - +
    +
    +
    +

    {% site_name %} monitors the heartbeat messages sent by your cron jobs, services and APIs. + Get immediate alerts when they don't arrive on schedule.

    + + Sign Up – It's Free + +
    -
    {% endif %}
    -
    -

    A quick peek of what's inside:

    -
    +
    +

    A quick peek of what's inside:

    +
    -
    - My Checks page -
    -
    -

    Live-updating Dashboard

    -

    - A list of your checks, one for each Cron job, daemon or - scheduled task you want to monitor. -

    -

    - Give names and assign tags to your checks to easily recognize - them later. -

    -

    - Tap on the integration icons to toggle them on and off. -

    -

    - Adjust Period and Grace time to match the - periodicity and duration of your tasks. -

    -
    +
    + My Checks page +
    +
    +

    Live-updating Dashboard

    +

    + A list of your checks, one for each Cron job, daemon or + scheduled task you want to monitor. +

    +

    + Give names and assign tags to your checks to easily recognize + them later. +

    +

    + Tap on the integration icons to toggle them on and off. +

    +

    + Adjust Period and Grace time to match the + periodicity and duration of your tasks. +

    +
    -
    - Period/Grace Time dialog -
    -
    -

    Simple Configuration

    - Each check has configurable Period and Grace Time parameters. - Depending on these parameters and time since the last ping, the check is in one of the - following states: - - - - - - - - - - - - - - - - - - -
    - - - New. - A check that has been created, but has not received any pings yet. -
    - - - Up. - Time since last ping has not exceeded Period. -
    - - - Late. - Time since last ping has exceeded Period, - but has not yet exceeded Period + Grace. -
    - - - Down. - Time since last ping has exceeded Period + Grace. - When check goes from "Late" to "Down", {% site_name %} - sends you a notification. -
    +
    + Period/Grace Time dialog +
    +
    +

    Simple Configuration

    + Each check has configurable Period and Grace Time parameters. + Depending on these parameters and time since the last ping, the check is in one of the + following states: + + + + + + + + + + + + + + + + + + +
    + + + New. + A check that has been created, but has not received any pings yet. +
    + + + Up. + Time since last ping has not exceeded Period. +
    + + + Late. + Time since last ping has exceeded Period, + but has not yet exceeded Period + Grace. +
    + + + Down. + Time since last ping has exceeded Period + Grace. + When check goes from "Late" to "Down", {% site_name %} + sends you a notification. +
    -
    +
    -
    - Cron dialog -
    -
    -

    Cron Expression Support

    -

    - Alternatively, you can define the expected ping dates and times - using a cron expression. See - Cron Syntax Cheatsheet - for the supported syntax features. -

    -

    - Grace Time specifies how "late" a ping can - be before you will be alerted. Set it to be a little above - the expected duration of your cron job. -

    -
    +
    + Cron dialog +
    +
    +

    Cron Expression Support

    +

    + Alternatively, you can define the expected ping dates and times + using a cron expression. See + Cron Syntax Cheatsheet + for the supported syntax features. +

    +

    + Grace Time specifies how "late" a ping can + be before you will be alerted. Set it to be a little above + the expected duration of your cron job. +

    +
    -
    - Details Page -
    -
    -

    Details and Event Log

    -

    - You can add a longer, free-form description to each - check. Leave notes and pointers for yourself and - for your team. -

    -

    - You can also see the log of received pings and - sent "Down" notifications. -

    -
    +
    + Details Page +
    +
    +

    Details and Event Log

    +

    + You can add a longer, free-form description to each + check. Leave notes and pointers for yourself and + for your team. +

    +

    + You can also see the log of received pings and + sent "Down" notifications. +

    +
    -
    - Details Page -
    -
    -

    Public Status Badges

    -

    - {% site_name %} provides status badges for each of the tags - you have used. Additionally, the "{% site_name %}" badge - shows the overall status of all checks in your account. -

    -

    - The badges have public, but hard-to-guess URLs. - You can use them in your READMEs, dashboards or status pages. -

    -
    +
    + Details Page +
    +
    +

    Public Status Badges

    +

    + {% site_name %} provides status badges for each of the tags + you have used. Additionally, the "{% site_name %}" badge + shows the overall status of all checks in your account. +

    +

    + The badges have public, but hard-to-guess URLs. + You can use them in your READMEs, dashboards or status pages. +

    +
    @@ -412,6 +401,14 @@
    +
    +
    + +

    Spike.sh
    Incident Management and Alerts

    +
    +
    + +
    @@ -504,9 +501,9 @@

    Cron Jobs

    {% site_name %} monitoring is a great fit for cron jobs and cron-like systems - (systemd timers, Jenkins build jobs, Windows Scheduled Tasks, wp-cron, uwsgi cron-like - interface, Heroku Scheduler, ...). A failed cron job often has no immediate visible - consequences, and can go unnoticed for a long time.

    + (systemd timers, Jenkins build jobs, Windows Scheduled Tasks, wp-cron, uwsgi cron-like + interface, Heroku Scheduler, ...). A failed cron job often has no immediate visible + consequences, and can go unnoticed for a long time.

    Specific examples:

      @@ -523,9 +520,9 @@

      Processes, Services, Servers

      {% site_name %} monitoring can be used for lightweight server monitoring: - ensuring a particular system service, or the server as a whole is alive and healthy. - Write a shell script that checks for a specific condition, and pings {% site_name %} - if successful. Run the shell script regularly.

      + ensuring a particular system service, or the server as a whole is alive and healthy. + Write a shell script that checks for a specific condition, and pings {% site_name %} + if successful. Run the shell script regularly.

      Specific examples:

        @@ -541,21 +538,21 @@
        - {% if registration_open %} -
        @@ -572,4 +569,4 @@ {% endcompress %} -{% endblock %} +{% endblock %} \ No newline at end of file