pingdom服务的客户端

pypingdom的Python项目详细描述


https://img.shields.io/pypi/v/pypingdom.svghttps://img.shields.io/pypi/l/pypingdom.svghttps://img.shields.io/pypi/pyversions/pypingdom.svghttps://travis-ci.org/sekipaolo/pypingdom.svg?branch=master

用于与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")
如果检查不存在,则不会返回任何值。

使用productionfrontend标记进行列表检查:

>>>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")

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java根据两个数组的值对数组进行排序   具有自签名证书和NTLM代理的java Maven SSL repo错误   java自定义字体按钮不工作AndroidStudio   java通过Spring MVC web应用程序向客户端发送文本文件   Java Spring Web服务SOAP身份验证   ANT property environment=“env”无法在JAVA中检索它,但如果作为ANT命令运行,则可以正常工作   java是为spring mvc rest api或spring boot api对应用服务器的每个新请求创建的服务、存储库和组件的新实例吗?   java私有静态最终字符串未完成其工作   PKCS12的安全Java密钥重新处理   java JPA继承表每类SQLSyntaxErrorException