Skip to content
Newer
Older
100755 53 lines (42 sloc) 1.69 KB
5a6f90c @jacobian Make trac_tickets.py a module so it can be imported.
jacobian authored
1 #!/usr/bin/python
2
3 import sys
4 import munin
5
6 class TracTickets(munin.Plugin):
7
8 # Queries to perform. Syntax is (label, info, query)
9 queries = [
10 ('unreviewed', 'Unreviewed', 'status=new|assigned|reopened&stage=Unreviewed'),
11 ('design', 'Design decision needed', 'status=new|assigned|reopened&stage=Design decision needed'),
12 ('accepted', 'Accepted', 'status=new|assigned|reopened&stage=Accepted'),
13 ('ready', 'Ready for checkin', 'status=new|assigned|reopened&stage=Ready for checkin'),
14 ]
15
16 def fetch(self):
17 from trac.ticket.query import Query
18
19 env = self._connect()
20 cursor = env.get_db_cnx().cursor()
21
22 for label, info, query in self.queries:
23 q = Query.from_string(env, query)
24 cursor.execute(*q.get_sql())
25 yield ("%s.value" % label, len(list(cursor)))
26
27 def config(self):
28 yield ('graph_title', 'Trac tickets')
29 yield ('graph_args', '-l 0 --base 1000')
30 yield ('graph_vlabel', 'Tickets')
31 yield ('graph_scale', 'no')
32 yield ('graph_category', 'Trac')
33 yield ('graph_info', 'Shows current Trac ticket counts')
34 for label, info, query in self.queries:
35 yield ("%s.label" % label, label)
af5a354 @jacobian A few more teaks to trac stuff.
jacobian authored
36 yield ("%s.info" % label, info)
5a6f90c @jacobian Make trac_tickets.py a module so it can be imported.
jacobian authored
37
38 def _connect(self):
39 # Both of the below won't work if PYTHONPATH and TRAC_ENV aren't
40 # set in the munin-node plugin conf.
41 import trac.env
42 return trac.env.open_environment()
43
44 def autoconf(self):
45 try:
46 self._connect()
47 except:
48 return False
49 return True
50
51 if __name__ == '__main__':
52 munin.run(TracTickets)
Something went wrong with that request. Please try again.