From d87c392e32e13807c6cb0b1a2f3064f384670a5b Mon Sep 17 00:00:00 2001 From: Hayk Davtyan <46712946+hayk96@users.noreply.github.com> Date: Sat, 24 Jun 2023 22:59:48 +0400 Subject: [PATCH] Release alerta-web-0.1.6 (#25) * Bump version Signed-off-by: hayk96 * Renamed images * Updated chart description * Update Dockerfile * Removed plugins dir --------- Signed-off-by: hayk96 --- .github/workflows/docker-image.yml | 2 +- Dockerfile | 8 +- charts/alerta-web/Chart.yaml | 8 +- ...tile-150x50.png.png => mstile-150x150.png} | Bin ...ile-310x150.png.png => mstile-310x150.png} | Bin ...ile-310x310.png.png => mstile-310x310.png} | Bin plugins/alerta_prometheus.py | 184 ------------------ 7 files changed, 11 insertions(+), 191 deletions(-) rename logo/{mstile-150x50.png.png => mstile-150x150.png} (100%) rename logo/{mstile-310x150.png.png => mstile-310x150.png} (100%) rename logo/{mstile-310x310.png.png => mstile-310x310.png} (100%) delete mode 100644 plugins/alerta_prometheus.py diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 87e91ed..c79e20a 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,7 +2,7 @@ name: Alerta Web Docker Image CI env: IMAGE_NAME: alerta-web - IMAGE_TAG: 9.0.0 + IMAGE_TAG: 9.0.1 on: pull_request: diff --git a/Dockerfile b/Dockerfile index f8d80a5..6e4eb73 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ ARG version FROM alerta/alerta-web:${version} +ARG PIP_PLUGINS_PATH="git+https://github.com/hayk96/alerta-contrib.git#subdirectory=plugins" LABEL maintainer="Hayk Davtyan" -COPY logo/* /web/ -COPY plugins/alerta_prometheus.py /venv/lib/python3.8/site-packages +RUN pip install \ + ${PIP_PLUGINS_PATH}/prometheus \ + ${PIP_PLUGINS_PATH}/pagerduty \ + ${PIP_PLUGINS_PATH}/enhance +COPY logo/* /web/ \ No newline at end of file diff --git a/charts/alerta-web/Chart.yaml b/charts/alerta-web/Chart.yaml index 21510c8..74a76d9 100644 --- a/charts/alerta-web/Chart.yaml +++ b/charts/alerta-web/Chart.yaml @@ -1,10 +1,10 @@ apiVersion: v2 -appVersion: "9.0.0" -description: A Helm chart for Kubernetes +appVersion: "9.0.1" +description: A Kubernetes Helm chart of Alerta monitoring system name: alerta-web -version: 0.1.5 +version: 0.1.6 home: https://github.com/hayk96/alerta-web -icon: https://raw.githubusercontent.com/hayk96/alerta-web/main/logo/mstile-310x310.png.png +icon: https://raw.githubusercontent.com/hayk96/alerta-web/main/logo/mstile-310x310.png dependencies: - name: postgresql version: "12.2.3" diff --git a/logo/mstile-150x50.png.png b/logo/mstile-150x150.png similarity index 100% rename from logo/mstile-150x50.png.png rename to logo/mstile-150x150.png diff --git a/logo/mstile-310x150.png.png b/logo/mstile-310x150.png similarity index 100% rename from logo/mstile-310x150.png.png rename to logo/mstile-310x150.png diff --git a/logo/mstile-310x310.png.png b/logo/mstile-310x310.png similarity index 100% rename from logo/mstile-310x310.png.png rename to logo/mstile-310x310.png diff --git a/plugins/alerta_prometheus.py b/plugins/alerta_prometheus.py deleted file mode 100644 index b1f96a3..0000000 --- a/plugins/alerta_prometheus.py +++ /dev/null @@ -1,184 +0,0 @@ -import datetime -import logging -import os -import requests -import json -from typing import Any - -try: - from alerta.plugins import app # alerta >= 5.0 -except ImportError: - from alerta.app import app # alerta < 5.0 - -from alerta.models.alert import Alert -from alerta.plugins import PluginBase - -LOG = logging.getLogger('alerta.plugins.prometheus') - -DEFAULT_ALERTMANAGER_API_URL = 'http://localhost:9093' - -ALERTMANAGER_API_URL = os.environ.get('ALERTMANAGER_API_URL') or app.config.get('ALERTMANAGER_API_URL', None) -ALERTMANAGER_USERNAME = os.environ.get('ALERTMANAGER_USERNAME') or app.config.get('ALERTMANAGER_USERNAME', None) -ALERTMANAGER_PASSWORD = os.environ.get('ALERTMANAGER_PASSWORD') or app.config.get('ALERTMANAGER_PASSWORD', None) -ALERTMANAGER_SILENCE_DAYS = os.environ.get('ALERTMANAGER_SILENCE_DAYS') or app.config.get('ALERTMANAGER_SILENCE_DAYS', 1) -ALERTMANAGER_SILENCE_FROM_ACK = os.environ.get('ALERTMANAGER_SILENCE_FROM_ACK') or app.config.get('ALERTMANAGER_SILENCE_FROM_ACK', False) -ALERTMANAGER_USE_EXTERNALURL_FOR_SILENCES = os.environ.get('ALERTMANAGER_USE_EXTERNALURL_FOR_SILENCES') or app.config.get('ALERTMANAGER_USE_EXTERNALURL_FOR_SILENCES',False) - - -class AlertmanagerSilence(PluginBase): - - def __init__(self, name=None): - - self.auth = (ALERTMANAGER_USERNAME, ALERTMANAGER_PASSWORD) if ALERTMANAGER_USERNAME else None - - super(AlertmanagerSilence, self).__init__(name) - - def pre_receive(self, alert): - return alert - - def post_receive(self, alert): - return - - def status_change(self, alert, status, text): - ''' - If a silence exists for an open or closed alert we probably want to remove it - ''' - if status in ('open', 'closed'): - - silenceId = alert.attributes.get('silenceId', None) - if silenceId: - LOG.debug('Alertmanager: Remove silence for alertname=%s instance=%s', alert.event, alert.resource) - base_url = ALERTMANAGER_API_URL or alert.attributes.get('externalUrl', DEFAULT_ALERTMANAGER_API_URL) - url = base_url + '/api/v1/silence/%s' % silenceId - try: - r = requests.delete(url, auth=self.auth, timeout=2) - except Exception as e: - raise RuntimeError("Alertmanager: ERROR - %s" % e) - LOG.debug('Alertmanager: %s - %s', r.status_code, r.text) - - try: - alert.attributes['silenceId'] = None - except Exception as e: - raise RuntimeError("Alertmanager: ERROR - %s" % e) - LOG.debug('Alertmanager: Removed silenceId %s from attributes', silenceId) - if status == 'closed': - LOG.warning("Status is now closed") - - return alert - - def take_action(self, alert: Alert, action: str, text: str, **kwargs) -> Any: - ''' - Set silence in alertmanager. - ''' - - if alert.event_type != 'prometheusAlert': - return alert - - - base_url = ALERTMANAGER_API_URL or alert.attributes.get('externalUrl', DEFAULT_ALERTMANAGER_API_URL) - if action == 'close': - LOG.warning("Got a close action so trying to close this in alertmanager too") - url = base_url + '/api/v1/alerts' - raw_data_string = alert.raw_data - raw_data = json.loads(raw_data_string) - # set the endsAt to now so alertmanager will consider it expired or whatever - raw_data["endsAt"] = (datetime.datetime.utcnow() - datetime.timedelta(minutes=5)).replace(microsecond=0).isoformat() + ".000Z" - LOG.debug("Raw data type: {}, Raw data contents: {}".format(type(raw_data),raw_data)) - data = [ raw_data ] - try: - r = requests.post(url, json=data, auth=self.auth, timeout=2) - except Exception as e: - raise RuntimeError("Alertmanager: ERROR - %s" % e) - LOG.debug('Alertmanager response was: %s - %s', r.status_code, r.text) - - elif action == 'ack' and ALERTMANAGER_SILENCE_FROM_ACK: - - if not ALERTMANAGER_SILENCE_DAYS: - silence_seconds = kwargs.get('timeout', alert.timeout) - else: - try: - silence_days = int(ALERTMANAGER_SILENCE_DAYS) - except Exception as e: - LOG.error( - "Alertmanager: Could not parse 'ALERTMANAGER_SILENCE_DAYS': %s", e) - raise RuntimeError( - "Could not parse 'ALERTMANAGER_SILENCE_DAYS': %s" % e) - silence_seconds = silence_days * 86400 - - LOG.debug('Alertmanager: Add silence for alertname=%s instance=%s environment=%s customer=%s timeout=%s', - alert.event, alert.resource, str(silence_seconds)) - data = { - "matchers": [ - { - "name": "alertname", - "value": alert.event - }, - { - "name": "instance", - "value": alert.resource - }, - { - "name": "environment", - "value": alert.environment - }, - { - "name": "customer", - "value": alert.customer - } - ], - "startsAt": datetime.datetime.utcnow().replace(microsecond=0).isoformat() + ".000Z", - "endsAt": (datetime.datetime.utcnow() + datetime.timedelta(seconds=silence_seconds)) - .replace(microsecond=0).isoformat() + ".000Z", - "createdBy": "alerta", - "comment": text if text != '' else "silenced by alerta" - } - - # if alertmanager is clustered behind a load balancer that mirrors requests we should prefer to create one silence - # rather than many - if ALERTMANAGER_USE_EXTERNALURL_FOR_SILENCES: - base_url = alert.attributes.get('externalUrl', DEFAULT_ALERTMANAGER_API_URL) or ALERTMANAGER_API_URL - else: - base_url = ALERTMANAGER_API_URL or alert.attributes.get('externalUrl', DEFAULT_ALERTMANAGER_API_URL) - - url = base_url + '/api/v1/silences' - - - try: - r = requests.post(url, json=data, auth=self.auth, timeout=2) - except Exception as e: - raise RuntimeError("Alertmanager: ERROR - %s" % e) - LOG.debug('Alertmanager: %s - %s', r.status_code, r.text) - - # example r={"status":"success","data":{"silenceId":8}} - try: - data = r.json().get('data', []) - if data: - silenceId = data['silenceId'] - alert.attributes['silenceId'] = silenceId - else: - silenceId = alert.attributes.get('silenceId', "unknown") - text = text + ' (silenced in Alertmanager)' - except Exception as e: - raise RuntimeError("Alertmanager: ERROR - %s" % e) - LOG.debug('Alertmanager: Added silenceId %s to attributes', silenceId) - - elif action == 'unack': - LOG.debug('Alertmanager: Remove silence for alertname=%s instance=%s environment=%s customer=%s', alert.event, alert.resource) - - silenceId = alert.attributes.get('silenceId', None) - if silenceId: - base_url = ALERTMANAGER_API_URL or alert.attributes.get('externalUrl', DEFAULT_ALERTMANAGER_API_URL) - url = base_url + '/api/v1/silence/%s' % silenceId - try: - r = requests.delete(url, auth=self.auth, timeout=2) - except Exception as e: - raise RuntimeError("Alertmanager: ERROR - %s" % e) - LOG.debug('Alertmanager: %s - %s', r.status_code, r.text) - - try: - alert.attributes['silenceId'] = None - except Exception as e: - raise RuntimeError("Alertmanager: ERROR - %s" % e) - LOG.debug('Alertmanager: Removed silenceId %s from attributes', silenceId) - - return alert \ No newline at end of file