From 82546b1620e71626b77b15ab8dd6e10d44cca95f Mon Sep 17 00:00:00 2001 From: Alexander James Phillips Date: Tue, 14 Jan 2014 15:03:27 +0000 Subject: [PATCH] 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 --- app/cabotapp/jenkins.py | 15 ++++++++---- app/cabotapp/models.py | 2 +- app/cabotapp/templatetags/__init__.py | 0 app/cabotapp/templatetags/extra.py | 9 +++++++ app/celeryconfig.py | 4 ++-- app/templates/cabotapp/_statuscheck_list.html | 24 ++++++++++++++++++- manage.py | 4 ++-- requirements.txt | 2 +- 8 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 app/cabotapp/templatetags/__init__.py create mode 100644 app/cabotapp/templatetags/extra.py diff --git a/app/cabotapp/jenkins.py b/app/cabotapp/jenkins.py index f88ed02..73c10dd 100644 --- a/app/cabotapp/jenkins.py +++ b/app/cabotapp/jenkins.py @@ -1,22 +1,27 @@ +from datetime import datetime 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 django.conf import settings +from django.utils import timezone +import requests logger = get_task_logger(__name__) 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): ret = { 'active': True, 'succeeded': False, '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.raise_for_status() status = resp.json diff --git a/app/cabotapp/models.py b/app/cabotapp/models.py index f43ff17..bedd148 100644 --- a/app/cabotapp/models.py +++ b/app/cabotapp/models.py @@ -497,7 +497,7 @@ class JenkinsStatusCheck(StatusCheck): @property def check_category(self): - return "Jenkins check" + return 'Jenkins check' @property def failing_short_status(self): diff --git a/app/cabotapp/templatetags/__init__.py b/app/cabotapp/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/cabotapp/templatetags/extra.py b/app/cabotapp/templatetags/extra.py new file mode 100644 index 0000000..4292b57 --- /dev/null +++ b/app/cabotapp/templatetags/extra.py @@ -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) diff --git a/app/celeryconfig.py b/app/celeryconfig.py index 5c6b68e..c5a207d 100644 --- a/app/celeryconfig.py +++ b/app/celeryconfig.py @@ -3,8 +3,8 @@ from datetime import timedelta BROKER_URL = os.environ['CELERY_BROKER_URL'] CELERY_IMPORTS = ('app.cabotapp.tasks', ) -CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler" -CELERY_TASK_SERIALIZER = "json" +CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler' +CELERY_TASK_SERIALIZER = 'json' CELERY_ACCEPT_CONTENT = ['json', 'msgpack', 'yaml'] CELERYBEAT_SCHEDULE = { diff --git a/app/templates/cabotapp/_statuscheck_list.html b/app/templates/cabotapp/_statuscheck_list.html index a614099..8fa4c36 100644 --- a/app/templates/cabotapp/_statuscheck_list.html +++ b/app/templates/cabotapp/_statuscheck_list.html @@ -1,3 +1,5 @@ +{% load extra %} +

@@ -59,7 +61,22 @@ {% 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 %} + {% 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 not check.recent_results %} @@ -91,6 +108,11 @@ + {% if checks_type == "Jenkins" %} + + + + {% endif %} {% endfor %} diff --git a/manage.py b/manage.py index fc806f8..8989781 100755 --- a/manage.py +++ b/manage.py @@ -2,8 +2,8 @@ import os import sys -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings') from django.core.management import execute_from_command_line diff --git a/requirements.txt b/requirements.txt index 1bdbe81..f2a7442 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ anyjson==0.3.3 argparse==1.2.1 billiard==3.3.0.13 celery==3.1.7 -distribute==0.6.24 +distribute==0.6.49 dj-database-url==0.2.2 django-appconf==0.6 django-celery==3.1.1