diff --git a/docker-compose/alerta-web/alertad.conf b/docker-compose/alerta-web/alertad.conf index a9e3e93c6ed20e12751714c5680aa8a7c469003e..8650866eea480d08cbce0975a48ea207cdb047fa 100644 --- a/docker-compose/alerta-web/alertad.conf +++ b/docker-compose/alerta-web/alertad.conf @@ -34,7 +34,7 @@ SLACK_WEBHOOK_URL = 'https://slack.com/api/chat.postMessage' SLACK_TOKEN = secrets["SLACK_TOKEN"] SLACK_CHANNEL = secrets["SLACK_CHANNEL"] SLACK_ATTACHMENTS = True -DASHBOARD_URL = os.environ.get("DASHBOARD_URL", "") +BASE_URL = os.environ.get("BASE_URL", "") # for the Slack message configuration syntax, see https://api.slack.com/methods/chat.postMessage # and https://app.slack.com/block-kit-builder @@ -49,8 +49,8 @@ SLACK_PAYLOAD = { {"title": "Attribute", "value": "{{ alert.attributes.lofarAttribute }}", "short": True }, {"title": "Environment", "value": "{{ alert.environment }}", "short": True }, {"title": "Status", "value": "{{ status|capitalize }}", "short": True }, - {"title": "Dashboards", "value": "<{{ config.DASHBOARD_URL }}/#/alert/{{ alert.id }}|Alerta>\nGrafana <{{ alert.attributes.grafanaDashboardUrl }}|Dashboard> <{{ alert.attributes.grafanaPanelUrl }}|Panel>", "short": True }, - {"title": "Configure", "value": "Grafana <{{ alert.attributes.grafanaAlertUrl }}|Edit> <{{ alert.attributes.grafanaSilenceUrl }}|Silence>", "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/grafana-plugin/alerta_grafana.py b/docker-compose/alerta-web/grafana-plugin/alerta_grafana.py index 917cddae1e57191151e8405eaeb277c330859745..7f6b840a4e6517bd5be2afa083ee317196725e0e 100644 --- a/docker-compose/alerta-web/grafana-plugin/alerta_grafana.py +++ b/docker-compose/alerta-web/grafana-plugin/alerta_grafana.py @@ -15,10 +15,38 @@ class EnhanceGrafana(PluginBase): def pre_receive(self, alert, **kwargs): # Parse Grafana-specific fields alert.attributes['grafanaStatus'] = alert.raw_data.get('status', '') - alert.attributes['grafanaPanelUrl'] = alert.raw_data.get('panelURL', '') - alert.attributes['grafanaDashboardUrl'] = alert.raw_data.get('dashboardURL', '') - alert.attributes['grafanaAlertUrl'] = alert.raw_data.get('generatorURL', '') - alert.attributes['grafanaSilenceUrl'] = alert.raw_data.get('silenceURL', '') + + def htmlify(link: str, desc: str) -> str: + return f'<a href="{link}" target="_blank">{desc}</a>'; + + # User-specified "Panel ID" annotation + panelURL = alert.raw_data.get('panelURL', '') + if panelURL: + alert.attributes['grafanaPanelUrl'] = panelURL + alert.attributes['grafanaPanelHtml'] = htmlify(panelURL, "Grafana Panel") + + # User-specified "Dashboard UID" annotation + dashboardURL = alert.raw_data.get('dashboardURL', '') + if dashboardURL: + alert.attributes['grafanaDashboardUrl'] = dashboardURL + alert.attributes['grafanaDashboardHtml'] = htmlify(dashboardURL, "Grafana Dashboard") + + alertURL = alert.raw_data.get('generatorURL', '') + if alertURL: + # expose alert view URL, as user may not have edit rights + # Convert from + # http://host:3000/alerting/kujybCynk/edit + # to + # http://host:3000/alerting/grafana/kujybCynk/view + alertURL = alertURL.replace("/alerting/", "/alerting/grafana/").replace("/edit", "/view") + + alert.attributes['grafanaAlertUrl'] = alertURL + alert.attributes['grafanaAlertHtml'] = htmlify(alertURL, "Grafana Alert") + + silenceURL = alert.raw_data.get('silenceURL', '') + if silenceURL: + alert.attributes['grafanaSilenceUrl'] = silenceURL + alert.attributes['grafanaSilenceHtml'] = htmlify(silenceURL, "Grafana Silence Alert") return alert diff --git a/docker-compose/alerta.yml b/docker-compose/alerta.yml index 696fcb24e77871d0cd94fb9cefb3fc49158138e1..2ae3be42c17e450007914facd2a686c7cce1d63e 100644 --- a/docker-compose/alerta.yml +++ b/docker-compose/alerta.yml @@ -22,6 +22,7 @@ services: environment: - DEBUG=1 # remove this line to turn DEBUG off - DATABASE_URL=postgres://postgres:postgres@alerta-db:5432/monitoring + - BASE_URL=http://${HOSTNAME}:8081 - DASHBOARD_URL=http://${HOSTNAME}:8081 - AUTH_REQUIRED=True - ADMIN_USERS=admin #default password: alerta diff --git a/docker-compose/grafana/dashboards/home.json b/docker-compose/grafana/dashboards/home.json index c798b4621671135c3f1d2060547b913f820669ba..ef3b8e02d3c2ea6aa1236041cde0d71cbfe89874 100644 --- a/docker-compose/grafana/dashboards/home.json +++ b/docker-compose/grafana/dashboards/home.json @@ -26,152 +26,212 @@ "liveNow": false, "panels": [ { + "alignNumbersToRightEnabled": true, + "columnAliases": [], + "columnFiltersEnabled": false, + "columnWidthHints": [], + "columns": [], + "compactRowsEnabled": true, "datasource": { "type": "yesoreyeram-infinity-datasource", "uid": "alertaui" }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "custom": { - "align": "auto", - "displayMode": "auto" - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - } - }, - "overrides": [ - { - "matcher": { - "id": "byName", - "options": "severity" - }, - "properties": [ - { - "id": "custom.width", - "value": 101 - } - ] - }, - { - "matcher": { - "id": "byName", - "options": "status" - }, - "properties": [ - { - "id": "custom.width", - "value": 83 - } - ] - }, - { - "matcher": { - "id": "byName", - "options": "event" - }, - "properties": [ - { - "id": "custom.width", - "value": 176 - } - ] - }, - { - "matcher": { - "id": "byName", - "options": "device" - }, - "properties": [ - { - "id": "custom.width", - "value": 98 - } - ] - }, - { - "matcher": { - "id": "byName", - "options": "attribute" - }, - "properties": [ - { - "id": "custom.width", - "value": 113 - } - ] - } - ] - }, + "datatablePagingType": "simple_numbers", + "datatableTheme": "basic_theme", + "emptyData": false, + "fontSize": "100%", "gridPos": { "h": 6, "w": 24, "x": 0, "y": 0 }, + "hoverEnabled": true, "id": 58, - "options": { - "footer": { - "fields": "", - "reducer": [ - "sum" - ], - "show": false + "infoEnabled": false, + "lengthChangeEnabled": true, + "orderColumnEnabled": true, + "pagingTypes": [ + { + "$$hashKey": "object:142", + "text": "Page number buttons only", + "value": "numbers" }, - "showHeader": true, - "sortBy": [] - }, + { + "$$hashKey": "object:143", + "text": "'Previous' and 'Next' buttons only", + "value": "simple" + }, + { + "$$hashKey": "object:144", + "text": "'Previous' and 'Next' buttons, plus page numbers", + "value": "simple_numbers" + }, + { + "$$hashKey": "object:145", + "text": "'First', 'Previous', 'Next' and 'Last' buttons", + "value": "full" + }, + { + "$$hashKey": "object:146", + "text": "'First', 'Previous', 'Next' and 'Last' buttons, plus page numbers", + "value": "full_numbers" + }, + { + "$$hashKey": "object:147", + "text": "'First' and 'Last' buttons, plus page numbers", + "value": "first_last_numbers" + } + ], + "panelHeight": 137, "pluginVersion": "8.4.5", + "rowNumbersEnabled": false, + "rowsPerPage": 5, + "scroll": false, + "scrollHeight": "default", + "searchEnabled": true, + "searchHighlightingEnabled": false, + "showCellBorders": false, + "showHeader": true, + "showRowBorders": true, + "sort": { + "col": 0, + "desc": true + }, + "sortByColumns": [ + { + "$$hashKey": "object:17", + "columnData": 0, + "sortMethod": "desc" + } + ], + "sortByColumnsData": [ + [ + 0, + "desc" + ] + ], + "stripedRowsEnabled": true, + "styles": [ + { + "$$hashKey": "object:19", + "dateFormat": "dd DD/MM HH:mm", + "pattern": "Time", + "type": "date" + }, + { + "$$hashKey": "object:20", + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "decimals": 2, + "pattern": "/.*/", + "splitPattern": "/ /", + "thresholds": [], + "type": "number", + "unit": "short" + }, + { + "$$hashKey": "object:45", + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "Panel", + "sanitize": true, + "splitPattern": "/ /", + "thresholds": [], + "type": "string", + "unit": "short", + "valueMaps": [] + }, + { + "$$hashKey": "object:76", + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "link": true, + "mappingType": 1, + "pattern": "Alerta", + "splitPattern": "/ /", + "thresholds": [], + "type": "string", + "unit": "short", + "valueMaps": [] + }, + { + "$$hashKey": "object:867", + "colors": [ + "rgba(245, 54, 54, 0.9)", + "rgba(237, 129, 40, 0.89)", + "rgba(50, 172, 45, 0.97)" + ], + "dateFormat": "YYYY-MM-DD HH:mm:ss", + "decimals": 2, + "mappingType": 1, + "pattern": "Since", + "splitPattern": "/ /", + "thresholds": [], + "type": "date", + "unit": "short" + } + ], "targets": [ { "columns": [ + { + "selector": "createTime", + "text": "Since", + "type": "string" + }, { "selector": "severity", - "text": "", + "text": "Severity", "type": "string" }, { "selector": "status", - "text": "", + "text": "Status", "type": "string" }, { "selector": "event", - "text": "", + "text": "Name", "type": "string" }, { "selector": "text", - "text": "", + "text": "Description", "type": "string" }, { "selector": "attributes.lofarDevice", - "text": "device", + "text": "Device", "type": "string" }, { "selector": "attributes.lofarAttribute", - "text": "attribute", + "text": "Attribute", + "type": "string" + }, + { + "selector": "attributes.grafanaPanelHtml", + "text": "Panel", "type": "string" }, { "selector": "href", - "text": "", + "text": "Alerta", "type": "string" } ], @@ -182,6 +242,7 @@ "filters": [], "format": "table", "global_query_id": "", + "hide": false, "refId": "A", "root_selector": "", "source": "url", @@ -193,8 +254,39 @@ } } ], + "themeOptions": { + "dark": "./styles/dark.scss", + "light": "./styles/light.scss" + }, + "themes": [ + { + "$$hashKey": "object:117", + "disabled": false, + "text": "Basic", + "value": "basic_theme" + }, + { + "$$hashKey": "object:118", + "disabled": true, + "text": "Bootstrap", + "value": "bootstrap_theme" + }, + { + "$$hashKey": "object:119", + "disabled": true, + "text": "Foundation", + "value": "foundation_theme" + }, + { + "$$hashKey": "object:120", + "disabled": true, + "text": "ThemeRoller", + "value": "themeroller_theme" + } + ], "title": "Alerta Alerts", - "type": "table" + "transform": "table", + "type": "briangann-datatable-panel" }, { "description": "",