forked from sethhall/bro-scripts
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhttp-size-metrics.bro
45 lines (36 loc) · 907 Bytes
/
http-size-metrics.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
@load base/frameworks/metrics
@load base/protocols/http
@load base/protocols/ssl
@load base/utils/site
redef enum Metrics::ID += {
HTTP_REQUEST_SIZE_BY_HOST,
};
redef record connection += {
resp_hostname: string &optional;
};
event bro_init()
{
Metrics::add_filter(HTTP_REQUEST_SIZE_BY_HOST,
[$name="all",
$break_interval=600secs
]);
}
event connection_finished(c: connection)
{
if (c?$resp_hostname) {
local size = c$orig$num_bytes_ip + c$resp$num_bytes_ip;
Metrics::add_data(HTTP_REQUEST_SIZE_BY_HOST, [$str=c$resp_hostname], size);
}
}
event http_header (c: connection, is_orig: bool, name: string, value: string)
{
if(name == "HOST") {
c$resp_hostname = value;
}
}
event ssl_established(c: connection)
{
if(c?$ssl && c$ssl?$server_name) {
c$resp_hostname = c$ssl$server_name;
}
}