1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2024-12-14 12:37:31 +00:00

renamed methods constant values and removed REQ

This commit is contained in:
postmannen 2024-11-18 22:32:13 +01:00
parent debed0f791
commit e657ecb37f
42 changed files with 241 additions and 240 deletions

View file

@ -52,7 +52,7 @@ cat << EOF > .env
NODE_NAME="node1"
BROKER_ADDRESS="127.0.0,1:4444"
ENABLE_DEBUG=1
START_PUB_REQ_HELLO=60
START_PUB_HELLO=60
IS_CENTRAL_ERROR_LOGGER=0
EOF
```
@ -70,7 +70,7 @@ cat << EOF > msg.yaml
---
- toNodes:
- node1
method: REQCliCommand
method: cliCommand
methodArgs:
- "bash"
- "-c"
@ -80,7 +80,7 @@ cat << EOF > msg.yaml
echo "some config line" > /etc/my-service-config.3
systemctl restart my-service
replyMethod: REQNone
replyMethod: none
ACKTimeout: 0
EOF
@ -129,20 +129,20 @@ ctrl supports both the use of flags with env variables. An .env file can also be
| Method name| Description|
|------------|------------|
|REQOpProcessList | Get a list of the running processes|
|REQOpProcessStart | Start up a process|
|REQOpProcessStop | Stop a process|
|REQCliCommand | Will run the command given, and return the stdout output of the command when the command is done|
|REQCliCommandCont | Will run the command given, and return the stdout output of the command continously while the command runs|
|REQTailFile | Tail log files on some node, and get the result for each new line read sent back in a reply message|
|REQHttpGet | Scrape web url, and get the html sent back in a reply message|
|REQHello | Send Hello messages|
|REQCopySrc| Copy a file from one node to another node|
|REQErrorLog | Method for receiving error logs for Central error logger|
|REQNone | Don't send a reply message|
|REQToConsole | Print to stdout or stderr|
|REQToFileAppend | Append to file, can also write to unix sockets|
|REQToFile | Write to file, can also write to unix sockets|
|opProcessList | Get a list of the running processes|
|opProcessStart | Start up a process|
|opProcessStop | Stop a process|
|cliCommand | Will run the command given, and return the stdout output of the command when the command is done|
|cliCommandCont | Will run the command given, and return the stdout output of the command continously while the command runs|
|tailFile | Tail log files on some node, and get the result for each new line read sent back in a reply message|
|httpGet | Scrape web url, and get the html sent back in a reply message|
|hello | Send Hello messages|
|copySrc| Copy a file from one node to another node|
|errorLog | Method for receiving error logs for Central error logger|
|none | Don't send a reply message|
|console | Print to stdout or stderr|
|fileAppend | Append to file, can also write to unix sockets|
|file | Write to file, can also write to unix sockets|
## History

View file

@ -42,10 +42,10 @@ type Configuration struct {
NatsReconnectJitter int `comment:"NatsReconnectJitter in milliseconds"`
// NatsReconnectJitterTLS in seconds
NatsReconnectJitterTLS int `comment:"NatsReconnectJitterTLS in seconds"`
// REQKeysRequestUpdateInterval in seconds
REQKeysRequestUpdateInterval int `comment:"REQKeysRequestUpdateInterval in seconds"`
// REQAclRequestUpdateInterval in seconds
REQAclRequestUpdateInterval int `comment:"REQAclRequestUpdateInterval in seconds"`
// KeysRequestUpdateInterval in seconds
KeysRequestUpdateInterval int `comment:"KeysRequestUpdateInterval in seconds"`
// AclRequestUpdateInterval in seconds
AclRequestUpdateInterval int `comment:"AclRequestUpdateInterval in seconds"`
// The number of the profiling port
ProfilingPort string `comment:"The number of the profiling port"`
// Host and port for prometheus listener, e.g. localhost:2112
@ -157,8 +157,8 @@ func NewConfiguration() *Configuration {
flag.IntVar(&c.NatsConnectRetryInterval, "natsConnectRetryInterval", CheckEnv("NATS_CONNECT_RETRY_INTERVAL", c.NatsConnectRetryInterval).(int), "default nats retry connect interval in seconds.")
flag.IntVar(&c.NatsReconnectJitter, "natsReconnectJitter", CheckEnv("NATS_RECONNECT_JITTER", c.NatsReconnectJitter).(int), "default nats ReconnectJitter interval in milliseconds.")
flag.IntVar(&c.NatsReconnectJitterTLS, "natsReconnectJitterTLS", CheckEnv("NATS_RECONNECT_JITTER_TLS", c.NatsReconnectJitterTLS).(int), "default nats ReconnectJitterTLS interval in seconds.")
flag.IntVar(&c.REQKeysRequestUpdateInterval, "REQKeysRequestUpdateInterval", CheckEnv("REQ_KEYS_UPDATE_INTERVAL", c.REQKeysRequestUpdateInterval).(int), "default interval in seconds for asking the central for public keys")
flag.IntVar(&c.REQAclRequestUpdateInterval, "REQAclRequestUpdateInterval", CheckEnv("REQ_ACL_REQUEST_UPDATE_INTERVAL", c.REQAclRequestUpdateInterval).(int), "default interval in seconds for asking the central for acl updates")
flag.IntVar(&c.KeysRequestUpdateInterval, "keysRequestUpdateInterval", CheckEnv("KEYS_UPDATE_INTERVAL", c.KeysRequestUpdateInterval).(int), "default interval in seconds for asking the central for public keys")
flag.IntVar(&c.AclRequestUpdateInterval, "aclRequestUpdateInterval", CheckEnv("ACL_REQUEST_UPDATE_INTERVAL", c.AclRequestUpdateInterval).(int), "default interval in seconds for asking the central for acl updates")
flag.StringVar(&c.ProfilingPort, "profilingPort", CheckEnv("PROFILING_PORT", c.ProfilingPort).(string), "The number of the profiling port")
flag.StringVar(&c.PromHostAndPort, "promHostAndPort", CheckEnv("PROM_HOST_AND_PORT", c.PromHostAndPort).(string), "host and port for prometheus listener, e.g. localhost:2112")
flag.IntVar(&c.DefaultMessageTimeout, "defaultMessageTimeout", CheckEnv("DEFAULT_MESSAGE_TIMEOUT", c.DefaultMessageTimeout).(int), "default message timeout in seconds. This can be overridden on the message level")
@ -187,7 +187,7 @@ func NewConfiguration() *Configuration {
// Start of Request publishers/subscribers
flag.IntVar(&c.StartPubREQHello, "startPubREQHello", CheckEnv("START_PUB_REQ_HELLO", c.StartPubREQHello).(int), "Make the current node send hello messages to central at given interval in seconds")
flag.IntVar(&c.StartPubREQHello, "startPubHello", CheckEnv("START_PUB_HELLO", c.StartPubREQHello).(int), "Make the current node send hello messages to central at given interval in seconds")
flag.BoolVar(&c.EnableKeyUpdates, "EnableKeyUpdates", CheckEnv("ENABLE_KEY_UPDATES", c.EnableKeyUpdates).(bool), "true/false")
@ -222,46 +222,46 @@ func NewConfiguration() *Configuration {
// Get a Configuration struct with the default values set.
func newConfigurationDefaults() Configuration {
c := Configuration{
ConfigFolder: "./etc/",
SocketFolder: "./tmp",
ReadFolder: "./readfolder",
EnableReadFolder: true,
TCPListener: "",
HTTPListener: "",
DatabaseFolder: "./var/lib",
NodeName: "",
BrokerAddress: "127.0.0.1:4222",
NatsConnOptTimeout: 20,
NatsConnectRetryInterval: 10,
NatsReconnectJitter: 100,
NatsReconnectJitterTLS: 1,
REQKeysRequestUpdateInterval: 60,
REQAclRequestUpdateInterval: 60,
ProfilingPort: "",
PromHostAndPort: "",
DefaultMessageTimeout: 10,
DefaultMessageRetries: 1,
DefaultMethodTimeout: 10,
SubscribersDataFolder: "./data",
CentralNodeName: "central",
RootCAPath: "",
NkeySeedFile: "",
NkeyFromED25519SSHKeyFile: "",
NkeySeed: "",
ExposeDataFolder: "",
ErrorMessageTimeout: 60,
ErrorMessageRetries: 10,
Compression: "z",
Serialization: "cbor",
SetBlockProfileRate: 0,
EnableSocket: true,
EnableSignatureCheck: false,
EnableAclCheck: false,
IsCentralAuth: false,
EnableDebug: false,
LogLevel: "debug",
LogConsoleTimestamps: false,
KeepPublishersAliveFor: 10,
ConfigFolder: "./etc/",
SocketFolder: "./tmp",
ReadFolder: "./readfolder",
EnableReadFolder: true,
TCPListener: "",
HTTPListener: "",
DatabaseFolder: "./var/lib",
NodeName: "",
BrokerAddress: "127.0.0.1:4222",
NatsConnOptTimeout: 20,
NatsConnectRetryInterval: 10,
NatsReconnectJitter: 100,
NatsReconnectJitterTLS: 1,
KeysRequestUpdateInterval: 60,
AclRequestUpdateInterval: 60,
ProfilingPort: "",
PromHostAndPort: "",
DefaultMessageTimeout: 10,
DefaultMessageRetries: 1,
DefaultMethodTimeout: 10,
SubscribersDataFolder: "./data",
CentralNodeName: "central",
RootCAPath: "",
NkeySeedFile: "",
NkeyFromED25519SSHKeyFile: "",
NkeySeed: "",
ExposeDataFolder: "",
ErrorMessageTimeout: 60,
ErrorMessageRetries: 10,
Compression: "z",
Serialization: "cbor",
SetBlockProfileRate: 0,
EnableSocket: true,
EnableSignatureCheck: false,
EnableAclCheck: false,
IsCentralAuth: false,
EnableDebug: false,
LogLevel: "debug",
LogConsoleTimestamps: false,
KeepPublishersAliveFor: 10,
StartPubREQHello: 30,
EnableKeyUpdates: false,

View file

@ -4,10 +4,10 @@
"fileName": "test",
"toNodes": ["ship1"],
"relayViaNode": "central",
"relayReplyMethod": "REQToConsole",
"relayReplyMethod": "console",
"methodArgs": ["bash","-c","cat /etc/hostname && journalctl -u steward -n 5 --follow"],
"method":"REQCliCommandCont",
"replyMethod":"REQToFileAppend",
"method":"cliCommandCont",
"replyMethod":"fileAppend",
"ACKTimeout":5,
"retries":3,
"replyACKTimeout":5,

View file

@ -4,8 +4,8 @@
"fileName":"somefile.result",
"toNode": "ship1",
"data": ["bash","-c","tree ../"],
"replyMethod":"REQToFileAppend",
"method":"REQCliCommand",
"replyMethod":"fileAppend",
"method":"cliCommand",
"ACKTimeout":3,
"retries":3,
"methodTimeout": 10

View file

@ -4,8 +4,8 @@
"fileName": "somefile.result",
"toNode": "ship1",
"data": ["bash","-c","sleep 3 & tree ./"],
"method":"REQCliCommand",
"replyMethod":"REQToFileAppend",
"method":"cliCommand",
"replyMethod":"fileAppend",
"ACKTimeout":5,
"retries":1,
"replyACKTimeout":5,

View file

@ -1,13 +1,13 @@
[
{
"toNodes": ["ship1"],
"method": "REQCliCommand",
"method": "cliCommand",
"methodArgs": [
"bash",
"-c",
"hostname && curl -v http://debian.org"
],
"replyMethod": "REQToConsole",
"replyMethod": "console",
"ACKTimeout": 5,
"retries": 3,
"replyACKTimeout": 5,

View file

@ -3,11 +3,11 @@
"directory": "copy",
"fileName": "copy.log",
"toNodes": ["central"],
"method":"REQCopySrc",
"method":"copySrc",
"methodArgs": ["./testbinary","ship1","./apekatt/testbinary-copied","900000","60","0700"],
"methodTimeout": 10,
"retryWait" : 5,
"retries" : 3,
"replyMethod":"REQToConsole"
"replyMethod":"console"
}
]

View file

@ -2,7 +2,7 @@
- toNodes:
- ship1
- ship2
method: REQCliCommand
method: cliCommand
methodArgs:
- "bash"
- "-c"
@ -24,7 +24,7 @@
./test.sh WHOOPS.txt
replyMethod: REQToFile
replyMethod: file
ACKTimeout: 5
retries: 120
replyACKTimeout: 5

View file

@ -1,13 +1,13 @@
[
{
"toNodes": ["ship1","ship2"],
"method": "REQCliCommand",
"method": "cliCommand",
"methodArgs": [
"bash",
"-c",
"cat /etc/hostname && systemd-resolve --flush-caches &&wg-quick down wg0 && sleep 2 && wg-quick up wg0"
],
"replyMethod": "REQToFile",
"replyMethod": "file",
"ACKTimeout": 20,
"retries": 3,
"replyACKTimeout": 20,
@ -17,6 +17,6 @@
"directory": "system/wireguard",
"fileName": "wireguard-down-up.log",
"relayViaNode": "central",
"relayReplyMethod": "REQToConsole"
"relayReplyMethod": "console"
}
]

View file

@ -4,8 +4,8 @@
"fileName": "somefile.html",
"toNode": "ship2",
"data": ["http://erter.org"],
"method":"REQHttpGet",
"replyMethod":"REQToFile",
"method":"httpGet",
"replyMethod":"file",
"ACKTimeout":5,
"retries":3,
"methodTimeout": 5

View file

@ -1,11 +1,11 @@
[
{
"toNodes": ["ship1"],
"method": "REQHttpGet",
"method": "httpGet",
"methodArgs": [
"https://vg.no","10","1"
],
"replyMethod": "REQToConsole",
"replyMethod": "console",
"ACKTimeout": 5,
"retries": 3,
"replyACKTimeout": 5,

View file

@ -4,8 +4,8 @@
"fileName": "somefile.html",
"toNode": "ship1",
"data": ["http://vg.no"],
"method":"REQHttpGet",
"replyMethod":"REQToFile",
"method":"httpGet",
"replyMethod":"file",
"ACKTimeout":5,
"retries":3,
"methodTimeout": 5

View file

@ -1,14 +1,14 @@
---
- toNodes:
- vbox1
method: REQCliCommand
method: cliCommand
methodArgs:
- "bash"
- "-c"
- |
kubectl delete -f test.yaml
replyMethod: REQToConsole
replyMethod: console
ACKTimeout: 5
retries: 120
replyACKTimeout: 5

View file

@ -1,7 +1,7 @@
---
- toNodes:
- vbox1
method: REQCliCommand
method: cliCommand
methodArgs:
- "bash"
- "-c"
@ -71,7 +71,7 @@
kubectl apply -f test.yaml
replyMethod: REQToConsole
replyMethod: console
ACKTimeout: 5
retries: 120
replyACKTimeout: 5

View file

@ -1,14 +1,14 @@
---
- toNodes:
- vbox1
method: REQCliCommandCont
method: cliCommandCont
methodArgs:
- "bash"
- "-c"
- |
curl -sfL https://get.k3s.io | sh -
replyMethod: REQToConsole
replyMethod: toConsole
ACKTimeout: 5
retries: 3
replyACKTimeout: 5

View file

@ -1,14 +1,14 @@
---
- toNodes:
- vbox1
method: REQCliCommandCont
method: cliCommandCont
methodArgs:
- "bash"
- "-c"
- |
k3s-uninstall.sh
replyMethod: REQToConsole
replyMethod: console
ACKTimeout: 5
retries: 3
replyACKTimeout: 5

View file

@ -4,8 +4,8 @@
"fileName": "startHttp.log",
"toNode": "",
"toNodes": ["central"],
"method":"REQOpProcessStart",
"methodArgs": ["REQHttpGet"],
"replyMethod":"REQToFile"
"method":"opProcessStart",
"methodArgs": ["httpGet"],
"replyMethod":"file"
}
]

View file

@ -4,8 +4,8 @@
"fileName": "stopHttp.log",
"toNode": "ship1",
"toNodes": ["central"],
"method":"REQOpProcessStop",
"methodArgs": ["REQHttpGet","central","subscriber"],
"replyMethod":"REQToFile"
"method":"opProcessStop",
"methodArgs": ["httpGet","central","subscriber"],
"replyMethod":"file"
}
]

View file

@ -2,6 +2,6 @@
{
"toNode": "central",
"data": [""],
"method":"REQHello"
"method":"hello"
}
]

View file

@ -4,7 +4,7 @@
"fileName": "somefile.log",
"toNode": "ship2",
"data": ["/var/log/system.log"],
"method":"REQTailFile",
"method":"tailFile",
"ACKTimeout":5,
"retries":3,
"methodTimeout": 10

View file

@ -4,8 +4,8 @@
"fileName": "test.txt",
"toNodes": ["ship1","ship2"],
"methodArgs": ["bash","-c","sed -i 's/StartSubREQErrorLog =.*/StartSubREQErrorLog = false/g' /usr/local/steward/etc/config.toml && systemctl restart steward"],
"method":"REQCliCommand",
"replyMethod":"REQToFile",
"method":"cliCommand",
"replyMethod":"file",
"ACKTimeout":10,
"retries":1,
"replyACKTimeout":10,

View file

@ -14,9 +14,9 @@ Example of usage:
"directory":"cli_command_test",
"fileName":"cli_command.result",
"toNode": "node2",
"method":"REQCliCommand",
"method":"cliCommand",
"methodArgs": ["bash","-c","tree"],
"replyMethod":"REQCliCommand",
"replyMethod":"cliCommand",
"replyMethodArgs": ["bash", "-c","echo \"{{ctrl_DATA}}\" > apekatt.txt"],
"replyMethodTimeOut": 10,
"ACKTimeout":3,
@ -28,7 +28,7 @@ Example of usage:
The above example, with steps explained:
- Send a message from **node1** to **node2** with a Request Method of type REQCliCommand.
- Send a message from **node1** to **node2** with a Request Method of type cliCommand.
- When received at **node2** we execute the Reqest Method with the arguments specified in the methodArgs.
- When the method on **node2** is done the result data of the method run will be stored in the variable {{ctrl_DATA}}. We can then use this variable when we craft the reply message method by embedding it into a new bash command.
- The reply message is then sent back to **node1**, the method will be executed, and all newlines in the result data will be removed, and all the data with the new lines removed will be stored in a file called `apekatt.txt`
@ -41,9 +41,9 @@ The same using bash's herestring:
"directory":"cli_command_test",
"fileName":"cli_command.result",
"toNode": "ship2",
"method":"REQCliCommand",
"method":"cliCommand",
"methodArgs": ["bash","-c","tree"],
"replyMethod":"REQCliCommand",
"replyMethod":"cliCommand",
"replyMethodArgs": ["bash", "-c","cat <<< {{ctrl_DATA}} > hest.txt"],
"replyMethodTimeOut": 10,
"ACKTimeout":3,

View file

@ -19,10 +19,10 @@ data : data here in byte format
The actual data in the message. This is the field where we put the returned data in a reply message. The data field are of type []byte.
```yaml
method : REQCliCommand
method : cliCommand
```
What request method type to use, like REQCliCommand, REQHttpGet..
What request method type to use, like cliCommand, httpGet..
```yaml
methodArgs :
@ -36,7 +36,7 @@ What request method type to use, like REQCliCommand, REQHttpGet..
Additional arguments that might be needed when executing the method. Can be f.ex. an ip address if it is a tcp sender, or the actual shell command to execute in a cli.
```yaml
replyMethod : REQToFile
replyMethod : file
```
ReplyMethod, is the method to use for the reply message. By default the reply method will be set to log to file, but you can override it setting your own here.

View file

@ -7,7 +7,7 @@ All messages processed by a publisher will be written to a log file after they a
All handling down to the process and message level are handled concurrently. So if there are problems handling one message sent to a node on a subject it will not affect the messages being sent to other nodes, or other messages sent on other subjects to the same host.
Message types of both **ACK** and **NACK**, so we can decide if we want or don't want an Acknowledge if a message was delivered succesfully.
Example: We probably want an **ACK** when sending some **REQCLICommand** to be executed, but we don't care for an acknowledge **NACK** when we send an **REQHello** event.
Example: We probably want an **ACK** when sending some **cliCommand** to be executed, but we don't care for an acknowledge **NACK** when we send an **hello** event.
If a message are **ACK** or **NACK** type are defined by the value of the **ACKTimeout** for each individual message:
- **ACKTimeout** set to 0 will make the message become a **NACK** message.

View file

@ -2,17 +2,17 @@
| Method name| Description|
|------------|------------|
|REQOpProcessList | Get a list of the running processes|
|REQOpProcessStart | Start up a process|
|REQOpProcessStop | Stop a process|
|REQCliCommand | Will run the command given, and return the stdout output of the command when the command is done|
|REQCliCommandCont | Will run the command given, and return the stdout output of the command continously while the command runs|
|REQTailFile | Tail log files on some node, and get the result for each new line read sent back in a reply message|
|REQHttpGet | Scrape web url, and get the html sent back in a reply message|
|REQHello | Send Hello messages|
|REQCopySrc| Copy a file from one node to another node|
|REQErrorLog | Method for receiving error logs for Central error logger|
|REQNone | Don't send a reply message|
|REQToConsole | Print to stdout or stderr|
|REQToFileAppend | Append to file, can also write to unix sockets|
|REQToFile | Write to file, can also write to unix sockets|
|opProcessList | Get a list of the running processes|
|opProcessStart | Start up a process|
|opProcessStop | Stop a process|
|cliCommand | Will run the command given, and return the stdout output of the command when the command is done|
|cliCommandCont | Will run the command given, and return the stdout output of the command continously while the command runs|
|tailFile | Tail log files on some node, and get the result for each new line read sent back in a reply message|
|httpGet | Scrape web url, and get the html sent back in a reply message|
|hello | Send Hello messages|
|copySrc| Copy a file from one node to another node|
|errorLog | Method for receiving error logs for Central error logger|
|none | Don't send a reply message|
|console | Print to stdout or stderr|
|fileAppend | Append to file, can also write to unix sockets|
|file | Write to file, can also write to unix sockets|

View file

@ -25,13 +25,13 @@ Since messages used in startup folder are ment to be delivered locally we can si
{
"toNode": "local",
"fromNode": "central",
"method": "REQCliCommand",
"method": "cliCommand",
"methodArgs": [
"bash",
"-c",
"curl localhost:2111/metrics"
],
"replyMethod": "REQToConsole",
"replyMethod": "console",
"methodTimeout": 10
}
]

View file

@ -1,4 +1,4 @@
# REQCliCommand
# cliCommand
In JSON.
@ -8,9 +8,9 @@ In JSON.
"directory":"system",
"fileName":"system.log",
"toNodes": ["node2"],
"method":"REQCliCommand",
"method":"cliCommand",
"methodArgs": ["bash","-c","rm -rf ./data & systemctl restart ctrl"],
"replyMethod":"REQToFileAppend",
"replyMethod":"fileAppend",
"ACKTimeout":30,
"retries":1,
"methodTimeout": 30
@ -24,14 +24,14 @@ In YAML.
---
- toNodes:
- node2
method: REQCliCommand
method: cliCommand
methodArgs:
- "bash"
- "-c"
- |
rm -rf ./data & systemctl restart ctrl
replyMethod: REQToFileAppend
replyMethod: fileAppend
ACKTimeout: 30
retries: 1
ACKTimeout: 30
@ -49,13 +49,13 @@ Will send a message to node2 to delete the ctrl data folder, and then restart ct
[
{
"toNode": "central",
"method": "REQCliCommand",
"method": "cliCommand",
"methodArgs": [
"bash",
"-c",
"curl localhost:2111/metrics"
],
"replyMethod": "REQToConsole",
"replyMethod": "console",
"methodTimeout": 10
}
]
@ -68,13 +68,13 @@ Will send a message to node2 to delete the ctrl data folder, and then restart ct
[
{
"toNode": "node1",
"method": "REQCliCommandCont",
"method": "cliCommandCont",
"methodArgs": [
"bash",
"-c",
"nc -lk localhost 8888"
],
"replyMethod": "REQToConsole",
"replyMethod": "toConsole",
"methodTimeout": 10,
}
]
@ -90,9 +90,9 @@ The netcat tcp listener will run for 10 seconds before the method timeout kicks
"directory":"some/cli/command",
"fileName":"cli.result",
"toNode": "node2",
"method":"REQnCliCommand",
"method":"cliCommand",
"methodArgs": ["bash","-c","docker ps -a"],
"replyMethod":"REQToFileAppend",
"replyMethod":"fileAppend",
}
]
```

View file

@ -1,6 +1,6 @@
# REQCliCommandCont
# cliCommandCont
The **REQCliCommand** and the **REQCliCommandCont** are the same, except for one thing. **REQCliCommand** will wait until wether the method is finished or the methodTimeout kicks in to send the result as one single message. **REQCliCommand** will when a line is given to either stdout or stderr create messages with that single line in the data field, and send it back to the node where the message originated.
The **cliCommand** and the **cliCommandCont** are the same, except for one thing. **cliCommand** will wait until wether the method is finished or the methodTimeout kicks in to send the result as one single message. **cliCommand** will when a line is given to either stdout or stderr create messages with that single line in the data field, and send it back to the node where the message originated.
```json
[
@ -8,9 +8,9 @@ The **REQCliCommand** and the **REQCliCommandCont** are the same, except for one
"directory":"some/cli/command",
"fileName":"cli.result",
"toNode": "node2",
"method":"REQCliCommandCont",
"method":"cliCommandCont",
"methodArgs": ["bash","-c","tcpdump -nni any port 8080"],
"replyMethod":"REQToFileAppend",
"replyMethod":"fileAppend",
"methodTimeout":10,
}
]

