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 /py3status/modules/glpi.py | |
| parent | 62b2bd2251997bf8608e9620d91f688585221040 (diff) | |
move modules folder so we can install it as a module of py3status
Diffstat (limited to 'py3status/modules/glpi.py')
| -rw-r--r-- | py3status/modules/glpi.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/py3status/modules/glpi.py b/py3status/modules/glpi.py new file mode 100644 index 0000000..929749d --- /dev/null +++ b/py3status/modules/glpi.py @@ -0,0 +1,52 @@ +# You need MySQL-python from http://pypi.python.org/pypi/MySQL-python +import MySQLdb + + +class Py3status: + """ + 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. + + 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 = '' + POSITION = 0 + + mydb = MySQLdb.connect( + host=MYSQL_HOST, + user=MYSQL_USER, + passwd=MYSQL_PASSWD, + db=MYSQL_DB, + connect_timeout=5, + ) + 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() + + return (POSITION, response) |
