mirror of
https://github.com/postmannen/ctrl.git
synced 2024-12-14 12:37:31 +00:00
updated doc for with cliCommand reply method
This commit is contained in:
parent
a1fbdffd36
commit
c212335f62
2 changed files with 52 additions and 16 deletions
33
README.md
33
README.md
|
@ -35,6 +35,7 @@ The idea behind Steward is to help out with exactly these issues, allowing you t
|
|||
- [REQToConsole](#reqtoconsole)
|
||||
- [REQToFileAppend](#reqtofileappend)
|
||||
- [REQToFile](#reqtofile)
|
||||
- [ReqCliCommand](#reqclicommand-1)
|
||||
- [Errors reporting](#errors-reporting)
|
||||
- [Prometheus metrics](#prometheus-metrics)
|
||||
- [Other](#other)
|
||||
|
@ -467,6 +468,38 @@ Write the output of the reply message to a file specified with the `directory` a
|
|||
]
|
||||
```
|
||||
|
||||
#### ReqCliCommand
|
||||
|
||||
**ReqCliCommand** is a bit special in that it can be used as both **method** and **replyMethod**
|
||||
|
||||
The final result, if any, of the replyMethod will be sent to the central server.
|
||||
|
||||
By using the `{{STEWARD_DATA}}` you can grab the output of your initial request method, and then use it as input in your reply method.
|
||||
|
||||
**NB:** The echo command in the example below will remove new lines from the data. To also keep any new lines we need to put escaped **quotes** around the template variable. Like this:
|
||||
|
||||
- `\"{{STEWARD_DATA}}\"`
|
||||
|
||||
Example of usage:
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"directory":"cli_command_test",
|
||||
"fileName":"cli_command.result",
|
||||
"toNode": "ship2",
|
||||
"method":"REQCliCommand",
|
||||
"methodArgs": ["bash","-c","tree"],
|
||||
"replyMethod":"REQCliCommand",
|
||||
"replyMethodArgs": ["bash", "-c","echo \"{{STEWARD_DATA}}\" > apekatt.txt"],
|
||||
"replyMethodTimeOut": 10,
|
||||
"ACKTimeout":3,
|
||||
"retries":3,
|
||||
"methodTimeout": 10
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### Errors reporting
|
||||
|
||||
- Errors happening on **all** nodes will be reported back in to the node name defined with the `-centralNodeName` flag.
|
||||
|
|
35
requests.go
35
requests.go
|
@ -1075,22 +1075,6 @@ func (m methodREQCliCommand) handler(proc process, message Message, node string)
|
|||
go func() {
|
||||
defer proc.processes.wg.Done()
|
||||
|
||||
// Check if {{data}} is defined in the method arguments. If found put the
|
||||
// data payload there.
|
||||
var foundEnvData bool
|
||||
var envData string
|
||||
for i, v := range message.MethodArgs {
|
||||
if strings.Contains(v, "{{STEWARD_DATA}}") {
|
||||
foundEnvData = true
|
||||
// Replace the found env variable placeholder with an actual env variable
|
||||
message.MethodArgs[i] = strings.Replace(message.MethodArgs[i], "{{STEWARD_DATA}}", "$STEWARD_DATA", -1)
|
||||
|
||||
// Put all the data which is a slice of string into a single
|
||||
// string so we can put it in a single env variable.
|
||||
envData = strings.Join(message.Data, "")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("* DEBUG * handler: received message contains : %#v\n", message)
|
||||
|
||||
c := message.MethodArgs[0]
|
||||
|
@ -1104,6 +1088,22 @@ func (m methodREQCliCommand) handler(proc process, message Message, node string)
|
|||
go func() {
|
||||
defer proc.processes.wg.Done()
|
||||
|
||||
// Check if {{data}} is defined in the method arguments. If found put the
|
||||
// data payload there.
|
||||
var foundEnvData bool
|
||||
var envData string
|
||||
for i, v := range message.MethodArgs {
|
||||
if strings.Contains(v, "{{STEWARD_DATA}}") {
|
||||
foundEnvData = true
|
||||
// Replace the found env variable placeholder with an actual env variable
|
||||
message.MethodArgs[i] = strings.Replace(message.MethodArgs[i], "{{STEWARD_DATA}}", "$STEWARD_DATA", -1)
|
||||
|
||||
// Put all the data which is a slice of string into a single
|
||||
// string so we can put it in a single env variable.
|
||||
envData = strings.Join(message.Data, "")
|
||||
}
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, c, a...)
|
||||
|
||||
// Check for the use of env variable for STEWARD_DATA, and set env if found.
|
||||
|
@ -1142,6 +1142,9 @@ func (m methodREQCliCommand) handler(proc process, message Message, node string)
|
|||
case out := <-outCh:
|
||||
cancel()
|
||||
|
||||
// NB: Not quite sure what is the best way to handle the below
|
||||
// isReply right now. Implementing as send to central for now.
|
||||
//
|
||||
// If this is this a reply message swap the toNode and fromNode
|
||||
// fields so the output of the command are sent to central node.
|
||||
if message.IsReply {
|
||||
|
|
Loading…
Reference in a new issue