Explorar el Código

check for diff on events

abhishek9686 hace 3 meses
padre
commit
6c4c488caf
Se han modificado 3 ficheros con 9 adiciones y 3 borrados
  1. 2 2
      controllers/hosts.go
  2. 0 1
      models/events.go
  3. 7 0
      pro/logic/events.go

+ 2 - 2
controllers/hosts.go

@@ -305,7 +305,7 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
 		Target: models.Subject{
 			ID:   currHost.ID.String(),
 			Name: newHost.Name,
-			Type: models.HostSub,
+			Type: models.DeviceSub,
 		},
 		Diff: models.Diff{
 			Old: currHost,
@@ -998,7 +998,7 @@ func syncHost(w http.ResponseWriter, r *http.Request) {
 		Target: models.Subject{
 			ID:   host.ID.String(),
 			Name: host.Name,
-			Type: models.HostSub,
+			Type: models.DeviceSub,
 		},
 		Origin: models.Dashboard,
 	})

+ 0 - 1
models/events.go

@@ -23,7 +23,6 @@ const (
 	UserAccessTokenSub SubjectType = "USER_ACCESS_TOKEN"
 	DeviceSub          SubjectType = "DEVICE"
 	NodeSub            SubjectType = "NODE"
-	HostSub            SubjectType = "HOST"
 	SettingSub         SubjectType = "SETTING"
 	AclSub             SubjectType = "ACL"
 	TagSub             SubjectType = "TAG"

+ 7 - 0
pro/logic/events.go

@@ -3,6 +3,7 @@ package logic
 import (
 	"context"
 	"encoding/json"
+	"reflect"
 	"time"
 
 	"github.com/google/uuid"
@@ -20,6 +21,12 @@ func LogEvent(a *models.Event) {
 func EventWatcher() {
 
 	for e := range EventActivityCh {
+		if e.Action == models.Update {
+			// check if diff
+			if reflect.DeepEqual(e.Diff.Old, e.Diff.New) {
+				continue
+			}
+		}
 		sourceJson, _ := json.Marshal(e.Source)
 		dstJson, _ := json.Marshal(e.Target)
 		diff, _ := json.Marshal(e.Diff)