MCPcopy Index your code
hub / github.com/ABORGT/PylertAlertManager

github.com/ABORGT/PylertAlertManager @v0.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.1 ↗ · + Follow
43 symbols 116 edges 7 files 30 documented · 70%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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

  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

Acknowledgments

  • Kenneth Reitz -> setup - Thanks!

Core symbols most depended-on inside this repo

from_dict
called by 9
alertmanager/alert_objects.py
_check_response
called by 8
alertmanager/alertmanager.py
_make_request
called by 8
alertmanager/alertmanager.py
status
called by 4
setup.py
validate_and_dump
called by 4
alertmanager/alert_objects.py
get_alerts
called by 2
alertmanager/alertmanager.py
_validate
called by 1
alertmanager/alert_objects.py
_validate_get_alert_kwargs
called by 1
alertmanager/alertmanager.py

Shape

Method 29
Function 9
Class 5

Languages

Python100%

Modules by API surface

alertmanager/alertmanager.py15 symbols
alertmanager/alert_objects.py14 symbols
examples/qlight.py9 symbols
setup.py5 symbols

For agents

$ claude mcp add PylertAlertManager \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page