コード例 #1
0
def modal_form(request,resource_name,resource_id=None):
    '''Modal Form that posts to Tastypie endpoints'''

    if not RESOURCE_NAME_MAP.has_key(resource_name):
        raise Http404
    resource_cls = RESOURCE_NAME_MAP[resource_name]
    resource_form_cls = RESOURCE_FORM_MAP[resource_cls] if RESOURCE_FORM_MAP.has_key(resource_cls) else generate_check_modelform_cls(resource_cls)

    if resource_id:
        instance = get_object_or_404(resource_cls,pk=resource_id)
        method="PUT"
        action = "/api/v1/%s/%s/?format=json" % (resource_cls.resource_name,
                                                 instance.id)
    else:
        instance = None
        method="POST"
        action="/api/v1/%s/?format=json" % (resource_cls.resource_name)

    #Most of this junk is to make tastypie happy. I regret using it. 
    if resource_cls == CodeServiceCheck:
        method="POST"

    if hasattr(instance,"service") or request.GET.has_key("sid"):
        form = resource_form_cls(instance=instance,
                                 initial={'service':instance.service.id if instance else request.GET.get("sid")})
    else:
        form = resource_form_cls(instance=instance)

    return render_to_response(form.template,
                              {"form":form,
                               "action":action,
                               'method':method},
                              RequestContext(request))
コード例 #2
0
def silence(request,resource_name,resource_id):
    if not RESOURCE_NAME_MAP.has_key(resource_name):
        raise Http404
    resource_cls = RESOURCE_NAME_MAP[resource_name]
    resource = get_object_or_404(resource_cls,pk=resource_id)
    resource.silenced = not resource.silenced
    resource.save()
    return HttpResponse("OK")
コード例 #3
0
def refresh(request,resource_name,resource_id):
    '''Run a specific check.'''

    if not RESOURCE_NAME_MAP.has_key(resource_name):
        raise Http404
    resource_cls = RESOURCE_NAME_MAP[resource_name]
    resource = get_object_or_404(resource_cls,pk=resource_id)
    resource.update_status()
    return HttpResponse("OK")
コード例 #4
0
def check(request, check_name, check_id):
    if not RESOURCE_NAME_MAP.has_key(check_name):
        raise Http404
    check_cls = RESOURCE_NAME_MAP[check_name]
    template_map = {
        SimpleServiceCheck: "simple_check.html",
        UmpireServiceCheck: "umpire_check.html",
        SensuServiceCheck: "sensu_check.html",
        CompareServiceCheck: "compare_check.html",
        CodeServiceCheck: "code_check.html"
    }
    template_file = template_map[check_cls]
    check = get_object_or_404(check_cls, pk=check_id)
    return render_to_response("mobile/checks/%s" % template_file,
                              {'check': check}, RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: abhishekamralkar/momonitor
def check(request,check_name,check_id):
    if not RESOURCE_NAME_MAP.has_key(check_name):
        raise Http404    
    check_cls = RESOURCE_NAME_MAP[check_name]
    template_map = {
        SimpleServiceCheck:"simple_check.html",
        UmpireServiceCheck:"umpire_check.html",
        SensuServiceCheck:"sensu_check.html",
        CompareServiceCheck:"compare_check.html",
        CodeServiceCheck:"code_check.html"
        }
    template_file = template_map[check_cls]
    check = get_object_or_404(check_cls,pk=check_id)
    return render_to_response("mobile/checks/%s" % template_file,
                              {'check':check},
                              RequestContext(request))