github.com/zartbot/goflow@v0.0.0-20221001080520-456f7dfad288/service/optiontemplatemap/option_template_fw_event.go (about) 1 package optiontemplatemap 2 3 import ( 4 "errors" 5 "fmt" 6 "sync" 7 ) 8 9 type FWEventMapKey struct { 10 AgentID string 11 EventID uint32 12 } 13 14 var FWEvent sync.Map 15 16 func UpdateFWEvent(AgentID string, eventid uint32, Description string) error { 17 key := FWEventMapKey{ 18 AgentID: AgentID, 19 EventID: eventid, 20 } 21 FWEvent.Store(key, Description) 22 23 return nil 24 } 25 26 func FetchFWEventByIndex(AgentID string, eventid uint32) (string, error) { 27 var err error 28 var i string 29 key := FWEventMapKey{ 30 AgentID: AgentID, 31 EventID: eventid, 32 } 33 34 value, ok := FWEvent.Load(key) 35 if ok { 36 i, valid := value.(string) 37 if !valid { 38 err = errors.New("invalid type assertion") 39 return i, err 40 } else { 41 return i, nil 42 } 43 } else { 44 err = errors.New("Event does not found in database") 45 return i, err 46 } 47 } 48 49 func ShowFWEvent() { 50 FWEvent.Range(func(k, v interface{}) bool { 51 value := v.(string) 52 key := k.(FWEventMapKey) 53 fmt.Printf("FW Event Map[%10s:%-6d] | Description: %-50s \n", key.AgentID, key.EventID, value) 54 return true 55 }) 56 } 57 58 func UpdateFWEventMap(d map[string]interface{}, AgentID string) error { 59 var err error 60 eventID, hasEventID := d["policy_firewall_event_extended"] 61 if hasEventID { 62 //isTemplate ? 63 eventDescription, hasEventDescription := d["policy_firewall_event_extended_description"] 64 65 if hasEventID && hasEventDescription { 66 err = UpdateFWEvent(AgentID, eventID.(uint32), eventDescription.(string)) 67 } else { 68 //data record contains interface field 69 r, err := FetchFWEventByIndex(AgentID, eventID.(uint32)) 70 if err == nil { 71 //var ir fieldvalue.FieldValue 72 //ir.Name = "ingressInterfaceName" 73 //ir.Value = r.Description 74 //ir.Type = "string" 75 d["firewall_event"] = r 76 } 77 } 78 } 79 return err 80 }