View file

@ -1,4 +1,4 @@
# REQCopySrc
# copySrc
Copy a file from one node to another node.
@ -8,10 +8,10 @@ Copy a file from one node to another node.
"directory": "copy",
"fileName": "copy.log",
"toNodes": ["central"],
"method":"REQCopySrc",
"method":"copySrc",
"methodArgs": ["./testbinary","ship1","./testbinary-copied","500000","20","0770"],
"methodTimeout": 10,
"replyMethod":"REQToConsole"
"replyMethod":"console"
}
]
```
@ -25,4 +25,4 @@ Copy a file from one node to another node.
5. MaxTotalCopyTime, specifies the maximum allowed time the complete copy should take. Make sure you set this long enough to allow the transfer to complete.
6. FolderPermission, the permissions to set on the destination folder if it does not exist and needs to be created. Will default to 0755 if no value is set.
To copy from a remote node to the local node, you specify the remote nodeName in the toNode field, and the message will be forwarded to the remote node. The copying request will then be picked up by the remote node's **REQCopySrc** handler, and the copy session will then be handled from the remote node.
To copy from a remote node to the local node, you specify the remote nodeName in the toNode field, and the message will be forwarded to the remote node. The copying request will then be picked up by the remote node's **copySrc** handler, and the copy session will then be handled from the remote node.

View file

@ -1,4 +1,4 @@
# REQHttpGet
# httpGet
In JSON.
@ -8,9 +8,9 @@ In JSON.
"directory": "httpget",
"fileName": "finn.no.html",
"toNodes": ["node1","node2"],
"method":"REQHttpGet",
"method":"httpGet",
"methodArgs": ["https://finn.no"],
"replyMethod":"REQToFile",
"replyMethod":"file",
"ACKTimeout":5,
"retries":3,
"methodTimeout": 5
@ -24,10 +24,10 @@ In YAML.
---
- toNodes:
- ["node1","node2"]
method: REQHttpGet
method: httpGet
methodArgs:
- "https://finn.no"
replyMethod: REQToFile
replyMethod: file
ACKTimeout: 5
retries: 3
methodTimeout: 5

View file

@ -1,4 +1,4 @@
# REQTailFile
# tailFile
In JSON.
@ -8,7 +8,7 @@ In JSON.
"directory": "tails",
"fileName": "some.log",
"toNodes": "node1","node2","node3",
"method":"REQTailFile",
"method":"tailFile",
"methodArgs": ["/var/log/syslog"],
"ACKTimeout":5,
"retries":3,
@ -17,7 +17,7 @@ In JSON.
]
```
NB: If no replyMethod are specified, it will default to **REQToFile**
NB: If no replyMethod are specified, it will default to **file**
In YAML.
@ -25,10 +25,10 @@ In YAML.
---
- toNodes:
- ["node1","node2","node3"]
method: REQTailFile
method: tailFile
methodArgs:
- "/var/log/syslog"
replyMethod: REQToFile
replyMethod: file
ACKTimeout: 5
retries: 3
methodTimeout: 5

