forked from ultrabug/py3status
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PEP8 identation and python3 compatible examples
- Loading branch information
Showing
3 changed files
with
98 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
class Py3status: | ||
""" | ||
Empty and basic py3status class | ||
""" | ||
def empty(self, json, i3status_config): | ||
""" | ||
This method will return an empty text message, so it will NOT be displayed. | ||
If you want something displayed you should write something in the 'full_text' key of your response. | ||
See the i3bar protocol spec for more information: | ||
http://i3wm.org/docs/i3bar-protocol.html | ||
""" | ||
response = {'full_text' : '', 'name' : 'empty'} | ||
return (0, response) | ||
""" | ||
Empty and basic py3status class | ||
""" | ||
def empty(self, json, i3status_config): | ||
""" | ||
This method will return an empty text message, so it will NOT be displayed. | ||
If you want something displayed you should write something in the 'full_text' key of your response. | ||
See the i3bar protocol spec for more information: | ||
http://i3wm.org/docs/i3bar-protocol.html | ||
""" | ||
response = {'full_text' : '', 'name' : 'empty'} | ||
return (0, response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
class Py3status: | ||
""" | ||
This example class demonstrates how to display the current total number of | ||
open tickets from GLPI in your i3bar. | ||
""" | ||
This example class demonstrates how to display the current total number of | ||
open tickets from GLPI in your i3bar. | ||
It features thresholds to colorize the output and forces a low timeout to | ||
limit the impact of a server connectivity problem on your i3bar freshness. | ||
It features thresholds to colorize the output and forces a low timeout to | ||
limit the impact of a server connectivity problem on your i3bar freshness. | ||
Note that we don't have to implement a cache layer as it is handled by | ||
py3status automagically. | ||
""" | ||
def count_glpi_open_tickets(self, json, i3status_config): | ||
response = {'full_text' : '', 'name' : 'glpi_tickets'} | ||
Note that we don't have to implement a cache layer as it is handled by | ||
py3status automagically. | ||
""" | ||
def count_glpi_open_tickets(self, json, i3status_config): | ||
response = {'full_text' : '', 'name' : 'glpi_tickets'} | ||
|
||
# user-defined variables | ||
CRIT_THRESHOLD = 20 | ||
WARN_THRESHOLD = 15 | ||
MYSQL_DB = '' | ||
MYSQL_HOST = '' | ||
MYSQL_PASSWD = '' | ||
MYSQL_USER = '' | ||
# user-defined variables | ||
CRIT_THRESHOLD = 20 | ||
WARN_THRESHOLD = 15 | ||
MYSQL_DB = '' | ||
MYSQL_HOST = '' | ||
MYSQL_PASSWD = '' | ||
MYSQL_USER = '' | ||
|
||
try: | ||
# You need MySQL-python from http://pypi.python.org/pypi/MySQL-python | ||
import MySQLdb | ||
try: | ||
# You need MySQL-python from http://pypi.python.org/pypi/MySQL-python | ||
import MySQLdb | ||
|
||
mydb = MySQLdb.connect( | ||
host=MYSQL_HOST, | ||
user=MYSQL_USER, | ||
passwd=MYSQL_PASSWD, | ||
db=MYSQL_DB, | ||
connect_timeout=1, # dont cause a lag on i3bar freshness | ||
) | ||
mycr = mydb.cursor() | ||
mycr.execute('select count(*) from glpi_tickets where closedate is NULL and solvedate is NULL;') | ||
row = mycr.fetchone() | ||
if row: | ||
open_tickets = int(row[0]) | ||
if i3status_config['colors']: | ||
if open_tickets > CRIT_THRESHOLD: | ||
response.update({'color': i3status_config['color_bad']}) | ||
elif open_tickets > WARN_THRESHOLD: | ||
response.update({'color': i3status_config['color_degraded']}) | ||
response['full_text'] = '%s tickets' % open_tickets | ||
mydb.close() | ||
except Exception, e: | ||
pass | ||
finally: | ||
return (0, response) | ||
mydb = MySQLdb.connect( | ||
host=MYSQL_HOST, | ||
user=MYSQL_USER, | ||
passwd=MYSQL_PASSWD, | ||
db=MYSQL_DB, | ||
connect_timeout=1, # dont cause a lag on i3bar freshness | ||
) | ||
mycr = mydb.cursor() | ||
mycr.execute('select count(*) from glpi_tickets where closedate is NULL and solvedate is NULL;') | ||
row = mycr.fetchone() | ||
if row: | ||
open_tickets = int(row[0]) | ||
if i3status_config['colors']: | ||
if open_tickets > CRIT_THRESHOLD: | ||
response.update({'color': i3status_config['color_bad']}) | ||
elif open_tickets > WARN_THRESHOLD: | ||
response.update({'color': i3status_config['color_degraded']}) | ||
response['full_text'] = '%s tickets' % open_tickets | ||
mydb.close() | ||
except Exception as e: | ||
pass | ||
finally: | ||
return (0, response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |