The silliest, tiniest little whitespace fixes.

This commit is contained in:
Seth Hall 2012-01-04 13:37:07 -05:00
parent 0b8428d1bb
commit adfbed8e56

View file

@ -10,19 +10,19 @@ module Notice;
export { export {
## Activate pretty-printed alarm summaries. ## Activate pretty-printed alarm summaries.
const pretty_print_alarms = T &redef; const pretty_print_alarms = T &redef;
## Address to send the pretty-printed reports to. Default if not set is ## Address to send the pretty-printed reports to. Default if not set is
## :bro:id:`Notice::mail_dest`. ## :bro:id:`Notice::mail_dest`.
const mail_dest_pretty_printed = "" &redef; const mail_dest_pretty_printed = "" &redef;
## If an address from one of these networks is reported, we mark ## If an address from one of these networks is reported, we mark
## the entry with an addition quote symbol (i.e., ">"). Many MUAs ## the entry with an addition quote symbol (i.e., ">"). Many MUAs
## then highlight such lines differently. ## then highlight such lines differently.
global flag_nets: set[subnet] &redef; global flag_nets: set[subnet] &redef;
## Function that renders a single alarm. Can be overidden. ## Function that renders a single alarm. Can be overidden.
global pretty_print_alarm: function(out: file, n: Info) &redef; global pretty_print_alarm: function(out: file, n: Info) &redef;
## Force generating mail file, even if reading from traces or no mail ## Force generating mail file, even if reading from traces or no mail
## destination is defined. This is mainly for testing. ## destination is defined. This is mainly for testing.
global force_email_summaries = F &redef; global force_email_summaries = F &redef;
@ -38,7 +38,7 @@ function want_pp() : bool
{ {
if ( force_email_summaries ) if ( force_email_summaries )
return T; return T;
return (pretty_print_alarms && ! reading_traces() return (pretty_print_alarms && ! reading_traces()
&& (mail_dest != "" || mail_dest_pretty_printed != "")); && (mail_dest != "" || mail_dest_pretty_printed != ""));
} }
@ -48,7 +48,7 @@ function pp_open()
{ {
if ( pp_alarms_open ) if ( pp_alarms_open )
return; return;
pp_alarms_open = T; pp_alarms_open = T;
pp_alarms = open(pp_alarms_name); pp_alarms = open(pp_alarms_name);
} }
@ -58,17 +58,17 @@ function pp_send(rinfo: Log::RotationInfo)
{ {
if ( ! pp_alarms_open ) if ( ! pp_alarms_open )
return; return;
write_file(pp_alarms, "\n\n--\n[Automatically generated]\n\n"); write_file(pp_alarms, "\n\n--\n[Automatically generated]\n\n");
close(pp_alarms); close(pp_alarms);
pp_alarms_open = F; pp_alarms_open = F;
local from = strftime("%H:%M:%S", rinfo$open); local from = strftime("%H:%M:%S", rinfo$open);
local to = strftime("%H:%M:%S", rinfo$close); local to = strftime("%H:%M:%S", rinfo$close);
local subject = fmt("Alarm summary from %s-%s", from, to); local subject = fmt("Alarm summary from %s-%s", from, to);
local dest = mail_dest_pretty_printed != "" ? mail_dest_pretty_printed local dest = mail_dest_pretty_printed != "" ? mail_dest_pretty_printed
: mail_dest; : mail_dest;
if ( dest == "" ) if ( dest == "" )
# No mail destination configured, just leave the file alone. This is mainly for # No mail destination configured, just leave the file alone. This is mainly for
# testing. # testing.
@ -90,7 +90,7 @@ function pp_postprocessor(info: Log::RotationInfo): bool
{ {
if ( want_pp() ) if ( want_pp() )
pp_send(info); pp_send(info);
return T; return T;
} }
@ -98,7 +98,7 @@ event bro_init()
{ {
if ( ! want_pp() ) if ( ! want_pp() )
return; return;
# This replaces the standard non-pretty-printing filter. # This replaces the standard non-pretty-printing filter.
Log::add_filter(Notice::ALARM_LOG, Log::add_filter(Notice::ALARM_LOG,
[$name="alarm-mail", $writer=Log::WRITER_NONE, [$name="alarm-mail", $writer=Log::WRITER_NONE,
@ -110,13 +110,13 @@ event notice(n: Notice::Info) &priority=-5
{ {
if ( ! want_pp() ) if ( ! want_pp() )
return; return;
if ( ACTION_ALARM !in n$actions ) if ( ACTION_ALARM !in n$actions )
return; return;
if ( ! pp_alarms_open ) if ( ! pp_alarms_open )
pp_open(); pp_open();
pretty_print_alarm(pp_alarms, n); pretty_print_alarm(pp_alarms, n);
} }
@ -126,12 +126,12 @@ function do_msg(out: file, n: Info, line1: string, line2: string, line3: string,
@ifdef ( Notice::ACTION_ADD_GEODATA ) # Make tests happy, cyclic dependency. @ifdef ( Notice::ACTION_ADD_GEODATA ) # Make tests happy, cyclic dependency.
if ( n?$remote_location && n$remote_location?$country_code ) if ( n?$remote_location && n$remote_location?$country_code )
country = fmt(" (remote location %s)", n$remote_location$country_code); country = fmt(" (remote location %s)", n$remote_location$country_code);
@endif @endif
line1 = cat(line1, country); line1 = cat(line1, country);
local resolved = ""; local resolved = "";
if ( host1 != 0.0.0.0 ) if ( host1 != 0.0.0.0 )
resolved = fmt("%s # %s = %s", resolved, host1, name1); resolved = fmt("%s # %s = %s", resolved, host1, name1);
@ -151,60 +151,58 @@ function do_msg(out: file, n: Info, line1: string, line2: string, line3: string,
function pretty_print_alarm(out: file, n: Info) function pretty_print_alarm(out: file, n: Info)
{ {
local pdescr = ""; local pdescr = "";
@if ( Cluster::is_enabled() ) @if ( Cluster::is_enabled() )
pdescr = "local"; pdescr = "local";
if ( n?$src_peer ) if ( n?$src_peer )
pdescr = n$src_peer?$descr ? n$src_peer$descr : fmt("%s", n$src_peer$host); pdescr = n$src_peer?$descr ? n$src_peer$descr : fmt("%s", n$src_peer$host);
pdescr = fmt("<%s> ", pdescr); pdescr = fmt("<%s> ", pdescr);
@endif @endif
local msg = fmt( "%s%s", pdescr, n$msg); local msg = fmt( "%s%s", pdescr, n$msg);
local who = ""; local who = "";
local h1 = 0.0.0.0; local h1 = 0.0.0.0;
local h2 = 0.0.0.0; local h2 = 0.0.0.0;
local orig_p = ""; local orig_p = "";
local resp_p = ""; local resp_p = "";
if ( n?$id ) if ( n?$id )
{ {
h1 = n$id$orig_h; h1 = n$id$orig_h;
h2 = n$id$resp_h; h2 = n$id$resp_h;
who = fmt("%s:%s -> %s:%s", h1, n$id$orig_p, h2, n$id$resp_p); who = fmt("%s:%s -> %s:%s", h1, n$id$orig_p, h2, n$id$resp_p);
} }
else if ( n?$src && n?$dst ) else if ( n?$src && n?$dst )
{ {
h1 = n$src; h1 = n$src;
h2 = n$dst; h2 = n$dst;
who = fmt("%s -> %s", h1, h2); who = fmt("%s -> %s", h1, h2);
} }
else if ( n?$src ) else if ( n?$src )
{ {
h1 = n$src; h1 = n$src;
who = fmt("%s%s", h1, (n?$p ? fmt(":%s", n$p) : "")); who = fmt("%s%s", h1, (n?$p ? fmt(":%s", n$p) : ""));
} }
if ( n?$uid ) if ( n?$uid )
who = fmt("%s (uid %s)", who, n$uid ); who = fmt("%s (uid %s)", who, n$uid );
local flag = (h1 in flag_nets || h2 in flag_nets); local flag = (h1 in flag_nets || h2 in flag_nets);
local line1 = fmt(">%s %D %s %s", (flag ? ">" : " "), network_time(), n$note, who); local line1 = fmt(">%s %D %s %s", (flag ? ">" : " "), network_time(), n$note, who);
local line2 = fmt(" %s", msg); local line2 = fmt(" %s", msg);
local line3 = n?$sub ? fmt(" %s", n$sub) : ""; local line3 = n?$sub ? fmt(" %s", n$sub) : "";
if ( h1 == 0.0.0.0 ) if ( h1 == 0.0.0.0 )
{ {
do_msg(out, n, line1, line2, line3, h1, "", h2, ""); do_msg(out, n, line1, line2, line3, h1, "", h2, "");
return; return;
} }
if ( reading_traces() ) if ( reading_traces() )
{ {
do_msg(out, n, line1, line2, line3, h1, "<skipped>", h2, "<skipped>"); do_msg(out, n, line1, line2, line3, h1, "<skipped>", h2, "<skipped>");