1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-05 14:56:49 +00:00

updated readme

This commit is contained in:
postmannen 2021-04-06 11:02:58 +02:00
parent 2c2f53f6f4
commit cdc92ceff4
3 changed files with 77 additions and 84 deletions

153
README.md
View file

@ -107,7 +107,7 @@ A default config file will be created at first startup if one does not exist, wi
If new values are provided via flags they will take precedence over the ones currently in the config file, and they will also replace the current value in the config file, making it the default for the next restart. If new values are provided via flags they will take precedence over the ones currently in the config file, and they will also replace the current value in the config file, making it the default for the next restart.
The only exception from the above are the `startSubscriberX` flags which got one extra value that can be used which is the value `RST` for Reset. This will disable the specified subscriber, and also null out the array for which Nodes the subscriber will allow traffic from. The only exception from the above are the `startSubX` flags which got one extra value that can be used which is the value `RST` for Reset. This will disable the specified subscriber, and also null out the array for which Nodes the subscriber will allow traffic from.
The config file can also be edited directly, making the use of flags not needed. The config file can also be edited directly, making the use of flags not needed.
@ -151,34 +151,32 @@ clone the repository, then cd `./steward/cmd` and do `go build -o steward`, and
-profilingPort string -profilingPort string
The number of the profiling port The number of the profiling port
-promHostAndPort string -promHostAndPort string
host and port for prometheus listener, e.g. localhost:2112 host and port for prometheus listener, e.g. localhost:2112 (default ":2112")
-startPubSayHello int -startPubREQHello int
Make the current node send hello messages to central at given interval in seconds Make the current node send hello messages to central at given interval in seconds
-startSubCLICommand value -startSubREQCliCommand value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber. Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-startSubCLICommandReply value -startSubREQErrorLog value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber. Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-startSubCLICommandRequest value -startSubREQHello value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber. Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-startSubCLICommandRequestNOSEQ value -startSubREQPing value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber. Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-startSubEchoReply value -startSubREQPong value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber. Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-startSubEchoRequest value -startSubREQTextToConsole value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber. Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-startSubErrorLog value -startSubREQTextToLogFile value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber. Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-startSubSayHello value -startSubREQnCliCommand value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-startSubTextLogging value
Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber. Specify comma separated list for nodes to allow messages from. Use "*" for from all. Value RST will turn off subscriber.
-subscribersDataFolder string -subscribersDataFolder string
The data folder where subscribers are allowed to write their data if needed (default "./data") The data folder where subscribers are allowed to write their data if needed (default "./var")
``` ```
### How to Run ### How to Run
The broker for messaging is Nats-server from <https://nats.io>. Download, run it, and use the `--brokerAddress` flag on Steward to point to it. The broker for messaging is Nats-server from <https://nats.io>. Download, run it, and use the `-brokerAddress` flag on Steward to point to it.
On some central server which will act as your command and control server. On some central server which will act as your command and control server.
@ -188,7 +186,7 @@ One the nodes out there
`./steward --node="ship1"` & `./steward --node="ship1"` and so on. `./steward --node="ship1"` & `./steward --node="ship1"` and so on.
Use the `--help` flag to get all possibilities. Use the `-help` flag to get all possibilities.
#### Start subscriber flags #### Start subscriber flags
@ -222,17 +220,19 @@ Right now the API for sending a message from one node to another node is by past
The `method` is what defines what the event will do. The preconfigured methods are: The `method` is what defines what the event will do. The preconfigured methods are:
```go ```go
// Execute a CLI command in for example bash or cmd. // Command for client operation request of the system. The op
// This is a command type, so the output of the command executed // command to execute shall be given in the data field of the
// will directly showed in the ACK message received. // message as string value. For example "ps".
CLICommand Method = "CLICommand" REQOpCommand Method = "REQOpCommand"
// Execute a CLI command in for example bash or cmd. // Execute a CLI command in for example bash or cmd.
// This is an event type, where a message will be sent to a // 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 // node with the command to execute and an ACK will be replied
// if it was delivered succesfully. The output of the command // if it was delivered succesfully. The output of the command
// ran will be delivered back to the node where it was initiated // ran will be delivered back to the node where it was initiated
// as a new message. // as a new message.
CLICommandRequest Method = "CLICommandRequest" // 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"
// Execute a CLI command in for example bash or cmd. // Execute a CLI command in for example bash or cmd.
// This is an event type, where a message will be sent to a // 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 // node with the command to execute and an ACK will be replied
@ -242,44 +242,48 @@ CLICommandRequest Method = "CLICommandRequest"
// The NOSEQ method will process messages as they are recived, // The NOSEQ method will process messages as they are recived,
// and the reply back will be sent as soon as the process is // and the reply back will be sent as soon as the process is
// done. No order are preserved. // done. No order are preserved.
CLICommandRequestNOSEQ Method = "CLICommandRequestNOSEQ" // The data field is a slice of strings where the first string
// Will generate a reply for a CLICommandRequest. // value should be the command, and the following the arguments.
// This type is normally not used by the user when creating REQnCliCommand Method = "REQnCliCommand"
// a message. It is used in creating the reply message with // Send text to be logged to the console.
// request messages. It is also used when defining a process to // The data field is a slice of strings where the first string
// start up for receiving the CLICommand request messages. // value should be the command, and the following the arguments.
CLICommandReply Method = "CLICommandReply" REQTextToConsole Method = "REQTextToConsole"
// Send text logging to some host. // 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 // A file with the full subject+hostName will be created on
// the receiving end. // the receiving end.
TextLogging Method = "TextLogging" // The data field is a slice of strings where the values of the
// slice will be written to the log file.
REQTextToLogFile Method = "REQTextToLogFile"
// Send Hello I'm here message. // Send Hello I'm here message.
SayHello Method = "SayHello" REQHello Method = "REQHello"
// Error log methods to centralError node. // Error log methods to centralError node.
ErrorLog Method = "ErrorLog" REQErrorLog Method = "REQErrorLog"
// Echo request will ask the subscriber for a // Echo request will ask the subscriber for a
// reply generated as a new message, and sent back to where // reply generated as a new message, and sent back to where
// the initial request was made. // the initial request was made.
ECHORequest Method = "ECHORequest" REQPing Method = "REQPing"
// Will generate a reply for a ECHORequest // Will generate a reply for a ECHORequest
ECHOReply Method = "ECHOReply" REQPong Method = "REQPong"
``` ```
NB: Both the keys and the values used are case sensitive. NB: Both the keys and the values used are case sensitive.
#### Sending a command from one Node to Another Node #### Sending a command from one Node to Another Node
Example JSON for appending a message of type command into the `msg.pipe` file Example JSON for appending a message of type command into the `socket` file
```json ```json
[ [
{ {
"label":"cli-command-executed-result",
"toNode": "ship1", "toNode": "ship1",
"data": ["bash","-c","ls -l ../"], "data": ["bash","-c","sleep 3 & tree ./"],
"commandOrEvent":"CommandACK", "method":"REQCliCommand",
"method":"CLICommand" "timeout":10,
"retries":3,
"methodTimeout": 4
} }
] ]
``` ```
@ -289,20 +293,22 @@ To send specify more messages at once do
```json ```json
[ [
{ {
"label":"cli-command-executed-result",
"toNode": "ship1", "toNode": "ship1",
"data": ["bash","-c","ls -l ../"], "data": ["bash","-c","sleep 3 & tree ./"],
"commandOrEvent":"CommandACK", "method":"REQCliCommand",
"method":"CLICommand" "timeout":10,
"retries":3,
"methodTimeout": 4
}, },
{ {
"label":"cli-command-executed-result",
"toNode": "ship2", "toNode": "ship2",
"data": ["bash","-c","ls -l ../"], "data": ["bash","-c","sleep 3 & tree ./"],
"commandOrEvent":"CommandACK", "method":"REQCliCommand",
"method":"CLICommand" "timeout":10,
"retries":3,
"methodTimeout": 4
} }
] ]
``` ```
@ -312,41 +318,22 @@ To send a message with custom timeout and amount of retries
```json ```json
[ [
{ {
"label":"opcommand_logs",
"toNode": "ship1", "toNode": "ship1",
"data": ["bash","-c","netstat -an|grep -i listen"], "data": ["ps"],
"commandOrEvent":"CommandACK", "method":"REQOpCommand",
"method":"CLICommand",
"timeout":3, "timeout":3,
"retries":3 "retries":3,
"requestTimeout":3,
"requestRetries":3,
"MethodTimeout": 7
} }
] ]
``` ```
You can save the content to myfile.JSON and append it to `msg.pipe` You can save the content to myfile.JSON and append it to the `socket` file.
`cat myfile.json >> msg.pipe` `nc -U ./steward.sock < example/toShip1-REQCliCommand.json`
The content of `msg.pipe` will be erased as messages a processed.
#### Sending a message of type Event
```json
[
{
"toNode": "central",
"data": ["some message sent from a ship for testing\n"],
"commandOrEvent":"EventACK",
"method":"TextLogging"
}
]
```
You can save the content to myfile.JSON and append it to `msg.pipe`
`cat myfile.json >> msg.pipe`
The content of `msg.pipe` will be erased as messages a processed.
## Concepts/Ideas ## Concepts/Ideas
@ -354,7 +341,7 @@ The content of `msg.pipe` will be erased as messages a processed.
#### Subject #### Subject
`<nodename>.<command/event>.<method>` `<nodename>.<method>.<command/event>`
Nodename: Are the hostname of the device. This do not have to be resolvable via DNS, it is just a unique name for the host to receive the message. Nodename: Are the hostname of the device. This do not have to be resolvable via DNS, it is just a unique name for the host to receive the message.
@ -365,13 +352,13 @@ Method: Are the functionality the message provide. Example could be `CLICommand`
##### Complete subject example ##### Complete subject example
For syslog of type event to a host named "ship1" For Hello Message to a node named "central" of type Event and there is No Ack.
`ship1.EventACK.Syslogforwarding` `central.REQHello.EventNACK`
and for a shell command of type command to a host named "ship2" For CliCommand message to a node named "ship1" of type Command and it wants an Ack.
`ship2.CommandACK.CLICommand` `ship1.REQCliCommand.CommandACK`
## TODO ## TODO

