forked from jacobian/munin-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trac_tickets.py
executable file
·52 lines (42 loc) · 1.69 KB
/
trac_tickets.py
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
#!/usr/bin/python
import sys
import munin
class TracTickets(munin.Plugin):
# Queries to perform. Syntax is (label, info, query)
queries = [
('unreviewed', 'Unreviewed', 'status=new|assigned|reopened&stage=Unreviewed'),
('design', 'Design decision needed', 'status=new|assigned|reopened&stage=Design decision needed'),
('accepted', 'Accepted', 'status=new|assigned|reopened&stage=Accepted'),
('ready', 'Ready for checkin', 'status=new|assigned|reopened&stage=Ready for checkin'),
]
def fetch(self):
from trac.ticket.query import Query
env = self._connect()
cursor = env.get_db_cnx().cursor()
for label, info, query in self.queries:
q = Query.from_string(env, query)
cursor.execute(*q.get_sql())
yield ("%s.value" % label, len(list(cursor)))
def config(self):
yield ('graph_title', 'Trac tickets')
yield ('graph_args', '-l 0 --base 1000')
yield ('graph_vlabel', 'Tickets')
yield ('graph_scale', 'no')
yield ('graph_category', 'Trac')
yield ('graph_info', 'Shows current Trac ticket counts')
for label, info, query in self.queries:
yield ("%s.label" % label, label)
yield ("%s.info" % label, info)
def _connect(self):
# Both of the below won't work if PYTHONPATH and TRAC_ENV aren't
# set in the munin-node plugin conf.
import trac.env
return trac.env.open_environment()
def autoconf(self):
try:
self._connect()
except:
return False
return True
if __name__ == '__main__':
munin.run(TracTickets)