コード例 #1
0
ファイル: services.py プロジェクト: oskarm91/openduty
def silence(request, service_id):
    try:
        service = Service.objects.get(id = service_id)
        silence_for = request.POST.get('silence_for')
        url = request.POST.get("url")
        incident_id = request.POST.get('incident_id')
        incident = Incident.objects.get(id=incident_id)
        if ServiceSilenced.objects.filter(service=service).count() < 1:
            silenced_service = ServiceSilenced()
            silenced_service.service = service
            silenced_service.silenced_until = timezone.now() + timezone.timedelta(hours=int(silence_for))
            silenced_service.silenced = True
            silenced_service.save()

            event_log_message = "%s silenced the of service %s for %s hours" % (request.user.username, incident.incident_key, silence_for)
            event_log = EventLog()
            event_log.incident_key = incident
            event_log.action = 'silence_service'
            event_log.user = request.user
            event_log.service_key = service
            event_log.data = event_log_message
            event_log.occurred_at = timezone.now()
            event_log.save()

            unsilence_service.apply_async((service_id,), eta=silenced_service.silenced_until)
        return HttpResponseRedirect(url)
    except Service.DoesNotExist:
        raise Http404
コード例 #2
0
ファイル: services.py プロジェクト: trytercept/openduty
def silence(request, service_id):
    try:
        service = Service.objects.get(id=service_id)
        silence_for = request.POST.get('silence_for')
        url = request.POST.get("url")
        incident_id = request.POST.get('incident_id')
        if incident_id:
            incident = Incident.objects.get(id=incident_id)
        else:
            incident = None
        if ServiceSilenced.objects.filter(service=service).count() < 1:
            silenced_service = ServiceSilenced()
            silenced_service.service = service
            silenced_service.silenced_until = timezone.now(
            ) + timezone.timedelta(hours=int(silence_for))
            silenced_service.silenced = True
            silenced_service.save()

            event_log_message = "%s silenced the service %s for %s hours" % (
                request.user.username, service.name, silence_for)
            event_log = EventLog()
            event_log.incident_key = incident
            event_log.action = 'silence_service'
            event_log.user = request.user
            event_log.service_key = service
            event_log.data = event_log_message
            event_log.occurred_at = timezone.now()
            event_log.save()

            unsilence_service.apply_async((service_id, ),
                                          eta=silenced_service.silenced_until)
        return HttpResponseRedirect(url)
    except Service.DoesNotExist:
        raise Http404
コード例 #3
0
ファイル: services.py プロジェクト: tarokkk/openduty
def unsilence(request, service_id):
    try:
        service = Service.objects.get(id = service_id)
        url = request.POST.get("url")
        try:
            ServiceSilenced.objects.filter(service=service).delete()
            event_log_message = "%s removed silence from service %s" % (request.user.username, service.name)
            event_log = EventLog()
            event_log.action = 'unsilence_service'
            event_log.user = request.user
            event_log.incident_key = None
            event_log.service_key = service
            event_log.data = event_log_message
            event_log.occurred_at = timezone.now()
            event_log.save()
        except ServiceSilenced.DoesNotExist:
            # No need to delete
            pass
        return HttpResponseRedirect(url)
    except Service.DoesNotExist:
        raise Http404
コード例 #4
0
ファイル: services.py プロジェクト: trytercept/openduty
def unsilence(request, service_id):
    try:
        service = Service.objects.get(id=service_id)
        url = request.POST.get("url")
        try:
            ServiceSilenced.objects.filter(service=service).delete()
            event_log_message = "%s removed silence from service %s" % (
                request.user.username, service.name)
            event_log = EventLog()
            event_log.action = 'unsilence_service'
            event_log.user = request.user
            event_log.incident_key = None
            event_log.service_key = service
            event_log.data = event_log_message
            event_log.occurred_at = timezone.now()
            event_log.save()
        except ServiceSilenced.DoesNotExist:
            # No need to delete
            pass
        return HttpResponseRedirect(url)
    except Service.DoesNotExist:
        raise Http404