integrations: Add Insping integration.
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 77 KiB |
|
@ -326,6 +326,7 @@ WEBHOOK_INTEGRATIONS = [
|
|||
function='zerver.webhooks.ifttt.view.api_iftt_app_webhook',
|
||||
display_name='IFTTT'
|
||||
),
|
||||
WebhookIntegration('insping', ['monitoring'], display_name='Insping'),
|
||||
WebhookIntegration('intercom', ['customer-support'], display_name='Intercom'),
|
||||
WebhookIntegration('jira', ['project-management'], display_name='JIRA'),
|
||||
WebhookIntegration('librato', ['monitoring']),
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
Get Insping notifications in Zulip! Insping (stylized as !nsping) is a
|
||||
simple uptime and performance monitoring tool, which notifies you when
|
||||
a website or service is up and running or down.
|
||||
|
||||
{!create-stream.md!}
|
||||
|
||||
{!create-bot-construct-url.md!}
|
||||
|
||||
{!append-stream-name.md!}
|
||||
|
||||
{!append-topic.md!}
|
||||
|
||||
You can configure the integration on Insping's site as follows:
|
||||
|
||||
1. Go to [Insping's website](https://www.insping.com). If you haven't
|
||||
created an account yet, sign up for a free account.
|
||||
|
||||
2. If you haven't already, create an organization in the
|
||||
[manage section](https://app.insping.com/#manage) of the Insping
|
||||
app.
|
||||
|
||||
3. Provide the URL you would like to monitor in the
|
||||
**Checks / Monitoring URLs** field, like so:
|
||||
![](/static/images/integrations/insping/001.png)
|
||||
|
||||
4. Navigate to [the integrations](https://app.insping.com/#integrations) section:
|
||||
![](/static/images/integrations/insping/002.png)
|
||||
|
||||
5. In the **Webhooks** section, click on **Create Webhook**:
|
||||
![](/static/images/integrations/insping/003.png)
|
||||
|
||||
6. In the **Webhook URL** section, provide the webhook URL constructed above.
|
||||
|
||||
7. Choose an organization that you would like to monitor:
|
||||
![](/static/images/integrations/insping/004.png)
|
||||
|
||||
8. After that, click **Create**:
|
||||
![](/static/images/integrations/insping/005.png)
|
||||
|
||||
9. Finally, to confirm that the incoming webhook works, click the
|
||||
**Test** button:
|
||||
![](/static/images/integrations/insping/006.png)
|
||||
|
||||
10. Click **Send Test Data** to confirm the webhook test.
|
||||
|
||||
{!congrats.md!}
|
||||
|
||||
![](/static/images/integrations/insping/007.png)
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"organization_name": "test",
|
||||
"webhook_event_id": 73418,
|
||||
"organization_id": 2587,
|
||||
"webhook_type": "AL",
|
||||
"webhook_event_data": {
|
||||
"check_state_name": "Available",
|
||||
"application_id": 2971,
|
||||
"check_id": 5630,
|
||||
"recently_started_check_start_time": null,
|
||||
"http_status_code": 200,
|
||||
"request_start_time": "2017-12-29T17:23:46.457990+00:00",
|
||||
"recently_started_check_state_name": null,
|
||||
"recently_started_check_http_status_code": null,
|
||||
"application_name": "test",
|
||||
"recently_started_check_response_time": null,
|
||||
"request_url": "http://privisus.zulipdev.org:9991",
|
||||
"response_time": 223
|
||||
},
|
||||
"webhook_id": 290,
|
||||
"webhook_event_created_on": "2017-12-29T17:23:47.790118+00:00"
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"organization_name": "test",
|
||||
"webhook_event_id": 73417,
|
||||
"organization_id": 2587,
|
||||
"webhook_type": "AL",
|
||||
"webhook_event_data": {
|
||||
"check_state_name": "Not Responding",
|
||||
"application_id": 2971,
|
||||
"check_id": 5630,
|
||||
"recently_started_check_start_time": null,
|
||||
"http_status_code": null,
|
||||
"request_start_time": "2017-12-29T17:13:46.788129+00:00",
|
||||
"recently_started_check_state_name": null,
|
||||
"recently_started_check_http_status_code": null,
|
||||
"application_name": "test",
|
||||
"recently_started_check_response_time": null,
|
||||
"request_url": "http://privisus.zulipdev.org:9991",
|
||||
"response_time": 942
|
||||
},
|
||||
"webhook_id": 290,
|
||||
"webhook_event_created_on": "2017-12-29T17:13:48.265870+00:00"
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from typing import Text
|
||||
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
|
||||
class InspingHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'test'
|
||||
URL_TEMPLATE = "/api/v1/external/insping?&api_key={api_key}"
|
||||
FIXTURE_DIR_NAME = 'insping'
|
||||
|
||||
def test_website_state_available_message(self) -> None:
|
||||
expected_subject = u"insping"
|
||||
expected_message = u"State changed: Available\n" \
|
||||
u"URL: http://privisus.zulipdev.org:9991\n" \
|
||||
u"Response time: 223 ms\n" \
|
||||
u"Timestamp: Fri Dec 29 17:23:46 2017"
|
||||
|
||||
self.send_and_test_stream_message('website_state_available',
|
||||
expected_subject, expected_message,
|
||||
content_type="application/x-www-form-urlencoded")
|
||||
|
||||
def test_website_state_not_responding_message(self) -> None:
|
||||
expected_subject = u"insping"
|
||||
expected_message = u"State changed: Not Responding\n" \
|
||||
u"URL: http://privisus.zulipdev.org:9991\n" \
|
||||
u"Response time: 942 ms\n" \
|
||||
u"Timestamp: Fri Dec 29 17:13:46 2017"
|
||||
|
||||
self.send_and_test_stream_message('website_state_not_responding',
|
||||
expected_subject, expected_message,
|
||||
content_type="application/x-www-form-urlencoded")
|
||||
|
||||
def get_body(self, fixture_name: Text) -> Text:
|
||||
return self.fixture_data("insping", fixture_name, file_type="json")
|
|
@ -0,0 +1,44 @@
|
|||
from django.utils.translation import ugettext as _
|
||||
from zerver.lib.actions import check_send_stream_message
|
||||
from zerver.lib.response import json_success, json_error
|
||||
from zerver.decorator import REQ, has_request_variables, \
|
||||
api_key_only_webhook_view
|
||||
from zerver.lib.validator import check_dict, check_string
|
||||
|
||||
from zerver.models import Client, UserProfile
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from typing import Dict, Any, Iterable, Optional, Text
|
||||
|
||||
import time
|
||||
|
||||
|
||||
@api_key_only_webhook_view('Insping')
|
||||
@has_request_variables
|
||||
def api_insping_webhook(
|
||||
request: HttpRequest, user_profile: UserProfile,
|
||||
payload: Dict[str, Dict[str, Any]]=REQ(argument_type='body'),
|
||||
stream: Text=REQ(default='test'),
|
||||
topic: Text=REQ(default='insping')
|
||||
) -> HttpResponse:
|
||||
|
||||
data = payload['webhook_event_data']
|
||||
|
||||
state_name = data['check_state_name']
|
||||
url_tested = data['request_url']
|
||||
response_time = data['response_time']
|
||||
timestamp = data['request_start_time']
|
||||
|
||||
time_formatted = time.strftime("%c", time.strptime(timestamp,
|
||||
"%Y-%m-%dT%H:%M:%S.%f+00:00"))
|
||||
|
||||
body = """State changed: {}
|
||||
URL: {}
|
||||
Response time: {} ms
|
||||
Timestamp: {}
|
||||
""".format(state_name, url_tested, response_time, time_formatted)
|
||||
|
||||
check_send_stream_message(user_profile, request.client,
|
||||
stream, topic, body)
|
||||
|
||||
return json_success()
|