From 0509e24ec373efbcd1912f7ca285cdf7ff90e2ce Mon Sep 17 00:00:00 2001 From: dortega Date: Mon, 28 Aug 2017 18:46:13 +0200 Subject: [PATCH 1/4] - adding *.ini and *.j2 files to package data - referencing *.ini and *.j2 files in MANIFEST file - versioning all the source code files under prom2teams namespace - loading prom2teams package in local using fallback in bin/prom2teams file Please enter the commit message for your changes. Lines starting --- MANIFEST.in | 4 ++++ bin/prom2teams | 7 +++++-- {app => prom2teams}/__init__.py | 0 config.ini => prom2teams/config.ini | 0 {app => prom2teams}/exceptions.py | 0 .../logging_console_config.ini | 0 .../logging_file_config.ini | 0 {app => prom2teams}/message/__init__.py | 0 {app => prom2teams}/message/parser.py | 0 {app => prom2teams}/server.py | 14 +++++++------- {app => prom2teams}/teams/__init__.py | 0 {app => prom2teams}/teams/client.py | 0 {app => prom2teams}/teams/exceptions.py | 0 {app => prom2teams}/teams/json_composer.py | 0 {app => prom2teams}/teams/template.j2 | 0 setup.py | 5 ++++- 16 files changed, 20 insertions(+), 10 deletions(-) rename {app => prom2teams}/__init__.py (100%) rename config.ini => prom2teams/config.ini (100%) rename {app => prom2teams}/exceptions.py (100%) rename logging_console_config.ini => prom2teams/logging_console_config.ini (100%) rename logging_file_config.ini => prom2teams/logging_file_config.ini (100%) rename {app => prom2teams}/message/__init__.py (100%) rename {app => prom2teams}/message/parser.py (100%) rename {app => prom2teams}/server.py (88%) rename {app => prom2teams}/teams/__init__.py (100%) rename {app => prom2teams}/teams/client.py (100%) rename {app => prom2teams}/teams/exceptions.py (100%) rename {app => prom2teams}/teams/json_composer.py (100%) rename {app => prom2teams}/teams/template.j2 (100%) diff --git a/MANIFEST.in b/MANIFEST.in index bb910eb..1bdaeaf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,7 @@ include README.md include LICENSE include requirements.txt +include config.ini +include logging_console_config.ini +include logging_file_config.ini +include prom2teams/teams/template.j2 diff --git a/bin/prom2teams b/bin/prom2teams index 8d86284..7add482 100755 --- a/bin/prom2teams +++ b/bin/prom2teams @@ -4,8 +4,11 @@ import sys import os import argparse -sys.path.append(os.path.abspath('./app')) -from server import run +try: + from prom2teams.server import run +except ImportError: + sys.path.append(os.path.abspath('./')) + from prom2teams.server import run if __name__ == "__main__": parser = argparse.ArgumentParser(description='Receives alert notifications ' diff --git a/app/__init__.py b/prom2teams/__init__.py similarity index 100% rename from app/__init__.py rename to prom2teams/__init__.py diff --git a/config.ini b/prom2teams/config.ini similarity index 100% rename from config.ini rename to prom2teams/config.ini diff --git a/app/exceptions.py b/prom2teams/exceptions.py similarity index 100% rename from app/exceptions.py rename to prom2teams/exceptions.py diff --git a/logging_console_config.ini b/prom2teams/logging_console_config.ini similarity index 100% rename from logging_console_config.ini rename to prom2teams/logging_console_config.ini diff --git a/logging_file_config.ini b/prom2teams/logging_file_config.ini similarity index 100% rename from logging_file_config.ini rename to prom2teams/logging_file_config.ini diff --git a/app/message/__init__.py b/prom2teams/message/__init__.py similarity index 100% rename from app/message/__init__.py rename to prom2teams/message/__init__.py diff --git a/app/message/parser.py b/prom2teams/message/parser.py similarity index 100% rename from app/message/parser.py rename to prom2teams/message/parser.py diff --git a/app/server.py b/prom2teams/server.py similarity index 88% rename from app/server.py rename to prom2teams/server.py index 6196a7f..ba6215b 100644 --- a/app/server.py +++ b/prom2teams/server.py @@ -4,11 +4,11 @@ from http.server import BaseHTTPRequestHandler, HTTPServer from logging.config import fileConfig -from teams.client import post -from teams.json_composer import compose -from message.parser import parse +from prom2teams.teams.client import post +from prom2teams.teams.json_composer import compose +from prom2teams.message.parser import parse -from exceptions import MissingConnectorConfigKeyException +from prom2teams.exceptions import MissingConnectorConfigKeyException logger = logging.getLogger() @@ -50,7 +50,7 @@ def log_message(self, format, *args): def run(provided_config_file, template_path, log_file_path, log_level): - config = get_config('config.ini', provided_config_file) + config = get_config('prom2teams/config.ini', provided_config_file) load_logging_config(log_file_path, log_level) @@ -72,11 +72,11 @@ def run(provided_config_file, template_path, log_file_path, log_level): def load_logging_config(log_file_path, log_level): - config_file = 'logging_console_config.ini' + config_file = 'prom2teams/logging_console_config.ini' defaults = {'log_level': log_level} if(log_file_path): - config_file = 'logging_file_config.ini' + config_file = 'prom2teams/logging_file_config.ini' defaults = { 'log_level': log_level, 'log_file_path': log_file_path diff --git a/app/teams/__init__.py b/prom2teams/teams/__init__.py similarity index 100% rename from app/teams/__init__.py rename to prom2teams/teams/__init__.py diff --git a/app/teams/client.py b/prom2teams/teams/client.py similarity index 100% rename from app/teams/client.py rename to prom2teams/teams/client.py diff --git a/app/teams/exceptions.py b/prom2teams/teams/exceptions.py similarity index 100% rename from app/teams/exceptions.py rename to prom2teams/teams/exceptions.py diff --git a/app/teams/json_composer.py b/prom2teams/teams/json_composer.py similarity index 100% rename from app/teams/json_composer.py rename to prom2teams/teams/json_composer.py diff --git a/app/teams/template.j2 b/prom2teams/teams/template.j2 similarity index 100% rename from app/teams/template.j2 rename to prom2teams/teams/template.j2 diff --git a/setup.py b/setup.py index d6563a2..9714e97 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def read_requirements_file(): setup(name='prom2teams', - version='1.1.0', + version='1.1.1', description='Project that redirects Prometheus Alert Manager ' 'notifications to Microsoft Teams', long_description=readme, @@ -34,6 +34,9 @@ def read_requirements_file(): 'pypandoc' ], scripts=['bin/prom2teams'], + package_data = { + '': ['*.ini', '*.j2',], + }, url='http://github.com/idealista/prom2teams', author='Idealista, S.A.U', author_email='labs@idealista.com', From 527c7c8728852d4ba95896d6c37ad1d5fdd2e171 Mon Sep 17 00:00:00 2001 From: dortega Date: Mon, 28 Aug 2017 19:16:34 +0200 Subject: [PATCH 2/4] - fixing file relative path from invoking source code - adding changes to CHANGELOG - fixing tests --- CHANGELOG.md | 5 +++++ README.md | 2 ++ prom2teams/server.py | 9 ++++++--- setup.py | 2 +- tests/context.py | 5 ++--- tests/test_server.py | 2 +- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c0775..37422b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +## [1.1.1](https://github.com/idealista/prom2teams/tree/1.1.1) +[Full Changelog](https://github.com/idealista/prom2teams/compare/1.1.0...1.1.1) +### Fixed +- *[#15](https://github.com/idealista/prom2teams/issues/15) Fixing setuptools config and packaging (broken in versions 1.1.0 and 1.0.0) * @dortegau + ## [1.1.0](https://github.com/idealista/prom2teams/tree/1.1.0) [Full Changelog](https://github.com/idealista/prom2teams/compare/1.0.0...1.1.0) ### Added diff --git a/README.md b/README.md index 97f6d25..88c89cc 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ prom2teams is present on [PyPI](https://pypi.python.org/pypi/prom2teams), so cou $ pip3 install prom2teams ``` +**Note:** Only works since version 1.1.1 (see: ) + ## Usage ```bash diff --git a/prom2teams/server.py b/prom2teams/server.py index ba6215b..3a3ae97 100644 --- a/prom2teams/server.py +++ b/prom2teams/server.py @@ -1,5 +1,6 @@ import logging import configparser +import os from http.server import BaseHTTPRequestHandler, HTTPServer from logging.config import fileConfig @@ -12,6 +13,7 @@ logger = logging.getLogger() +dir = os.path.dirname(__file__) def generate_request_handler(teams_webhook_url, template_path): @@ -50,7 +52,8 @@ def log_message(self, format, *args): def run(provided_config_file, template_path, log_file_path, log_level): - config = get_config('prom2teams/config.ini', provided_config_file) + config = get_config(os.path.join(dir, 'config.ini'), + provided_config_file) load_logging_config(log_file_path, log_level) @@ -72,11 +75,11 @@ def run(provided_config_file, template_path, log_file_path, log_level): def load_logging_config(log_file_path, log_level): - config_file = 'prom2teams/logging_console_config.ini' + config_file = os.path.join(dir, 'logging_console_config.ini') defaults = {'log_level': log_level} if(log_file_path): - config_file = 'prom2teams/logging_file_config.ini' + config_file = os.path.join(dir, 'logging_file_config.ini') defaults = { 'log_level': log_level, 'log_file_path': log_file_path diff --git a/setup.py b/setup.py index 9714e97..acc5183 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def read_requirements_file(): setup(name='prom2teams', - version='1.1.1', + version='1.1.12', description='Project that redirects Prometheus Alert Manager ' 'notifications to Microsoft Teams', long_description=readme, diff --git a/tests/context.py b/tests/context.py index 2a7a196..dd02872 100644 --- a/tests/context.py +++ b/tests/context.py @@ -1,7 +1,6 @@ import os import sys -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../app'))) +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../prom2teams'))) -import server -import exceptions +from prom2teams import server, exceptions diff --git a/tests/test_server.py b/tests/test_server.py index d39828b..bb73161 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -7,7 +7,7 @@ class TestServer(unittest.TestCase): TEST_CONFIG_FILES_PATH = 'tests/data/' - DEFAULT_CONFIG_RELATIVE_PATH = './config.ini' + DEFAULT_CONFIG_RELATIVE_PATH = './prom2teams/config.ini' def test_get_config_with_invalid_path(self): invalid_relative_path = self.TEST_CONFIG_FILES_PATH + 'invalid_path' From 26a634a28464c5c3ff0dc02d8c2bf0ecae914bc9 Mon Sep 17 00:00:00 2001 From: dortega Date: Mon, 28 Aug 2017 19:18:16 +0200 Subject: [PATCH 3/4] #15 upgrading to 1.1.1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index acc5183..9714e97 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def read_requirements_file(): setup(name='prom2teams', - version='1.1.12', + version='1.1.1', description='Project that redirects Prometheus Alert Manager ' 'notifications to Microsoft Teams', long_description=readme, From 5d709446d4a52589a074f1beea9bb25e0a439c2e Mon Sep 17 00:00:00 2001 From: dortega Date: Mon, 28 Aug 2017 19:20:50 +0200 Subject: [PATCH 4/4] #15 works since v1.1.1 (README file) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 88c89cc..2072825 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ prom2teams is present on [PyPI](https://pypi.python.org/pypi/prom2teams), so cou $ pip3 install prom2teams ``` -**Note:** Only works since version 1.1.1 (see: ) +**Note:** Only works since v1.1.1 ## Usage