forked from sethhall/bro-scripts
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmetrics.smtp-ext.bro
52 lines (45 loc) · 1.39 KB
/
metrics.smtp-ext.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
#output something like this
#smtp_metrics time=1261506588.216565 total=54 inbound=49 outbound=5 inbound_err=17 outbound_err=0
@load global-ext
@load smtp-ext
export {
global smtp_metrics: table[string] of count &default=0; #&synchronized;
global smtp_metrics_interval = +60sec;
const smtp_metrics_log = open_log_file("smtp-ext-metrics");
}
event smtp_write_stats()
{
if (smtp_metrics["total"]!=0)
{
print smtp_metrics_log, fmt("smtp_metrics time=%.6f total=%d inbound=%d outbound=%d inbound_err=%d outbound_err=%d",
network_time(),
smtp_metrics["total"],
smtp_metrics["inbound"],
smtp_metrics["outbound"],
smtp_metrics["inbound_err"],
smtp_metrics["outbound_err"]);
clear_table(smtp_metrics);
}
schedule smtp_metrics_interval { smtp_write_stats() };
}
event bro_init()
{
set_buf(smtp_metrics_log, F);
schedule smtp_metrics_interval { smtp_write_stats() };
}
event smtp_ext(id: conn_id, si: smtp_ext_session_info) &priority=-10
{
++smtp_metrics["total"];
if(is_local_addr(id$orig_h))
{
++smtp_metrics["outbound"];
if(si$last_reply!="")
++smtp_metrics["outbound_err"];
}
else
{
++smtp_metrics["inbound"];
if(si$last_reply!="")
++smtp_metrics["inbound_err"];
}
}