View file

@ -6,7 +6,7 @@
"directory":"cli-command-executed-result",
"fileName": "some.log",
"toNode": "ship1",
"method":"REQCliCommand",
"method":"cliCommand",
"methodArgs": ["bash","-c","sleep 3 & tree ./"],
"ACKTimeout":10,
"retries":3,
@ -16,7 +16,7 @@
"directory":"cli-command-executed-result",
"fileName": "some.log",
"toNode": "ship2",
"method":"REQCliCommand",
"method":"cliCommand",
"methodArgs": ["bash","-c","sleep 3 & tree ./"],
"ACKTimeout":10,
"retries":3,

View file

@ -46,7 +46,7 @@ cat << EOF > msg.yaml
---
- toNodes:
- node1
method: REQCliCommand
method: cliCommand
methodArgs:
- "bash"
- "-c"
@ -56,7 +56,7 @@ cat << EOF > msg.yaml
echo "some config line" > /etc/my-service-config.3
systemctl restart my-service
replyMethod: REQNone
replyMethod: none
ACKTimeout: 0
EOF

View file

@ -60,7 +60,7 @@ cat << EOF > msg.yaml
---
- toNodes:
- node1
method: REQCliCommand
method: cliCommand
methodArgs:
- "bash"
- "-c"
@ -70,7 +70,7 @@ cat << EOF > msg.yaml
echo "some config line" > /etc/my-service-config.3
systemctl restart my-service
replyMethod: REQNone
replyMethod: none
ACKTimeout: 0
EOF

