库以简化与警报管理器API的交互。
pylertalertmanager的Python项目详细描述
PylertAlertManager
pylertalertmanager旨在成为一个易于使用的接口,用于与alert manager api交互。
开始
pypi提供了最新的稳定版本:
pip install pylertalertmanager
否则您可以从git安装:
pip install git+https://github.com/ABORGT/PylertAlertManager.git
使用量
在这里,我们将介绍一些基本的使用示例,以使人们能够离开并运行。我们在这里导入json只是为了漂亮地打印我们的对象。另外,我们有一个警报管理器实例在Docker中运行。
>>>importjson>>>fromalertmanagerimportAlertManager>>>fromalertmanagerimportAlert>>>>>># 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"}]
运行测试
TOdo:添加测试
贡献
- 用叉子叉。
- 创建一个分支来描述您正在处理的问题或功能。
- 一路上做出改变,承诺。
- 跟随PEP8,除了荒谬的地方。
- 包括任何功能更改的测试。
- 推动更改并创建拉取请求:d。
使用
构建- Python3-语言优美。
作者
- tyler线圈-Other Projects
- justin palmer-Other Projects
致谢
- Kenneth Reitz->;setup-谢谢!