0

I am new learner to use pingdom-api in django-project to check the status of website. I have imported pingdom library to access methods directly in my views.py

my views.py

import datetime
import pingdomlib

api = pingdomlib.Pingdom( username = "anilxxxx@gmail.com", password = "xxxxxx", apikey = "xf8xyxxxxxxxxxxxxxxxxxxxxxxx")


def get_actions_alerts(request):
    pingdomactions=api.actions()
    print "pingdomactions=",  pingdomactions 

    for alert in api.alerts(limit=10):
        time = datetime.datetime.fromtimestamp(alert['time'])
        timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
        print timestamp
        print "[%s] %s is %s" % (time, alert['name'], alert['status'])

    return render_to_response("base_audit_template.html") #need to render data to this page


def get_checks(request):
    pingdomchecks = api.getChecks()
    print "pingdomchecks" , pingdomchecks
    for check in pingdomchecks:
    # See pingdomlib.check documentation for information on PingdomCheck class
        if check.status != 'up':
            print check
        else :
            print "status up:" , check
    return render_to_response("base_audit_template.html")

But pingdomactions list is empty on hiting url, also not reading alerts

Terminal putput :


pingdomactions= {u'alerts': []}
[21/Jul/2013 05:19:08] "GET /data/actions/ HTTP/1.1" 200 2075

Questions:

  1. What are the possible problems for getting empty action list ? . Do you have any solutions for this error.

  2. Am i using this pingdomlib correctly? or there is another-way to use it.

Anil Arya
  • 3,100
  • 7
  • 43
  • 69
  • do you indeed have some alerts in your pingdom account? Can you access them directly via https://api.pingdom.com/api/2.0/actions ? – Hieu Nguyen Jul 21 '13 at 11:35
  • on hitting url ,It asked for username & password and is giving http 403 forbidden error – Anil Arya Jul 21 '13 at 12:17
  • How to provide app-key in url? – Anil Arya Jul 21 '13 at 12:19
  • Ah right, nevermind. Still do you have some alerts in your pingdom account? – Hieu Nguyen Jul 21 '13 at 12:22
  • always this error comes.....{ "error":{ "statuscode":403, "statusdesc":"Forbidden", "errormessage":"Something went wrong! This string describes what happened." } } – Anil Arya Jul 21 '13 at 17:13
  • Sorry you should use tools like hurl.it to make the request. Provide username and password in basic auth and App-key in header – Hieu Nguyen Jul 21 '13 at 17:41
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33868/discussion-between-hieu-nguyen-and-arya) – Hieu Nguyen Jul 21 '13 at 18:19
  • See what happens if you provide a deliberately incorrect apikey. If you get the same behavior, then it's likely a typo in the credentials. If you get an authentication error instead (not sure, haven't used pingdomlib), then triple-check that you actually have had some alerts - if not, what you're seeing is the expected response. Also try .getChecks(): even if you've never had an alert, as long as you have a check running, it should return some data. – AdamKG Jul 21 '13 at 18:48
  • @AdamKG :I have ckecked app-key many time, its right . I have also checked .getChecks() , but its giving error , no positive output. – Anil Arya Jul 21 '13 at 19:13
  • Right. Please post the output of the getChecks error. And I don't need you to recheck the api key, I need you to *make* it incorrect and see what happens - I'm trying to make sure that what I expect (an exception about the credentials) is actually what happens in that case. – AdamKG Jul 21 '13 at 19:17
  • "pingdomchecks [] " This thing is coming on terminal – Anil Arya Jul 21 '13 at 19:28
  • OK. So I think that's it then: it's working fine, you just haven't had any alerts. (Try taking your site down if you want to be sure :D) – AdamKG Jul 21 '13 at 19:42
  • @AdamKG : Yes !! check status giving +ve response but still i am getting empty action and alert list. Any solution? – Anil Arya Jul 22 '13 at 04:38
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33884/discussion-between-arya-and-adamkg) – Anil Arya Jul 22 '13 at 07:22
  • @Arya it is working, you're fine. You're getting empty action and alerts data because you've had no alerts... when your site goes down, it won't be empty anymore. But everything is working exactly like it is supposed to: since there are no alerts (downtime), the alert list is empty. – AdamKG Jul 22 '13 at 12:36

1 Answers1

1

The api.action() will pass up the alerts returned by the pingdom api, it'll be empty if pingdom has taken no actions in response to alerts. Typically what I've seen from actions is a list of the email alerts pingdom has sent out as a response to downs, so if you haven't had any downs or any email/sms/other alerts sent out from pingdom that's most likely why it is empty.

Overall it looks like you are using my lib as intended, please let me know if it's still giving you any struggles!

Kenneth Wilke
  • 4,631
  • 1
  • 15
  • 7