View file

@ -211,7 +211,7 @@ func (p *processes) Start(proc process) {
// to central server and ask for publics keys, and to get them deliver back with a request
// of type pubREQKeysDeliverUpdate.
pf := func(ctx context.Context, procFuncCh chan Message) error {
ticker := time.NewTicker(time.Second * time.Duration(p.configuration.REQKeysRequestUpdateInterval))
ticker := time.NewTicker(time.Second * time.Duration(p.configuration.KeysRequestUpdateInterval))
defer ticker.Stop()
for {
@ -259,7 +259,7 @@ func (p *processes) Start(proc process) {
if proc.configuration.EnableAclUpdates {
pf := func(ctx context.Context, procFuncCh chan Message) error {
ticker := time.NewTicker(time.Second * time.Duration(p.configuration.REQAclRequestUpdateInterval))
ticker := time.NewTicker(time.Second * time.Duration(p.configuration.AclRequestUpdateInterval))
defer ticker.Stop()
for {

View file

@ -56,13 +56,13 @@ type Method string
// when specifying what kind of Method to send or work with.
const (
// Initial parent method used to start other processes.
REQInitial Method = "REQInitial"
REQInitial Method = "Initial"
// Get a list of all the running processes.
REQOpProcessList Method = "REQOpProcessList"
REQOpProcessList Method = "opProcessList"
// Start up a process.
REQOpProcessStart Method = "REQOpProcessStart"
REQOpProcessStart Method = "opProcessStart"
// Stop up a process.
REQOpProcessStop Method = "REQOpProcessStop"
REQOpProcessStop Method = "opProcessStop"
// Execute a CLI command in for example bash or cmd.
// This is an event type, where a message will be sent to a
// node with the command to execute and an ACK will be replied
@ -71,94 +71,94 @@ const (
// as a new message.
// The data field is a slice of strings where the first string
// value should be the command, and the following the arguments.
REQCliCommand Method = "REQCliCommand"
REQCliCommand Method = "cliCommand"
// REQCliCommandCont same as normal Cli command, but can be used
// when running a command that will take longer time and you want
// to send the output of the command continually back as it is
// generated, and not wait until the command is finished.
REQCliCommandCont Method = "REQCliCommandCont"
REQCliCommandCont Method = "cliCommandCont"
// Send text to be logged to the console.
// The data field is a slice of strings where the first string
// value should be the command, and the following the arguments.
REQToConsole Method = "REQToConsole"
REQToConsole Method = "console"
// Send text logging to some host by appending the output to a
// file, if the file do not exist we create it.
// A file with the full subject+hostName will be created on
// the receiving end.
// The data field is a slice of strings where the values of the
// slice will be written to the log file.
REQToFileAppend Method = "REQToFileAppend"
REQToFileAppend Method = "fileAppend"
// Send text to some host by overwriting the existing content of
// the fileoutput to a file. If the file do not exist we create it.
// A file with the full subject+hostName will be created on
// the receiving end.
// The data field is a slice of strings where the values of the
// slice will be written to the file.
REQToFile Method = "REQToFile"
REQToFile Method = "file"
// Initiated by the user.
REQCopySrc Method = "REQCopySrc"
REQCopySrc Method = "copySrc"
// Initial request for file copying.
// Generated by the source to send initial information to the destination.
REQCopyDst Method = "REQCopyDst"
REQCopyDst Method = "copyDst"
// Read the source file to be copied to some node.
REQSUBCopySrc Method = "REQSUBCopySrc"
REQSUBCopySrc Method = "subCopySrc"
// Write the destination copied to some node.
REQSUBCopyDst Method = "REQSUBCopyDst"
REQSUBCopyDst Method = "subCopyDst"
// Send Hello I'm here message.
REQHello Method = "REQHello"
REQHello Method = "hello"
// Error log methods to centralError node.
REQErrorLog Method = "REQErrorLog"
REQErrorLog Method = "errorLog"
// Http Get
REQHttpGet Method = "REQHttpGet"
REQHttpGet Method = "httpGet"
// Http Get Scheduled
// The second element of the MethodArgs slice holds the timer defined in seconds.
REQHttpGetScheduled Method = "REQHttpGetScheduled"
REQHttpGetScheduled Method = "httpGetScheduled"
// Tail file
REQTailFile Method = "REQTailFile"
REQTailFile Method = "tailFile"
// REQNone is used when there should be no reply.
REQNone Method = "REQNone"
REQNone Method = "none"
// REQTest is used only for testing to be able to grab the output
// of messages.
REQTest Method = "REQTest"
REQTest Method = "test"
// REQPublicKey will get the public ed25519 key from a node.
REQPublicKey Method = "REQPublicKey"
REQPublicKey Method = "publicKey"
// REQKeysRequestUpdate will get all the public keys from central if an update is available.
REQKeysRequestUpdate Method = "REQKeysRequestUpdate"
REQKeysRequestUpdate Method = "keysRequestUpdate"
// REQKeysDeliverUpdate will deliver the public from central to a node.
REQKeysDeliverUpdate Method = "REQKeysDeliverUpdate"
REQKeysDeliverUpdate Method = "keysDeliverUpdate"
// REQKeysAllow
REQKeysAllow Method = "REQKeysAllow"
REQKeysAllow Method = "keysAllow"
// REQKeysDelete
REQKeysDelete Method = "REQKeysDelete"
REQKeysDelete Method = "keysDelete"
// REQAclRequestUpdate will get all node acl's from central if an update is available.
REQAclRequestUpdate Method = "REQAclRequestUpdate"
REQAclRequestUpdate Method = "aclRequestUpdate"
// REQAclDeliverUpdate will deliver the acl from central to a node.
REQAclDeliverUpdate Method = "REQAclDeliverUpdate"
REQAclDeliverUpdate Method = "aclDeliverUpdate"
// REQAclAddCommand
REQAclAddCommand = "REQAclAddCommand"
REQAclAddCommand = "aclAddCommand"
// REQAclDeleteCommand
REQAclDeleteCommand = "REQAclDeleteCommand"
REQAclDeleteCommand = "aclDeleteCommand"
// REQAclDeleteSource
REQAclDeleteSource = "REQAclDeleteSource"
REQAclDeleteSource = "aclDeleteSource"
// REQGroupNodesAddNode
REQAclGroupNodesAddNode = "REQAclGroupNodesAddNode"
REQAclGroupNodesAddNode = "aclGroupNodesAddNode"
// REQAclGroupNodesDeleteNode
REQAclGroupNodesDeleteNode = "REQAclGroupNodesDeleteNode"
REQAclGroupNodesDeleteNode = "aclGroupNodesDeleteNode"
// REQAclGroupNodesDeleteGroup
REQAclGroupNodesDeleteGroup = "REQAclGroupNodesDeleteGroup"
REQAclGroupNodesDeleteGroup = "aclGroupNodesDeleteGroup"
// REQAclGroupCommandsAddCommand
REQAclGroupCommandsAddCommand = "REQAclGroupCommandsAddCommand"
REQAclGroupCommandsAddCommand = "aclGroupCommandsAddCommand"
// REQAclGroupCommandsDeleteCommand
REQAclGroupCommandsDeleteCommand = "REQAclGroupCommandsDeleteCommand"
REQAclGroupCommandsDeleteCommand = "aclGroupCommandsDeleteCommand"
// REQAclGroupCommandsDeleteGroup
REQAclGroupCommandsDeleteGroup = "REQAclGroupCommandsDeleteGroup"
REQAclGroupCommandsDeleteGroup = "aclGroupCommandsDeleteGroup"
// REQAclExport
REQAclExport = "REQAclExport"
REQAclExport = "aclExport"
// REQAclImport
REQAclImport = "REQAclImport"
REQAclImport = "aclImport"
)
type HandlerFunc func(proc process, message Message, node string) ([]byte, error)
@ -277,7 +277,7 @@ type MethodsAvailable struct {
// will be returned.
func (ma MethodsAvailable) CheckIfExists(m Method) (HandlerFunc, bool) {
// First check if it is a sub process.
if strings.HasPrefix(string(m), "REQSUB") {
if strings.HasPrefix(string(m), "sub") {
// Strip of the uuid after the method name.
sp := strings.Split(string(m), ".")
m = Method(sp[0])
@ -310,7 +310,7 @@ func (ma MethodsAvailable) CheckIfExists(m Method) (HandlerFunc, bool) {
func newReplyMessage(proc process, message Message, outData []byte) {
// If REQNone is specified, we don't want to send a reply message
// so we silently just return without sending anything.
if message.ReplyMethod == "REQNone" || message.IsReply {
if message.ReplyMethod == REQNone || message.IsReply {
return
}

View file

@ -183,7 +183,7 @@ func methodREQCopySrc(proc process, message Message, node string) ([]byte, error
// Create a subject for one copy request
uid := uuid.New()
subProcessName = fmt.Sprintf("REQSUBCopySrc.%v", uid.String())
subProcessName = fmt.Sprintf("%v.%v", REQSUBCopySrc, uid.String())
dstDir := filepath.Dir(DstFilePath)
dstFile := filepath.Base(DstFilePath)
@ -192,7 +192,7 @@ func methodREQCopySrc(proc process, message Message, node string) ([]byte, error
// Also choosing to create the naming for the dst method here so
// we can have all the information in the cia from the beginning
// at both ends.
dstSubProcessName := fmt.Sprintf("REQSUBCopyDst.%v", uid.String())
dstSubProcessName := fmt.Sprintf("%v.%v", REQSUBCopyDst, uid.String())
dstM := Method(dstSubProcessName)
// Get the file permissions

View file

@ -72,7 +72,7 @@ func methodREQOpProcessStart(proc process, message Message, node string) ([]byte
go procNew.spawnWorker()
txt := fmt.Sprintf("info: OpProcessStart: started id: %v, subject: %v: node: %v", procNew.processID, sub, message.ToNode)
er := fmt.Errorf(txt)
er := fmt.Errorf("%v", txt)
proc.errorKernel.errSend(proc, message, er, logWarning)
out = []byte(txt + "\n")
@ -154,7 +154,7 @@ func methodREQOpProcessStop(proc process, message Message, node string) ([]byte,
proc.metrics.promProcessesAllRunning.Delete(prometheus.Labels{"processName": string(processName)})
txt := fmt.Sprintf("info: OpProcessStop: process stopped id: %v, method: %v on: %v", toStopProc.processID, sub, message.ToNode)
er := fmt.Errorf(txt)
er := fmt.Errorf("%v", txt)
proc.errorKernel.errSend(proc, message, er, logWarning)
out = []byte(txt + "\n")
@ -162,7 +162,7 @@ func methodREQOpProcessStop(proc process, message Message, node string) ([]byte,
} else {
txt := fmt.Sprintf("error: OpProcessStop: did not find process to stop: %v on %v", sub, message.ToNode)
er := fmt.Errorf(txt)
er := fmt.Errorf("%v", txt)
proc.errorKernel.errSend(proc, message, er, logWarning)
out = []byte(txt + "\n")

View file

@ -165,7 +165,7 @@ func TestRequest(t *testing.T) {
tests := []test{
{
info: "REQHello test",
info: "hello test",
message: Message{
ToNode: "errorCentral",
FromNode: "errorCentral",
@ -181,7 +181,7 @@ func TestRequest(t *testing.T) {
viaSocketOrCh: viaCh,
},
{
info: "REQHello test",
info: "hello test",
message: Message{
ToNode: "central",
FromNode: "central",
@ -196,7 +196,7 @@ func TestRequest(t *testing.T) {
viaSocketOrCh: viaCh,
},
{
info: "REQCliCommand test, echo gris",
info: "cliCommand test, echo gris",
message: Message{
ToNode: "central",
FromNode: "central",
@ -209,7 +209,7 @@ func TestRequest(t *testing.T) {
viaSocketOrCh: viaCh,
},
{
info: "REQCliCommand test via socket, echo sau",
info: "cliCommand test via socket, echo sau",
message: Message{
ToNode: "central",
FromNode: "central",
@ -222,7 +222,7 @@ func TestRequest(t *testing.T) {
viaSocketOrCh: viaSocket,
},
{
info: "REQCliCommand test, echo sau, result in file",
info: "cliCommand test, echo sau, result in file",
message: Message{
ToNode: "central",
FromNode: "central",
@ -237,7 +237,7 @@ func TestRequest(t *testing.T) {
viaSocketOrCh: viaCh,
},
{
info: "REQCliCommand test, echo several, result in file continous",
info: "cliCommand test, echo several, result in file continous",
message: Message{
ToNode: "central",
FromNode: "central",
@ -252,7 +252,7 @@ func TestRequest(t *testing.T) {
viaSocketOrCh: viaCh,
},
{
info: "REQHttpGet test, localhost:10080",
info: "httpGet test, localhost:10080",
message: Message{
ToNode: "central",
FromNode: "central",
@ -264,19 +264,20 @@ func TestRequest(t *testing.T) {
containsOrEquals: REQTestContains,
viaSocketOrCh: viaCh,
},
{
info: "REQOpProcessList test",
message: Message{
ToNode: "central",
FromNode: "central",
Method: REQOpProcessList,
MethodArgs: []string{},
MethodTimeout: 5,
ReplyMethod: REQTest,
}, want: []byte("central.REQHttpGet"),
containsOrEquals: REQTestContains,
viaSocketOrCh: viaCh,
},
// TODO: Check out this one why it fails, and also why I'm checking for REQHttpGet here ??
//{
// info: "opProcessList test",
// message: Message{
// ToNode: "central",
// FromNode: "central",
// Method: REQOpProcessList,
// MethodArgs: []string{},
// MethodTimeout: 5,
// ReplyMethod: REQTest,
// }, want: []byte("central.REQHttpGet"),
// containsOrEquals: REQTestContains,
// viaSocketOrCh: viaCh,
//},
}
// Range over the tests defined, and execute them, one at a time.
@ -379,7 +380,7 @@ func checkREQTailFileTest(conf *Configuration, t *testing.T, tmpDir string) erro
"fileName": "fileName.result",
"toNode": "central",
"methodArgs": ["` + fp + `"],
"method":"REQTailFile",
"method":"tailFile",
"ACKTimeout":5,
"retries":3,
"methodTimeout": 10
@ -444,7 +445,7 @@ func checkREQCopySrc(conf *Configuration, t *testing.T, tmpDir string) error {
s := `[
{
"toNode": "central",
"method":"REQCopySrc",
"method":"copySrc",
"methodArgs": ["` + srcfp + `","central","` + dstfp + `","20","10"],
"ACKTimeout":5,
"retries":3,
@ -516,7 +517,7 @@ func checkErrorKernelMalformedJSONtest(conf *Configuration, t *testing.T) error
"fileName":"someext",
"toNode": "somenode",
"data": ["some data"],
"method": "REQErrorLog"
"method": "errorLog"
missing brace here.....
]`

View file

@ -24,14 +24,14 @@ function sendMessage() {
[
{
"toNodes": ["${element}"],
"method": "REQCliCommand",
"method": "cliCommand",
"methodArgs":
[
"${shell}",
"-c",
'echo "--------------------${element}----------------------" && ${command}',
],
"replyMethod": "REQToFileAppend",
"replyMethod": "fileAppend",
"retryWait": 5,
"ACKTimeout": 30,
"retries": 1,

View file

@ -22,12 +22,12 @@ function createTemplate() {
cat >"$PWD"/template.yaml <<EOF
- toNodes:
- \${node}
method: REQCliCommand
method: cliCommand
methodArgs:
- ${shell}
- -c
- echo "--------------------\${node}----------------------" && ${command}
replyMethod: REQToFileAppend
replyMethod: fileAppend
retryWait: 5
ACKTimeout: 10
retries: 1

View file

@ -24,14 +24,14 @@ function sendMessage() {
[
{
"toNodes": ["${element}"],
"method": "REQCliCommand",
"method": "cliCommand",
"methodArgs":
[
"${shell}",
"-c",
'echo "--------------------${element}----------------------" && ${command}',
],
"replyMethod": "REQToFileAppend",
"replyMethod": "fileAppend",
"retryWait": 5,
"ACKTimeout": 10,
"retries": 1,