@@ -25,6 +25,80 @@ import (
2525 datamodels "github.com/nvidia/nvsentinel/data-models/pkg/model"
2626)
2727
28+ // ParseSequenceStage parses a JSON stage string and replaces "this." references with actual event values
29+ func ParseSequenceStage (stage string , event datamodels.HealthEventWithStatus ) (map [string ]interface {}, error ) {
30+ var stageMap map [string ]interface {}
31+ if err := json .Unmarshal ([]byte (stage ), & stageMap ); err != nil {
32+ return nil , fmt .Errorf ("failed to unmarshal stage '%s': %w" , stage , err )
33+ }
34+
35+ for key , value := range stageMap {
36+ processedValue , err := processValue (value , event )
37+ if err != nil {
38+ return nil , err
39+ }
40+
41+ stageMap [key ] = processedValue
42+ }
43+
44+ return stageMap , nil
45+ }
46+
47+ // processValue recursively processes any value type and replaces "this." references with actual event values
48+ func processValue (value interface {}, event datamodels.HealthEventWithStatus ) (interface {}, error ) {
49+ switch v := value .(type ) {
50+ case string :
51+ if strings .HasPrefix (v , "this." ) {
52+ fieldPath := strings .TrimPrefix (v , "this." )
53+
54+ resolvedValue , err := getValueFromPath (fieldPath , event )
55+ if err != nil {
56+ return nil , fmt .Errorf ("error in getting value from path '%s': %w" , fieldPath , err )
57+ }
58+
59+ return resolvedValue , nil
60+ }
61+
62+ return v , nil
63+ case map [string ]interface {}:
64+ return processMapValue (v , event )
65+ case []interface {}:
66+ return processArrayValue (v , event )
67+ default :
68+ return v , nil
69+ }
70+ }
71+
72+ func processMapValue (v map [string ]interface {}, event datamodels.HealthEventWithStatus ) (map [string ]interface {}, error ) {
73+ result := make (map [string ]interface {})
74+
75+ for key , val := range v {
76+ processedVal , err := processValue (val , event )
77+ if err != nil {
78+ return nil , err
79+ }
80+
81+ result [key ] = processedVal
82+ }
83+
84+ return result , nil
85+ }
86+
87+ func processArrayValue (v []interface {}, event datamodels.HealthEventWithStatus ) ([]interface {}, error ) {
88+ result := make ([]interface {}, len (v ))
89+
90+ for i , val := range v {
91+ processedVal , err := processValue (val , event )
92+ if err != nil {
93+ return nil , err
94+ }
95+
96+ result [i ] = processedVal
97+ }
98+
99+ return result , nil
100+ }
101+
28102// ParseSequenceString converts a criteria map into a database filter map
29103// This uses the same map[string]interface{} type as store-client filters
30104func ParseSequenceString (
0 commit comments