Exemplo n.º 1
0
def send_finding_alerts_api(request, finding_id):
    if request.GET.get("raw", None) and request.GET.get("raw") == "true":
        finding = get_object_or_404(RawFinding, id=finding_id)
    else:
        finding = get_object_or_404(Finding, id=finding_id)

    # Create a new rule
    rule = Rule(title="manual",
                severity=finding.severity.capitalize(),
                owner_id=request.user.id)
    if request.GET.get("type", None) and request.GET.get("type") == "slack":
        rule.target = "slack"
        rule.notify(finding.title)
    elif request.GET.get("type",
                         None) and request.GET.get("type") == "thehive":
        rule.target = "thehive"
        rule.notify(message=finding.title,
                    asset=finding.asset,
                    description=finding.description)
    elif request.GET.get("type", None) and request.GET.get("type") == "email":
        rule.target = "email"
        rule.notify(message=finding.title,
                    asset=finding.asset,
                    description=finding.description)

    rule.delete()

    return JsonResponse({"status": "success"})
Exemplo n.º 2
0
 def test_delete_rule(self):
     rule = Rule(start_sort='100000', end_sort='100001', mod_rule='MOD10',
                 weight=[0,1,2,3,4,5,6,7,8,9,10,11,12,13], mod_exception='')
     rule.save()
     rule.delete()
     assert rule.id is None