Skip to content

Commit

Permalink
Merge pull request #165 from pgraziano/update-check
Browse files Browse the repository at this point in the history
update script to accept curation day count as argument
  • Loading branch information
twaldrop authored May 29, 2018
2 parents 6c130bc + 32f276e commit 09b40b7
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions sensu/plugins/check-logstash-index-dates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# Checks to ensure curator has deleted old indexes.
#

INDEX_MAX_AGE=$1
if [[ -z $INDEX_MAX_AGE ]]; then
echo -e "USAGE: $0 INDEX_MAX_AGE\nERROR: Missing INDEX_MAX_AGE argument"
exit 2
fi

declare -a ERR_MSGS

# joins elements of an array with the given character
Expand All @@ -27,23 +33,18 @@ function find_future_indexes {

# checks for old indexes that were not curated
function find_old_indexes {
for file in /etc/elasticsearch/delete_*.yml; do
INDEX_PREFIX=$(awk '/value/ {print $2}' $file | sed 's/-$//')
CUTOFF_DAYS_AGO=$(awk '/unit_count/ {print $2}' $file)
CUTOFF_DATE=`date --date="$(( $CUTOFF_DAYS_AGO + 1 )) day ago" +%Y.%m.%d`

count=0
for i in $(curl -s 'localhost:9200/_cat/indices' | grep -E "$INDEX_PREFIX-[0-9]{4}.[0-9]{2}.[0-9]{2}" | awk '{print $3}' | sort -n); do
if [[ ${i##$INDEX_PREFIX-} < $CUTOFF_DATE ]]; then
count=$(( $count + 1 ))
#echo "$i is older than $CUTOFF_DATE"
fi
done

if [[ $count -gt 0 ]]; then
ERR_MSGS+=("$count $INDEX_PREFIX index(es) older than $CUTOFF_DAYS_AGO days found.")
CUTOFF_DATE=`date --date="$(( $INDEX_MAX_AGE + 1 )) day ago" +%Y.%m.%d`

count=0
for i in $(curl -s 'localhost:9200/_cat/indices' | grep -E "[0-9]{4}.[0-9]{2}.[0-9]{2}" | awk '{print $3}' | sort -n); do
if [[ ${i##*-} < $CUTOFF_DATE ]]; then
count=$(( $count + 1 ))
fi
done

if [[ $count -gt 0 ]]; then
ERR_MSGS+=("$count $INDEX_PREFIX index(es) older than $INDEX_MAX_AGE days found.")
fi
}

find_future_indexes
Expand Down

0 comments on commit 09b40b7

Please sign in to comment.