diff --git a/hc/api/transports.py b/hc/api/transports.py index 0d5585e7..98be7d53 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -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) diff --git a/hc/front/views.py b/hc/front/views.py index 31063be7..6eb24d85 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -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 diff --git a/static/img/down.png b/static/img/down.png new file mode 100644 index 00000000..468da711 Binary files /dev/null and b/static/img/down.png differ diff --git a/static/img/logo-512-green.png b/static/img/logo-512-green.png index cd749c33..7250adca 100644 Binary files a/static/img/logo-512-green.png and b/static/img/logo-512-green.png differ diff --git a/static/img/up.png b/static/img/up.png new file mode 100644 index 00000000..ae06aa11 Binary files /dev/null and b/static/img/up.png differ diff --git a/templates/integrations/hipchat_capabilities.json b/templates/integrations/hipchat_capabilities.json new file mode 100644 index 00000000..cceabd84 --- /dev/null +++ b/templates/integrations/hipchat_capabilities.json @@ -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" + ] + } + } +} \ No newline at end of file diff --git a/templates/integrations/hipchat_message.html b/templates/integrations/hipchat_message.html deleted file mode 100644 index cfdd8afa..00000000 --- a/templates/integrations/hipchat_message.html +++ /dev/null @@ -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 %} diff --git a/templates/integrations/hipchat_message.json b/templates/integrations/hipchat_message.json new file mode 100644 index 00000000..cc46ef2d --- /dev/null +++ b/templates/integrations/hipchat_message.json @@ -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 }}." + } + } +}