<commit_before># -*- coding: utf-8 -*-
"""
Display the total number of open tickets from GLPI.

Configuration parameters:
    critical: set bad color above this threshold
    db: database to use
    host: database host to connect to
    password: login password
    user: login user
    warning: set degraded color above this threshold

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.
"""

# You need MySQL-python from http://pypi.python.org/pypi/MySQL-python
import MySQLdb


class Py3status:
    """
    """
    # available configuration parameters
    critical = 20
    db = ''
    host = ''
    password = ''
    timeout = 5
    user = ''
    warning = 15

    def count_glpi_open_tickets(self, i3s_output_list, i3s_config):
        response = {'full_text': ''}

        mydb = MySQLdb.connect(
            host=self.host,
            user=self.user,
            passwd=self.password,
            db=self.db,
            connect_timeout=self.timeout,
        )
        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 i3s_config['colors']:
                if open_tickets > self.critical:
                    response.update({'color': i3s_config['color_bad']})
                elif open_tickets > self.warning:
                    response.update(
                        {'color': i3s_config['color_degraded']}
                    )
            response['full_text'] = '%s tickets' % open_tickets
        mydb.close()

        return response

if __name__ == "__main__":
    """
    Run module in test mode.
    """
    from py3status.module_test import module_test
    module_test(Py3status)<commit_msg>Color updates: glpi<commit_after># -*- coding: utf-8 -*-
"""
Display the total number of open tickets from GLPI.

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.

Configuration parameters:
    critical: set bad color above this threshold
    db: database to use
    host: database host to connect to
    password: <PASSWORD>
    user: login user
    warning: set degraded color above this threshold

Color options:
    color_bad: Open ticket above critical threshold
    color_degraded: Open ticket above warning threshold

Requires:
    MySQL-python: http://pypi.python.org/pypi/MySQL-python
"""

import MySQLdb


class Py3status:
    """
    """
    # available configuration parameters
    critical = 20
    db = ''
    host = ''
    password = ''
    timeout = 5
    user = ''
    warning = 15

    def count_glpi_open_tickets(self):
        response = {'full_text': ''}

        mydb = MySQLdb.connect(
            host=self.host,
            user=self.user,
            passwd=<PASSWORD>,
            db=self.db,
            connect_timeout=self.timeout,
        )
        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 open_tickets > self.critical:
                response.update({'color': self.py3.COLOR_BAD})
            elif open_tickets > self.warning:
                response.update(
                    {'color': self.py3.COLOR_DEGRADED}
                )
            response['full_text'] = '%s tickets' % open_tickets
        mydb.close()

        return response

if __name__ == "__main__":
    """
    Run module in test mode.
    """
    from py3status.module_test import module_test
    module_test(Py3status)
{'fraction_non_alphanumeric': 0.0920276852089208, 'fraction_numerical': 0.007433991284286081, 'mean_word_length': 2.024806201550388, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2455612', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1071, 'n_words': 322}