1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-31 01:24:31 +00:00

updated doc and error messages

This commit is contained in:
postmannen 2024-12-18 06:54:07 +01:00
parent 0451a90332
commit 0d6517f6ec
3 changed files with 44 additions and 8 deletions

View file

@ -127,7 +127,7 @@ func (c *centralAuth) addPublicKey(proc process, msg Message) {
c.pki.nodesAcked.mu.Unlock()
if ok && bytes.Equal(existingKey, msg.Data) {
er := fmt.Errorf("info: public key value for REGISTERED node %v is the same, doing nothing", msg.FromNode)
er := fmt.Errorf("info: public key value for registered node %v is the same, doing nothing", msg.FromNode)
proc.errorKernel.logDebug(er)
return
}
@ -145,7 +145,7 @@ func (c *centralAuth) addPublicKey(proc process, msg Message) {
c.pki.nodeNotAckedPublicKeys.KeyMap[msg.FromNode] = msg.Data
c.pki.nodeNotAckedPublicKeys.mu.Unlock()
er := fmt.Errorf("info: detected new public key for node: %v. This key will need to be authorized by operator to be allowed into the system", msg.FromNode)
er := fmt.Errorf("info: new public key for node: %v. Key needs to be authorized by operator to be allowed into the system by using the keysAllow method", msg.FromNode)
c.pki.errorKernel.infoSend(proc, msg, er)
c.pki.errorKernel.logDebug(er)
}

View file

@ -8,9 +8,48 @@ Messages put in the startup folder will not be sent to the broker but handled lo
This can be really handy when you have some 1-off job you want to done at startup, like some cleaning up.
Another example could be that you have some local prometheus metrics you want to scrape every 5 minutes, and you want to send them to some central metrics system.
## Example reqest metrics from nodes
#### How to send the reply to another node
Another example could be that you have some local prometheus metrics you want to scrape every 5 minutes, and you want to send them to some central metrics system.
```yaml
---
- toNodes:
- ["node1","node2"]
method: httpGet
methodArgs:
- "http://localhost:8080/metrics"
replyMethod: file
methodTimeout: 5
directory: metrics
fileName: metrics.html
schedule : [120,999999999]
```
The example above will send out a request to node1 and node2 every 120 second to scrape the metrics and write the results that came back to a folder named **data/metrics** in the current running directory.
## Example read metrics locally first, and then send to remote node
But we can also make the nodes publish their metrics instead of requesting it by putting a message in each nodes startup folder, set the **toNode** field to local, and instead use the **fromNode** field to decide where to deliver the result.
```yaml
---
- toNodes:
- ["local"]
fromNode: my-metrics-node
method: httpGet
methodArgs:
- "http://localhost:8080/metrics"
replyMethod: file
methodTimeout: 5
directory: metrics
fileName: metrics.html
schedule : [120,999999999]
```
In the above example, the httpGet will be run on the local node, and the result will be sent to my-metrics-node.
### How to send the reply to another node further explained
Normally the **fromNode** field is automatically filled in with the node name of the node where a message originated. Since messages within the startup folder is not received from another node via the normal message path we need set the **fromNode** field in the message to where we want the reply (result) delivered.
@ -38,4 +77,4 @@ Since messages used in startup folder are ment to be delivered locally we can si
```
This example message will be read at startup, and executed on the local node where it was read, the method will be executed, and the result of the method will be sent to **central**.
This example message will be read at startup, and executed on the local node where it was read, the method will be executed, and the result of the method will be sent to **central**. This is basically the same as the previous example, but we're using cliCommand method with curl instead of the httpGet method.

View file

@ -35,9 +35,6 @@ func methodPublicKey(proc process, message Message, node string) ([]byte, error)
// case proc.toRingbufferCh <- []subjectAndMessage{sam}:
case <-ctx.Done():
case out := <-outCh:
// Prepare and queue for sending a new message with the output
// of the action executed.
newReplyMessage(proc, message, out)
}
}()