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.
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
>>> from pyconvertalert import Converter
>>>
>>> test_lookup_dict_1 = {
... "values": [
... {
... "people": [
... {
... "email": "[email protected]",
... "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': '[email protected]', 'phone_number': '111-111-1111'}}
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'.
Should be as simple as:
python -m unittest test_py_convert_alert.py
- Fork it.
- Create a branch describing either the issue or feature you're working.
- Making changes, committing along the way.
- Follow PEP8, except where ridiculous.
- Include tests for any functionality changes.
- Push the changes and create a pull request :D.
- Python3 - Beautiful language.
- Justin Palmer - Urrverything - Me