mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Add Cluster::nodeid_to_node() helper function
This translates backend-specific node identifiers (like Broker IDs) to
cluster nodes and their names, if available.
(cherry picked from commit 46a11ec37d
)
This commit is contained in:
parent
1cbbbc5c40
commit
06fa47e21d
1 changed files with 20 additions and 0 deletions
|
@ -295,6 +295,15 @@ export {
|
||||||
## Returns: a topic string that may used to send a message exclusively to
|
## Returns: a topic string that may used to send a message exclusively to
|
||||||
## a given cluster node.
|
## a given cluster node.
|
||||||
global nodeid_topic: function(id: string): string;
|
global nodeid_topic: function(id: string): string;
|
||||||
|
|
||||||
|
## Retrieve the cluster-level naming of a node based on its node ID,
|
||||||
|
## a backend-specific identifier.
|
||||||
|
##
|
||||||
|
## id: the node ID of a peer.
|
||||||
|
##
|
||||||
|
## Returns: the :zeek:see:`Cluster::NamedNode` for the requested node, if
|
||||||
|
## known, otherwise a "null" instance with an empty name field.
|
||||||
|
global nodeid_to_node: function(id: string): NamedNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Track active nodes per type.
|
# Track active nodes per type.
|
||||||
|
@ -374,6 +383,17 @@ function nodeid_topic(id: string): string
|
||||||
return nodeid_topic_prefix + id + "/";
|
return nodeid_topic_prefix + id + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nodeid_to_node(id: string): NamedNode
|
||||||
|
{
|
||||||
|
for ( name, n in nodes )
|
||||||
|
{
|
||||||
|
if ( n?$id && n$id == id )
|
||||||
|
return NamedNode($name=name, $node=n);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NamedNode($name="", $node=[$node_type=NONE, $ip=0.0.0.0]);
|
||||||
|
}
|
||||||
|
|
||||||
event Cluster::hello(name: string, id: string) &priority=10
|
event Cluster::hello(name: string, id: string) &priority=10
|
||||||
{
|
{
|
||||||
if ( name !in nodes )
|
if ( name !in nodes )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue