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

renamed label field in message to directory

This commit is contained in:
postmannen 2021-04-07 06:33:29 +02:00
parent 3368448cd7
commit 23b6b58439
9 changed files with 28 additions and 31 deletions

View file

@ -277,7 +277,7 @@ Example JSON for appending a message of type command into the `socket` file
```json ```json
[ [
{ {
"label":"cli-command-executed-result", "directory":"cli-command-executed-result",
"toNode": "ship1", "toNode": "ship1",
"data": ["bash","-c","sleep 3 & tree ./"], "data": ["bash","-c","sleep 3 & tree ./"],
"method":"REQCliCommand", "method":"REQCliCommand",
@ -293,7 +293,7 @@ To send specify more messages at once do
```json ```json
[ [
{ {
"label":"cli-command-executed-result", "directory":"cli-command-executed-result",
"toNode": "ship1", "toNode": "ship1",
"data": ["bash","-c","sleep 3 & tree ./"], "data": ["bash","-c","sleep 3 & tree ./"],
"method":"REQCliCommand", "method":"REQCliCommand",
@ -302,7 +302,7 @@ To send specify more messages at once do
"methodTimeout": 4 "methodTimeout": 4
}, },
{ {
"label":"cli-command-executed-result", "directory":"cli-command-executed-result",
"toNode": "ship2", "toNode": "ship2",
"data": ["bash","-c","sleep 3 & tree ./"], "data": ["bash","-c","sleep 3 & tree ./"],
"method":"REQCliCommand", "method":"REQCliCommand",
@ -318,7 +318,7 @@ To send a message with custom timeout and amount of retries
```json ```json
[ [
{ {
"label":"opcommand_logs", "directory":"opcommand_logs",
"toNode": "ship1", "toNode": "ship1",
"data": ["ps"], "data": ["ps"],
"method":"REQOpCommand", "method":"REQOpCommand",

View file

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

View file

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

View file

@ -1,6 +1,6 @@
[ [
{ {
"label":"metrics/network/sniffer", "directory":"metrics/network/sniffer",
"toNode": "ship1", "toNode": "ship1",
"data": ["http://vg.no"], "data": ["http://vg.no"],
"method":"REQHttpGet", "method":"REQHttpGet",

View file

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

View file

@ -1,6 +1,6 @@
[ [
{ {
"label": "ping", "directory": "ping",
"toNode": "ship1", "toNode": "ship1",
"data": [""], "data": [""],
"method":"REQPing", "method":"REQPing",

View file

@ -11,14 +11,11 @@ import (
// --- Message // --- Message
type Message struct { type Message struct {
// Label is a word without white spaces that can be used to // Directory is a string that can be used to create the
// desribe what kind of service the message is for. For //directory structure when saving the result of some method.
// example syslog, web_log, prometheus_scraper, metrics. // For example "syslog","metrics", or "metrics/mysensor"
// The intentention is that it can be used to add some extra // The type is typically used in the handler of a method.
// information that can be used on the subscriber side to for Directory string `json:"directory" yaml:"directory"`
// example create specific folders using the Format name to
// logically group data recevied.
Label string `json:"label" yaml:"label"`
// The node to send the message to // The node to send the message to
ToNode node `json:"toNode" yaml:"toNode"` ToNode node `json:"toNode" yaml:"toNode"`
// The Unique ID of the message // The Unique ID of the message

View file

@ -181,7 +181,7 @@ func createErrorMsgContent(FromNode node, theError error) subjectAndMessage {
sam := subjectAndMessage{ sam := subjectAndMessage{
Subject: newSubject(REQErrorLog, "errorCentral"), Subject: newSubject(REQErrorLog, "errorCentral"),
Message: Message{ Message: Message{
Label: "errorLog", Directory: "errorLog",
ToNode: "errorCentral", ToNode: "errorCentral",
FromNode: FromNode, FromNode: FromNode,
Data: []string{er}, Data: []string{er},

View file

@ -296,13 +296,13 @@ func (m methodREQTextToLogFile) handler(proc process, message Message, node stri
// If this was a direct request there are no previous message to take // 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. // 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.log", message.ToNode, message.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Label, string(message.FromNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.FromNode))
case message.PreviousMessage.ToNode != "": case message.PreviousMessage.ToNode != "":
fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method) fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Label, string(message.PreviousMessage.ToNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
case message.PreviousMessage.ToNode == "": case message.PreviousMessage.ToNode == "":
fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method) fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Label, string(message.PreviousMessage.ToNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
} }
// Check if folder structure exist, if not create it. // Check if folder structure exist, if not create it.
@ -358,15 +358,15 @@ func (m methodREQTextToFile) handler(proc process, message Message, node string)
// If this was a direct request there are no previous message to take // 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. // 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.log", message.ToNode, message.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Label, string(message.FromNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.FromNode))
fmt.Printf(" ** DEBUG1: foldertree: %v\n", folderTree) fmt.Printf(" ** DEBUG1: foldertree: %v\n", folderTree)
case message.PreviousMessage.ToNode != "": case message.PreviousMessage.ToNode != "":
fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method) fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Label, string(message.PreviousMessage.ToNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
fmt.Printf(" ** DEBUG2: foldertree: %v\n", folderTree) fmt.Printf(" ** DEBUG2: foldertree: %v\n", folderTree)
case message.PreviousMessage.ToNode == "": case message.PreviousMessage.ToNode == "":
fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method) fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Label, string(message.PreviousMessage.ToNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
fmt.Printf(" ** DEBUG3: foldertree: %v\n", folderTree) fmt.Printf(" ** DEBUG3: foldertree: %v\n", folderTree)
} }
@ -447,13 +447,13 @@ func (m methodREQErrorLog) handler(proc process, message Message, node string) (
// If this was a direct request there are no previous message to take // 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. // 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.log", message.ToNode, message.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Label, string(message.FromNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.Directory, string(message.FromNode))
case message.PreviousMessage.ToNode != "": case message.PreviousMessage.ToNode != "":
fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method) fileName = fmt.Sprintf("%v.%v.log", message.PreviousMessage.ToNode, message.PreviousMessage.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Label, string(message.PreviousMessage.ToNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
case message.PreviousMessage.ToNode == "": case message.PreviousMessage.ToNode == "":
fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method) fileName = fmt.Sprintf("%v.%v.log", message.FromNode, message.Method)
folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Label, string(message.PreviousMessage.ToNode)) folderTree = filepath.Join(proc.configuration.SubscribersDataFolder, message.PreviousMessage.Directory, string(message.PreviousMessage.ToNode))
} }
// Check if folder structure exist, if not create it. // Check if folder structure exist, if not create it.