From 0d896312898448c8cc98ca34b191c83992d8aa41 Mon Sep 17 00:00:00 2001 From: postmannen Date: Fri, 11 Mar 2022 11:44:19 +0100 Subject: [PATCH] doc - create example message files --- .../cli-command-cont-tail-log-file.json | 17 ++++++++++ ...nCliCommand.json => cli-command-tree.json} | 0 ...p1-REQCliCommand.json => cli-command.json} | 0 .../clicommand-to-console.json | 20 +++++++++++ doc/example-messages/copy-files.json | 10 ++++++ ...-and-execute-bash-script-with-heredoc.yaml | 34 +++++++++++++++++++ .../create-msg-startup-folder.json | 19 +++++++++++ .../create-startup-relay-central.json | 19 +++++++++++ ...ip1-ECHORequest.json => echo-request.json} | 0 .../flush-dns-restart-wireguard.json | 22 ++++++++++++ ...hip2-REQHttpGet.json => http-get-ex2.json} | 0 doc/example-messages/http-get-scheduled.json | 18 ++++++++++ ...{toShip1-REQHttpGet.json => http-get.json} | 0 .../operation-start-proc.json | 0 doc/example-messages/operation-stop-proc.json | 0 .../{toShip1-REQPing.json => ping.json} | 0 ...toCentral-sayHello.json => say-hello.json} | 0 ...oShip2-REQTailFile.json => tail-file.json} | 0 .../toShip2-REQOpCmdStart_REQHttpGet.json | 21 ------------ .../toShip2-REQOpCmdStop_REQHttpGet.json | 23 ------------- doc/example-messages/toShip2-REQOpPs.json | 18 ---------- .../use-sed-to-edit-files.json | 15 ++++++++ 22 files changed, 174 insertions(+), 62 deletions(-) create mode 100644 doc/example-messages/cli-command-cont-tail-log-file.json rename doc/example-messages/{toShip1-REQnCliCommand.json => cli-command-tree.json} (100%) rename doc/example-messages/{toShip1-REQCliCommand.json => cli-command.json} (100%) create mode 100644 doc/example-messages/clicommand-to-console.json create mode 100644 doc/example-messages/copy-files.json create mode 100644 doc/example-messages/create-and-execute-bash-script-with-heredoc.yaml create mode 100644 doc/example-messages/create-msg-startup-folder.json create mode 100644 doc/example-messages/create-startup-relay-central.json rename doc/example-messages/{toShip1-ECHORequest.json => echo-request.json} (100%) create mode 100644 doc/example-messages/flush-dns-restart-wireguard.json rename doc/example-messages/{toShip2-REQHttpGet.json => http-get-ex2.json} (100%) create mode 100644 doc/example-messages/http-get-scheduled.json rename doc/example-messages/{toShip1-REQHttpGet.json => http-get.json} (100%) create mode 100644 doc/example-messages/operation-start-proc.json create mode 100644 doc/example-messages/operation-stop-proc.json rename doc/example-messages/{toShip1-REQPing.json => ping.json} (100%) rename doc/example-messages/{toCentral-sayHello.json => say-hello.json} (100%) rename doc/example-messages/{toShip2-REQTailFile.json => tail-file.json} (100%) delete mode 100644 doc/example-messages/toShip2-REQOpCmdStart_REQHttpGet.json delete mode 100644 doc/example-messages/toShip2-REQOpCmdStop_REQHttpGet.json delete mode 100644 doc/example-messages/toShip2-REQOpPs.json create mode 100644 doc/example-messages/use-sed-to-edit-files.json diff --git a/doc/example-messages/cli-command-cont-tail-log-file.json b/doc/example-messages/cli-command-cont-tail-log-file.json new file mode 100644 index 0000000..62deb02 --- /dev/null +++ b/doc/example-messages/cli-command-cont-tail-log-file.json @@ -0,0 +1,17 @@ +[ + { + "directory":"system", + "fileName": "test", + "toNodes": ["ship1"], + "relayViaNode": "central", + "relayReplyMethod": "REQToConsole", + "methodArgs": ["bash","-c","cat /etc/hostname && journalctl -u steward -n 5 --follow"], + "method":"REQCliCommandCont", + "replyMethod":"REQToFileAppend", + "ACKTimeout":5, + "retries":3, + "replyACKTimeout":5, + "replyRetries":3, + "methodTimeout": 5 + } +] \ No newline at end of file diff --git a/doc/example-messages/toShip1-REQnCliCommand.json b/doc/example-messages/cli-command-tree.json similarity index 100% rename from doc/example-messages/toShip1-REQnCliCommand.json rename to doc/example-messages/cli-command-tree.json diff --git a/doc/example-messages/toShip1-REQCliCommand.json b/doc/example-messages/cli-command.json similarity index 100% rename from doc/example-messages/toShip1-REQCliCommand.json rename to doc/example-messages/cli-command.json diff --git a/doc/example-messages/clicommand-to-console.json b/doc/example-messages/clicommand-to-console.json new file mode 100644 index 0000000..64d2614 --- /dev/null +++ b/doc/example-messages/clicommand-to-console.json @@ -0,0 +1,20 @@ +[ + { + "toNodes": ["ship1"], + "method": "REQCliCommand", + "methodArgs": [ + "bash", + "-c", + "hostname && curl -v http://debian.org" + ], + "replyMethod": "REQToConsole", + "ACKTimeout": 5, + "retries": 3, + "replyACKTimeout": 5, + "replyRetries": 5, + "methodTimeout": 5, + "replyMethodTimeout": 120, + "directory": "debug", + "fileName": "test.txt" + } +] \ No newline at end of file diff --git a/doc/example-messages/copy-files.json b/doc/example-messages/copy-files.json new file mode 100644 index 0000000..6d35c90 --- /dev/null +++ b/doc/example-messages/copy-files.json @@ -0,0 +1,10 @@ +[ + { + "directory": "copy", + "fileName": "copy.log", + "toNodes": ["ship1"], + "method":"REQCopyFileFrom", + "methodArgs": ["./tmp2.txt","ship2","/tmp/tmp2.txt"], + "replyMethod":"REQToFileAppend" + } +] \ No newline at end of file diff --git a/doc/example-messages/create-and-execute-bash-script-with-heredoc.yaml b/doc/example-messages/create-and-execute-bash-script-with-heredoc.yaml new file mode 100644 index 0000000..2ec62c1 --- /dev/null +++ b/doc/example-messages/create-and-execute-bash-script-with-heredoc.yaml @@ -0,0 +1,34 @@ +--- +- toNodes: + - ship1 + - ship2 + method: REQCliCommand + methodArgs: + - "bash" + - "-c" + - | + cat <<-"EOF" >test.sh + #!/bin/bash + + if [ -z "$1" ]; then + echo "error: No argument supplied, give the hostname as the only argument" + exit 1 + fi + + touch $1 + echo "sorry..." > $1 + + EOF + + chmod +x test.sh + + ./test.sh WHOOPS.txt + + replyMethod: REQToFile + ACKTimeout: 5 + retries: 120 + replyACKTimeout: 5 + replyRetries: 3 + methodTimeout: 5 + directory: system + fileName: system.log diff --git a/doc/example-messages/create-msg-startup-folder.json b/doc/example-messages/create-msg-startup-folder.json new file mode 100644 index 0000000..5977710 --- /dev/null +++ b/doc/example-messages/create-msg-startup-folder.json @@ -0,0 +1,19 @@ +[ + { + "relayViaNode": "central", + "relayReplyMethod": "REQToConsole", + "toNodes": ["ship1","ship2"], + "method": "REQCliCommand", + "methodArgs": [ + "bash","-c","cat <<< $'[{\"directory\": \"metrics\",\"fileName\": \"edgeAgent.prom\",\"fromNode\":\"metrics\",\"toNode\": \"ship1\",\"method\":\"REQHttpGetScheduled\",\"methodArgs\": [\"http://127.0.0.1:9601/metrics\",\"60\",\"5000000\"],\"replyMethod\":\"REQToFile\",\"ACKTimeout\":10,\"retries\": 3,\"methodTimeout\": 3}]'>/usr/local/steward/startup/scrape-edge-agent.msg && cat <<< $'[{\"directory\": \"metrics\",\"fileName\": \"edgeHub.prom\",\"fromNode\":\"metrics\",\"toNode\": \"ship2\",\"method\":\"REQHttpGetScheduled\",\"methodArgs\": [\"http://127.0.0.1:9602/metrics\",\"60\",\"5000000\"],\"replyMethod\":\"REQToFile\",\"ACKTimeout\":10,\"retries\": 3,\"methodTimeout\": 3}]'>/usr/local/steward/startup/scrape-edge-hub.msg && systemctl restart steward" + ], + "replyMethod": "REQToFile", + "ACKTimeout": 20, + "retries": 3, + "replyACKTimeout": 20, + "replyRetries": 3, + "methodTimeout": 5, + "directory": "system", + "fileName": "system.log" + } +] diff --git a/doc/example-messages/create-startup-relay-central.json b/doc/example-messages/create-startup-relay-central.json new file mode 100644 index 0000000..8658caa --- /dev/null +++ b/doc/example-messages/create-startup-relay-central.json @@ -0,0 +1,19 @@ +[ + { + "relayViaNode": "central", + "relayReplyMethod": "REQToConsole", + "toNodes": ["ship1"], + "method": "REQCliCommand", + "methodArgs": [ + "bash","-c","cat <<< $'[{\"directory\": \"metrics\",\"fileName\": \"edgeHub.prom\",\"fromNode\":\"metrics\",\"toNode\": \"ship1\",\"method\":\"REQHttpGetScheduled\",\"methodArgs\": [\"http://127.0.0.1:9602/metrics\",\"60\",\"5000000\"],\"replyMethod\":\"REQToFile\",\"ACKTimeout\":10,\"retries\": 3,\"methodTimeout\": 3}]'>/usr/local/steward/startup/scrape-edge-hub.msg && systemctl restart steward" + ], + "replyMethod": "REQToFile", + "ACKTimeout": 5, + "retries": 3, + "replyACKTimeout": 5, + "replyRetries": 3, + "methodTimeout": 5, + "directory": "system", + "fileName": "system.log" + } +] diff --git a/doc/example-messages/toShip1-ECHORequest.json b/doc/example-messages/echo-request.json similarity index 100% rename from doc/example-messages/toShip1-ECHORequest.json rename to doc/example-messages/echo-request.json diff --git a/doc/example-messages/flush-dns-restart-wireguard.json b/doc/example-messages/flush-dns-restart-wireguard.json new file mode 100644 index 0000000..97b35af --- /dev/null +++ b/doc/example-messages/flush-dns-restart-wireguard.json @@ -0,0 +1,22 @@ +[ + { + "toNodes": ["ship1","ship2"], + "method": "REQCliCommand", + "methodArgs": [ + "bash", + "-c", + "cat /etc/hostname && systemd-resolve --flush-caches &&wg-quick down wg0 && sleep 2 && wg-quick up wg0" + ], + "replyMethod": "REQToFile", + "ACKTimeout": 20, + "retries": 3, + "replyACKTimeout": 20, + "replyRetries": 3, + "methodTimeout": 20, + "replyMethodTimeout": 120, + "directory": "system/wireguard", + "fileName": "wireguard-down-up.log", + "relayViaNode": "central", + "relayReplyMethod": "REQToConsole" + } +] \ No newline at end of file diff --git a/doc/example-messages/toShip2-REQHttpGet.json b/doc/example-messages/http-get-ex2.json similarity index 100% rename from doc/example-messages/toShip2-REQHttpGet.json rename to doc/example-messages/http-get-ex2.json diff --git a/doc/example-messages/http-get-scheduled.json b/doc/example-messages/http-get-scheduled.json new file mode 100644 index 0000000..98487f7 --- /dev/null +++ b/doc/example-messages/http-get-scheduled.json @@ -0,0 +1,18 @@ +[ + { + "toNodes": ["ship1"], + "method": "REQHttpGetScheduled", + "methodArgs": [ + "https://vg.no","10","1" + ], + "replyMethod": "REQToConsole", + "ACKTimeout": 5, + "retries": 3, + "replyACKTimeout": 5, + "replyRetries": 3, + "methodTimeout": 5, + "replyMethodTimeout": 120, + "directory": "test", + "fileName": "test.txt" + } +] \ No newline at end of file diff --git a/doc/example-messages/toShip1-REQHttpGet.json b/doc/example-messages/http-get.json similarity index 100% rename from doc/example-messages/toShip1-REQHttpGet.json rename to doc/example-messages/http-get.json diff --git a/doc/example-messages/operation-start-proc.json b/doc/example-messages/operation-start-proc.json new file mode 100644 index 0000000..e69de29 diff --git a/doc/example-messages/operation-stop-proc.json b/doc/example-messages/operation-stop-proc.json new file mode 100644 index 0000000..e69de29 diff --git a/doc/example-messages/toShip1-REQPing.json b/doc/example-messages/ping.json similarity index 100% rename from doc/example-messages/toShip1-REQPing.json rename to doc/example-messages/ping.json diff --git a/doc/example-messages/toCentral-sayHello.json b/doc/example-messages/say-hello.json similarity index 100% rename from doc/example-messages/toCentral-sayHello.json rename to doc/example-messages/say-hello.json diff --git a/doc/example-messages/toShip2-REQTailFile.json b/doc/example-messages/tail-file.json similarity index 100% rename from doc/example-messages/toShip2-REQTailFile.json rename to doc/example-messages/tail-file.json diff --git a/doc/example-messages/toShip2-REQOpCmdStart_REQHttpGet.json b/doc/example-messages/toShip2-REQOpCmdStart_REQHttpGet.json deleted file mode 100644 index 822805d..0000000 --- a/doc/example-messages/toShip2-REQOpCmdStart_REQHttpGet.json +++ /dev/null @@ -1,21 +0,0 @@ -[ - { - "directory":"opcommand_logs", - "fileName": "somefile.log", - "toNode": "ship2", - "data": [], - "method":"REQOpCommand", - "operation":{ - "opCmd":"startProc", - "opArg": { - "method": "REQHttpGet" - } - }, - "replyMethod":"REQToFileAppend", - "ACKTimeout":3, - "retries":3, - "replyACKTimeout":3, - "replyRetries":3, - "MethodTimeout": 7 - } -] \ No newline at end of file diff --git a/doc/example-messages/toShip2-REQOpCmdStop_REQHttpGet.json b/doc/example-messages/toShip2-REQOpCmdStop_REQHttpGet.json deleted file mode 100644 index 1310d10..0000000 --- a/doc/example-messages/toShip2-REQOpCmdStop_REQHttpGet.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - { - "directory":"opcommand_logs", - "fileName": "somefile.log", - "toNode": "ship2", - "data": [], - "method":"REQOpCommand", - "operation":{ - "opCmd":"stopProc", - "opArg": { - "method": "REQHttpGet", - "kind": "subscriber", - "receivingNode": "ship2" - } - }, - "replyMethod":"REQToFileAppend", - "ACKTimeout":3, - "retries":3, - "replyACKTimeout":3, - "replyRetries":3, - "MethodTimeout": 7 - } -] \ No newline at end of file diff --git a/doc/example-messages/toShip2-REQOpPs.json b/doc/example-messages/toShip2-REQOpPs.json deleted file mode 100644 index e1fc55c..0000000 --- a/doc/example-messages/toShip2-REQOpPs.json +++ /dev/null @@ -1,18 +0,0 @@ -[ - { - "directory":"opcommand_logs", - "fileName": "somefile.log", - "toNode": "ship2", - "data": [], - "method":"REQOpCommand", - "operation":{ - "opCmd":"ps" - }, - "replyMethod":"REQToFileAppend", - "ACKTimeout":3, - "retries":3, - "replyACKTimeout":3, - "replyRetries":3, - "MethodTimeout": 7 - } -] \ No newline at end of file diff --git a/doc/example-messages/use-sed-to-edit-files.json b/doc/example-messages/use-sed-to-edit-files.json new file mode 100644 index 0000000..14e799b --- /dev/null +++ b/doc/example-messages/use-sed-to-edit-files.json @@ -0,0 +1,15 @@ +[ + { + "directory":"system", + "fileName": "test.txt", + "toNodes": ["ship1","ship2"], + "methodArgs": ["bash","-c","sed -i 's/StartSubREQErrorLog =.*/StartSubREQErrorLog = false/g' /usr/local/steward/etc/config.toml && systemctl restart steward"], + "method":"REQCliCommand", + "replyMethod":"REQToFile", + "ACKTimeout":10, + "retries":1, + "replyACKTimeout":10, + "replyRetries":3, + "methodTimeout": 60 + } +] \ No newline at end of file