From 30b4e65c538a4fd554745372bedd79bbbed647db Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Tue, 28 May 2019 09:07:41 +0200 Subject: [PATCH] Fix bug in gitlab plugin and only execute when really an issue should be created --- templates/gitlab/alerta_gitlab.py | 19 +++++++++---------- templates/gitlab/setup.py | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/templates/gitlab/alerta_gitlab.py b/templates/gitlab/alerta_gitlab.py index d1546a8..4e6c1d5 100644 --- a/templates/gitlab/alerta_gitlab.py +++ b/templates/gitlab/alerta_gitlab.py @@ -1,8 +1,6 @@ import gitlab import json import logging -import requests -import urllib.parse from alerta.plugins import PluginBase, app LOG = logging.getLogger('alerta.plugins') @@ -29,17 +27,18 @@ class GitlabIssue(PluginBase): return alert, status, text def take_action(self, alert, action, text, **kwargs): - """should return internal id of external system""" + if action == 'createIssue': + """should return internal id of external system""" - LOG.info('Create GitLab issue for %s' % alert.environment) - git = gitlab.Gitlab(GITLAB_URL, GITLAB_ACCESS_TOKEN, ssl_verify=True) # type: gitlab - git.auth() - project = git.projects.get('ansible-inventories/hosts/{}/{}'.format(alert.environment, alert.origin.split('/').pop())) + LOG.info('Create GitLab issue for %s' % alert.environment) + git = gitlab.Gitlab(GITLAB_URL, GITLAB_ACCESS_TOKEN, ssl_verify=True) # type: gitlab + git.auth() + project = git.projects.get('ansible-inventories/hosts/{}/{}'.format(alert.environment, alert.origin.split('/').pop())) + + if project: + LOG.info('Project ID %s' % project.id) - if project: - LOG.info('Project ID %s' % project.id) - if action == 'createIssue': if 'issue_iid' not in alert.attributes: # noinspection PyBroadException try: diff --git a/templates/gitlab/setup.py b/templates/gitlab/setup.py index 674de3b..02edd36 100644 --- a/templates/gitlab/setup.py +++ b/templates/gitlab/setup.py @@ -1,7 +1,7 @@ from setuptools import find_packages, setup -version = '1.1.0' +version = '1.2.0' setup( name='alerta-gitlab', -- GitLab