mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
fixed error printing readfolder, created script for writing to readfolder and socket
This commit is contained in:
parent
956a62eec1
commit
1b26ad854a
5 changed files with 39 additions and 108 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -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 <<EOF
|
||||
[
|
||||
{
|
||||
"toNodes": ["${element}"],
|
||||
"method": "REQCliCommand",
|
||||
"methodArgs":
|
||||
[
|
||||
"/bin/ash",
|
||||
"-c",
|
||||
'echo "--------------------${element}----------------------" && ${command}',
|
||||
],
|
||||
"replyMethod": "REQToFileAppend",
|
||||
"retryWait": 5,
|
||||
"ACKTimeout": 10,
|
||||
"retries": 1,
|
||||
"replyACKTimeout": 10,
|
||||
"replyRetries": 1,
|
||||
"methodTimeout": 10,
|
||||
"replyMethodTimeout": 10,
|
||||
"directory": "./data/",
|
||||
"fileName": "debug.log",
|
||||
},
|
||||
]
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
for element in "${array[@]}"; do
|
||||
sendMessage element command
|
||||
nc -U ./tmp/steward.sock <msg.yaml
|
||||
done
|
|
@ -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 <<EOF
|
||||
[
|
||||
{
|
||||
"toNodes": ["${element}"],
|
||||
"method": "REQCliCommand",
|
||||
"methodArgs":
|
||||
[
|
||||
"/bin/bash",
|
||||
"-c",
|
||||
'echo "--------------------${element}----------------------" && ${command}',
|
||||
],
|
||||
"replyMethod": "REQToFileAppend",
|
||||
"retryWait": 5,
|
||||
"ACKTimeout": 10,
|
||||
"retries": 1,
|
||||
"replyACKTimeout": 10,
|
||||
"replyRetries": 1,
|
||||
"methodTimeout": 10,
|
||||
"replyMethodTimeout": 10,
|
||||
"directory": "./data/",
|
||||
"fileName": "debug.log",
|
||||
},
|
||||
]
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
for element in "${array[@]}"; do
|
||||
sendMessage element command
|
||||
cp msg.yaml ./readfolder
|
||||
done
|
|
@ -5,13 +5,23 @@ if [ -z "$1" ]; then
|
|||
exit 1
|
||||
fi
|
||||
if [ -z "$2" ]; then
|
||||
echo "No shell path supplied"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$3" ]; then
|
||||
echo "No cmd supplied"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
command=$2
|
||||
echo $1
|
||||
echo $2
|
||||
echo $3
|
||||
|
||||
IFS=',' read -r -a array <<<"$1"
|
||||
nodes=$1
|
||||
shell=$2
|
||||
command=$3
|
||||
|
||||
IFS=',' read -r -a array <<<"$nodes"
|
||||
|
||||
function sendMessage() {
|
||||
cat >msg.yaml <<EOF
|
||||
|
@ -21,7 +31,7 @@ function sendMessage() {
|
|||
"method": "REQCliCommand",
|
||||
"methodArgs":
|
||||
[
|
||||
"/bin/bash",
|
||||
"${shell}",
|
||||
"-c",
|
||||
'echo "--------------------${element}----------------------" && ${command}',
|
||||
],
|
||||
|
|
|
@ -5,13 +5,23 @@ if [ -z "$1" ]; then
|
|||
exit 1
|
||||
fi
|
||||
if [ -z "$2" ]; then
|
||||
echo "No shell path supplied"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$3" ]; then
|
||||
echo "No cmd supplied"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
command=$2
|
||||
echo $1
|
||||
echo $2
|
||||
echo $3
|
||||
|
||||
IFS=',' read -r -a array <<<"$1"
|
||||
nodes=$1
|
||||
shell=$2
|
||||
command=$3
|
||||
|
||||
IFS=',' read -r -a array <<<"$nodes"
|
||||
|
||||
function sendMessage() {
|
||||
cat >msg.yaml <<EOF
|
||||
|
@ -21,7 +31,7 @@ function sendMessage() {
|
|||
"method": "REQCliCommand",
|
||||
"methodArgs":
|
||||
[
|
||||
"/bin/ash",
|
||||
"${shell}",
|
||||
"-c",
|
||||
'echo "--------------------${element}----------------------" && ${command}',
|
||||
],
|
||||
|
@ -42,6 +52,6 @@ EOF
|
|||
}
|
||||
|
||||
for element in "${array[@]}"; do
|
||||
sendMessage element command
|
||||
sendMessage element "$command"
|
||||
cp msg.yaml ./readfolder
|
||||
done
|
Loading…
Reference in a new issue