mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 17:22:49 +01:00
Merge pull request #195 from Security-Onion-Solutions/feature/zeek_clean
add Zeek clean script
This commit is contained in:
63
salt/bro/cron/zeek_clean
Normal file
63
salt/bro/cron/zeek_clean
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
# Delete Zeek Logs based on defined CRIT_DISK_USAGE value
|
||||
|
||||
# Copyright 2014,2015,2016,2017,2018, 2019 Security Onion Solutions, LLC
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
clean () {
|
||||
|
||||
SENSOR_DIR='/nsm'
|
||||
CRIT_DISK_USAGE=90
|
||||
CUR_USAGE=$(df -P $SENSOR_DIR | tail -1 | awk '{print $5}' | tr -d %)
|
||||
LOG="/nsm/bro/logs/zeek_clean.log"
|
||||
|
||||
if [ "$CUR_USAGE" -gt "$CRIT_DISK_USAGE" ]; then
|
||||
while [ "$CUR_USAGE" -gt "$CRIT_DISK_USAGE" ];
|
||||
do
|
||||
TODAY=$(date -u "+%Y-%m-%d")
|
||||
|
||||
# find the oldest Zeek logs directory and exclude today
|
||||
OLDEST_DIR=$(ls /nsm/bro/logs/ | grep -v "current" | grep -v "stats" | grep -v "packetloss" | grep -v "zeek_clean" | sort | grep -v $TODAY | head -n 1)
|
||||
if [ -z "$OLDEST_DIR" -o "$OLDEST_DIR" == ".." -o "$OLDEST_DIR" == "." ]
|
||||
then
|
||||
echo "$(date) - No old Zeek logs available to clean up in /nsm/bro/logs/" >> $LOG
|
||||
exit 0
|
||||
else
|
||||
echo "$(date) - Removing directory: /nsm/bro/logs/$OLDEST_DIR" >> $LOG
|
||||
rm -rf /nsm/bro/logs/"$OLDEST_DIR"
|
||||
fi
|
||||
|
||||
# find oldest files in extracted directory and exclude today
|
||||
OLDEST_EXTRACT=$(find /nsm/bro/extracted -type f -printf '%T+ %p\n' 2>/dev/null | sort | grep -v $TODAY | head -n 1)
|
||||
if [ -z "$OLDEST_EXTRACT" -o "$OLDEST_EXTRACT" == ".." -o "$OLDEST_EXTRACT" == "." ]
|
||||
then
|
||||
echo "$(date) - No old extracted files available to clean up in /nsm/bro/extracted/" >> $LOG
|
||||
else
|
||||
OLDEST_EXTRACT_DATE=`echo $OLDEST_EXTRACT | awk '{print $1}' | cut -d+ -f1`
|
||||
OLDEST_EXTRACT_FILE=`echo $OLDEST_EXTRACT | awk '{print $2}'`
|
||||
echo "$(date) - Removing extracted files for $OLDEST_EXTRACT_DATE" >> $LOG
|
||||
find /nsm/bro/extracted -type f -printf '%T+ %p\n' | grep $OLDEST_EXTRACT_DATE | awk '{print $2}' |while read FILE
|
||||
do
|
||||
echo "$(date) - Removing extracted file: $FILE" >> $LOG
|
||||
rm -f "$FILE"
|
||||
done
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "$(date) - CRIT_DISK_USAGE value of $CRIT_DISK_USAGE not greater than current usage of $CUR_USAGE..." >> $LOG
|
||||
fi
|
||||
}
|
||||
|
||||
clean
|
||||
@@ -79,6 +79,21 @@ plcronscript:
|
||||
- source: salt://bro/cron/packetloss.sh
|
||||
- mode: 755
|
||||
|
||||
zeekcleanscript:
|
||||
file.managed:
|
||||
- name: /usr/local/bin/zeek_clean
|
||||
- source: salt://bro/cron/zeek_clean
|
||||
- mode: 755
|
||||
|
||||
/usr/local/bin/zeek_clean:
|
||||
cron.present:
|
||||
- user: root
|
||||
- minute: '*'
|
||||
- hour: '*'
|
||||
- daymonth: '*'
|
||||
- month: '*'
|
||||
- dayweek: '*'
|
||||
|
||||
/usr/local/bin/packetloss.sh:
|
||||
cron.present:
|
||||
- user: root
|
||||
|
||||
Reference in New Issue
Block a user