diff options
author | Weitian LI <liweitianux@gmail.com> | 2014-06-13 21:12:21 +0800 |
---|---|---|
committer | Weitian LI <liweitianux@gmail.com> | 2014-06-13 21:12:21 +0800 |
commit | 78f7be4e4b6501b15b5fefc9f7824bbadf0daf2a (patch) | |
tree | b761e28709e4a6f45458c323b8870150827ef831 /.i3/py3status/backup/pingdom.py | |
parent | e1ce158f65c472b7c8d14c04fce94c85bc881a6c (diff) | |
download | dotfiles-78f7be4e4b6501b15b5fefc9f7824bbadf0daf2a.tar.bz2 |
Added various dotfiles.
* Xresources
* profile, xprofile, xinitrc
* bash (aliases, logout, profile, rc, completion)
* gitconfig
* gtkrc and gtk-bookmarks
* i3 configs (with py3status configs)
* i3status.conf
* lftp/rc
* tmux.conf
* xbindkeysrc
* mpdconf
* ncmpcpp (config and keys)
* sbclrc
* vifm (vifmrc, colors)
* urxvt (perl extensions)
* conkyrc (and conky/cronograph configs)
Diffstat (limited to '.i3/py3status/backup/pingdom.py')
-rw-r--r-- | .i3/py3status/backup/pingdom.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/.i3/py3status/backup/pingdom.py b/.i3/py3status/backup/pingdom.py new file mode 100644 index 0000000..cddf1a9 --- /dev/null +++ b/.i3/py3status/backup/pingdom.py @@ -0,0 +1,59 @@ +# -*- 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) |