mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Merge remote-tracking branch 'origin/topic/seth/metrics-merge' into topic/bernhard/hyperloglog-with-measurement
This commit is contained in:
commit
7aa11291a5
56 changed files with 2353 additions and 935 deletions
|
@ -38,6 +38,7 @@ scripts/base/init-default.bro
|
|||
scripts/base/utils/files.bro
|
||||
scripts/base/utils/numbers.bro
|
||||
scripts/base/utils/paths.bro
|
||||
scripts/base/utils/queue.bro
|
||||
scripts/base/utils/strings.bro
|
||||
scripts/base/utils/thresholds.bro
|
||||
scripts/base/utils/urls.bro
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Host: 6.5.4.3 - num:2 - sum:6.0 - avg:3.0 - max:5.0 - min:1.0 - var:8.0 - std_dev:2.8 - unique:2
|
||||
Host: 10.10.10.10 - num:1 - sum:5.0 - avg:5.0 - max:5.0 - min:5.0 - var:0.0 - std_dev:0.0 - unique:1
|
||||
Host: 1.2.3.4 - num:9 - sum:437.0 - avg:48.6 - max:95.0 - min:3.0 - var:758.8 - std_dev:27.5 - unique:8
|
||||
Host: 7.2.1.5 - num:2 - sum:145.0 - avg:72.5 - max:91.0 - min:54.0 - var:684.5 - std_dev:26.2 - unique:2
|
|
@ -0,0 +1,3 @@
|
|||
Host: 6.5.4.3 - num:1 - sum:2.0 - var:0.0 - avg:2.0 - max:2.0 - min:2.0 - std_dev:0.0 - unique:1
|
||||
Host: 1.2.3.4 - num:5 - sum:221.0 - var:1144.2 - avg:44.2 - max:94.0 - min:5.0 - std_dev:33.8 - unique:4
|
||||
Host: 7.2.1.5 - num:1 - sum:1.0 - var:0.0 - avg:1.0 - max:1.0 - min:1.0 - std_dev:0.0 - unique:1
|
|
@ -0,0 +1 @@
|
|||
A test metric threshold was crossed with a value of: 100.0
|
|
@ -0,0 +1,6 @@
|
|||
THRESHOLD_SERIES: hit a threshold series value at 3 for measurement_key(host=1.2.3.4)
|
||||
THRESHOLD: hit a threshold value at 6 for measurement_key(host=1.2.3.4)
|
||||
THRESHOLD_SERIES: hit a threshold series value at 6 for measurement_key(host=1.2.3.4)
|
||||
THRESHOLD: hit a threshold value at 1001 for measurement_key(host=7.2.1.5)
|
||||
THRESHOLD_SERIES: hit a threshold series value at 1001 for measurement_key(host=7.2.1.5)
|
||||
THRESHOLD WITH RATIO BETWEEN REDUCERS: hit a threshold value at 55x for measurement_key(host=7.2.1.5)
|
|
@ -3,10 +3,10 @@
|
|||
#empty_field (empty)
|
||||
#unset_field -
|
||||
#path metrics
|
||||
#open 2012-07-20-01-50-41
|
||||
#fields ts metric_id filter_name index.host index.str index.network value
|
||||
#types time enum string addr string subnet count
|
||||
1342749041.601712 TEST_METRIC foo-bar 6.5.4.3 - - 4
|
||||
1342749041.601712 TEST_METRIC foo-bar 7.2.1.5 - - 2
|
||||
1342749041.601712 TEST_METRIC foo-bar 1.2.3.4 - - 6
|
||||
#close 2012-07-20-01-50-49
|
||||
#open 2012-12-17-18-43-15
|
||||
#fields ts ts_delta metric index.str index.host index.network result.begin result.end result.num result.sum result.min result.max result.avg result.variance result.std_dev result.unique
|
||||
#types time interval string string addr subnet time time count double double double double double double count
|
||||
1355769795.365325 3.000000 test.metric - 6.5.4.3 - 1355769793.449322 1355769793.458467 2 6.0 1.0 5.0 3.0 4.0 2.0 2
|
||||
1355769795.365325 3.000000 test.metric - 1.2.3.4 - 1355769793.449322 1355769793.458467 9 437.0 3.0 95.0 48.555556 674.469136 25.970544 8
|
||||
1355769795.365325 3.000000 test.metric - 7.2.1.5 - 1355769793.449322 1355769793.458467 2 145.0 54.0 91.0 72.5 342.25 18.5 2
|
||||
#close 2012-12-17-18-43-21
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#empty_field (empty)
|
||||
#unset_field -
|
||||
#path metrics
|
||||
#open 2012-07-20-01-49-22
|
||||
#fields ts metric_id filter_name index.host index.str index.network value
|
||||
#types time enum string addr string subnet count
|
||||
1342748962.841548 TEST_METRIC foo-bar 6.5.4.3 - - 2
|
||||
1342748962.841548 TEST_METRIC foo-bar 7.2.1.5 - - 1
|
||||
1342748962.841548 TEST_METRIC foo-bar 1.2.3.4 - - 3
|
||||
#close 2012-07-20-01-49-22
|
||||
#open 2012-12-17-18-43-45
|
||||
#fields ts ts_delta metric index.str index.host index.network result.begin result.end result.num result.sum result.min result.max result.avg result.variance result.std_dev result.unique
|
||||
#types time interval string string addr subnet time time count double double double double double double count
|
||||
1355769825.947161 3.000000 test.metric - 6.5.4.3 - 1355769825.947161 1355769825.947161 1 2.0 2.0 2.0 2.0 0.0 0.0 -
|
||||
1355769825.947161 3.000000 test.metric - 1.2.3.4 - 1355769825.947161 1355769825.947161 5 221.0 5.0 94.0 44.2 915.36 30.254917 -
|
||||
1355769825.947161 3.000000 test.metric - 7.2.1.5 - 1355769825.947161 1355769825.947161 1 1.0 1.0 1.0 1.0 0.0 0.0 -
|
||||
#close 2012-12-17-18-43-45
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
A test metric threshold was crossed!
|
|
@ -0,0 +1,8 @@
|
|||
THRESHOLD_SERIES: hit a threshold series value at 3 for metric_index(host=1.2.3.4)
|
||||
THRESHOLD_FUNC: hit a threshold function value at 3 for metric_index(host=1.2.3.4)
|
||||
THRESHOLD_FUNC: hit a threshold function value at 2 for metric_index(host=6.5.4.3)
|
||||
THRESHOLD_FUNC: hit a threshold function value at 1 for metric_index(host=7.2.1.5)
|
||||
THRESHOLD: hit a threshold value at 6 for metric_index(host=1.2.3.4)
|
||||
THRESHOLD_SERIES: hit a threshold series value at 6 for metric_index(host=1.2.3.4)
|
||||
THRESHOLD: hit a threshold value at 1001 for metric_index(host=7.2.1.5)
|
||||
THRESHOLD_SERIES: hit a threshold series value at 1001 for metric_index(host=7.2.1.5)
|
11
testing/btest/Baseline/scripts.base.utils.queue/output
Normal file
11
testing/btest/Baseline/scripts.base.utils.queue/output
Normal file
|
@ -0,0 +1,11 @@
|
|||
This is a get_cnt_vector test: 3
|
||||
This is a get_cnt_vector test: 4
|
||||
This is a get_str_vector test: 3
|
||||
This is a get_str_vector test: 4
|
||||
Testing pop: 3
|
||||
Length after pop: 1
|
||||
Size of q2: 4
|
||||
String queue value: test 1
|
||||
String queue value: test 2
|
||||
String queue value: test 2
|
||||
String queue value: test 1
|
|
@ -0,0 +1,83 @@
|
|||
# @TEST-SERIALIZE: comm
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager-1 BROPATH=$BROPATH:.. CLUSTER_NODE=manager-1 bro %INPUT
|
||||
# @TEST-EXEC: sleep 1
|
||||
# @TEST-EXEC: btest-bg-run worker-1 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-1 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-run worker-2 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-2 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 15
|
||||
|
||||
# @TEST-EXEC: btest-diff manager-1/.stdout
|
||||
|
||||
@TEST-START-FILE cluster-layout.bro
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=37757/tcp, $workers=set("worker-1", "worker-2")],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37760/tcp, $manager="manager-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37761/tcp, $manager="manager-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
redef Log::default_rotation_interval = 0secs;
|
||||
|
||||
global n = 0;
|
||||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
local r1: Measurement::Reducer = [$stream="test.metric", $apply=set(Measurement::SUM, Measurement::MIN, Measurement::MAX, Measurement::AVERAGE, Measurement::STD_DEV, Measurement::VARIANCE, Measurement::UNIQUE)];
|
||||
Measurement::create([$epoch=5secs,
|
||||
$reducers=set(r1),
|
||||
$epoch_finished(rt: Measurement::ResultTable) =
|
||||
{
|
||||
for ( key in rt )
|
||||
{
|
||||
local r = rt[key]["test.metric"];
|
||||
print fmt("Host: %s - num:%d - sum:%.1f - avg:%.1f - max:%.1f - min:%.1f - var:%.1f - std_dev:%.1f - unique:%d", key$host, r$num, r$sum, r$average, r$max, r$min, r$variance, r$std_dev, r$unique);
|
||||
}
|
||||
|
||||
terminate();
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
event remote_connection_closed(p: event_peer)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
global ready_for_data: event();
|
||||
redef Cluster::manager2worker_events += /^ready_for_data$/;
|
||||
|
||||
event ready_for_data()
|
||||
{
|
||||
if ( Cluster::node == "worker-1" )
|
||||
{
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=34]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=30]);
|
||||
Measurement::add_data("test.metric", [$host=6.5.4.3], [$num=1]);
|
||||
Measurement::add_data("test.metric", [$host=7.2.1.5], [$num=54]);
|
||||
}
|
||||
if ( Cluster::node == "worker-2" )
|
||||
{
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=75]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=30]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=3]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=57]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=52]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=61]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=95]);
|
||||
Measurement::add_data("test.metric", [$host=6.5.4.3], [$num=5]);
|
||||
Measurement::add_data("test.metric", [$host=7.2.1.5], [$num=91]);
|
||||
Measurement::add_data("test.metric", [$host=10.10.10.10], [$num=5]);
|
||||
}
|
||||
}
|
||||
|
||||
@if ( Cluster::local_node_type() == Cluster::MANAGER )
|
||||
|
||||
global peer_count = 0;
|
||||
event remote_connection_handshake_done(p: event_peer) &priority=-5
|
||||
{
|
||||
++peer_count;
|
||||
if ( peer_count == 2 )
|
||||
event ready_for_data();
|
||||
}
|
||||
|
||||
@endif
|
34
testing/btest/scripts/base/frameworks/measurement/basic.bro
Normal file
34
testing/btest/scripts/base/frameworks/measurement/basic.bro
Normal file
|
@ -0,0 +1,34 @@
|
|||
# @TEST-EXEC: bro %INPUT
|
||||
# @TEST-EXEC: btest-diff .stdout
|
||||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
local r1: Measurement::Reducer = [$stream="test.metric",
|
||||
$apply=set(Measurement::SUM,
|
||||
Measurement::VARIANCE,
|
||||
Measurement::AVERAGE,
|
||||
Measurement::MAX,
|
||||
Measurement::MIN,
|
||||
Measurement::STD_DEV,
|
||||
Measurement::UNIQUE)];
|
||||
Measurement::create([$epoch=3secs,
|
||||
$reducers=set(r1),
|
||||
$epoch_finished(data: Measurement::ResultTable) =
|
||||
{
|
||||
for ( key in data )
|
||||
{
|
||||
local r = data[key]["test.metric"];
|
||||
print fmt("Host: %s - num:%d - sum:%.1f - var:%.1f - avg:%.1f - max:%.1f - min:%.1f - std_dev:%.1f - unique:%d", key$host, r$num, r$sum, r$variance, r$average, r$max, r$min, r$std_dev, r$unique);
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=5]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=22]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=94]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=50]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=50]);
|
||||
|
||||
Measurement::add_data("test.metric", [$host=6.5.4.3], [$num=2]);
|
||||
Measurement::add_data("test.metric", [$host=7.2.1.5], [$num=1]);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
# @TEST-SERIALIZE: comm
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager-1 BROPATH=$BROPATH:.. CLUSTER_NODE=manager-1 bro %INPUT
|
||||
# @TEST-EXEC: sleep 3
|
||||
# @TEST-EXEC: btest-bg-run worker-1 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-1 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-run worker-2 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-2 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 10
|
||||
# @TEST-EXEC: btest-diff manager-1/.stdout
|
||||
|
||||
@TEST-START-FILE cluster-layout.bro
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=37757/tcp, $workers=set("worker-1", "worker-2")],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37760/tcp, $manager="manager-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37761/tcp, $manager="manager-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
redef Log::default_rotation_interval = 0secs;
|
||||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
local r1: Measurement::Reducer = [$stream="test.metric", $apply=set(Measurement::SUM)];
|
||||
Measurement::create([$epoch=1hr,
|
||||
$reducers=set(r1),
|
||||
$threshold_val(key: Measurement::Key, result: Measurement::Result) =
|
||||
{
|
||||
return double_to_count(result["test.metric"]$sum);
|
||||
},
|
||||
$threshold=100,
|
||||
$threshold_crossed(key: Measurement::Key, result: Measurement::Result) =
|
||||
{
|
||||
print fmt("A test metric threshold was crossed with a value of: %.1f", result["test.metric"]$sum);
|
||||
terminate();
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
event remote_connection_closed(p: event_peer)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
event do_metrics(i: count)
|
||||
{
|
||||
# Worker-1 will trigger an intermediate update and then if everything
|
||||
# works correctly, the data from worker-2 will hit the threshold and
|
||||
# should trigger the notice.
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=i]);
|
||||
}
|
||||
|
||||
event remote_connection_handshake_done(p: event_peer)
|
||||
{
|
||||
if ( p$descr == "manager-1" )
|
||||
{
|
||||
if ( Cluster::node == "worker-1" )
|
||||
schedule 0.1sec { do_metrics(1) };
|
||||
if ( Cluster::node == "worker-2" )
|
||||
schedule 0.5sec { do_metrics(99) };
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
# @TEST-EXEC: bro %INPUT
|
||||
# @TEST-EXEC: btest-diff .stdout
|
||||
|
||||
redef enum Notice::Type += {
|
||||
Test_Notice,
|
||||
};
|
||||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
local r1: Measurement::Reducer = [$stream="test.metric", $apply=set(Measurement::SUM)];
|
||||
Measurement::create([$epoch=3secs,
|
||||
$reducers=set(r1),
|
||||
#$threshold_val = Measurement::sum_threshold("test.metric"),
|
||||
$threshold_val(key: Measurement::Key, result: Measurement::Result) =
|
||||
{
|
||||
return double_to_count(result["test.metric"]$sum);
|
||||
},
|
||||
$threshold=5,
|
||||
$threshold_crossed(key: Measurement::Key, result: Measurement::Result) =
|
||||
{
|
||||
local r = result["test.metric"];
|
||||
print fmt("THRESHOLD: hit a threshold value at %.0f for %s", r$sum, Measurement::key2str(key));
|
||||
}
|
||||
]);
|
||||
|
||||
local r2: Measurement::Reducer = [$stream="test.metric", $apply=set(Measurement::SUM)];
|
||||
Measurement::create([$epoch=3secs,
|
||||
$reducers=set(r2),
|
||||
#$threshold_val = Measurement::sum_threshold("test.metric"),
|
||||
$threshold_val(key: Measurement::Key, result: Measurement::Result) =
|
||||
{
|
||||
return double_to_count(result["test.metric"]$sum);
|
||||
},
|
||||
$threshold_series=vector(3,6,800),
|
||||
$threshold_crossed(key: Measurement::Key, result: Measurement::Result) =
|
||||
{
|
||||
local r = result["test.metric"];
|
||||
print fmt("THRESHOLD_SERIES: hit a threshold series value at %.0f for %s", r$sum, Measurement::key2str(key));
|
||||
}
|
||||
]);
|
||||
|
||||
local r3: Measurement::Reducer = [$stream="test.metric", $apply=set(Measurement::SUM)];
|
||||
local r4: Measurement::Reducer = [$stream="test.metric2", $apply=set(Measurement::SUM)];
|
||||
Measurement::create([$epoch=3secs,
|
||||
$reducers=set(r3, r4),
|
||||
$threshold_val(key: Measurement::Key, result: Measurement::Result) =
|
||||
{
|
||||
# Calculate a ratio between sums of two reducers.
|
||||
if ( "test.metric2" in result && "test.metric" in result &&
|
||||
result["test.metric"]$sum > 0 )
|
||||
return double_to_count(result["test.metric2"]$sum / result["test.metric"]$sum);
|
||||
else
|
||||
return 0;
|
||||
},
|
||||
# Looking for metric2 sum to be 5 times the sum of metric
|
||||
$threshold=5,
|
||||
$threshold_crossed(key: Measurement::Key, result: Measurement::Result) =
|
||||
{
|
||||
local thold = result["test.metric2"]$sum / result["test.metric"]$sum;
|
||||
print fmt("THRESHOLD WITH RATIO BETWEEN REDUCERS: hit a threshold value at %.0fx for %s", thold, Measurement::key2str(key));
|
||||
}
|
||||
]);
|
||||
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=3]);
|
||||
Measurement::add_data("test.metric", [$host=6.5.4.3], [$num=2]);
|
||||
Measurement::add_data("test.metric", [$host=7.2.1.5], [$num=1]);
|
||||
Measurement::add_data("test.metric", [$host=1.2.3.4], [$num=3]);
|
||||
Measurement::add_data("test.metric", [$host=7.2.1.5], [$num=1000]);
|
||||
Measurement::add_data("test.metric2", [$host=7.2.1.5], [$num=10]);
|
||||
Measurement::add_data("test.metric2", [$host=7.2.1.5], [$num=1000]);
|
||||
Measurement::add_data("test.metric2", [$host=7.2.1.5], [$num=54321]);
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
# @TEST-SERIALIZE: comm
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager-1 BROPATH=$BROPATH:.. CLUSTER_NODE=manager-1 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-run proxy-1 BROPATH=$BROPATH:.. CLUSTER_NODE=proxy-1 bro %INPUT
|
||||
# @TEST-EXEC: sleep 1
|
||||
# @TEST-EXEC: btest-bg-run worker-1 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-1 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-run worker-2 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-2 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 30
|
||||
# @TEST-EXEC: btest-diff manager-1/metrics.log
|
||||
|
||||
@TEST-START-FILE cluster-layout.bro
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=37757/tcp, $workers=set("worker-1", "worker-2")],
|
||||
["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=37758/tcp, $manager="manager-1", $workers=set("worker-1", "worker-2")],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37760/tcp, $manager="manager-1", $proxy="proxy-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37761/tcp, $manager="manager-1", $proxy="proxy-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
redef Log::default_rotation_interval = 0secs;
|
||||
|
||||
redef enum Metrics::ID += {
|
||||
TEST_METRIC,
|
||||
};
|
||||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
Metrics::add_filter(TEST_METRIC,
|
||||
[$name="foo-bar",
|
||||
$break_interval=3secs]);
|
||||
}
|
||||
|
||||
event remote_connection_closed(p: event_peer)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
global ready_for_data: event();
|
||||
|
||||
redef Cluster::manager2worker_events += /ready_for_data/;
|
||||
|
||||
@if ( Cluster::local_node_type() == Cluster::WORKER )
|
||||
|
||||
event ready_for_data()
|
||||
{
|
||||
Metrics::add_data(TEST_METRIC, [$host=1.2.3.4], 3);
|
||||
Metrics::add_data(TEST_METRIC, [$host=6.5.4.3], 2);
|
||||
Metrics::add_data(TEST_METRIC, [$host=7.2.1.5], 1);
|
||||
}
|
||||
|
||||
@endif
|
||||
|
||||
@if ( Cluster::local_node_type() == Cluster::MANAGER )
|
||||
|
||||
global n = 0;
|
||||
global peer_count = 0;
|
||||
|
||||
event Metrics::log_metrics(rec: Metrics::Info)
|
||||
{
|
||||
n = n + 1;
|
||||
if ( n == 3 )
|
||||
{
|
||||
terminate_communication();
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
event remote_connection_handshake_done(p: event_peer)
|
||||
{
|
||||
print p;
|
||||
peer_count = peer_count + 1;
|
||||
if ( peer_count == 3 )
|
||||
{
|
||||
event ready_for_data();
|
||||
}
|
||||
}
|
||||
|
||||
@endif
|
|
@ -1,16 +0,0 @@
|
|||
# @TEST-EXEC: bro %INPUT
|
||||
# @TEST-EXEC: btest-diff metrics.log
|
||||
|
||||
redef enum Metrics::ID += {
|
||||
TEST_METRIC,
|
||||
};
|
||||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
Metrics::add_filter(TEST_METRIC,
|
||||
[$name="foo-bar",
|
||||
$break_interval=3secs]);
|
||||
Metrics::add_data(TEST_METRIC, [$host=1.2.3.4], 3);
|
||||
Metrics::add_data(TEST_METRIC, [$host=6.5.4.3], 2);
|
||||
Metrics::add_data(TEST_METRIC, [$host=7.2.1.5], 1);
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
# @TEST-SERIALIZE: comm
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager-1 BROPATH=$BROPATH:.. CLUSTER_NODE=manager-1 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-run proxy-1 BROPATH=$BROPATH:.. CLUSTER_NODE=proxy-1 bro %INPUT
|
||||
# @TEST-EXEC: sleep 1
|
||||
# @TEST-EXEC: btest-bg-run worker-1 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-1 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-run worker-2 BROPATH=$BROPATH:.. CLUSTER_NODE=worker-2 bro %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 20
|
||||
# @TEST-EXEC: btest-diff manager-1/notice.log
|
||||
|
||||
@TEST-START-FILE cluster-layout.bro
|
||||
redef Cluster::nodes = {
|
||||
["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=37757/tcp, $workers=set("worker-1")],
|
||||
["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=37758/tcp, $manager="manager-1", $workers=set("worker-1")],
|
||||
["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37760/tcp, $manager="manager-1", $proxy="proxy-1", $interface="eth0"],
|
||||
["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=37761/tcp, $manager="manager-1", $proxy="proxy-1", $interface="eth1"],
|
||||
};
|
||||
@TEST-END-FILE
|
||||
|
||||
redef Log::default_rotation_interval = 0secs;
|
||||
|
||||
redef enum Notice::Type += {
|
||||
Test_Notice,
|
||||
};
|
||||
|
||||
redef enum Metrics::ID += {
|
||||
TEST_METRIC,
|
||||
};
|
||||
|
||||
event bro_init() &priority=5
|
||||
{
|
||||
Metrics::add_filter(TEST_METRIC,
|
||||
[$name="foo-bar",
|
||||
$break_interval=1hr,
|
||||
$note=Test_Notice,
|
||||
$notice_threshold=100,
|
||||
$log=T]);
|
||||
}
|
||||
|
||||
event remote_connection_closed(p: event_peer)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
|
||||
@if ( Cluster::local_node_type() == Cluster::MANAGER )
|
||||
|
||||
event Notice::log_notice(rec: Notice::Info)
|
||||
{
|
||||
terminate_communication();
|
||||
terminate();
|
||||
}
|
||||
|
||||
@endif
|
||||
|
||||
@if ( Cluster::local_node_type() == Cluster::WORKER )
|
||||
|
||||
event do_metrics(i: count)
|
||||
{
|
||||
# Worker-1 will trigger an intermediate update and then if everything
|
||||
# works correctly, the data from worker-2 will hit the threshold and
|
||||
# should trigger the notice.
|
||||
Metrics::add_data(TEST_METRIC, [$host=1.2.3.4], i);
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
if ( Cluster::node == "worker-1" )
|
||||
schedule 2sec { do_metrics(99) };
|
||||
if ( Cluster::node == "worker-2" )
|
||||
event do_metrics(1);
|
||||
}
|
||||
|
||||
@endif
|
35
testing/btest/scripts/base/utils/queue.test
Normal file
35
testing/btest/scripts/base/utils/queue.test
Normal file
|
@ -0,0 +1,35 @@
|
|||
# @TEST-EXEC: bro -b %INPUT > output
|
||||
# @TEST-EXEC: btest-diff output
|
||||
|
||||
# This is loaded by default
|
||||
@load base/utils/queue
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local q = Queue::init([$max_len=2]);
|
||||
Queue::push(q, 1);
|
||||
Queue::push(q, 2);
|
||||
Queue::push(q, 3);
|
||||
Queue::push(q, 4);
|
||||
local test1 = Queue::get_cnt_vector(q);
|
||||
for ( i in test1 )
|
||||
print fmt("This is a get_cnt_vector test: %d", test1[i]);
|
||||
|
||||
local test2 = Queue::get_str_vector(q);
|
||||
for ( i in test2 )
|
||||
print fmt("This is a get_str_vector test: %s", test2[i]);
|
||||
|
||||
local test_val = Queue::pop(q);
|
||||
print fmt("Testing pop: %s", test_val);
|
||||
print fmt("Length after pop: %d", Queue::len(q));
|
||||
|
||||
local q2 = Queue::init([]);
|
||||
Queue::push(q2, "test 1");
|
||||
Queue::push(q2, "test 2");
|
||||
Queue::push(q2, "test 2");
|
||||
Queue::push(q2, "test 1");
|
||||
print fmt("Size of q2: %d", Queue::len(q2));
|
||||
local test3: vector of string = Queue::get_str_vector(q2);
|
||||
for ( i in test3 )
|
||||
print fmt("String queue value: %s", test3[i]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue