Add link to jenkins job from service-checks dashboard

Upgrade to distribute==0.6.49
Add templatetags
Add link to jenkins job to service-checks dashbooard
This commit is contained in:
Alexander James Phillips 2014-01-14 15:03:27 +00:00
parent ea7deb1586
commit 82546b1620
8 changed files with 48 additions and 12 deletions

View File

@ -1,22 +1,27 @@
from datetime import datetime
from os import environ as env from os import environ as env
from django.conf import settings
import requests
from datetime import datetime
from django.utils import timezone
from celery.utils.log import get_task_logger from celery.utils.log import get_task_logger
from django.conf import settings
from django.utils import timezone
import requests
logger = get_task_logger(__name__) logger = get_task_logger(__name__)
auth = (settings.JENKINS_USER, settings.JENKINS_PASS) auth = (settings.JENKINS_USER, settings.JENKINS_PASS)
def get_jenkins_url(jobname):
return settings.JENKINS_API + 'job/%s/api/json' % jobname
def get_job_status(jobname): def get_job_status(jobname):
ret = { ret = {
'active': True, 'active': True,
'succeeded': False, 'succeeded': False,
'blocked_build_time': None 'blocked_build_time': None
} }
endpoint = settings.JENKINS_API + 'job/%s/api/json' % jobname endpoint = get_jenkins_url(jobname)
resp = requests.get(endpoint, auth=auth, verify=True) resp = requests.get(endpoint, auth=auth, verify=True)
resp.raise_for_status() resp.raise_for_status()
status = resp.json status = resp.json

View File

@ -497,7 +497,7 @@ class JenkinsStatusCheck(StatusCheck):
@property @property
def check_category(self): def check_category(self):
return "Jenkins check" return 'Jenkins check'
@property @property
def failing_short_status(self): def failing_short_status(self):

View File

View File

@ -0,0 +1,9 @@
from django import template
from ..jenkins import get_jenkins_url
register = template.Library()
@register.simple_tag
def jenkins_url(jobname):
return get_jenkins_url(jobname)

View File

@ -3,8 +3,8 @@ from datetime import timedelta
BROKER_URL = os.environ['CELERY_BROKER_URL'] BROKER_URL = os.environ['CELERY_BROKER_URL']
CELERY_IMPORTS = ('app.cabotapp.tasks', ) CELERY_IMPORTS = ('app.cabotapp.tasks', )
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler" CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
CELERY_TASK_SERIALIZER = "json" CELERY_TASK_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json', 'msgpack', 'yaml'] CELERY_ACCEPT_CONTENT = ['json', 'msgpack', 'yaml']
CELERYBEAT_SCHEDULE = { CELERYBEAT_SCHEDULE = {

View File

@ -1,3 +1,5 @@
{% load extra %}
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<div class="col-xs-1"><h3><i class="{% if checks_type == "All" %}fa fa-cog{% else %}glyphicon glyphicon-{% if checks_type == "Http" %}arrow-up{% elif checks_type == "Jenkins" %}ok{% else %}signal{% endif %}{% endif %}"></i></h3></div> <div class="col-xs-1"><h3><i class="{% if checks_type == "All" %}fa fa-cog{% else %}glyphicon glyphicon-{% if checks_type == "Http" %}arrow-up{% elif checks_type == "Jenkins" %}ok{% else %}signal{% endif %}{% endif %}"></i></h3></div>
@ -59,7 +61,22 @@
</td> </td>
{% endif %} {% endif %}
<td title=""> <td title="">
{% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}{{ check.metric|truncatechars:70 }} {{ check.check_type }} {{ check.value }}{% if check.expected_num_hosts %} (from {{ check.expected_num_hosts }} hosts){% endif %}{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}Status code {{ check.status_code }} from {{ check.endpoint }}{% if check.text_match %}; match text /{{ check.text_match }}/{% endif %}{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}Monitor job {{ check.name }}{% if check.max_queued_build_time %}; check no build waiting for >{{ check.max_queued_build_time }} minutes{% endif %}{% endif %} {% if check.polymorphic_ctype.model == 'graphitestatuscheck' %}
{{ check.metric|truncatechars:70 }} {{ check.check_type }} {{ check.value }}
{% if check.expected_num_hosts %}
(from {{ check.expected_num_hosts }} hosts)
{% endif %}
{% elif check.polymorphic_ctype.model == 'httpstatuscheck' %}
Status code {{ check.status_code }} from {{ check.endpoint }}
{% if check.text_match %}
; match text /{{ check.text_match }}/
{% endif %}
{% elif check.polymorphic_ctype.model == 'jenkinsstatuscheck' %}
Monitor job {{ check.name }}
{% if check.max_queued_build_time %}
; check no build waiting for >{{ check.max_queued_build_time }} minutes
{% endif %}
{% endif %}
</td> </td>
<td title="Last result from {{ check.last_run|timesince }} ago (rightmost is newest)" class="text-right"> <td title="Last result from {{ check.last_run|timesince }} ago (rightmost is newest)" class="text-right">
{% if not check.recent_results %} {% if not check.recent_results %}
@ -91,6 +108,11 @@
<a class="btn btn-xs" href="{% url run-check pk=check.id %}"> <a class="btn btn-xs" href="{% url run-check pk=check.id %}">
<i class="glyphicon glyphicon-refresh"></i><span class="break"></span> <i class="glyphicon glyphicon-refresh"></i><span class="break"></span>
</a> </a>
{% if checks_type == "Jenkins" %}
<a class="btn btn-xs" href="{% jenkins_url check.name %}">
<i class="glyphicon glyphicon-link"></i><span class="break"></span>
</a>
{% endif %}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@ -2,8 +2,8 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == '__main__':
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line

View File

@ -6,7 +6,7 @@ anyjson==0.3.3
argparse==1.2.1 argparse==1.2.1
billiard==3.3.0.13 billiard==3.3.0.13
celery==3.1.7 celery==3.1.7
distribute==0.6.24 distribute==0.6.49
dj-database-url==0.2.2 dj-database-url==0.2.2
django-appconf==0.6 django-appconf==0.6
django-celery==3.1.1 django-celery==3.1.1