From 1b26ad854a56059d87af74efc03c97831cc3ff7c Mon Sep 17 00:00:00 2001 From: postmannen Date: Mon, 9 Jan 2023 09:10:52 +0100 Subject: [PATCH] fixed error printing readfolder, created script for writing to readfolder and socket --- message_readers.go | 19 +++++--- scripts/cliAshSocket.sh | 47 ------------------- scripts/cliBashReadfolder.sh | 47 ------------------- scripts/cliBashSocket.sh | 16 +++++-- scripts/{cliAshReadfolder.sh => clifolder.sh} | 18 +++++-- 5 files changed, 39 insertions(+), 108 deletions(-) delete mode 100755 scripts/cliAshSocket.sh delete mode 100755 scripts/cliBashReadfolder.sh rename scripts/{cliAshReadfolder.sh => clifolder.sh} (78%) diff --git a/message_readers.go b/message_readers.go index 7620f50..0d0226b 100644 --- a/message_readers.go +++ b/message_readers.go @@ -232,18 +232,21 @@ func (s *server) readFolder() { } if event.Op == fsnotify.Create || event.Op == fsnotify.Chmod { - fmt.Printf(" *** got *** : %v, op: %v\n", event.Name, event.Op) + er := fmt.Errorf("readFolder: got file event, name: %v, op: %v", event.Name, event.Op) + s.errorKernel.logConsoleOnlyIfDebug(er, s.configuration) func() { fh, err := os.Open(event.Name) if err != nil { - log.Printf("error: failed to open readFile from readFolder: %v\n", err) + er := fmt.Errorf("error: readFolder: failed to open readFile from readFolder: %v", err) + s.errorKernel.errSend(s.processInitial, Message{}, er) return } b, err := io.ReadAll(fh) if err != nil { - log.Printf("error: failed to readall from readFolder: %v\n", err) + er := fmt.Errorf("error: readFolder: failed to readall from readFolder: %v", err) + s.errorKernel.errSend(s.processInitial, Message{}, er) fh.Close() return } @@ -254,7 +257,7 @@ func (s *server) readFolder() { // unmarshal the JSON into a struct sams, err := s.convertBytesToSAMs(b) if err != nil { - er := fmt.Errorf("error: malformed json received on socket: %s\n %v", b, err) + er := fmt.Errorf("error: readFolder: malformed json received: %s\n %v", b, err) s.errorKernel.errSend(s.processInitial, Message{}, er) return } @@ -267,7 +270,7 @@ func (s *server) readFolder() { // Send an info message to the central about the message picked // for auditing. - er := fmt.Errorf("info: message read from socket on %v: %v", s.nodeName, sams[i].Message) + er := fmt.Errorf("info: readFolder: message read from readFolder on %v: %v", s.nodeName, sams[i].Message) s.errorKernel.errSend(s.processInitial, Message{}, er) } @@ -277,7 +280,8 @@ func (s *server) readFolder() { // Delete the file. err = os.Remove(event.Name) if err != nil { - log.Printf("error: failed to remove readFile from readFolder: %v\n", err) + er := fmt.Errorf("error: readFolder: failed to remove readFile from readFolder: %v", err) + s.errorKernel.errSend(s.processInitial, Message{}, er) return } @@ -288,7 +292,8 @@ func (s *server) readFolder() { if !ok { return } - log.Println("error:", err) + er := fmt.Errorf("error: readFolder: file watcher error: %v", err) + s.errorKernel.errSend(s.processInitial, Message{}, er) } } }() diff --git a/scripts/cliAshSocket.sh b/scripts/cliAshSocket.sh deleted file mode 100755 index 1ac345e..0000000 --- a/scripts/cliAshSocket.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -if [ -z "$1" ]; then - echo "No toNode supplied" - exit 1 -fi -if [ -z "$2" ]; then - echo "No cmd supplied" - exit 1 -fi - -command=$2 - -IFS=',' read -r -a array <<<"$1" - -function sendMessage() { - cat >msg.yaml <msg.yaml <msg.yaml <msg.yaml <