Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#53 Fix prom2teams uwsgi bin startup #55

Merged
merged 4 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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/ *
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# 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)
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='labs@idealista.com',
Expand Down