Browse Source

Nicer HipChat alerts.

pull/133/head
Pēteris Caune 7 years ago
parent
commit
40bc11782e
8 changed files with 83 additions and 38 deletions
  1. +2
    -6
      hc/api/transports.py
  2. +2
    -24
      hc/front/views.py
  3. BIN
      static/img/down.png
  4. BIN
      static/img/logo-512-green.png
  5. BIN
      static/img/up.png
  6. +24
    -0
      templates/integrations/hipchat_capabilities.json
  7. +0
    -8
      templates/integrations/hipchat_message.html
  8. +55
    -0
      templates/integrations/hipchat_message.json

+ 2
- 6
hc/api/transports.py View File

@ -170,12 +170,8 @@ class Slack(HttpTransport):
class HipChat(HttpTransport):
def notify(self, check):
text = tmpl("hipchat_message.html", check=check)
payload = {
"message": text,
"color": "green" if check.status == "up" else "red",
}
text = tmpl("hipchat_message.json", check=check)
payload = json.loads(text)
self.channel.refresh_hipchat_access_token()
return self.post(self.channel.hipchat_webhook_url, json=payload)


+ 2
- 24
hc/front/views.py View File

@ -569,30 +569,8 @@ def add_hipchat(request):
def hipchat_capabilities(request):
return JsonResponse({
"name": settings.SITE_NAME,
"description": "Get Notified When Your Cron Jobs Fail",
"key": "io.healthchecks.hipchat",
"links": {
"homepage": settings.SITE_ROOT,
"self": settings.SITE_ROOT + reverse("hc-hipchat-capabilities")
},
"capabilities": {
"installable": {
"allowGlobal": False,
"allowRoom": True,
"callbackUrl":
settings.SITE_ROOT + reverse("hc-hipchat-callback"),
"installedUrl":
settings.SITE_ROOT + reverse("hc-channels") + "?added=hipchat"
},
"hipchatApiConsumer": {
"scopes": [
"send_notification"
]
}
}
})
return render(request, "integrations/hipchat_capabilities.json", {},
content_type="application/json")
@csrf_exempt


BIN
static/img/down.png View File

Before After
Width: 64  |  Height: 64  |  Size: 1.2 KiB

BIN
static/img/logo-512-green.png View File

Before After
Width: 512  |  Height: 512  |  Size: 7.5 KiB Width: 512  |  Height: 512  |  Size: 8.3 KiB

BIN
static/img/up.png View File

Before After
Width: 64  |  Height: 64  |  Size: 1.1 KiB

+ 24
- 0
templates/integrations/hipchat_capabilities.json View File

@ -0,0 +1,24 @@
{% load hc_extras staticfiles %}
{
"name": "{% site_name %}",
"description": "Get Notified When Your Cron Jobs Fail",
"key": "io.healthchecks.hipchat",
"links": {
"homepage": "{% site_root %}",
"self": "{% site_root %}{% url 'hc-hipchat-capabilities' %}"
},
"capabilities": {
"installable": {
"allowGlobal": false,
"allowRoom": true,
"callbackUrl": "{% site_root %}{% url 'hc-hipchat-callback'%}",
"installedUrl": "{% site_root %}{% url 'hc-channels'%}?added=hipchat"
},
"hipchatApiConsumer": {
"avatar": "{% site_root %}{% static 'img/logo-512-green.png' %}",
"scopes": [
"send_notification"
]
}
}
}

+ 0
- 8
templates/integrations/hipchat_message.html View File

@ -1,8 +0,0 @@
{% load humanize %}
{% if check.status == "down" %}
The check "{{ check.name_then_code }}" is DOWN.
Last ping was {{ check.last_ping|naturaltime }}
{% else %}
The check "{{ check.name_then_code }}" received a ping and is now UP.
{% endif %}

+ 55
- 0
templates/integrations/hipchat_message.json View File

@ -0,0 +1,55 @@
{% load hc_extras humanize staticfiles %}
{
"message": "“{{ check.name_then_code|escapejs }}” is {{ check.status|upper }}.",
{% if check.status == "up" %}
"color": "green",
{% else %}
"color": "red",
{% endif %}
"card": {
"style": "application",
"url": "{% site_root %}{% url 'hc-log' check.code %}",
"format": "medium",
"id": "{{ check.code }}",
"title": "{{ check.name_then_code|escapejs }}",
"icon": {
{% if check.status == "up" %}
"url": "{% site_root %}{% static 'img/up.png' %}"
{% else %}
"url": "{% site_root %}{% static 'img/down.png' %}"
{% endif %}
},
"attributes": [
{% if check.kind == "simple" %}
{"label": "Period",
"value": {"label": "{{ check.timeout|hc_duration }}"}
},
{% elif check.kind == "cron" %}
{"label": "Schedule",
"value": {"label": "{{ check.schedule|escapejs }}"}
},
{% endif %}
{"label": "Last Ping",
{% if check.last_ping %}
"value": {"label": "{{ check.last_ping|naturaltime }}"}
{% else %}
"value": {"label": "Never"}
{% endif %}
},
{% if check.tags_list %}
{"label": "Tags",
"value": {"label": "{{ check.tags_list|join:", " }}"}
},
{% endif %}
{"label": "Total Pings",
"value": {"label": "{{ check.n_pings }}"}
}
],
"activity": {
"html": "“{{ check.name_then_code|escapejs }}” is {{ check.status|upper }}."
}
}
}

Loading…
Cancel
Save