blob: 708ed4fedea45f28b175c9aab1ca0dd8ad0415f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# -*- 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.
"""
# 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__":
"""
Test this module by calling it directly.
"""
from time import sleep
x = Py3status()
config = {
'color_good': '#00FF00',
'color_bad': '#FF0000',
}
while True:
print(x.count_glpi_open_tickets([], config))
sleep(1)
|