diff options
| author | Ultrabug <ultrabug@gentoo.org> | 2014-11-23 20:55:53 +0100 |
|---|---|---|
| committer | Ultrabug <ultrabug@gentoo.org> | 2014-11-23 20:55:53 +0100 |
| commit | d9747b64e1e62abee12ef0bafd365cf380ff7fe9 (patch) | |
| tree | 11a1d156c38ec96b83b4a1780719fc856cbbebad /modules/pingdom.py | |
| parent | 62b2bd2251997bf8608e9620d91f688585221040 (diff) | |
move modules folder so we can install it as a module of py3status
Diffstat (limited to 'modules/pingdom.py')
| -rw-r--r-- | modules/pingdom.py | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/modules/pingdom.py b/modules/pingdom.py deleted file mode 100644 index cddf1a9..0000000 --- a/modules/pingdom.py +++ /dev/null @@ -1,59 +0,0 @@ -# -*- coding: utf-8 -*- - -import requests -from time import time - - -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/ - - #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 # recheck every 10 mins - CHECKS = [] # checks' names you want added to your bar - LATENCY_THRESHOLD = 500 # when to colorize the output - LOGIN = '' # pingdom login - PASSWORD = '' # pingdom password - TIMEOUT = 15 - POSITION = 0 - - 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'] += '{}: {}ms, '.format( - check['name'], - check['lastresponsetime'] - ) - if check['lastresponsetime'] > LATENCY_THRESHOLD: - response.update( - {'color': i3status_config['color_degraded']} - ) - else: - response['full_text'] += '{}: DOWN'.format( - check['name'], - check['lastresponsetime'] - ) - response.update({'color': i3status_config['color_bad']}) - response['full_text'] = response['full_text'].strip(', ') - response['cached_until'] = time() + CACHE_TIMEOUT - - return (POSITION, response) |
