diff --git a/example/plugins/api-call-example/mod/zoraxy_plugin/events/events.go b/example/plugins/api-call-example/mod/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/example/plugins/api-call-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/api-call-example/mod/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name { diff --git a/example/plugins/debugger/mod/zoraxy_plugin/events/events.go b/example/plugins/debugger/mod/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/example/plugins/debugger/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/debugger/mod/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name { diff --git a/example/plugins/dynamic-capture-example/mod/zoraxy_plugin/events/events.go b/example/plugins/dynamic-capture-example/mod/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/example/plugins/dynamic-capture-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/dynamic-capture-example/mod/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name { diff --git a/example/plugins/event-subscriber-example/mod/zoraxy_plugin/events/events.go b/example/plugins/event-subscriber-example/mod/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/example/plugins/event-subscriber-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/event-subscriber-example/mod/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name { diff --git a/example/plugins/helloworld/mod/zoraxy_plugin/events/events.go b/example/plugins/helloworld/mod/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/example/plugins/helloworld/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/helloworld/mod/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name { diff --git a/example/plugins/restful-example/mod/zoraxy_plugin/events/events.go b/example/plugins/restful-example/mod/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/example/plugins/restful-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/restful-example/mod/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name { diff --git a/example/plugins/static-capture-example/mod/zoraxy_plugin/events/events.go b/example/plugins/static-capture-example/mod/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/example/plugins/static-capture-example/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/static-capture-example/mod/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name { diff --git a/example/plugins/upnp/mod/zoraxy_plugin/events/events.go b/example/plugins/upnp/mod/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/example/plugins/upnp/mod/zoraxy_plugin/events/events.go +++ b/example/plugins/upnp/mod/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name { diff --git a/src/mod/eventsystem/event_system.go b/src/mod/eventsystem/event_system.go index 7c4f820..d529217 100644 --- a/src/mod/eventsystem/event_system.go +++ b/src/mod/eventsystem/event_system.go @@ -4,8 +4,8 @@ import ( "sync" "time" + "github.com/google/uuid" "imuslab.com/zoraxy/mod/info/logger" - // "imuslab.com/zoraxy/mod/plugins" "imuslab.com/zoraxy/mod/plugins/zoraxy_plugin/events" ) @@ -102,6 +102,7 @@ func (em *eventManager) Emit(payload events.EventPayload) error { event := events.Event{ Name: eventName, Timestamp: time.Now().Unix(), + UUID: uuid.New().String(), Data: payload, } diff --git a/src/mod/eventsystem/event_system_test.go b/src/mod/eventsystem/event_system_test.go index 432ae5a..f4751a8 100644 --- a/src/mod/eventsystem/event_system_test.go +++ b/src/mod/eventsystem/event_system_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/google/uuid" "imuslab.com/zoraxy/mod/plugins/zoraxy_plugin/events" ) @@ -18,6 +19,7 @@ func TestEventDeSerialization(t *testing.T) { } timestamp := time.Now().Unix() + uuid := uuid.New().String() tests := []SerializationTest{ { @@ -25,6 +27,7 @@ func TestEventDeSerialization(t *testing.T) { event: events.Event{ Name: events.EventBlacklistedIPBlocked, Timestamp: timestamp, + UUID: uuid, Data: &events.BlacklistedIPBlockedEvent{ IP: "192.168.1.1", Comment: "Test comment", @@ -34,25 +37,27 @@ func TestEventDeSerialization(t *testing.T) { Method: "GET", }, }, - expectedJson: `{"name":"blacklistedIpBlocked","timestamp":` + fmt.Sprintf("%d", timestamp) + `,"data":{"ip":"192.168.1.1","comment":"Test comment","requested_url":"http://example.com","hostname":"example.com","user_agent":"TestUserAgent","method":"GET"}}`, + expectedJson: `{"name":"blacklistedIpBlocked","timestamp":` + fmt.Sprintf("%d", timestamp) + `,"uuid":"` + uuid + `","data":{"ip":"192.168.1.1","comment":"Test comment","requested_url":"http://example.com","hostname":"example.com","user_agent":"TestUserAgent","method":"GET"}}`, }, { name: "BlacklistToggled", event: events.Event{ Name: events.EventBlacklistToggled, Timestamp: timestamp, + UUID: uuid, Data: &events.BlacklistToggledEvent{ RuleID: "rule123", Enabled: true, }, }, - expectedJson: `{"name":"blacklistToggled","timestamp":` + fmt.Sprintf("%d", timestamp) + `,"data":{"rule_id":"rule123","enabled":true}}`, + expectedJson: `{"name":"blacklistToggled","timestamp":` + fmt.Sprintf("%d", timestamp) + `,"uuid":"` + uuid + `","data":{"rule_id":"rule123","enabled":true}}`, }, { name: "AccessRuleCreated", event: events.Event{ Name: events.EventAccessRuleCreated, Timestamp: timestamp, + UUID: uuid, Data: &events.AccessRuleCreatedEvent{ ID: "rule456", Name: "New Access Rule", @@ -61,7 +66,7 @@ func TestEventDeSerialization(t *testing.T) { WhitelistEnabled: false, }, }, - expectedJson: `{"name":"accessRuleCreated","timestamp":` + fmt.Sprintf("%d", timestamp) + `,"data":{"id":"rule456","name":"New Access Rule","desc":"A dummy access rule","blacklist_enabled":true,"whitelist_enabled":false}}`, + expectedJson: `{"name":"accessRuleCreated","timestamp":` + fmt.Sprintf("%d", timestamp) + `,"uuid":"` + uuid + `","data":{"id":"rule456","name":"New Access Rule","desc":"A dummy access rule","blacklist_enabled":true,"whitelist_enabled":false}}`, }, } diff --git a/src/mod/plugins/zoraxy_plugin/events/events.go b/src/mod/plugins/zoraxy_plugin/events/events.go index 2bd6536..c743ec6 100644 --- a/src/mod/plugins/zoraxy_plugin/events/events.go +++ b/src/mod/plugins/zoraxy_plugin/events/events.go @@ -17,7 +17,10 @@ type EventPayload interface { // Event represents a system event type Event struct { Name EventName `json:"name"` - Timestamp int64 `json:"timestamp"` // Unix timestamp + // Unix timestamp + Timestamp int64 `json:"timestamp"` + // UUID for the event + UUID string `json:"uuid"` Data EventPayload `json:"data"` } @@ -88,6 +91,7 @@ func ParseEvent(jsonData []byte, event *Event) error { var temp struct { Name EventName `json:"name"` Timestamp int64 `json:"timestamp"` + UUID string `json:"uuid"` } if err := json.Unmarshal(jsonData, &temp); err != nil { return err @@ -96,6 +100,7 @@ func ParseEvent(jsonData []byte, event *Event) error { // Set the event name and timestamp event.Name = temp.Name event.Timestamp = temp.Timestamp + event.UUID = temp.UUID // Now, based on the event type, unmarshal the specific payload switch temp.Name {