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

Added fileExtension type to message

This commit is contained in:
postmannen 2021-04-07 07:00:40 +02:00
parent 23b6b58439
commit b08dd4558e
8 changed files with 26 additions and 23 deletions

View file

@ -1,6 +1,7 @@
[
{
"directory": "random_text_log",
"fileExtension": "log",
"toNode": "central",
"data": ["some message sent from a ship for testing\n"],
"commandOrEvent":"EventACK",

View file

@ -1,6 +1,7 @@
[
{
"directory":"cli_command__result",
"fileExtension": "result",
"toNode": "ship1",
"data": ["bash","-c","sleep 3 & tree ./"],
"method":"REQCliCommand",

View file

@ -1,7 +1,8 @@
[
{
"directory": "metrics/network/sniffer",
"toNode": "ship1",
"fileExtension": "html",
"toNode": "ship2",
"data": ["http://vg.no"],
"method":"REQHttpGet",
"timeout":10,

View file

@ -1,6 +1,7 @@
[
{
"directory":"opcommand_logs",
"fileExtension": "log",
"toNode": "ship1",
"data": ["ps"],
"method":"REQOpCommand",

View file

@ -1,6 +1,7 @@
[
{
"directory": "ping",
"fileExtension":"ping.log",
"toNode": "ship1",
"data": [""],
"method":"REQPing",

View file

@ -1,6 +1,7 @@
[
{
"directory":"some-directory",
"fileExtension":"result",
"toNode": "ship1",
"data": ["bash","-c","tree ../"],
"method":"REQnCliCommand",

View file

@ -11,11 +11,6 @@ import (
// --- Message
type Message struct {
// 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"`
// The node to send the message to
ToNode node `json:"toNode" yaml:"toNode"`
// The Unique ID of the message
@ -35,7 +30,15 @@ type Message struct {
RequestRetries int `json:"requestRetries" yaml:"requestRetries"`
// Timeout for long a process should be allowed to operate
MethodTimeout int `json:"methodTimeout" yaml:"methodTimeout"`
// 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"`
// FileExtension is used to be able to set a wanted extension
// on a file being saved as the result of data being handled
// by a method handler.
FileExtension string `json:"fileExtension" yaml:"fileExtension"`
// PreviousMessage are used for example if a reply message is
// generated and we also need a copy of thedetails of the the
// initial request message

View file

@ -288,20 +288,19 @@ func (m methodREQTextToLogFile) handler(proc process, message Message, node stri
// If it was a request type message we want to check what the initial messages
// method, so we can use that in creating the file name to store the data.
fmt.Printf(" ** DEBUG: %v\n", message.PreviousMessage)
var fileName string
var folderTree string
switch {
case message.PreviousMessage == nil:
// If this was a direct request there are no previous message to take
// information from, so we use the one that are in the current mesage.
fileName = fmt.Sprintf("%v.%v.log", message.ToNode, message.Method)
fileName = fmt.Sprintf("%v.%v.%v", message.ToNode, message.Method, message.PreviousMessage.FileExtension)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.FromNode))
case message.PreviousMessage.ToNode != "":
fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method)
fileName = fmt.Sprintf("%v.%v.%v", message.PreviousMessage.ToNode, message.PreviousMessage.Method, message.PreviousMessage.FileExtension)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
case message.PreviousMessage.ToNode == "":
fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method)
fileName = fmt.Sprintf("%v.%v.%v", message.FromNode, message.Method, message.PreviousMessage.FileExtension)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
}
@ -350,7 +349,6 @@ func (m methodREQTextToFile) handler(proc process, message Message, node string)
// If it was a request type message we want to check what the initial messages
// method, so we can use that in creating the file name to store the data.
fmt.Printf(" ** DEBUG: %v\n", message.PreviousMessage)
var fileName string
var folderTree string
switch {
@ -359,15 +357,12 @@ func (m methodREQTextToFile) handler(proc process, message Message, node string)
// information from, so we use the one that are in the current mesage.
fileName = fmt.Sprintf("%v.%v.log", message.ToNode, message.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.FromNode))
fmt.Printf(" ** DEBUG1: foldertree: %v\n", folderTree)
case message.PreviousMessage.ToNode != "":
fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method)
fileName = fmt.Sprintf("%v.%v.%v", message.PreviousMessage.ToNode, message.PreviousMessage.Method, message.PreviousMessage.FileExtension)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
fmt.Printf(" ** DEBUG2: foldertree: %v\n", folderTree)
case message.PreviousMessage.ToNode == "":
fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method)
fileName = fmt.Sprintf("%v.%v.%v", message.FromNode, message.Method, message.PreviousMessage.FileExtension)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
fmt.Printf(" ** DEBUG3: foldertree: %v\n", folderTree)
}
// Check if folder structure exist, if not create it.
@ -439,20 +434,19 @@ func (m methodREQErrorLog) handler(proc process, message Message, node string) (
// If it was a request type message we want to check what the initial messages
// method, so we can use that in creating the file name to store the data.
fmt.Printf(" ** DEBUG: %v\n", message.PreviousMessage)
var fileName string
var folderTree string
switch {
case message.PreviousMessage == nil:
// If this was a direct request there are no previous message to take
// information from, so we use the one that are in the current mesage.
fileName = fmt.Sprintf("%v.%v.log", message.ToNode, message.Method)
fileName = fmt.Sprintf("%v.%v.%v", message.ToNode, message.Method, message.PreviousMessage.FileExtension)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.FromNode))
case message.PreviousMessage.ToNode != "":
fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method)
fileName = fmt.Sprintf("%v.%v.%v", message.PreviousMessage.ToNode, message.PreviousMessage.Method, message.PreviousMessage.FileExtension)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
case message.PreviousMessage.ToNode == "":
fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method)
fileName = fmt.Sprintf("%v.%v.%v", message.FromNode, message.Method, message.PreviousMessage.FileExtension)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
}