Permalink
Browse files

add in monitor page (bug 604073)

  • Loading branch information...
1 parent 013e48c commit 082de1cdcfdf7b8f9ca1de284a8a9952e26b27ae @andymckay andymckay committed Dec 22, 2010
Showing with 93 additions and 4 deletions.
  1. +30 −0 apps/base/templates/monitor.html
  2. +6 −0 apps/base/urls.py
  3. +53 −3 apps/base/views.py
  4. +4 −1 urls.py
@@ -0,0 +1,30 @@
+{% extends 'base.html' %}
+
+{% block title %}Mozilla FlightDeck Site Status{% endblock title %}
+
+{% block app_content %}
+
+<h2 class="UI_Heading" style="padding-top: 3em">Filepaths</h2>
+<dl>
+{% for path, exists, permissions, extra in filepaths %}
+ <dt style="font-weight: bold">{{ path }}</dt>
+ <dd style="padding-bottom: 1em">
+ {% if exists %}
+ Exists...
+ {% else %}
+ <b style="color: red">Does not exist</b>
+ {% endif %}
+
+ {% if permissions %}
+ with proper permissions.
+ {% else %}
+ <b>and does not have the permissions we expect.</b>
+ {% endif %}
+ {% if extra %}
+ ({{ extra }})
+ {% endif %}
+ </dd>
+{% endfor %}
+</dl>
+
+{% endblock %}
View
@@ -0,0 +1,6 @@
+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('',
+ url('^services/monitor$', 'base.views.monitor', name='monitor'),
+ url('^services/settings$', 'base.views.site_settings', name='settings'),
+)
View
@@ -1,8 +1,58 @@
-from django.template import RequestContext
-from django.shortcuts import render_to_response
+import os
+
from django.conf import settings
+from django.contrib.auth.decorators import user_passes_test
+from django.http import HttpResponse
+from django.shortcuts import render_to_response
+from django.template import RequestContext, loader
+from django.views.debug import get_safe_settings
+
+
+from jetpack.models import Package, SDK
+
+
+@user_passes_test(lambda u: u.is_superuser)
+def site_settings(request):
+ safe = sorted(list(get_safe_settings().items()))
+ return render_to_response(
+ 'settings.html',
+ {'settings': safe},
+ context_instance=RequestContext(request))
+
+
+def monitor(request):
+ status = True
+ data = {}
+
+ filepaths = [
+ (settings.UPLOAD_DIR, os.R_OK | os.W_OK, 'We want read + write.'),
+ ]
+
+ if hasattr(settings, 'XPI_TARGETDIR'):
+ filepaths.append((settings.XPI_TARGETDIR, os.R_OK | os.W_OK,
+ 'We want read + write.'))
+
+ for sdk in SDK.objects.all():
+ filepaths.append((sdk.get_source_dir(), os.R_OK,
+ 'We want read on %s' % sdk.version),)
+
+ filepath_results = []
+ filepath_status = True
+
+ for path, perms, notes in filepaths:
+ path_exists = os.path.isdir(path)
+ path_perms = os.access(path, perms)
+ filepath_status = filepath_status and path_exists and path_perms
+ if not filepath_status and status:
+ status = False
+ filepath_results.append((path, path_exists, path_perms, notes))
+
+ data['filepaths'] = filepath_results
+ template = loader.get_template('monitor.html')
+ context = RequestContext(request, data)
+ status = 200 if status else 500
-from jetpack.models import Package
+ return HttpResponse(template.render(context), status=status)
def homepage(r):
View
@@ -54,6 +54,9 @@
(r'^user/', include('person.urls')),
# Jetpack
- (r'', include('jetpack.urls'))
+ (r'', include('jetpack.urls')),
+
+ # Monitor
+ (r'', include('base.urls'))
])
urlpatterns = patterns('', *urls)

0 comments on commit 082de1c

Please sign in to comment.