# $Id: netstats.bro,v 1.1 2003/01/16 00:24:45 vern Exp $

@load alert

redef enum Alert += {
	DroppedPackets,	# Bro reported packets dropped by the packet filter
};

global last_stat: net_stats;
global last_stat_time: time;
global have_stats = F;

event net_stats_update(t: time, ns: net_stats)
	{
	if ( have_stats )
		{
		local new_dropped = ns$pkts_dropped - last_stat$pkts_dropped;
		if ( new_dropped > 0 )
			{
			local new_recvd = ns$pkts_recvd - last_stat$pkts_recvd;
			ALERT([$alert=DroppedPackets,
				$msg=fmt("dropped %d packets out of %d received",
					new_dropped, new_recvd)]);
			}
		}
	else
		have_stats = T;

	last_stat = ns;
	last_stat_time = t;
	}
