Package: pypingdom
Python library for interacting with Pingdom services (REST API and maintenance windows).FeaturesSupport forMulti-User AuthenticationCheck management: create, delete, update, listMaintenance windows: create, delete, listFetching outage summariesWarningSince the Pingdom REST API don’t support maintenance windows, we interact
with the Website for it. Therefore this feature is highly fragile and canbreakat any moment due to frontend changes on the Pingdom website.RequirementsPingdom accountrequests (0.10.8 or newer)InstallationpipinstallpypingdomUsageTheclientobject will allow you to interact both with the REST API and the
GUI (for maintenance windows).>>>importpypingdom>>>client=pypingdom.Client(username="username@example.com",password="your_password",apikey="your_api_key",email="your_email")theemailparameter is required forMultiuser Authentication.ChecksSince Pingdom does not treat the check name as identifier (as we probably want
to do) the client object will retrieve the check list from the API and cache it
as a dictionary ( check_name => check_instance). You can access it through thechecksattribute:>>>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:[]a better way to retrieve a check would be:>>>client.get_check("my awesome check")that will return None if the check doesn’t existsList checks withproductionandfrontendtags:>>>client.get_checks(filters={"tags":["production","frontend"]})Create a check:>>>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)Refers tothis pagefor the list of options.When you create or modify a check some related entity need to be referenced by id:IntegrationsTo enable/disable an integration plugins (like webhooks) use the fieldintegrationids(array with integer ids to set or “null” tring to remove it)Alert policiesTo bind an alerting policy use the fieldalert_policy(numeric id to set it or string “null” to disable alerts)Update a check:>>>client.update_check(check,{"paused":True})this will return True if an effective change was sent to the API and False
otherwise (useful for idempotent usage, like ansible modules)Delete a check:>>>client.delete_check(check)Maintenance windowsRetreive maintenance windows for production websites in the last 7 days:>>>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})Create a 1 hour maintenance window for production websites:>>>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})Delete future maintenance windows:>>>windows=client.get_maintenances(filters={"checks":checks,"after":datetime.datetime.now()}):>>>forminmaintenances:client.delete_maintenance(m)Reporting/summaryRetrieve average response time and uptime summaries:>>>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")