PylertAlertManager
PylertAlertManager aims to be an easy-to-use interface for interacting with the Alert Manager API.
Getting Started
The latest stable release is available from PyPI:
pip install pylertalertmanager
Otherwise you can install from git:
pip install git+https://github.com/ABORGT/PylertAlertManager.git
Usage
Here we cover some basic usage examples to get folks off and running. We are importing json here just to pretty print our objects. Additionally, we have an Alert Manager instance running in docker to target.
>>> import json
>>> from alertmanager import AlertManager
>>> from alertmanager import Alert
>>>
>>> # Provide some test data to be converted into an Alert object.
>>> test_data = {
... "labels": {
... "alertname": "TestAlert",
... "instance": "TestInstance",
... "severity": "critical"
... },
... "annotations": {
... "description": "This is a test alert",
... "info": "Test Alert",
... "summary": "A simple Test alert"
... }
... }
>>># Run the from_dict method on our test_data.
>>> test_alert = Alert.from_dict(test_data)
>>> type(test_alert)
<class 'alertmanager.alertmanager.Alert'>
>>>
>>> # Add an annotation with the add_annotation method.
>>> test_alert.add_annotation('test_annotation', 'this is a test annotation')
>>> print(json.dumps(test_alert, indent=4))
{
"labels": {
"alertname": "TestAlert",
"instance": "TestInstance",
"severity": "critical"
},
"annotations": {
"description": "This is a test alert",
"info": "Test Alert",
"summary": "A simple Test alert",
"test_annotation": "this is a test annotation"
}
}
>>> # Add a label with the add_label method.
>>> test_alert.add_label('test_label', 'this is a test label')
>>> print(json.dumps(test_alert, indent=4))
{
"labels": {
"alertname": "TestAlert",
"instance": "TestInstance",
"severity": "critical",
"test_label": "this is a test label"
},
"annotations": {
"description": "This is a test alert",
"info": "Test Alert",
"summary": "A simple Test alert",
"test_annotation": "this is a test annotation"
}
}
>>> # Specify an Alert Manager host to connect to.
>>> host = 'http://127.0.0.1'
>>> a_manager = AlertManager(host=host)
>>>
>>> # Post an alert to our Alert Manager.
>>> a_manager.post_alerts(test_alert)
<Box: {'status': 'success'}>
>>> # Return a list of alerts from our Alert Manager.
>>> alerts = a_manager.get_alerts()
>>> print(json.dumps(alerts, indent=4))
[
{
"labels": {
"alertname": "TestAlert",
"instance": "TestInstance",
"severity": "critical",
"test_label": "this is a test label"
},
"annotations": {
"description": "This is a test alert",
"info": "Test Alert",
"summary": "A simple Test alert",
"test_annotation": "this is a test annotation"
},
"startsAt": "2018-11-08T16:25:02.327027475Z",
"endsAt": "2018-11-08T16:30:02.327027475Z",
"generatorURL": "",
"status": {
"state": "unprocessed",
"silencedBy": [],
"inhibitedBy": []
},
"receivers": [
"team-X-mails"
],
"fingerprint": "e6b119b9ce57e0c4"
}
]
Running the tests
TODO: Add tests
Contributing
- 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.
Built With
- Python3 - Beautiful language.
Authors
- Tyler Coil - Other Projects
- Justin Palmer - Other Projects
Acknowledgments
- Kenneth Reitz -> setup - Thanks!
Metadata
Release files for pylertalertmanager 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pylertalertmanager-0.1.1.tar.gz | 8.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pylertalertmanager-0.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 18.7 kB
Release files / pylertalertmanager-0.1.1.tar.gz
| Download URL | pylertalertmanager-0.1.1.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3d03968f5e0abc98aecf7458f846c94e53b74df34e18c8db9ecf8d78c8eee02
|
|
BLAKE2b-256 checksum How to use checksums |
a57e6d6ebc7d42764cc27c30bc5701738fa511fe7bcbc078b2d82e45b1463cac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Release files / pylertalertmanager-0.1.1-py2.py3-none-any.whl
| Download URL | pylertalertmanager-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f453c225fe1e4fc841a29206fc1617ba2ec00b7c1e647041b37be88173ec4e8c
|
|
BLAKE2b-256 checksum How to use checksums |
b64a6750d37916a3734940e8e310db97d7b90de1202939bb63bc3f880d261ab2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Security for pylertalertmanager 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.