-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiler.bro
77 lines (67 loc) · 2.52 KB
/
profiler.bro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
##############
# HARD LINK BEWTEEN GIT VERSION AND THE VERSTION @ /usr/local/bro/share/bro/site
##############
module profiler;
export {
redef enum Log::ID += { ci_results };
type script_results: record
{
time_stamp: time &log;
hits: double &log;
script_name: string &log;
pass_or_fail: string &log;
};
global test_vector: vector of string;
global log_event: function(name: string,hits: double);
global init_test: function(test_name: string, threshold: double);
global test_hit: function(stream_name: string);
global pass_counter: int;
}
event bro_init()
{
print "CI Started";
Log::create_stream(profiler::ci_results, [$columns=script_results]);
}
function init_test(test_name: string, threshold: double)
{
test_vector[0]= test_name;
local r1 = SumStats::Reducer($stream= test_name, $apply=set(SumStats::SUM));
SumStats::create([$name = test_vector[0],
$epoch = 1min,
$reducers = set(r1),
$threshold = threshold,
$threshold_val(key: SumStats::Key, result: SumStats::Result) =
{
print result[test_vector[0]]$sum;
return result[test_vector[0]]$sum;
},
$threshold_crossed(key: SumStats::Key, result: SumStats::Result) =
{
pass_counter = 0;
print("THRESHOLD CROSSEED");
log_event(test_vector[0],result[test_vector[0]]$sum);
}]);
}
#We need to call this method for every
function log_event(name: string, hits: double)
{
local p_or_f = "FAIL";
if (pass_counter == 0)
{
p_or_f = "PASS";
}
local now = network_time();
local script_name = name;
local rec0: script_results = [$time_stamp = now,
$hits = hits,
$script_name = script_name,
$pass_or_fail = p_or_f
];
Log::write(ci_results,rec0);
}
function test_hit(stream_name: string)
{
SumStats::observe(stream_name,
SumStats::Key(),
SumStats::Observation($num=1));
}