Skip to content

Commit 973a3d9

Browse files
authored
Add --all flag to send all log types (#10)
1 parent 819e290 commit 973a3d9

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

zeek_log_transport.sh

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22

3-
#Version 0.3.9
3+
#Version 0.4.0
44

5-
#This sends any bro/zeek logs less than three days old to the rita/aihunter server. It only sends logs of these types:
6-
#conn., dns., http., ssl., x509., and known_certs. Any logs that already exist on the target system are not retransferred.
5+
#This sends any bro/zeek logs less than three days old to the rita/aihunter server.
6+
#Any logs that already exist on the target system are not retransferred.
77

88
#Before using this, run these on the rita/aihunter server (use zeek in place of bro if necesssary):
99
#sudo adduser dataimport
@@ -57,24 +57,22 @@ status () {
5757

5858

5959
usage () {
60-
echo 'Usage: '"$0"' [--localdir /local/top/dir/] [--dest where_to_ssh] [--remotedir /remote/top/dir/] [--rsyncparams '"' --aparam --anotherparam '"']' >&2
61-
echo 'The optional --dest can be a hostname, IP, user@hostname, user@ip, or any label in an ~/.ssh/config stanza' >&2
62-
echo 'If left off, we use the "Location" field from /etc/rita/agent.yaml' >&2
63-
echo 'The user@... format is discouraged - we want to use dataimport@... on the remote server.' >&2
64-
echo '' >&2
65-
echo 'The optional --localdir is where the Bro/Zeek logs can be found on this system system.' >&2
66-
echo 'If you look in this directory, it should contain at least a directory or symlink called current .' >&2
67-
echo 'By default we will look in common locations for this directory tree.' >&2
68-
echo '' >&2
69-
echo 'The optional --remotedir is where you want the Bro/Zeek logs to end up on the target system.' >&2
70-
echo 'If left off, it will be /opt/bro/remotelogs/$my_id/ or /opt/zeek/remotelogs/$my_id/' >&2
71-
echo '' >&2
72-
echo 'The optional --rsyncparams allows you to specify parameters for rsync. MAKE SURE to enclose the entire block in a pair of single quotes. Suggestions:' >&2
73-
echo ' --bwlimit=NNN #Limit bandwidth used to NNN kilobytes/sec' >&2
74-
echo ' -v #Verbose; list out the files being transferred, discouraged if running from cron' >&2
75-
echo ' -q #Turn off any messages that are not errors, encouraged if running from cron' >&2
76-
echo ' --dry-run #Test, do not actually transfer files' >&2
77-
echo ' DO NOT add --compress ; the files we are sending are already compressed.' >&2
60+
cat <<HEREDOC >&2
61+
Usage: $0 [--all] [--dest where_to_ssh] [--localdir /local/top/dir/] [--remotedir /remote/top/dir/] [--rsyncparams '--aparam --anotherparam']
62+
63+
Options:
64+
--all Sync all Zeek log types instead of the default subset.
65+
--dest SSH destination target (e.g hostname, IP, user@hostname, user@ip)
66+
--localdir Location of Zeek logs on local system. (default: searches common locations)
67+
--remotedir Location of Zeek logs on remote system. (default: /opt/zeek/remotelogs/<sensorname>/)
68+
--rsyncparams Allows specifying parameters for rsync. Enclose in a pair of single quotes.
69+
70+
Suggestions:
71+
--bwlimit=NNN Limit bandwidth used to NNN kilobytes/sec
72+
-v Verbose; list out the files being transferred
73+
-q Turn off any messages that are not errors
74+
-n Dry run, do not actually transfer files
75+
HEREDOC
7876
exit
7977
}
8078

@@ -102,8 +100,14 @@ else
102100
nice_me=' nice -n 19 '
103101
fi
104102

103+
#Default log types to send
104+
log_type_regex='(conn|dns|http|ssl|x509|known_certs|capture_loss|notice|stats)'
105+
106+
#Parse command line flags
105107
while [ -n "$1" ]; do
106-
if [ "z$1" = "z--localdir" -a -e "$2" ]; then
108+
if [ "z$1" = "z--all" ]; then
109+
log_type_regex='.' #dot matches all log types
110+
elif [ "z$1" = "z--localdir" -a -e "$2" ]; then
107111
local_tld="$2"
108112
shift
109113
elif [ "z$1" = "z--remotedir" -a -n "$2" ]; then
@@ -117,7 +121,6 @@ while [ -n "$1" ]; do
117121
#No "@" symbol in target system, force username to $default_user_on_aihunter
118122
aih_location="${default_user_on_aihunter}@${2}"
119123
fi
120-
121124
shift
122125
elif [ "z$1" = "z--rsyncparams" -a -n "$2" ]; then
123126
rsyncparams="$2"
@@ -238,7 +241,7 @@ status "Preparing remote directories"
238241
ssh $extra_ssh_params "$aih_location" "mkdir -p ${remote_top_dir}/$today/ ${remote_top_dir}/$yesterday/ ${remote_top_dir}/$twoda/ ${remote_top_dir}/$threeda/ ${remote_top_dir}/current/"
239242

240243
cd "$local_tld" || fail "Unable to change to $local_tld"
241-
send_candidates=`find . -type f -mtime -3 -iname '*.gz' | egrep '(conn|dns|http|ssl|x509|known_certs|capture_loss|notice|stats)' | sort -u`
244+
send_candidates=`find . -type f -mtime -3 -iname '*.gz' | egrep "$log_type_regex" | sort -u`
242245
if [ ${#send_candidates} -eq 0 ]; then
243246
echo
244247
printf "WARNING: No logs found, if your log directory is not $local_tld please use the flag: --localdir [bro_zeek_log_directory]"

0 commit comments

Comments
 (0)