MCPcopy
hub / github.com/crowdsecurity/crowdsec / DeleteAlertGraph

Method DeleteAlertGraph

pkg/database/alerts.go:931–964  ·  view source on GitHub ↗
(ctx context.Context, alertItem *ent.Alert)

Source from the content-addressed store, hash-verified

929}
930
931func (c *Client) DeleteAlertGraph(ctx context.Context, alertItem *ent.Alert) error {
932 // delete the associated events
933 _, err := c.Ent.Event.Delete().
934 Where(event.HasOwnerWith(alert.IDEQ(alertItem.ID))).Exec(ctx)
935 if err != nil {
936 c.Log.Warningf("DeleteAlertGraph : %s", err)
937 return fmt.Errorf("event with alert ID '%d': %w", alertItem.ID, DeleteFail)
938 }
939
940 // delete the associated meta
941 _, err = c.Ent.Meta.Delete().
942 Where(meta.HasOwnerWith(alert.IDEQ(alertItem.ID))).Exec(ctx)
943 if err != nil {
944 c.Log.Warningf("DeleteAlertGraph : %s", err)
945 return fmt.Errorf("meta with alert ID '%d': %w", alertItem.ID, DeleteFail)
946 }
947
948 // delete the associated decisions
949 _, err = c.Ent.Decision.Delete().
950 Where(decision.HasOwnerWith(alert.IDEQ(alertItem.ID))).Exec(ctx)
951 if err != nil {
952 c.Log.Warningf("DeleteAlertGraph : %s", err)
953 return fmt.Errorf("decision with alert ID '%d': %w", alertItem.ID, DeleteFail)
954 }
955
956 // delete the alert
957 err = c.Ent.Alert.DeleteOne(alertItem).Exec(ctx)
958 if err != nil {
959 c.Log.Warningf("DeleteAlertGraph : %s", err)
960 return fmt.Errorf("alert with ID '%d': %w", alertItem.ID, DeleteFail)
961 }
962
963 return nil
964}
965
966func (c *Client) DeleteAlertByID(ctx context.Context, id int) error {
967 alertItem, err := c.Ent.Alert.Query().Where(alert.IDEQ(id)).Only(ctx)

Callers 1

DeleteAlertByIDMethod · 0.95

Calls 8

HasOwnerWithFunction · 0.92
IDEQFunction · 0.92
HasOwnerWithFunction · 0.92
HasOwnerWithFunction · 0.92
ExecMethod · 0.45
WhereMethod · 0.45
DeleteMethod · 0.45
DeleteOneMethod · 0.45

Tested by

no test coverage detected