Documentation
¶
Overview ¶
Notes:
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewServer ¶
func NewServer(c *Configuration, version string) (*server, error)
newServer will prepare and return a server type
Types ¶
type CommandOrEvent ¶
type CommandOrEvent string
CommandOrEvent describes on the message level if this is an event or command kind of message in the Subject name. This field is mainly used to be able to spawn up different worker processes based on the Subject name so we can have one process for handling event kind, and another for handling command kind of messages. This type is used in both building the subject name, and also inside the Message type to describe if it is a Command or Event.
const ( // Command, command that will just wait for an // ack, and nothing of the output of the command are // delivered back in the reply ack message. // The message should contain the unique ID of the // command. CommandACK CommandOrEvent = "CommandACK" // Same as above, but No ACK. CommandNACK CommandOrEvent = "CommandNACK" // Same as above, but No ACK // Event, wait for and return the ACK message. This means // that the command should be executed immediately // and that we should get the confirmation if it // was successful or not. EventACK CommandOrEvent = "EventACK" // Same as above, but No ACK. EventNACK CommandOrEvent = "EventNACK" )
func (CommandOrEvent) GetCommandOrEventAvailable ¶
func (c CommandOrEvent) GetCommandOrEventAvailable() CommandOrEventAvailable
type CommandOrEventAvailable ¶
type CommandOrEventAvailable struct {
// contains filtered or unexported fields
}
CommandOrEventAvailable are used for checking if the commands or events are defined.
func (CommandOrEventAvailable) CheckIfExists ¶
func (co CommandOrEventAvailable) CheckIfExists(c CommandOrEvent, subject Subject) bool
Check if a command or even exists.
type Configuration ¶
type Configuration struct {
// The configuration folder on disk
ConfigFolder string
// The folder where the socket file should live
SocketFolder string
// TCP Listener for sending messages to the system
TCPListener string
// HTTP Listener for sending messages to the system
HTTPListener string
// The folder where the database should live
DatabaseFolder string
// some unique string to identify this Edge unit
NodeName string
// the address of the message broker
BrokerAddress string
// nats connect retry
NatsConnectRetryInterval int
// The number of the profiling port
ProfilingPort string
// host and port for prometheus listener, e.g. localhost:2112
PromHostAndPort string
// set to true if this is the node that should receive the error log's from other nodes
DefaultMessageTimeout int
// default amount of retries that will be done before a message is thrown away, and out of the system
DefaultMessageRetries int
// Publisher data folder
SubscribersDataFolder string
// central node to receive messages published from nodes
CentralNodeName string
// Path to the certificate of the root CA
RootCAPath string
// Full path to the NKEY's seed file
NkeySeedFile string
// The host and port to expose the data folder
ExposeDataFolder string
// Timeout for error messages
ErrorMessageTimeout int
// Retries for error messages.
ErrorMessageRetries int
// Make the current node send hello messages to central at given interval in seconds
StartPubREQHello int
// Start the central error logger.
// Takes a comma separated string of nodes to receive from or "*" for all nodes.
StartSubREQErrorLog bool
// Subscriber for hello messages
StartSubREQHello bool
// Subscriber for text logging
StartSubREQToFileAppend bool
// Subscriber for writing to file
StartSubREQToFile bool
// Subscriber for Echo Request
StartSubREQPing bool
// Subscriber for Echo Reply
StartSubREQPong bool
// Subscriber for CLICommandRequest
StartSubREQCliCommand bool
// Subscriber for REQToConsole
StartSubREQToConsole bool
// Subscriber for REQHttpGet
StartSubREQHttpGet bool
// Subscriber for tailing log files
StartSubREQTailFile bool
// Subscriber for continously delivery of output from cli commands.
StartSubREQCliCommandCont bool
}
Configuration are the structure that holds all the different configuration options used both with flags and the config file. If a new field is added to this struct there should also be added the same field to the ConfigurationFromFile struct, and an if check should be added to the checkConfigValues function to set default values when reading from config file.
func NewConfiguration ¶
func NewConfiguration() *Configuration
NewConfiguration will return a *Configuration.
func (*Configuration) CheckFlags ¶
func (c *Configuration) CheckFlags() error
CheckFlags will parse all flags
func (*Configuration) ReadConfigFile ¶
func (c *Configuration) ReadConfigFile(configFolder string) (Configuration, error)
Reads the current config file from disk.
func (*Configuration) WriteConfigFile ¶
func (c *Configuration) WriteConfigFile() error
WriteConfigFile will write the current config to file. If the file or the directory for the config file does not exist it will be created.
type ConfigurationFromFile ¶ added in v0.1.10
type ConfigurationFromFile struct {
ConfigFolder *string
SocketFolder *string
TCPListener *string
HTTPListener *string
DatabaseFolder *string
NodeName *string
BrokerAddress *string
NatsConnectRetryInterval *int
ProfilingPort *string
PromHostAndPort *string
DefaultMessageTimeout *int
DefaultMessageRetries *int
SubscribersDataFolder *string
CentralNodeName *string
RootCAPath *string
NkeySeedFile *string
ExposeDataFolder *string
ErrorMessageTimeout *int
ErrorMessageRetries *int
StartPubREQHello *int
StartSubREQErrorLog *bool
StartSubREQHello *bool
StartSubREQToFileAppend *bool
StartSubREQToFile *bool
StartSubREQPing *bool
StartSubREQPong *bool
StartSubREQCliCommand *bool
StartSubREQToConsole *bool
StartSubREQHttpGet *bool
StartSubREQTailFile *bool
StartSubREQCliCommandCont *bool
}
ConfigurationFromFile should have the same structure as Configuration. This structure is used when parsing the configuration values from file, so we are able to detect if a value were given or not when parsing.
type Message ¶
type Message struct {
// The node to send the message to.
ToNode Node `json:"toNode" yaml:"toNode"`
// ToNodes to specify several hosts to send message to in the
// form of an slice/array.
ToNodes []Node `json:"toNodes,omitempty" yaml:"toNodes,omitempty"`
// The Unique ID of the message
ID int `json:"id" yaml:"id"`
// The actual data in the message. This is typically where we
// specify the cli commands to execute on a node, and this is
// also the field where we put the returned data in a reply
// message.
Data []string `json:"data" yaml:"data"`
// Method, what request type to use, like REQCliCommand, REQHttpGet..
Method Method `json:"method" yaml:"method"`
// 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
// shell command to execute in a cli session.
// TODO:
MethodArgs []string `json:"methodArgs" yaml:"methodArgs"`
// 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.
ReplyMethod Method `json:"replyMethod" yaml:"replyMethod"`
// Additional arguments that might be needed when executing the reply
// method. Can be f.ex. an ip address if it is a tcp sender, or the
// shell command to execute in a cli session.
// TODO:
ReplyMethodArgs []string `json:"replyMethodArgs" yaml:"replyMethodArgs"`
// IsReply are used to tell that this is a reply message. By default
// the system sends the output of a request method back to the node
// the message originated from. If it is a reply method we want the
// result of the reply message to be sent to the central server, so
// we can use this value if set to swap the toNode, and fromNode
// fields.
IsReply bool `json:"isReply" yaml:"isReply"`
// From what node the message originated
FromNode Node
// ACKTimeout for waiting for an ack message
ACKTimeout int `json:"ACKTimeout" yaml:"ACKTimeout"`
// Resend retries
Retries int `json:"retries" yaml:"retries"`
// The ACK timeout of the new message created via a request event.
ReplyACKTimeout int `json:"replyACKTimeout" yaml:"replyACKTimeout"`
// The retries of the new message created via a request event.
ReplyRetries int `json:"replyRetries" yaml:"replyRetries"`
// Timeout for long a process should be allowed to operate
MethodTimeout int `json:"methodTimeout" yaml:"methodTimeout"`
// Timeout for long a process should be allowed to operate
ReplyMethodTimeout int `json:"replyMethodTimeout" yaml:"replyMethodTimeout"`
// Directory is a string that can be used to create the
//directory structure when saving the result of some method.
// For example "syslog","metrics", or "metrics/mysensor"
// The type is typically used in the handler of a method.
Directory string `json:"directory" yaml:"directory"`
// FileName is used to be able to set a wanted name
// on a file being saved as the result of data being handled
// by a method handler.
FileName string `json:"fileName" yaml:"fileName"`
// operation are used to give an opCmd and opArg's.
Operation Operation `json:"operation"`
// PreviousMessage are used for example if a reply message is
// generated and we also need a copy of the details of the the
// initial request message.
PreviousMessage *Message
// contains filtered or unexported fields
}
type Method ¶
type Method string
Method is used to specify the actual function/method that is represented in a typed manner.
const ( // Initial parent method used to start other processes. REQInitial Method = "REQInitial" // 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" // Get a list of all the running processes. REQOpProcessList Method = "REQOpProcessList" // Start up a process. REQOpProcessStart Method = "REQOpProcessStart" // Stop up a process. REQOpProcessStop Method = "REQOpProcessStop" // 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 // if it was delivered succesfully. The output of the command // ran will be delivered back to the node where it was initiated // 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" // 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" // 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" // 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" // 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" // Send Hello I'm here message. REQHello Method = "REQHello" // Error log methods to centralError node. REQErrorLog Method = "REQErrorLog" // Echo request will ask the subscriber for a // reply generated as a new message, and sent back to where // the initial request was made. REQPing Method = "REQPing" // Will generate a reply for a ECHORequest REQPong Method = "REQPong" // Http Get REQHttpGet Method = "REQHttpGet" // Tail file REQTailFile Method = "REQTailFile" // Write to steward socket REQToSocket Method = "REQToSocket" )
------------------------------------------------------------ The constants that will be used throughout the system for when specifying what kind of Method to send or work with.
func (Method) GetMethodsAvailable ¶
func (m Method) GetMethodsAvailable() MethodsAvailable
The mapping of all the method constants specified, what type it references, and the kind if it is an Event or Command, and if it is ACK or NACK.
Allowed values for the commandOrEvent field are: - CommandACK - CommandNACK - EventACK - EventNack
func (Method) GetReplyMethods ¶ added in v0.1.5
Reply methods. The slice generated here is primarily used within the Stew client for knowing what of the req types are generally used as reply methods.
type MethodsAvailable ¶
type MethodsAvailable struct {
Methodhandlers map[Method]methodHandler
}
MethodsAvailable holds a map of all the different method types and the associated handler to that method type.
func (MethodsAvailable) CheckIfExists ¶
func (ma MethodsAvailable) CheckIfExists(m Method) (methodHandler, bool)
Check if exists will check if the Method is defined. If true the bool value will be set to true, and the methodHandler function for that type will be returned.
type Node ¶ added in v0.1.5
type Node string
Node is the type definition for the node who receive or send a message.
type OpCmdStartProc ¶
type OpCmdStopProc ¶
type Operation ¶
type Operation struct {
OpCmd string `json:"opCmd"`
OpArg json.RawMessage `json:"opArg"`
}
operation are used to specify opCmd and opArg's.
type Subject ¶
type Subject struct {
// node, the name of the node to receive the message.
ToNode string `json:"node" yaml:"toNode"`
// messageType, command/event
CommandOrEvent CommandOrEvent `json:"commandOrEvent" yaml:"commandOrEvent"`
// method, what is this message doing, etc. CLICommand, Syslog, etc.
Method Method `json:"method" yaml:"method"`
// contains filtered or unexported fields
}
subject contains the representation of a subject to be used with one specific process
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
stew
command
|
|
|
steward
command
|
|
|
scripts
|
|
|
nats-server/generate-nkeys
command
|
|