diff --git a/README.md b/README.md index ef20fdc..5ab39e1 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ All code in this repository are to be concidered not-production-ready. The code - Report errors happening on some node in to central error handler. - 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 shellcommand to be executed, but we don't care for an acknowledge (NACK) when we send an "hello I'm here" 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 I'm here" event. - Prometheus exporters for Metrics @@ -95,7 +95,7 @@ Nodename: Are the hostname of the device. This do not have to be resolvable via Command/Event: Are type of message sent. `CommandACK`/`EventACK`/`CommandNACK`/`EventNACK`. Description of the differences are mentioned earlier.\ Info: The command/event which is called a MessageType are present in both the Subject structure and the Message structure. The reason for this is that it is used both in the naming of a subject, and in the message for knowing what kind of message it is and how to handle it. -Method: Are the functionality the message provide. Example could be `Shellcommand` or `Syslogforwarding` +Method: Are the functionality the message provide. Example could be `CLICommand` or `Syslogforwarding` ##### Complete subject example @@ -105,13 +105,14 @@ For syslog of type event to a host named "ship1" and for a shell command of type command to a host named "ship2" -`ship2.CommandACK.Shellcommand` +`ship2.CommandACK.CLICommand +` ## TODO - Add config file options to use when starting up the program for options. -- Rename ShellCommand to cli +- Rename CLICommand to cli - Make a scraper that first send an EventACK, and the content of the scraping is returned by a node as a new EventACK back the where the initial event originated. @@ -199,7 +200,7 @@ Example JSON for pasting a message of type command into the `inmsg.txt` file "toNode": "ship1", "data": ["bash","-c","ls -l ../"], "commandOrEvent":"CommandACK", - "method":"ShellCommand" + "method":"CLICommand" } ] @@ -214,7 +215,7 @@ To send specify more messages at once do "toNode": "ship1", "data": ["bash","-c","ls -l ../"], "commandOrEvent":"CommandACK", - "method":"ShellCommand" + "method":"CLICommand" }, { @@ -222,7 +223,7 @@ To send specify more messages at once do "toNode": "ship2", "data": ["bash","-c","ls -l ../"], "commandOrEvent":"CommandACK", - "method":"ShellCommand" + "method":"CLICommand" } ] @@ -237,7 +238,7 @@ To send a message with custom timeout and amount of retries "toNode": "ship1", "data": ["bash","-c","netstat -an|grep -i listen"], "commandOrEvent":"CommandACK", - "method":"ShellCommand", + "method":"CLICommand", "timeout":3, "retries":3 } diff --git a/example/toShip1.json b/example/toShip1.json index 26ac4f4..df8966d 100644 --- a/example/toShip1.json +++ b/example/toShip1.json @@ -4,7 +4,7 @@ "toNode": "ship1", "data": ["bash","-c","netstat -an|grep -i listen"], "commandOrEvent":"CommandACK", - "method":"ShellCommand", + "method":"CLICommand", "timeout":3, "retries":3 } diff --git a/example/toShip1FromShip2.json b/example/toShip1FromShip2.json index 26ac4f4..df8966d 100644 --- a/example/toShip1FromShip2.json +++ b/example/toShip1FromShip2.json @@ -4,7 +4,7 @@ "toNode": "ship1", "data": ["bash","-c","netstat -an|grep -i listen"], "commandOrEvent":"CommandACK", - "method":"ShellCommand", + "method":"CLICommand", "timeout":3, "retries":3 } diff --git a/example/toShip1and2.json b/example/toShip1and2.json index f2d5d28..e576207 100644 --- a/example/toShip1and2.json +++ b/example/toShip1and2.json @@ -3,7 +3,7 @@ "toNode": "*", "data": ["bash","-c","tree ../"], "commandOrEvent":"CommandACK", - "method":"ShellCommand" + "method":"CLICommand" } ] \ No newline at end of file diff --git a/example/toShip2.json b/example/toShip2.json index 84651df..00602cc 100644 --- a/example/toShip2.json +++ b/example/toShip2.json @@ -3,7 +3,7 @@ "toNode": "ship2", "data": ["bash","-c","tree ../"], "commandOrEvent":"CommandACK", - "method":"ShellCommand" + "method":"CLICommand" } ] \ No newline at end of file diff --git a/example/toShip2FromShip1.json b/example/toShip2FromShip1.json index f0d30f5..6abeb6b 100644 --- a/example/toShip2FromShip1.json +++ b/example/toShip2FromShip1.json @@ -4,7 +4,7 @@ "toNode": "ship2", "data": ["bash","-c","netstat -an|grep -i listen"], "commandOrEvent":"CommandACK", - "method":"ShellCommand", + "method":"CLICommand", "timeout":3, "retries":3 } diff --git a/go.mod b/go.mod index 5255bdd..30cf3a0 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/fsnotify/fsnotify v1.4.9 github.com/nats-io/nats-server/v2 v2.1.9 // indirect github.com/nats-io/nats.go v1.10.0 - github.com/pelletier/go-toml v1.8.1 // indirect + github.com/pelletier/go-toml v1.8.1 github.com/prometheus/client_golang v1.9.0 go.etcd.io/bbolt v1.3.5 google.golang.org/protobuf v1.25.0 // indirect diff --git a/go.sum b/go.sum index 2a27650..1e2d6a9 100644 --- a/go.sum +++ b/go.sum @@ -40,6 +40,7 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= diff --git a/incommmingBuffer.db b/incommmingBuffer.db index 961180e..1058577 100644 Binary files a/incommmingBuffer.db and b/incommmingBuffer.db differ diff --git a/message-and-subject.go b/message-and-subject.go index fdfb24e..5d24d04 100644 --- a/message-and-subject.go +++ b/message-and-subject.go @@ -18,7 +18,7 @@ type Message struct { Data []string `json:"data" yaml:"data"` // The type of the message being sent CommandOrEvent CommandOrEvent `json:"commandOrEvent" yaml:"commandOrEvent"` - // method, what is this message doing, etc. shellCommand, syslog, etc. + // method, what is this message doing, etc. CLI, syslog, etc. Method Method `json:"method" yaml:"method"` FromNode node // done is used to signal when a message is fully processed. @@ -54,7 +54,7 @@ type Subject struct { ToNode string `json:"node" yaml:"toNode"` // messageType, command/event CommandOrEvent CommandOrEvent `json:"commandOrEvent" yaml:"commandOrEvent"` - // method, what is this message doing, etc. shellCommand, syslog, etc. + // method, what is this message doing, etc. CLICommand, Syslog, etc. Method Method `json:"method" yaml:"method"` // messageCh is the channel for receiving new content to be sent messageCh chan Message diff --git a/server.go b/server.go index ff12d43..027c852 100644 --- a/server.go +++ b/server.go @@ -254,7 +254,7 @@ func (s *server) messageDeliverNats(proc process, message Message) { msg := &nats.Msg{ Subject: string(proc.subject.name()), - // Subject: fmt.Sprintf("%s.%s.%s", proc.node, "command", "shellCommand"), + // Subject: fmt.Sprintf("%s.%s.%s", proc.node, "command", "CLICommand"), // Structure of the reply message are: // reply... Reply: fmt.Sprintf("reply.%s", proc.subject.name()), diff --git a/subscriberMethodTypes.go b/subscriberMethodTypes.go index 964632a..88b5d7b 100644 --- a/subscriberMethodTypes.go +++ b/subscriberMethodTypes.go @@ -23,10 +23,10 @@ type Method string func (m Method) GetMethodsAvailable() MethodsAvailable { ma := MethodsAvailable{ topics: map[Method]methodHandler{ - ShellCommand: methodCommandShellCommand{}, - TextLogging: methodEventTextLogging{}, - SayHello: methodEventSayHello{}, - ErrorLog: methodEventErrorLog{}, + CLICommand: methodCommandCLICommand{}, + TextLogging: methodEventTextLogging{}, + SayHello: methodEventSayHello{}, + ErrorLog: methodEventErrorLog{}, }, } @@ -35,7 +35,7 @@ func (m Method) GetMethodsAvailable() MethodsAvailable { const ( // Shell command to be executed via f.ex. bash - ShellCommand Method = "ShellCommand" + CLICommand Method = "CLICommand" // Send text logging to some host TextLogging Method = "TextLogging" // Send Hello I'm here message @@ -70,9 +70,9 @@ type methodHandler interface { handler(server *server, message Message, node string) ([]byte, error) } -type methodCommandShellCommand struct{} +type methodCommandCLICommand struct{} -func (m methodCommandShellCommand) handler(s *server, message Message, node string) ([]byte, error) { +func (m methodCommandCLICommand) handler(s *server, message Message, node string) ([]byte, error) { // Since the command to execute is at the first position in the // slice we need to slice it out. The arguments are at the // remaining positions. diff --git a/subscribers.go b/subscribers.go index 7de9afb..3e9a751 100644 --- a/subscribers.go +++ b/subscribers.go @@ -24,10 +24,10 @@ func (s *server) subscribeMessages(proc process) { } func (s *server) subscribersStart() { - // Start a subscriber for shellCommand messages + // Start a subscriber for CLICommand messages { - fmt.Printf("Starting shellCommand subscriber: %#v\n", s.nodeName) - sub := newSubject(ShellCommand, CommandACK, s.nodeName) + fmt.Printf("Starting CLICommand subscriber: %#v\n", s.nodeName) + sub := newSubject(CLICommand, CommandACK, s.nodeName) proc := s.processPrepareNew(sub, s.errorKernel.errorCh, processKindSubscriber, []node{"central", "ship2"}) // fmt.Printf("*** %#v\n", proc) go s.spawnWorkerProcess(proc)