View file

@ -27,6 +27,7 @@ type flagNodeSlice struct {
Values []node Values []node
} }
// String method
func (f *flagNodeSlice) String() string { func (f *flagNodeSlice) String() string {
return "" return ""
} }
@ -117,6 +118,8 @@ type Configuration struct {
StartSubREQTextToConsole flagNodeSlice StartSubREQTextToConsole flagNodeSlice
} }
// NewConfiguration will set a default Configuration,
// and return a *Configuration.
func NewConfiguration() *Configuration { func NewConfiguration() *Configuration {
c := Configuration{} c := Configuration{}
return &c return &c
@ -146,6 +149,7 @@ func newConfigurationDefaults() Configuration {
return c return c
} }
// CheckFlags will parse all flags
func (c *Configuration) CheckFlags() error { func (c *Configuration) CheckFlags() error {
// Create an empty default config // Create an empty default config

View file

@ -50,7 +50,9 @@ type Method string
// The constants that will be used throughout the system for // The constants that will be used throughout the system for
// when specifying what kind of Method to send or work with. // when specifying what kind of Method to send or work with.
const ( const (
// Command for client operation request of the system // Command for client operation request of the system. The op
// command to execute shall be given in the data field of the
// message as string value. For example "ps".
REQOpCommand Method = "REQOpCommand" REQOpCommand Method = "REQOpCommand"
// Execute a CLI command in for example bash or cmd. // Execute a CLI command in for example bash or cmd.
// This is an event type, where a message will be sent to a // This is an event type, where a message will be sent to a