Last active
November 24, 2015 16:00
-
-
Save Tafkas/415069294ad42a34eb1c to your computer and use it in GitHub Desktop.
A munin plugin for Linux to monitor Codebase ticket progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
codebase_munin - A munin plugin for Linux to monitor Codebase ticket progress | |
Copyright (C) 2015 Christian Stade-Schuldt | |
Author: Christian Stade-Schuldt | |
Like Munin, this plugin is licensed under the GNU GPL v2 license | |
http://www.opensource.org/licenses/GPL-2.0 | |
Add the following section to your munin-node's plugin configuration: | |
[codebase_*] | |
env.codebase_user [codebase_api_user] | |
env.codebase_key [codebase_api_key] | |
This plugin supports the following munin configuration parameters: | |
#%# family=auto contrib | |
#%# capabilities=autoconf | |
""" | |
import os | |
import re | |
import sys | |
import time | |
import requests | |
def get_ticket_statuses(): | |
"""get the current ticket statuses""" | |
codebase_api_user = os.environ['codebase_user'] | |
codebase_api_key = os.environ['codebase_key'] | |
# ignore statuses Archive, Done and Invalid | |
statuses_list = ["Deployed", "In Progress", "In specification", "On hold", "Open", "QA", "Ready for deploy", "Specified"] | |
ticket_statuses = {s : 0 for s in statuses_list} | |
for s in statuses_list: | |
cnt = 1 | |
while True: | |
payload = {'page' : cnt, 'query' : 'status:"{}"'.format(s)} | |
r = requests.get('https://api3.codebasehq.com/bi/tickets.json', params=payload, auth=(codebase_api_user, codebase_api_key)) | |
if r.status_code == 200: | |
for ticket in r.json(): | |
if ticket['ticket']['status']: | |
status = ticket['ticket']['status']['name'] | |
ticket_statuses[status] += 1 | |
#time.sleep(1) | |
cnt += 1 | |
else: | |
break | |
for s in statuses_list: | |
print'%s.value %d' % (s.replace(' ', '_').lower(), ticket_statuses[s]) | |
def print_config(): | |
print "graph_title Codebase tickets by status" | |
print "graph_vlabel number of tickets" | |
print "graph_category codebase" | |
print "graph_order deployed, in_progress, in_specification, on_hold, open, qa, ready_for_deploy, specified" | |
print "graph_info This graph shows the ticket statuses of the bi project." | |
print "graph_scale no" | |
print "deployed.label deployed" | |
print "deployed.type GAUGE" | |
print "deployed.draw AREA" | |
print "in_progress.type GAUGE" | |
print "in_progress.draw STACK" | |
print "in_progress.label in_progress" | |
print "in_specification.type GAUGE" | |
print "in_specification.draw STACK" | |
print "in_specification.label in_specification" | |
print "on_hold.type GAUGE" | |
print "on_hold.draw STACK" | |
print "on_hold.label on_hold" | |
print "open.type GAUGE" | |
print "open.draw STACK" | |
print "open.label open" | |
print "qa.type GAUGE" | |
print "qa.draw STACK" | |
print "qa.label qa" | |
print "ready_for_deploy.type GAUGE" | |
print "ready_for_deploy.draw STACK" | |
print "ready_for_deploy.label ready_for_deploy" | |
print "specified.type GAUGE" | |
print "specified.draw STACK" | |
print "specified.label specified" | |
if __name__ == '__main__': | |
if len(sys.argv) == 2 and sys.argv[1] == 'config': | |
print_config() | |
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf': | |
print 'yes' | |
elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch': | |
# Some docs say it'll be called with fetch, some say no arg at all | |
try: | |
get_ticket_statuses() | |
except: | |
sys.exit("Couldn't retrieve codebase ticket statuses") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment