pingdom服务的客户端
pypingdom的Python项目详细描述
用于与pingdom服务(rest api和维护窗口)交互的python库。
功能
- 支持Multi-User Authentication
- 支票管理:创建、删除、更新、列表
- 维护窗口:创建、删除、列表
- 获取中断摘要
警告
因为pingdom rest api不支持维护窗口,所以我们交互 和它的网站。因此,此功能非常脆弱,可以 break由于pingdom网站的前端更改而随时中断。
要求
- pingdom帐户
- 请求(0.10.8或更新版本)
安装
pipinstallpypingdom
用法
客户机对象将允许您与rest api和 图形用户界面(用于维护窗口)。
>>>importpypingdom>>>client=pypingdom.Client(username="username@example.com",password="your_password",apikey="your_api_key",email="your_email")
Multiuser Authentication需要email参数。
检查
因为pingdom不将检查名作为标识符(我们可能希望 客户端对象将从api检索检查列表并缓存它 作为字典(check_name=>;check_instance)。你可以通过 检查属性:
>>>client.checks["my awesome check"]pingdom.Check<1895866>autoresolve:0alert_policy:2118909name:example_comcreated:1448565930lasterrortime:1489325292resolution:1lastresponsetime:558lasttesttime:1489847772alert_policy_name:ProductionSystemspaused:Falsehost:hostname.example.comacktimeout:0ipv6:Falseuse_legacy_notifications:Falsetype:httptags:[]
取回支票的更好方法是:
>>>client.get_check("my awesome check")如果检查不存在,则不会返回任何值。
使用production和frontend标记进行列表检查:
>>>client.get_checks(filters={"tags":["production","frontend"]})
创建支票:
>>>check_definition={"name":"My awesome check","paused":True,"alert_policy":201745,"type":"http","host":"www.google.com","url":"/","requestheaders":{'XCustom':'my header value'},"tags":[{"name":"pypingdom-test"},{"name":"custom-tag"}],"encryption":False}>>>client.create_check(check_definition)
为选项列表引用this page。
当您创建或修改支票时,某些相关实体需要被id引用:
集成
要启用/禁用集成插件(如webhook),请使用字段integration ids(要设置整数id的数组或要删除它的“null”字符串)
警报策略
若要绑定警报策略,请使用字段alert\u policy(数字标识设置它,或字符串“null”禁用警报)
更新支票:
>>>client.update_check(check,{"paused":True})
如果向api发送了有效的更改,则返回true,否则返回false 否则(对于幂等用法很有用,如ansible模块)
删除支票:
>>>client.delete_check(check)
维护窗口
检索最近7天内生产网站的维护窗口:
>>>importdatetime>>>checks=client.get_checks(filters={"tags":["production","frontend"]})>>>start=datetime.datetime.now()-datetime.timedelta(days=7)>>>client.get_maintenances(filters={"checks":checks,"after":start})
为生产网站创建1小时维护窗口:
>>>start=datetime.datetime.now()+datetime.timedelta(minutes=10)>>>end=start+datetime.timedelta(hours=1)>>>window=client.create_maintenance({"checks":checks,"name":"pypingdom test maintenance","start":start,"stop":end})
删除未来的维护窗口:
>>>windows=client.get_maintenances(filters={"checks":checks,"after":datetime.datetime.now()}):>>>forminmaintenances:client.delete_maintenance(m)
报告/摘要
检索平均响应时间和正常运行时间摘要:
>>>checkid=client.get_check("my awesome check")._id>>>start=int(time.time())-30*24*60*60# 30 days back>>>end=time.time()>>>client.get_summary_average(checkid,start,end,include_uptime="true")