Skip to content

Commit

Permalink
Merge pull request #56 from idealista/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jmonterrubio authored Mar 5, 2018
2 parents b70509e + 882730c commit e691157
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ 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.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

## [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)
Expand Down
10 changes: 0 additions & 10 deletions Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include README.md
include LICENSE
include requirements.txt
include bin/wsgi.py
include */config/*
recursive-include */resources/ *
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
![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

<img src="assets/example.png" alt="Alert example" style="width: 600px;"/>
<img src="https://raw.githubusercontent.com/idealista/prom2teams/master/assets/example.png" alt="Alert example" style="width: 600px;"/>

**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.

Expand Down Expand Up @@ -59,7 +59,13 @@ export APP_CONFIG_FILE=<config file path>
$ 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 <path to uwsgi ini config>
Expand All @@ -74,14 +80,18 @@ 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
```

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)


Expand All @@ -92,13 +102,14 @@ The config file is an [INI file](https://docs.python.org/3/library/configparser.
```
[Microsoft Teams]
# At least one connector is required here
Connector: <webhook url>
Connector: <webhook url>
AnotherConnector: <webhook url>
...
[HTTP Server]
Host: <host ip> # default: localhost
Port: <host port> # default: 8089
Name: <host name> # default: localhost:8089
[Log]
Level: <loglevel (DEBUG|INFO|WARNING|ERROR|CRITICAL)> # default: DEBUG
Expand Down Expand Up @@ -134,11 +145,11 @@ Other optional fields are skipped and not included in the Teams message.

Accessing to `<Host>:<Port>` (e.g. `localhost:8001`) in a web browser shows the API v1 documentation.

<img src="assets/swagger_v1.png" alt="Swagger UI" style="width: 600px;"/>
<img src="https://raw.githubusercontent.com/idealista/prom2teams/master/assets/swagger_v1.png" alt="Swagger UI" style="width: 600px;"/>

Accessing to `<Host>:<Port>/v2` (e.g. `localhost:8001/v2`) in a web browser shows the API v2 documentation.

<img src="assets/swagger_v2.png" alt="Swagger UI" style="width: 600px;"/>
<img src="https://raw.githubusercontent.com/idealista/prom2teams/master/assets/swagger_v2.png" alt="Swagger UI" style="width: 600px;"/>

## Testing

Expand Down
5 changes: 3 additions & 2 deletions bin/prom2teams
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion bin/prom2teams_uwsgi
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ else
exit 1
fi

uwsgi $config --chdir `dirname "$0"` --module wsgi
uwsgi $config --chdir /usr/local/etc/prom2teams --module wsgi
4 changes: 3 additions & 1 deletion bin/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@


if __name__ == "__main__":
application.run()
host = application.config['HOST']
port = application.config['PORT']
application.run(host=host, port=port)
3 changes: 2 additions & 1 deletion dockerhub/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM python:3.5-slim-jessie
FROM python:3.6-slim-stretch

LABEL maintainer="[email protected]"

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
Expand Down
7 changes: 6 additions & 1 deletion prom2teams/app/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ def _update_application_configuration(application, configuration):
_host, _port = application.config['SERVER_NAME'].split(':', 1)
if 'Host' in configuration['HTTP Server']:
_host = configuration['HTTP Server']['Host']
application.config['HOST'] = _host
if 'Port' in configuration['HTTP Server']:
_port = configuration['HTTP Server']['Port']
application.config['SERVER_NAME'] = _host + ':' + _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):
Expand Down
2 changes: 2 additions & 0 deletions prom2teams/config/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
APP_NAME = 'prom2teams'
HOST = 'localhost'
PORT = 8089
# Flask settings
DEBUG = False
SERVER_NAME = 'localhost:8089'
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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='[email protected]',
Expand Down

0 comments on commit e691157

Please sign in to comment.