From d17beadb1d3668b4833c5a85f66cd22491707585 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Tue, 5 Apr 2022 14:24:32 +0200
Subject: [PATCH] L2SS-685: Prepare alerta to recognise stations as resources

---
 docker-compose/alerta-web/alertad.conf                 | 6 +++---
 docker-compose/alerta-web/lofar-plugin/alerta_lofar.py | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/docker-compose/alerta-web/alertad.conf b/docker-compose/alerta-web/alertad.conf
index 2e95d1428..735a84fc2 100644
--- a/docker-compose/alerta-web/alertad.conf
+++ b/docker-compose/alerta-web/alertad.conf
@@ -16,7 +16,7 @@ DATE_FORMAT_MEDIUM_DATE = "dd DD/MM HH:mm"
 DATE_FORMAT_LONG_DATE   = "yyyy-MM-DD HH:mm:ss.sss"
 
 # Default overview settings
-COLUMNS = ['severity', 'status', 'lastReceiveTime', 'environment', 'resource', 'lofarDevice', 'lofarAttribute', 'event', 'text']
+COLUMNS = ['severity', 'status', 'lastReceiveTime', 'resource', 'lofarDevice', 'lofarAttribute', 'event', 'text']
 DEFAULT_FILTER = {'status': ['open']}
 SORT_LIST_BY = "createTime"
 AUTO_REFRESH_INTERVAL = 5000 # ms
@@ -44,13 +44,13 @@ BASE_URL = os.environ.get("BASE_URL", "")
 SLACK_PAYLOAD = {
   "channel": "{{ channel }}",
   "emoji": ":fire:",
-  "text": "*{{ alert.severity|capitalize }}* :: _{{ alert.event }}_\n\n```{{ alert.text }}```",
+  "text": "*{{ alert.severity|capitalize }}* :: *{{ alert.resource }}* :: _{{ alert.event }}_\n\n```{{ alert.text }}```",
   "attachments": [{
     "color": "{{ color }}",
     "fields": [
       {"title": "Device", "value": "{{ alert.attributes.lofarDevice }}", "short": True },
       {"title": "Attribute", "value": "{{ alert.attributes.lofarAttribute }}", "short": True },
-      {"title": "Environment", "value": "{{ alert.environment }}", "short": True },
+      {"title": "Resource", "value": "{{ alert.resource }}", "short": True },
       {"title": "Status", "value": "{{ status|capitalize }}", "short": True },
       {"title": "Dashboards", "value": "<{{ config.BASE_URL }}/#/alert/{{ alert.id }}|Alerta>\nGrafana <{{ alert.attributes.grafanaDashboardUrl }}|Dashboard> <{{ alert.attributes.grafanaPanelUrl }}|Panel>", "short": True },
       {"title": "Configure", "value": "Grafana <{{ alert.attributes.grafanaAlertUrl }}|View> <{{ alert.attributes.grafanaSilenceUrl }}|Silence>", "short": True },
diff --git a/docker-compose/alerta-web/lofar-plugin/alerta_lofar.py b/docker-compose/alerta-web/lofar-plugin/alerta_lofar.py
index eaaed8614..c4f618d2d 100644
--- a/docker-compose/alerta-web/lofar-plugin/alerta_lofar.py
+++ b/docker-compose/alerta-web/lofar-plugin/alerta_lofar.py
@@ -26,6 +26,9 @@ class EnhanceLOFAR(PluginBase):
             if key == "name":
                 alert.attributes['lofarAttribute'] = value
 
+            if key == "station":
+                alert.resource = value
+
         return alert
 
     def post_receive(self, alert, **kwargs):
-- 
GitLab