Last active
April 28, 2016 08:17
-
-
Save markuskont/2484ce30f548794b72ebbb9648558457 to your computer and use it in GitHub Desktop.
Delete moloch session indices as per retention period in days when indices are created hourly. Very hacky and quick solution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RETAINDAYS=7 | |
HOST="localhost" | |
PORT=9200 | |
INDICES=`curl -ss -XGET $HOST:$PORT/_cat/indices?v | awk -F " " '{print $3}' | grep sessions | sort -n` | |
TODAY=`date +"%y%m%d"` | |
for index in $INDICES; do | |
DATE=`echo $index | perl -ne 'if (m/sessions-(\d+)h\d+/){print "$1\n"}'` | |
DIFF=$(($TODAY - $DATE)) | |
if [ $DIFF -gt $RETAINDAYS ] | |
then | |
curl -XDELETE $HOST:$PORT/$index | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment