Skip to main content

Convert arbitrary json alerts to Alert Manager alerts

Project description

PyConvertAlert

PyConvertAlert makes it easy to take an arbitrary alert from some kind of alerting system (Uptime Robot, Rackspace Intelligence) and convert it into an Alert Manager (Prometheus) alert.

Getting Started

The latest stable release is available from PyPI:

pip install pyconvertalert

Otherwise you can install from git:

pip install git+https://github.com/jpavlav/PyConvertAlert

Usage

>>> from pyconvertalert import Converter
>>>
>>> test_lookup_dict_1 = {
...     "values": [
...         {
...             "people": [
...                 {
...                     "email": "jim@jim.com",
...                     "phone": "111-111-1111"
...                 }
...             ]
...         }
...     ]
... }
>>>
>>>
>>> test_mapper_dict_1 = {
...     "labels": {
...         "email_address": "email",
...         "phone_number": "phone"
...     }
... }
>>> convert = Converter(mapper=test_mapper_dict_1)
>>> convert.convert_it(test_lookup_dict_1)
{'labels': {'email_address': 'jim@jim.com', 'phone_number': '111-111-1111'}}

Further Usage

In some cases, there will be more than one key that matches a lookup. In this case, the value returned in our converted dict will be a list containing all of the values that match this key. In order to handle a situation where we need to be more specific, it is possible to specify a list of keys to drill down on a specific value. Here is an example:

>>> test_lookup_dict_2 = {
...     "flowers": [
...         {
...             "best_flower": {
...                 "name": "Orchid",
...                 "scientific_name": "Orchidaceae"
...             },
...             "wild_flower": {
...                 "name": "Gold Yarrow",
...                 "scientific_name": "Achillea filipendulinaa"
...             }
...         }
...     ]
... }
>>>
>>> test_mapper_dict_2 = {
...     "labels": {
...         "best_flower_name": ['best_flower', 'name'],
...         "best_flower_scientific_name": ['best_flower',
...                                         'scientific_name']
...     }
... }
>>>
>>>
>>> convert = Converter(mapper=test_mapper_dict_2)
>>> convert.convert_it(test_lookup_dict_2)
{'labels': {'best_flower_name': 'Orchid', 'best_flower_scientific_name': 'Orchidaceae'}}

Above, we see that we were able to get the 'best_flower' 'scientific_name' by specifying a list of keys to search through. We first return the value from the key 'best_flower', then return the value from the key 'name'.

Running the tests

Should be as simple as:

python -m unittest test_py_convert_alert.py

Contributing

  1. Fork it.
  2. Create a branch describing either the issue or feature you're working.
  3. Making changes, committing along the way.
  4. Follow PEP8, except where ridiculous.
  5. Include tests for any functionality changes.
  6. Push the changes and create a pull request :D.

Built With

Authors

  • Justin Palmer - Urrverything - Me

Acknowledgments

  • Kenneth Reitz -> setup - Thanks!
  • Kamori -> Cool Guy - Thanks to you as well!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyconvertalert-0.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

pyconvertalert-0.1.1-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pyconvertalert-0.1.1.tar.gz.

File metadata

  • Download URL: pyconvertalert-0.1.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for pyconvertalert-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d2801513fd94986b2eaeaa31c16c31e8b9c491974f77725644bf3738efe38ffa
MD5 4351d66f9b4ad0857bf855400baf221d
BLAKE2b-256 722f6f19a0d7f04060e5123352f46d41ee1ea32c3486b3f6fd3b0926c3f46d87

See more details on using hashes here.

File details

Details for the file pyconvertalert-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: pyconvertalert-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

File hashes

Hashes for pyconvertalert-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 84e63de42f7e8b8e05c929c6d65b56d22a1a93097339ced7abc5fbed88dd4fda
MD5 f4cde46d931e533a0ca55af88f09e9fb
BLAKE2b-256 5b4a26b82a57f8207e635f53629cd434634c02fb04fc6b5d0d34ca54a916f900

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page