Add page and email_admin to hostnames extension

This commit is contained in:
Vlad Grigorescu 2021-04-23 10:05:34 -05:00
parent 672504e265
commit 3bb4a35200
3 changed files with 33 additions and 4 deletions

View file

@ -33,3 +33,8 @@ hook notice(n: Notice::Info) &priority=-5
email_notice_to(n, email, T); email_notice_to(n, email, T);
} }
} }
# If hostnames.zeek was loaded first, add ourselves
@ifdef ( email_with_hostnames_types )
redef email_with_hostnames_types += { ACTION_EMAIL_ADMIN };
@endif

View file

@ -22,3 +22,8 @@ hook notice(n: Notice::Info) &priority=-5
if ( ACTION_PAGE in n$actions ) if ( ACTION_PAGE in n$actions )
email_notice_to(n, mail_page_dest, F); email_notice_to(n, mail_page_dest, F);
} }
# If hostnames.zeek was loaded first, add ourselves
@ifdef ( email_with_hostnames_types )
redef email_with_hostnames_types += { ACTION_PAGE };
@endif

View file

@ -1,12 +1,20 @@
##! Loading this script extends the :zeek:enum:`Notice::ACTION_EMAIL` action ##! Loading this script extends the emails that Zeek sends
##! by appending to the email the hostnames associated with ##! by appending to the email the hostnames associated with
##! :zeek:type:`Notice::Info`'s *src* and *dst* fields as determined by a ##! :zeek:type:`Notice::Info`'s *src* and *dst* fields as determined by a
##! DNS lookup. ##! DNS lookup. This is enabled for the :zeek:enum:`Notice::ACTION_EMAIL`
##! action by default, and :zeek:enum:`Notice::ACTION_EMAIL_ADMIN` and
##! :zeek:enum:`Notice::ACTION_PAGE` if their scripts are loaded.
@load base/frameworks/notice/main @load base/frameworks/notice/main
module Notice; module Notice;
export {
## The Notice action types whose e-mails will be extended with hostnames.
## :zeek:see:`Notice::Action`
option email_with_hostnames_types: set[Notice::Action] = {ACTION_EMAIL};
}
# We have to store references to the notices here because the when statement # We have to store references to the notices here because the when statement
# clones the frame which doesn't give us access to modify values outside # clones the frame which doesn't give us access to modify values outside
# of it's execution scope. (we get a clone of the notice instead of a # of it's execution scope. (we get a clone of the notice instead of a
@ -19,7 +27,8 @@ hook notice(n: Notice::Info) &priority=10
return; return;
# This should only be done for notices that are being sent to email. # This should only be done for notices that are being sent to email.
if ( ACTION_EMAIL !in n$actions ) # We calculate the intersection, and don't do anything if it's empty.
if ( |n$actions & email_with_hostnames_types| == 0 )
return; return;
# I'm not recovering gracefully from the when statements because I want # I'm not recovering gracefully from the when statements because I want
@ -50,3 +59,13 @@ hook notice(n: Notice::Info) &priority=10
} }
} }
} }
# If page.zeek was loaded first, add that action
@ifdef ( ACTION_PAGE )
redef email_with_hostnames_types += { ACTION_PAGE };
@endif
# If email_admin.zeek was loaded first, add that action
@ifdef ( ACTION_EMAIL_ADMIN )
redef email_with_hostnames_types += { ACTION_EMAIL_ADMIN };
@endif