def patch(self, request, pk): check = get_object_or_404(Check, pk=pk) # remove fields that should not be changed when editing a check from the frontend if "check_alert" not in request.data.keys(): [request.data.pop(i) for i in check.non_editable_fields] # set event id to 0 if wildcard because it needs to be an integer field for db # will be ignored anyway by the agent when doing wildcard check if check.check_type == "eventlog": try: request.data["event_id_is_wildcard"] except KeyError: pass else: if request.data["event_id_is_wildcard"]: request.data["event_id"] = 0 serializer = CheckSerializer(instance=check, data=request.data, partial=True) serializer.is_valid(raise_exception=True) obj = serializer.save() # Update policy check fields if check.policy: update_policy_check_fields_task(checkpk=pk) return Response(f"{obj.readable_desc} was edited!")
def patch(self, request, pk): check = get_object_or_404(Check, pk=pk) # remove fields that should not be changed when editing a check from the frontend if "check_alert" not in request.data.keys(): [request.data.pop(i) for i in check.non_editable_fields] # set event id to 0 if wildcard because it needs to be an integer field for db # will be ignored anyway by the agent when doing wildcard check if check.check_type == "eventlog" and request.data[ "event_id_is_wildcard"]: if check.agent.not_supported(version_added="0.10.2"): return notify_error({ "non_field_errors": "Wildcard is only available in agent 0.10.2 or greater" }) request.data["event_id"] = 0 serializer = CheckSerializer(instance=check, data=request.data, partial=True) serializer.is_valid(raise_exception=True) obj = serializer.save() # Update policy check fields if check.policy: update_policy_check_fields_task(checkpk=pk) return Response(f"{obj.readable_desc} was edited!")
def patch(self, request, pk): check = get_object_or_404(Check, pk=pk) # remove fields that should not be changed when editing a check from the frontend if "check_alert" not in request.data.keys(): [request.data.pop(i) for i in check.non_editable_fields] serializer = CheckSerializer(instance=check, data=request.data, partial=True) serializer.is_valid(raise_exception=True) obj = serializer.save() # Update policy check fields if check.policy: update_policy_check_fields_task(checkpk=pk) return Response(f"{obj.readable_desc} was edited!")