diff --git a/applications/ese/app.go b/applications/ese/app.go index 0ef9817cdf84a7df4d51620fc6910907b67ad7c5..7f05a15e82bc495f734ba4ddbeb9f3008c2dcf72 100644 --- a/applications/ese/app.go +++ b/applications/ese/app.go @@ -23,13 +23,8 @@ type Application struct { // Run runs the application. func (a *Application) Run(controllerAddress string) { - //init status map statusMap = make(map[string]map[string]*InterfaceStatus) - //load audio files - //initializeSoundFiles(soundFileOperStatusUP) - //initializeSoundFiles(soundFileOperStatusDOWN) - signal.Notify(a.stopChannel, os.Interrupt, syscall.SIGTERM) a.eventServiceDevices.SubscribeToEventType([]event.TypeToCallbackTuple{ @@ -75,13 +70,7 @@ func (a *Application) DeviceCallback(event *event.Event) { if changedInterfaces != nil { for _, changedInterface := range changedInterfaces { - playTTS(fmt.Sprintf("%s has changed the status to %s", changedInterface.Name, changedInterface.Status)) - //if changedInterface.Status == "UP" { - // PlaySound(true) - //} else { - // PlaySound(false) - //} - fmt.Printf(`Change for device "%s" : Operational-State changed for interface "%s" to %s`, changedInterface.NetworkElementName, changedInterface.Name, changedInterface.Status) + fmt.Printf("Change on %s: status of interface %s has changed to %s", changedInterface.NetworkElementName, changedInterface.Name, changedInterface.Status) } } } diff --git a/applications/ese/audio.go b/applications/ese/audio.go deleted file mode 100644 index 09b0dc9bf365cc67e991a8de732540bc03fbe848..0000000000000000000000000000000000000000 --- a/applications/ese/audio.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "log" - "os" - "time" - - "github.com/faiface/beep" - "github.com/faiface/beep/mp3" - "github.com/faiface/beep/speaker" - htgotts "github.com/hegedustibor/htgo-tts" - "github.com/hegedustibor/htgo-tts/voices" -) - -const ( - soundFileOperStatusUP = "audio-files/up.mp3" - soundFileOperStatusDOWN = "audio-files/down.mp3" -) - -var soundBuffers map[string]*beep.Buffer - -func initializeSoundFiles(filename string) { - if soundBuffers == nil { - // init streamer - sampleRate := beep.SampleRate(48000) - speaker.Init(sampleRate, sampleRate.N(time.Second/10)) - - soundBuffers = make(map[string]*beep.Buffer) - } - - f, err := os.Open(filename) - if err != nil { - log.Fatal(err) - } - - streamer, format, err := mp3.Decode(f) - if err != nil { - log.Fatal(err) - } - - buffer := beep.NewBuffer(format) - buffer.Append(streamer) - streamer.Close() - - soundBuffers[filename] = buffer -} - -func PlaySound(up bool) { - if up { - buffer := soundBuffers[soundFileOperStatusUP] - cableUP := buffer.Streamer(0, buffer.Len()) - speaker.Play(cableUP) - } else { - buffer := soundBuffers[soundFileOperStatusDOWN] - cableUP := buffer.Streamer(0, buffer.Len()) - speaker.Play(cableUP) - } -} - -func playTTS(text string) { - speech := htgotts.Speech{Folder: "audio-files", Language: voices.German} - speech.Speak(text) -} diff --git a/applications/ese/main.go b/applications/ese/main.go index 0fd31fd1e4567bf0554a4d8236c54e79764e0c98..0361abfe2517e281cdaf268067ce94fbee5b828b 100644 --- a/applications/ese/main.go +++ b/applications/ese/main.go @@ -9,7 +9,6 @@ import ( ) func main() { - // TODO: add defer? queueCredentials, err := registration.Register("localhost:55055", "ese-Application", "SecurePresharedToken") if err != nil { logrus.Errorf("failed to register application on control plane. %v", err) diff --git a/applications/ese/network-element.go b/applications/ese/network-element.go index d1330fb2d69a1ad64abbea1e8cfad8f0cf04ecbd..559c968ee7d9750e4b1c6708e542e00d870c2f45 100644 --- a/applications/ese/network-element.go +++ b/applications/ese/network-element.go @@ -82,9 +82,7 @@ func checkIfOperationStateHasChanged(deviceServer device.DeviceServiceClient, ne return nil, nil } - statusList := walkThroughInterfaces(*&networkElement.Model.Interfaces.Interface, storedInterfaces) - - return statusList, nil + return walkThroughInterfaces(*&networkElement.Model.Interfaces.Interface, storedInterfaces) } func addDeviceToStatusMap(networkElementName string, interfaces map[string]*arista.OpenconfigInterfaces_Interfaces_Interface) { @@ -101,13 +99,13 @@ func addDeviceToStatusMap(networkElementName string, interfaces map[string]*aris statusMap[networkElementName] = statusList } -func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_Interfaces_Interface, storedInterfaces map[string]*InterfaceStatus) []InterfaceStatus { +func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_Interfaces_Interface, storedInterfaces map[string]*InterfaceStatus) ([]InterfaceStatus, error) { statusList := make([]InterfaceStatus, 0) for _, receivedInterface := range interfaces { storedInterface, ok := storedInterfaces[*receivedInterface.Name] if !ok { - //TODO: add error + return statusList, fmt.Errorf("could not find %s in stored interfaces", *receivedInterface.Name) } if storedInterface.Status != receivedInterface.State.OperStatus.String() { @@ -124,7 +122,7 @@ func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_In go func() { b, err := json.Marshal(statusMapCopy) if err != nil { - fmt.Println(err) + fmt.Println("error: ", err) return } for clientChannel := range clientChannels { @@ -134,5 +132,5 @@ func walkThroughInterfaces(interfaces map[string]*arista.OpenconfigInterfaces_In } } - return statusList + return statusList, nil } diff --git a/applications/ese/webpage/index.html b/applications/ese/webpage/index.html index 35a0035a3ed0e20610b94bdc01fd67b5635f6652..d5d09482097d37ba662ce2031f349ec298ff5830 100644 --- a/applications/ese/webpage/index.html +++ b/applications/ese/webpage/index.html @@ -90,7 +90,7 @@ .changed { outline:10px dashed transparent; - animation: changed 1s step-end 8; + animation: changed 1s step-end 12; } @keyframes changed {