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

Method DeleteAlertGraphBatch

pkg/database/alerts.go:892–929  ·  view source on GitHub ↗
(ctx context.Context, alertItems []*ent.Alert)

Source from the content-addressed store, hash-verified

890}
891
892func (c *Client) DeleteAlertGraphBatch(ctx context.Context, alertItems []*ent.Alert) (int, error) {
893 idList := make([]int, 0)
894 for _, alert := range alertItems {
895 idList = append(idList, alert.ID)
896 }
897
898 _, err := c.Ent.Event.Delete().
899 Where(event.HasOwnerWith(alert.IDIn(idList...))).Exec(ctx)
900 if err != nil {
901 c.Log.Warningf("DeleteAlertGraphBatch : %s", err)
902 return 0, fmt.Errorf("alert graph delete batch events: %w", DeleteFail)
903 }
904
905 _, err = c.Ent.Meta.Delete().
906 Where(meta.HasOwnerWith(alert.IDIn(idList...))).Exec(ctx)
907 if err != nil {
908 c.Log.Warningf("DeleteAlertGraphBatch : %s", err)
909 return 0, fmt.Errorf("alert graph delete batch meta: %w", DeleteFail)
910 }
911
912 _, err = c.Ent.Decision.Delete().
913 Where(decision.HasOwnerWith(alert.IDIn(idList...))).Exec(ctx)
914 if err != nil {
915 c.Log.Warningf("DeleteAlertGraphBatch : %s", err)
916 return 0, fmt.Errorf("alert graph delete batch decisions: %w", DeleteFail)
917 }
918
919 deleted, err := c.Ent.Alert.Delete().
920 Where(alert.IDIn(idList...)).Exec(ctx)
921 if err != nil {
922 c.Log.Warningf("DeleteAlertGraphBatch : %s", err)
923 return deleted, fmt.Errorf("alert graph delete batch: %w", DeleteFail)
924 }
925
926 c.Log.Debug("Done batch delete alerts")
927
928 return deleted, nil
929}
930
931func (c *Client) DeleteAlertGraph(ctx context.Context, alertItem *ent.Alert) error {
932 // delete the associated events

Callers

nothing calls this directly

Calls 8

HasOwnerWithFunction · 0.92
IDInFunction · 0.92
HasOwnerWithFunction · 0.92
HasOwnerWithFunction · 0.92
ExecMethod · 0.45
WhereMethod · 0.45
DeleteMethod · 0.45
DebugMethod · 0.45

Tested by

no test coverage detected