Merge branch 'master' into salesforce_plugin
This commit is contained in:
commit
d7e35c905c
3 changed files with 48 additions and 17 deletions
9
.gitignore
vendored
9
.gitignore
vendored
|
@ -41,7 +41,10 @@ TODO
|
|||
|
||||
venv
|
||||
|
||||
.devcontainer
|
||||
.vscode
|
||||
pg-data/
|
||||
docker-compose.yml
|
||||
.devcontainer/
|
||||
.vscode/
|
||||
docker-compose.yml
|
||||
data/alertmanager
|
||||
data/prometheus
|
||||
config/*.yml
|
|
@ -2,9 +2,24 @@
|
|||
import logging
|
||||
|
||||
from alerta.plugins import PluginBase
|
||||
from flask import current_app
|
||||
|
||||
LOG = logging.getLogger('alerta.plugins.normalise')
|
||||
# LOG.setLevel(logging.DEBUG)
|
||||
handler = logging.FileHandler('/var/log/alertad.log')
|
||||
LOG.addHandler(handler)
|
||||
|
||||
def get_info(current_cluster):
|
||||
all_clusters = current_app.config['NORMALISE_ENVIRONMENTS']
|
||||
for customer, customer_data in all_clusters.items():
|
||||
LOG.debug("Searching %s clusters", customer)
|
||||
for environment, env_data in customer_data.items():
|
||||
LOG.debug("Searching %s", environment)
|
||||
for cluster_name, id in env_data.items():
|
||||
LOG.debug("Examining %s cluster", cluster_name)
|
||||
if id == current_cluster:
|
||||
LOG.debug("cluster identified for %s", id)
|
||||
return customer, environment, cluster_name
|
||||
|
||||
class NormaliseAlert(PluginBase):
|
||||
|
||||
|
@ -12,15 +27,25 @@ class NormaliseAlert(PluginBase):
|
|||
|
||||
LOG.info("Normalising alert...")
|
||||
|
||||
# prepend severity to alert text
|
||||
alert.text = '%s: %s' % (alert.severity.upper(), alert.text)
|
||||
|
||||
# supply different default values if missing
|
||||
if not alert.group or alert.group == 'Misc':
|
||||
alert.group = 'Unknown'
|
||||
if not alert.value or alert.value == 'n/a':
|
||||
alert.value = '--'
|
||||
|
||||
try:
|
||||
for t in alert.tags:
|
||||
if t.startswith("cluster_id"):
|
||||
x, cluster_info = t.split('=', 1)
|
||||
env = cluster_info.split('/')
|
||||
LOG.debug("Cluster information is %s", env)
|
||||
cluster_id = env[2]
|
||||
customer, environment, cluster_name = get_info(cluster_id)
|
||||
# alert.attributes['client'] = customer
|
||||
alert.customer = customer
|
||||
alert.environment = environment
|
||||
alert.resource = cluster_name
|
||||
except Exception:
|
||||
LOG.error(Exception.with_traceback())
|
||||
LOG.error("Unable to correctly normalise cluster information for %s", cluster_id)
|
||||
if not alert.environment:
|
||||
alert.environment = current_app.config['DEFAULT_ENVIRONMENT']
|
||||
if not alert.resource:
|
||||
alert.resource = "Unknown"
|
||||
return alert
|
||||
|
||||
def post_receive(self, alert):
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
version = '5.3.1'
|
||||
version = '0.3'
|
||||
|
||||
setup(
|
||||
name="alerta-normalise",
|
||||
version=version,
|
||||
description='Alerta plugin for alert normalisation',
|
||||
url='https://github.com/alerta/alerta-contrib',
|
||||
url='https://github.com/michael-chambers/alerta-contrib',
|
||||
license='MIT',
|
||||
author='Nick Satterly',
|
||||
author_email='nick.satterly@theguardian.com',
|
||||
author='Michael Chambers',
|
||||
author_email='mchambers@mirantis.com',
|
||||
packages=find_packages(),
|
||||
py_modules=['alerta_normalise'],
|
||||
install_requires=[
|
||||
'flask'
|
||||
],
|
||||
include_package_data=True,
|
||||
zip_safe=True,
|
||||
entry_points={
|
||||
|
@ -20,4 +23,4 @@ setup(
|
|||
'normalise = alerta_normalise:NormaliseAlert'
|
||||
]
|
||||
}
|
||||
)
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue