Skip to content

Instantly share code, notes, and snippets.

@KrisBuytaert
Created January 22, 2015 09:58
Show Gist options
  • Save KrisBuytaert/90a99bfea05b013bc43d to your computer and use it in GitHub Desktop.
Save KrisBuytaert/90a99bfea05b013bc43d to your computer and use it in GitHub Desktop.
curator++
cron { 'Clean_verbose_older_than_4_weeks_28 days':
command => '/usr/local/bin/clean_content.sh -d 28 -l verbose',
minute => '0',
hour => '5',
}
cron { 'Clean_debug_older_than_4_weeks_28_days':
command => '/usr/local/bin/clean_content.sh -d 28 -l debug',
minute => '10',
hour => '5',
}
cron { 'Clean_info_older_than_16_weeks_112_days':
command => '/usr/local/bin/clean_content.sh -d 112 -l info',
minute => '20',
hour => '5',
}
cron { 'Clean_all_older_than_1_year_365_days':
command => '/usr/local/bin/purge_elasticsearch.sh -d 365',
minute => '30',
hour => '5',
}
#!/bin/bash
# elasticsearch cleanup script
ES_BASEDIR='/var/lib/elasticsearch/asimov/nodes/0/indices'
ES_HTTP='http://localhost:9200'
RETENTION_PERIOD='365'
LOG_REDIRECT='&>/dev/null'
LOGLEVEL='clean'
usage(){
cat <<EOF
usage: $0 <options>
-s loglevel to clean
-d number of days to keep content
-h show this help message
-p set path to elasticsearch index dir
-u set url to elasticsearch http interface
-v verbose
EOF
}
while getopts 'l:d:hp:u:v' OPTION
do
case $OPTION in
d) RETENTION_PERIOD=$OPTARG;;
h) usage && exit 0;;
l) LOGLEVEL=$OPTARG;;
p) ES_BASEDIR=$OPTARG;;
u) ES_HTTP=$OPTARG;;
v) unset LOG_REDIRECT;;
esac
done
cd $ES_BASEDIR
INDICES=`find -maxdepth 1 -type d -ctime +$RETENTION_PERIOD | grep -v kibana |sed 's/\.\///'`
for INDEX in $INDICES; do
if [ -z "$LOG_REDIRECT" ];then
xcurl -s -XDELETE $ES_HTTP/$INDEX -d'
{"query": {"term": {
"level": {
"value": \""$LOGLEVEL"\"
}
}}}'
else
curl -s -XDELETE $ES_HTTP/$INDEX/_query -d "
{\"query\": {\"term\": {
\"level\": {
\"value\": \"$LOGLEVEL\"
}
}}}"
&>/dev/null
fi
done
@pulecp
Copy link

pulecp commented Jun 4, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment