Created
January 22, 2015 09:58
-
-
Save KrisBuytaert/90a99bfea05b013bc43d to your computer and use it in GitHub Desktop.
curator++
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
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', | |
} |
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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
check my fixies ;-)
https://gist.github.com/pulecp/3dfb53153c9cba517c86