mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Add Supervisor::node_status notification event
The Supervisor generates this event every time it receives a status update from the stem, meaning a node got created or re-created. A corresponding SupervisorControl::node_status event relays the same information for users interacting with the Supervisor over Broker.
This commit is contained in:
parent
bdfa7e70f5
commit
14188fc7a7
9 changed files with 98 additions and 0 deletions
47
testing/btest/supervisor/node_status.zeek
Normal file
47
testing/btest/supervisor/node_status.zeek
Normal file
|
@ -0,0 +1,47 @@
|
|||
# This test verifies that the Supervisor triggers Supervisor::node_status
|
||||
# events when the stem (re)creates nodes.
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run zeek zeek -j -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 30
|
||||
# @TEST-EXEC: btest-diff zeek/.stdout
|
||||
|
||||
# So the supervised node doesn't terminate right away.
|
||||
redef exit_only_after_terminate=T;
|
||||
|
||||
global status_count = 0;
|
||||
global check_interval = 0.1sec;
|
||||
|
||||
event Supervisor::node_status(node: string, pid: count)
|
||||
{
|
||||
# We handle this once for the initial node creation, once for the
|
||||
# restart, then quit.
|
||||
if ( ++status_count == 2)
|
||||
terminate();
|
||||
|
||||
print "got node_status event", node;
|
||||
|
||||
# The status update has a PID for the new node, so checking node status
|
||||
# now should report a matching PID. This will output only in case the
|
||||
# PIDs do not match, failing the test.
|
||||
local s = Supervisor::status(node);
|
||||
local ns = s$nodes["grault"];
|
||||
|
||||
if ( ! ns$pid )
|
||||
print "pid unavailable via Supervisor::status()", pid;
|
||||
else if ( ns$pid != pid )
|
||||
print "pid mismatch", ns$pid, pid;
|
||||
|
||||
Supervisor::restart("grault");
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
if ( Supervisor::is_supervisor() )
|
||||
{
|
||||
local sn = Supervisor::NodeConfig($name="grault");
|
||||
local res = Supervisor::create(sn);
|
||||
|
||||
if ( res != "" )
|
||||
print "failed to create node", res;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue