kennethwilke / pingdomlib Goto Github PK
View Code? Open in Web Editor NEWA python library to consume the pingdom API
License: ISC License
A python library to consume the pingdom API
License: ISC License
There's a bug in the Pingdom API:
$ curl -s -X PUT --data "sendnotificationwhendown=2" -H "Authorization: Basic $BAUTH" -H "App-Key: $APPKEY" https://api.pingdom.com/api/2.0/checks/1459050 | python -mjson.tool
{
"message": "Modification of check was successful!"
}
But it's lying, nothing has changed.
The apparent fix is to also supply use_legacy_notifications=true
when changing this particular value. This breaks PingdomCheck.__setattr__
(when pingdom.pushChanges is True).
Awaiting reply from Pingdom (whether they will fix it in their API).
For transactional checks, there's a new set of GET endpoints to retrieve information about them. It'd be great if this library supported them as well:
https://api.pingdom.com/api/2.0/tms.recipes
https://api.pingdom.com/api/2.0/tms.summary.performance/
https://api.pingdom.com/api/2.0/tms.summary.outage/
https://api.pingdom.com/api/2.0/tms.summary.average/
Python noob here. Is this code likely to be updated to work with Python3?
I get various errors trying to use it with Python 3.6.2. Some are simple and appear to be related to the removal of list.iteritems
and dict.iterkeys/values
in Python3; I've fixed locally and that code now appears to do the right thing. Not sure what to do with the below, however:
def __addDetails__(self, checkinfo):
"""Fills attributes from a dictionary, uses special handling for the
'type' key"""
# Auto-load instance attributes from passed in dictionary
for key in checkinfo:
if key == 'type':
if checkinfo[key] in checktypes:
self.type = checkinfo[key]
else:
# Take key from type dict, convert to string for type
self.type = checkinfo[key].keys().next()
# Take value from type dict, store to member of new attrib
object.__setattr__(self, self.type,
checkinfo[key].values().next())
else:
# Store other key value pairs as attributes
object.__setattr__(self, key, checkinfo[key])
The error I get is
>>> checks[0].getDetails()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/pingdomlib/check.py", line 178, in getDetails
self.__addDetails__(response.json()['check'])
File "/usr/local/lib/python3.6/site-packages/pingdomlib/check.py", line 155, in __addDetails__
self.type = checkinfo[key].keys().next()
AttributeError: 'dict_keys' object has no attribute 'next'
Hi Kenneth! I'm trying to install PingdomLib on Python 3 but with no luck because of wsgiref
dependency. As far as I know it is built-in to Python 3.
Couldn't you just remove this dependency from setup.py
? Is it somehow used by your library? I can't see any direct usages in the source code.
'name' is a valid attribute to change in the pingdom API, but the attribute list in check.py __setattr__
(line 64 in 2.0.2) doesn't include it.
I am trying to use PingdomLib to connect a django application on Google App Engine, but I am getting the following exception related to SSL. I couldn't find anything on google to solve this. Please look into this.
INFO 2016-05-12 11:31:32,447 connectionpool.py:788] Starting new HTTPS connection (1): api.pingdom.com
Internal Server Error: /
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/handlers/base.py", line 113, in get_response
response = callback(request, _callback_args, *_callback_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/Application/views.py", line 6, in index
pingdomchecks = api.getChecks()
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/pingdomlib/pingdom.py", line 212, in getChecks
response = self.request('GET', 'checks', parameters)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/pingdomlib/pingdom.py", line 66, in request
headers=headers)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/api.py", line 71, in get
return request('get', url, params=params, *_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/api.py", line 57, in request
return session.request(method=method, url=url, *_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/sessions.py", line 475, in request
resp = self.send(prep, *_send_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/sessions.py", line 585, in send
r = adapter.send(request, *_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/adapters.py", line 477, in send
raise SSLError(e, request=request)
SSLError: Can't connect to HTTPS URL because the SSL module is not available.
ERROR2016-05-12 11:31:32,447 base.py:210] Internal Server Error: /
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django-1.5/django/core/handlers/base.py", line 113, in get_response
response = callback(request, _callback_args, *_callback_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/Application/views.py", line 6, in index
pingdomchecks = api.getChecks()
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/pingdomlib/pingdom.py", line 212, in getChecks
response = self.request('GET', 'checks', parameters)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/pingdomlib/pingdom.py", line 66, in request
headers=headers)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/api.py", line 71, in get
return request('get', url, params=params, *_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/api.py", line 57, in request
return session.request(method=method, url=url, *_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/sessions.py", line 475, in request
resp = self.send(prep, *_send_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/sessions.py", line 585, in send
r = adapter.send(request, *_kwargs)
File "/Users/ankur/Documents/Ankur/ApplicationMonitor/lib/requests/adapters.py", line 477, in send
raise SSLError(e, request=request)
SSLError: Can't connect to HTTPS URL because the SSL module is not available.
INFO 2016-05-12 11:31:32,524 module.py:788] default: "GET / HTTP/1.1" 500 83729
In some places, a verification is done to know if the user is providing valid arguments. I think the lists have some arguments names missing:
While creating a Check, I got a warning about the "tags" argument but it works.
https://github.com/KennethWilke/PingdomLib/blob/master/pingdomlib/check.py#L66
While updating a Check, I got a warning about the "name" argument but it works.
https://github.com/KennethWilke/PingdomLib/blob/master/pingdomlib/check.py#L356
I don't know if these missing arguments are the only one, that's why I can't yet provide a PR. If you think I can make one with only these 2, I will.
Regards,
FYI, it's an API bug, that was reported to Pingdom at 2015-01-26
$ curl -su $PINGDOM_USER:$PINGDOM_PASS -H "App-Key: $PINGDOM_KEY" https://api.pingdom.com/api/2.0/checks/1236831 | python -mjson.tool | grep -A2 contactids
"contactids": [
10640040
],
$ curl -su $PINGDOM_USER:$PINGDOM_PASS -H "App-Key: $PINGDOM_KEY" -X PUT --data 'use_legacy_notifications=true&sendnotificationwhendown=16' https://api.pingdom.com/api/2.0/checks/1236831 | python -mjson.tool
{
"message": "Modification of check was successful!"
}
$ curl -su $PINGDOM_USER:$PINGDOM_PASS -H "App-Key: $PINGDOM_KEY" https://api.pingdom.com/api/2.0/checks/1236831 | python -mjson.tool | grep -A2 contactids
[...nothing...]
Line 242 of pingdom.py lists the "sendtoandroid" parameter, but the warnings that start on 411 do not exclude that parameter. Using that parameter will result in a warning, but nothing worse than that.
Hey there Kenneth,
Can you please create a tag when you upload to PyPi? That helps in collaborating ๐
Thanks!
Hi,
I want to query the pingdom api.
My problem is i can't use email, passwd and api-key.
I must curl the api like this:
curl -X GET -u email:password -H "account-email: main login mail" -H 'Content-Type: application/json' -H 'App-Key: API-KEY' "https://api.pingdom.com/api/2.1/summary.performance/354354354354?includeuptime=true&resolution=hour&order=desc"
The Header account-email is important, without this i get 403 back.
Can someone assist me how I can use the api with this challenge?
I think that Check.__getattr__
is in a loop of some kind when I try to access lasterrortime
attribute on a check where it doesn't exist:
In [1]: details = check.getDetails()
In [2]: details
Out[2]:
{u'contactids': [10919360, 10919362, 10919361],
u'created': 1419369381,
u'hostname': u'domainhasbeenchanged.com',
u'id': 1461209,
u'lastresponsetime': 630,
u'lasttesttime': 1421273340,
u'name': u'domainhasbeenchanged.com',
u'notifyagainevery': 3,
u'notifywhenbackup': True,
u'resolution': 1,
u'sendnotificationwhendown': 4,
u'sendtoandroid': False,
u'sendtoemail': True,
u'sendtoiphone': False,
u'sendtosms': False,
u'sendtotwitter': False,
u'status': u'up',
u'tags': [],
u'type': {u'http': {u'encryption': False,
u'port': 80,
u'requestheaders': {u'User-Agent': u'Pingdom.com_bot_version_1.4_(http://www.pingdom.com)'},
u'url': u'/'}},
u'use_legacy_notifications': True}
In [3]: 'lasterrortime' in details
Out[3]: False
In [4]: hasattr(check, 'lasterrortime')
<hangs here>
After about 30 seconds it finally returns with a False
value. A quick at the code shows that __getattr__
calls getattr
again internally, so I suspect a loop or something, but I haven't tested it.
Hi,
It seems accessing some additional data (by additional data, I mean the keys returned by /checks/{checkid} on Pingdom API but not returned by /checks, e.g. sendnotificationwhendown attribute) on a PingdomCheck returned by Pingdom.getChecks() does not return successfully the value we want.
From what I've understood in the source code, the missing detailed keys are set to None, causing the getattr method not to be called then. See https://github.com/KennethWilke/PingdomLib/blob/master/pingdomlib/check.py#L164.
Is there any explanation for this part of the code? Am I missing something?
Thank you.
Regards,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.