[VOL-3785] New Kafka event notifications for errors in OMCI communication and MDS audit

Change-Id: I98ca4092d18d364bc05e4a899886a9bcdc38cf17
diff --git a/internal/pkg/mib/onu_device_entry.go b/internal/pkg/mib/onu_device_entry.go
index ea47bbf..cb50e75 100755
--- a/internal/pkg/mib/onu_device_entry.go
+++ b/internal/pkg/mib/onu_device_entry.go
@@ -22,6 +22,7 @@
 	"encoding/json"
 	"errors"
 	"fmt"
+	"strconv"
 	"sync"
 	"time"
 
@@ -30,8 +31,10 @@
 	me "github.com/opencord/omci-lib-go/v2/generated"
 	"github.com/opencord/voltha-lib-go/v7/pkg/db"
 	"github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
+	"github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
 	vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc"
 	"github.com/opencord/voltha-protos/v5/go/inter_adapter"
+	"github.com/opencord/voltha-protos/v5/go/voltha"
 
 	"github.com/opencord/voltha-lib-go/v7/pkg/log"
 
@@ -156,6 +159,7 @@
 type OnuDeviceEntry struct {
 	deviceID                   string
 	baseDeviceHandler          cmn.IdeviceHandler
+	eventProxy                 eventif.EventProxy
 	pOpenOnuAc                 cmn.IopenONUAC
 	pOnuTP                     cmn.IonuUniTechProf
 	coreClient                 *vgrpc.Client
@@ -214,6 +218,7 @@
 	onuDeviceEntry.deviceID = dh.GetDeviceID()
 	logger.Debugw(ctx, "init-onuDeviceEntry", log.Fields{"device-id": onuDeviceEntry.deviceID})
 	onuDeviceEntry.baseDeviceHandler = dh
+	onuDeviceEntry.eventProxy = dh.GetEventProxy()
 	onuDeviceEntry.pOpenOnuAc = openonu
 	onuDeviceEntry.coreClient = cc
 	onuDeviceEntry.devState = cmn.DeviceStatusInit
@@ -999,3 +1004,22 @@
 	}
 	oo.PDevOmciCC = nil
 }
+
+//SendOnuDeviceEvent sends an ONU DeviceEvent via eventProxy
+func (oo *OnuDeviceEntry) SendOnuDeviceEvent(ctx context.Context, aDeviceEventName string, aDescription string) {
+
+	oo.MutexPersOnuConfig.RLock()
+	context := make(map[string]string)
+	context["onu-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersOnuID), 10)
+	context["intf-id"] = strconv.FormatUint(uint64(oo.SOnuPersistentData.PersIntfID), 10)
+	context["onu-serial-number"] = oo.SOnuPersistentData.PersSerialNumber
+	oo.MutexPersOnuConfig.RUnlock()
+
+	deviceEvent := &voltha.DeviceEvent{
+		ResourceId:      oo.deviceID,
+		DeviceEventName: aDeviceEventName,
+		Description:     aDescription,
+		Context:         context,
+	}
+	_ = oo.eventProxy.SendDeviceEvent(ctx, deviceEvent, voltha.EventCategory_COMMUNICATION, voltha.EventSubCategory_ONU, time.Now().Unix())
+}