Skip to content
This repository has been archived by the owner on Nov 25, 2017. It is now read-only.

Commit

Permalink
Make trac_tickets.py a module so it can be imported.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobian committed Feb 27, 2009
1 parent 2020e48 commit 5a6f90c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 53 deletions.
53 changes: 0 additions & 53 deletions trac_tickets

This file was deleted.

1 change: 1 addition & 0 deletions trac_tickets
53 changes: 53 additions & 0 deletions trac_tickets.py
@@ -0,0 +1,53 @@
#!/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" % info, info)
yield ("%s.type" % type, "GAUGE")

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)

0 comments on commit 5a6f90c

Please sign in to comment.