From 7f39c57695d6bd38185102090cf36146b1492e3b Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 1 Mar 2018 09:45:40 +0100 Subject: [PATCH 1/9] Update Docker image version to Python 3.6 Slim Stretch and install build-essential to be able to install WSGI --- dockerhub/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dockerhub/Dockerfile b/dockerhub/Dockerfile index 6fe7e27..19c0f0c 100644 --- a/dockerhub/Dockerfile +++ b/dockerhub/Dockerfile @@ -1,9 +1,10 @@ -FROM python:3.5-slim-jessie +FROM python:3.6-slim-stretch LABEL maintainer="labs@idealista.com" EXPOSE 8089 +RUN apt-get update && apt-get install -y build-essential RUN pip install prom2teams COPY config.ini /opt/prom2teams/config.ini COPY prom2teams_start.sh /opt/prom2teams/prom2teams_start.sh From 60d698747767689a5bda59bf1ff016689b9d48ad Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 1 Mar 2018 09:45:53 +0100 Subject: [PATCH 2/9] Add Dockerhub badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9628d7a..e7f061a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Logo](https://raw.githubusercontent.com/idealista/prom2teams/master/logo.gif) -[![Build Status](https://travis-ci.org/idealista/prom2teams.png)](https://travis-ci.org/idealista/prom2teams) +[![Build Status](https://travis-ci.org/idealista/prom2teams.png)](https://travis-ci.org/idealista/prom2teams) [![Docker Automated build](https://img.shields.io/docker/automated/jrottenberg/ffmpeg.svg)](https://hub.docker.com/r/idealista/prom2teams/) [![Docker Build Status](https://img.shields.io/docker/build/jrottenberg/ffmpeg.svg)](https://hub.docker.com/r/idealista/prom2teams/) # prom2teams @@ -92,7 +92,7 @@ The config file is an [INI file](https://docs.python.org/3/library/configparser. ``` [Microsoft Teams] # At least one connector is required here -Connector: +Connector: AnotherConnector: ... From 15624c9dd245273eaef175642856434aaa1880c4 Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 1 Mar 2018 09:46:09 +0100 Subject: [PATCH 3/9] Delete former Dockerfile --- Dockerfile | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 988102e..0000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM python:3.5-slim-jessie - -LABEL maintainer="labs@idealista.com" - -EXPOSE 8089 - -RUN pip install prom2teams -COPY config.ini /opt/prom2teams/config.ini - -ENTRYPOINT ["prom2teams", "--configpath", "/opt/prom2teams/config.ini"] From bd308df3982dde85401d24e9dc2baa4d87df4387 Mon Sep 17 00:00:00 2001 From: Javier Monterrubio Date: Thu, 1 Mar 2018 11:22:38 +0100 Subject: [PATCH 4/9] #53 Fix prom2teams uwsgi bin startup --- CHANGELOG.md | 2 ++ MANIFEST.in | 1 + README.md | 20 +++++++++++++++----- bin/prom2teams_uwsgi | 2 +- setup.py | 5 ++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a83bc..95c81ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +### Fixed +- *[#53](https://github.com/idealista/prom2teams/issues/53) Fix prom2teams uwsgi bin startup* @jmonterrubio ## [2.0.0](https://github.com/idealista/prom2teams/tree/2.0.0) [Full Changelog](https://github.com/idealista/prom2teams/compare/1.3.0...2.0.0) diff --git a/MANIFEST.in b/MANIFEST.in index 034ff77..41a7dd2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,6 @@ include README.md include LICENSE include requirements.txt +include bin/wsgi.py include */config/* recursive-include */resources/ * diff --git a/README.md b/README.md index 9628d7a..2b9ad44 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # prom2teams -Alert example +Alert example **prom2teams** is a Web server built with Python that receives alert notifications from a previously configured [Prometheus Alertmanager](https://github.com/prometheus/alertmanager) instance and forwards it to [Microsoft Teams](https://teams.microsoft.com/) using defined connectors. @@ -59,7 +59,13 @@ export APP_CONFIG_FILE= $ prom2teams ``` -For production environments you should prefer using a WSGI server. You can launch instead: +### Production + +For production environments you should prefer using a WSGI server. [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/) +dependency is installed for an easy usage. Some considerations must be taken to use it: + +The binary `prom2teams_uwsgi` launches the app using the uwsgi server. Due to some incompatibilities with [wheel](https://github.com/pypa/wheel) +you must install `prom2teams` using `sudo pip install --no-binary :all: prom2teams` (https://github.com/pypa/wheel/issues/92) ```bash $ prom2teams_uwsgi @@ -82,6 +88,10 @@ env = APP_CONFIG_FILE=/etc/default/prom2teams.ini Consider not provide `chdir` property neither `module` property. +Also you can set the `module` file, by doing a symbolic link: `sudo mkdir -p /usr/local/etc/prom2teams/ && sudo ln -sf /usr/local/lib/python3.5/dist-packages/usr/local/etc/prom2teams/wsgi.py /usr/local/etc/prom2teams/wsgi.py` (check your dist-packages folder) + +Another approach is to provide yourself the `module` file [module example](bin/wsgi.py) and the `bin` uwsgi call [uwsgi example](bin/prom2teams_uwsgi) + **Note:** default log level is DEBUG. Messages are redirected to stdout. To enable file log, set the env APP_ENVIRONMENT=(pro|pre) @@ -92,7 +102,7 @@ The config file is an [INI file](https://docs.python.org/3/library/configparser. ``` [Microsoft Teams] # At least one connector is required here -Connector: +Connector: AnotherConnector: ... @@ -134,11 +144,11 @@ Other optional fields are skipped and not included in the Teams message. Accessing to `:` (e.g. `localhost:8001`) in a web browser shows the API v1 documentation. -Swagger UI +Swagger UI Accessing to `:/v2` (e.g. `localhost:8001/v2`) in a web browser shows the API v2 documentation. -Swagger UI +Swagger UI ## Testing diff --git a/bin/prom2teams_uwsgi b/bin/prom2teams_uwsgi index 6e0a9b9..9db9cb6 100755 --- a/bin/prom2teams_uwsgi +++ b/bin/prom2teams_uwsgi @@ -9,4 +9,4 @@ else exit 1 fi -uwsgi $config --chdir `dirname "$0"` --module wsgi +uwsgi $config --chdir /usr/local/etc/prom2teams --module wsgi diff --git a/setup.py b/setup.py index c0c4172..9522053 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def read_requirements_file(): setup(name='prom2teams', - version='2.0.0', + version='2.0.1', description='Project that redirects Prometheus Alert Manager ' 'notifications to Microsoft Teams', long_description=readme, @@ -41,6 +41,9 @@ def read_requirements_file(): '': ['*.ini', '*.j2'], }, include_package_data=True, + data_files=[ + ('/usr/local/etc/prom2teams', ['bin/wsgi.py']) + ], url='http://github.com/idealista/prom2teams', author='Idealista, S.A.U', author_email='labs@idealista.com', From 83f3488cf977ba6558dc8fc83b2e631c7dbc5dad Mon Sep 17 00:00:00 2001 From: Javier Monterrubio Date: Sun, 4 Mar 2018 11:19:23 +0100 Subject: [PATCH 5/9] #53 Provide server name for http proxy config --- README.md | 3 ++- bin/prom2teams | 5 +++-- bin/wsgi.py | 4 +++- prom2teams/app/configuration.py | 8 ++++---- prom2teams/config/settings.py | 4 +++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2b9ad44..1d44825 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ processes = 5 #socket = 0.0.0.0:8001 #protocol = http socket = /tmp/prom2teams.sock -chmod-socket = 660 +chmod-socket = 777 vacuum = true env = APP_ENVIRONMENT=pro env = APP_CONFIG_FILE=/etc/default/prom2teams.ini @@ -109,6 +109,7 @@ AnotherConnector: [HTTP Server] Host: # default: localhost Port: # default: 8089 +Name: # default: prom2teams [Log] Level: # default: DEBUG diff --git a/bin/prom2teams b/bin/prom2teams index 1bb8c17..ecb628a 100755 --- a/bin/prom2teams +++ b/bin/prom2teams @@ -10,5 +10,6 @@ except ImportError: from prom2teams.app.api import app as application if __name__ == "__main__": - _host, _port = application.config['SERVER_NAME'].split(':', 1) - application.run(host=_host, port=int(_port)) + host = application.config['HOST'] + port = application.config['PORT'] + application.run(host=host, port=port) diff --git a/bin/wsgi.py b/bin/wsgi.py index d6a5001..cdc0f22 100644 --- a/bin/wsgi.py +++ b/bin/wsgi.py @@ -10,4 +10,6 @@ if __name__ == "__main__": - application.run() + host = application.config['HOST'] + port = application.config['PORT'] + application.run(host=host, port=port) diff --git a/prom2teams/app/configuration.py b/prom2teams/app/configuration.py index a6dd13e..89c243f 100644 --- a/prom2teams/app/configuration.py +++ b/prom2teams/app/configuration.py @@ -34,12 +34,12 @@ def _update_application_configuration(application, configuration): if 'Log' in configuration and 'Path' in configuration['Log']: application.config['LOG_FILE_PATH'] = configuration['Log']['Path'] if 'HTTP Server' in configuration: - _host, _port = application.config['SERVER_NAME'].split(':', 1) if 'Host' in configuration['HTTP Server']: - _host = configuration['HTTP Server']['Host'] + application.config['HOST'] = configuration['HTTP Server']['Host'] if 'Port' in configuration['HTTP Server']: - _port = configuration['HTTP Server']['Port'] - application.config['SERVER_NAME'] = _host + ':' + _port + application.config['PORT'] = configuration['HTTP Server']['Port'] + if 'Name' in configuration['HTTP Server']: + application.config['SERVER_NAME'] = configuration['HTTP Server']['Name'] def _config_provided(filepath): diff --git a/prom2teams/config/settings.py b/prom2teams/config/settings.py index ffcd41c..79e61f6 100644 --- a/prom2teams/config/settings.py +++ b/prom2teams/config/settings.py @@ -1,7 +1,9 @@ APP_NAME = 'prom2teams' +HOST = 'localhost' +PORT = 8089 # Flask settings DEBUG = False -SERVER_NAME = 'localhost:8089' +SERVER_NAME = 'prom2teams' # Flask-Restplus settings SWAGGER_UI_DOC_EXPANSION = 'list' From eb323c1b8dd13584f469a4a7dd08a21ad5da9363 Mon Sep 17 00:00:00 2001 From: Javier Monterrubio Date: Sun, 4 Mar 2018 15:45:12 +0100 Subject: [PATCH 6/9] #53 Fix http socket configuration --- README.md | 2 +- prom2teams/app/configuration.py | 9 +++++++-- prom2teams/config/settings.py | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1d44825..1de430e 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ AnotherConnector: [HTTP Server] Host: # default: localhost Port: # default: 8089 -Name: # default: prom2teams +Name: # default: localhost:8089 [Log] Level: # default: DEBUG diff --git a/prom2teams/app/configuration.py b/prom2teams/app/configuration.py index 89c243f..22a50f0 100644 --- a/prom2teams/app/configuration.py +++ b/prom2teams/app/configuration.py @@ -34,12 +34,17 @@ def _update_application_configuration(application, configuration): if 'Log' in configuration and 'Path' in configuration['Log']: application.config['LOG_FILE_PATH'] = configuration['Log']['Path'] if 'HTTP Server' in configuration: + _host, port = application.config['SERVER_NAME'].split(':', 1) if 'Host' in configuration['HTTP Server']: - application.config['HOST'] = configuration['HTTP Server']['Host'] + _host = configuration['HTTP Server']['Host'] + application.config['HOST'] = _host if 'Port' in configuration['HTTP Server']: - application.config['PORT'] = configuration['HTTP Server']['Port'] + _port = configuration['HTTP Server']['Port'] + application.config['PORT'] = _port if 'Name' in configuration['HTTP Server']: application.config['SERVER_NAME'] = configuration['HTTP Server']['Name'] + else: + application.config['SERVER_NAME'] = _host + ':' + _port def _config_provided(filepath): diff --git a/prom2teams/config/settings.py b/prom2teams/config/settings.py index 79e61f6..7230226 100644 --- a/prom2teams/config/settings.py +++ b/prom2teams/config/settings.py @@ -3,7 +3,7 @@ PORT = 8089 # Flask settings DEBUG = False -SERVER_NAME = 'prom2teams' +SERVER_NAME = 'localhost:8089' # Flask-Restplus settings SWAGGER_UI_DOC_EXPANSION = 'list' From 826108289ca91ee4357656a2d46f47f24d1ab27c Mon Sep 17 00:00:00 2001 From: Javier Monterrubio Date: Mon, 5 Mar 2018 09:17:42 +0100 Subject: [PATCH 7/9] #53 Fix port name var in configuration --- prom2teams/app/configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prom2teams/app/configuration.py b/prom2teams/app/configuration.py index 22a50f0..53f0eb9 100644 --- a/prom2teams/app/configuration.py +++ b/prom2teams/app/configuration.py @@ -34,7 +34,7 @@ def _update_application_configuration(application, configuration): if 'Log' in configuration and 'Path' in configuration['Log']: application.config['LOG_FILE_PATH'] = configuration['Log']['Path'] if 'HTTP Server' in configuration: - _host, port = application.config['SERVER_NAME'].split(':', 1) + _host, _port = application.config['SERVER_NAME'].split(':', 1) if 'Host' in configuration['HTTP Server']: _host = configuration['HTTP Server']['Host'] application.config['HOST'] = _host From 01e93a116859ce544398cba5f465a2ab2e2b0ecd Mon Sep 17 00:00:00 2001 From: Javier Monterrubio Date: Mon, 5 Mar 2018 11:42:05 +0100 Subject: [PATCH 8/9] Update changeloge before release --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95c81ce..f28d1f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +## [2.0.0](https://github.com/idealista/prom2teams/tree/2.0.1) +[Full Changelog](https://github.com/idealista/prom2teams/compare/2.0.0...2.0.1) ### Fixed - *[#53](https://github.com/idealista/prom2teams/issues/53) Fix prom2teams uwsgi bin startup* @jmonterrubio From 882730ccc4e7d7ad9aac602680a61fdc194e3671 Mon Sep 17 00:00:00 2001 From: Javier Monterrubio Date: Mon, 5 Mar 2018 11:43:36 +0100 Subject: [PATCH 9/9] Update changeloge before release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f28d1f1..1a0774b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) -## [2.0.0](https://github.com/idealista/prom2teams/tree/2.0.1) +## [2.0.1](https://github.com/idealista/prom2teams/tree/2.0.1) [Full Changelog](https://github.com/idealista/prom2teams/compare/2.0.0...2.0.1) ### Fixed - *[#53](https://github.com/idealista/prom2teams/issues/53) Fix prom2teams uwsgi bin startup* @jmonterrubio