summaryrefslogtreecommitdiffstats
path: root/examples/pingdom.py
diff options
context:
space:
mode:
authorUltrabug <ultrabug@gentoo.org>2013-04-07 17:11:43 +0200
committerUltrabug <ultrabug@gentoo.org>2013-04-07 17:11:43 +0200
commit1d0df93fda422538118984e801553d074d976117 (patch)
tree918b0c2393cbf77764c15319823d8e64d0558f44 /examples/pingdom.py
parent2b220ab5b0427212da6d00a7e52386265a10e736 (diff)
PEP8 identation and python3 compatible examples
Diffstat (limited to 'examples/pingdom.py')
-rw-r--r--examples/pingdom.py86
1 files changed, 43 insertions, 43 deletions
diff --git a/examples/pingdom.py b/examples/pingdom.py
index 676e6d3..5c4fb74 100644
--- a/examples/pingdom.py
+++ b/examples/pingdom.py
@@ -1,49 +1,49 @@
# -*- coding: utf-8 -*-
class Py3status:
- """
- Dynamically display the latest response time of the configured checks using
- the Pingdom API.
- We also verify the status of the checks and colorize if needed.
- Pingdom API doc : https://www.pingdom.com/services/api-documentation-rest/
+ """
+ Dynamically display the latest response time of the configured checks using
+ the Pingdom API.
+ We also verify the status of the checks and colorize if needed.
+ Pingdom API doc : https://www.pingdom.com/services/api-documentation-rest/
- #NOTE: This module needs the 'requests' python module from pypi
- https://pypi.python.org/pypi/requests
- """
- def pingdom_checks(self, json, i3status_config):
- response = {'full_text' : '', 'name' : 'pingdom_checks'}
+ #NOTE: This module needs the 'requests' python module from pypi
+ https://pypi.python.org/pypi/requests
+ """
+ def pingdom_checks(self, json, i3status_config):
+ response = {'full_text' : '', 'name' : 'pingdom_checks'}
- #NOTE: configure me !
- APP_KEY = '' # create an APP KEY on pingdom first
- CACHE_TIMEOUT = 600 # update every 10 mins
- CHECKS = [] # list of the checks' names you want added to your bar
- LATENCY_THRESHOLD = 500 # when to colorize the output
- LOGIN = '' # pingdom login
- PASSWORD = '' # pingdom password
- TIMEOUT = 3
+ #NOTE: configure me !
+ APP_KEY = '' # create an APP KEY on pingdom first
+ CACHE_TIMEOUT = 600 # update every 10 mins
+ CHECKS = [] # list of the checks' names you want added to your bar
+ LATENCY_THRESHOLD = 500 # when to colorize the output
+ LOGIN = '' # pingdom login
+ PASSWORD = '' # pingdom password
+ TIMEOUT = 3
- try:
- import requests
- from time import time
- r = requests.get(
- 'https://api.pingdom.com/api/2.0/checks',
- auth=(LOGIN, PASSWORD),
- headers={'App-Key': APP_KEY},
- timeout=TIMEOUT,
- )
- result = r.json()
- if 'checks' in result:
- for check in [ck for ck in result['checks'] if ck['name'] in CHECKS]:
- if check['status'] == 'up':
- response['full_text'] += '%s: %sms, ' % (check['name'], check['lastresponsetime'])
- if check['lastresponsetime'] > LATENCY_THRESHOLD:
- response.update({'color': i3status_config['color_degraded']})
- else:
- response['full_text'] += '%s: DOWN' % (check['name'], check['lastresponsetime'])
- response.update({'color': i3status_config['color_bad']})
- response['full_text'] = response['full_text'].strip(', ')
- response['cached_until'] = time() + CACHE_TIMEOUT
- except Exception, e:
- pass
- finally:
- return (0, response)
+ try:
+ import requests
+ from time import time
+ r = requests.get(
+ 'https://api.pingdom.com/api/2.0/checks',
+ auth=(LOGIN, PASSWORD),
+ headers={'App-Key': APP_KEY},
+ timeout=TIMEOUT,
+ )
+ result = r.json()
+ if 'checks' in result:
+ for check in [ck for ck in result['checks'] if ck['name'] in CHECKS]:
+ if check['status'] == 'up':
+ response['full_text'] += '%s: %sms, ' % (check['name'], check['lastresponsetime'])
+ if check['lastresponsetime'] > LATENCY_THRESHOLD:
+ response.update({'color': i3status_config['color_degraded']})
+ else:
+ response['full_text'] += '%s: DOWN' % (check['name'], check['lastresponsetime'])
+ response.update({'color': i3status_config['color_bad']})
+ response['full_text'] = response['full_text'].strip(', ')
+ response['cached_until'] = time() + CACHE_TIMEOUT
+ except Exception as e:
+ pass
+ finally:
+ return (0, response)