#!/bin/bash
LOGFILE='<%= @rotation_log_file %>'

#FIXME: 2014-01-12 - Ideally this should be 21 days - need to fix logstasher gem first
ARGS='--delete-old --delete-maxage 15 --optimize-old --optimize-maxage 1 logs'
CMD="/usr/local/bin/es-rotate"

function send_to_nagios() {
  local MESSAGE=$1
  local CODE=$2

  printf "<%= @fqdn %>\t${MESSAGE}\t${CODE}\t\n" | /usr/sbin/send_nsca -H alert.cluster >/dev/null
}

echo "Running es-rotate at `date`" > ${LOGFILE}

if [ -e "${CMD}" ]; then
  ${CMD} ${ARGS} 2>&1 > ${LOGFILE}
  CODE=$?
  if [ "${CODE}" -eq 0 ]; then
    send_to_nagios "es-rotate OK" 0
  else
    send_to_nagios "es-rotate exited abnormally" 1
  fi

  echo "Finished at `date`" >> ${LOGFILE}

  exit $CODE
else
  send_to_nagios "es-rotate: command '${CMD}' not found" 3
  exit 1
fi

#!/bin/bash
LOGFILE='<%= @rotation_log_file %>'

#FIXME: 2014-01-12 - Ideally this should be 21 days - need to fix logstasher gem first
ARGS='--delete-old --delete-maxage 15 --optimize-old --optimize-maxage 1 logs'
CMD="/usr/local/bin/es-rotate"

function send_to_nagios() {
  local MESSAGE=$1
  local CODE=$2

  printf "<%= @fqdn %>\tes-rotate\t${CODE}\t${MESSAGE}\n" | /usr/sbin/send_nsca -H alert.cluster >/dev/null
}

echo "Running es-rotate at `date`" > ${LOGFILE}

if [ -e "${CMD}" ]; then
  ${CMD} ${ARGS} 2>&1 > ${LOGFILE}
  CODE=$?
  if [ "${CODE}" -eq 0 ]; then
    send_to_nagios "es-rotate OK" 0
  else
    send_to_nagios "es-rotate exited abnormally" 1
  fi

  echo "Finished at `date`" >> ${LOGFILE}

  exit $CODE
else
  send_to_nagios "es-rotate: command '${CMD}' not found" 3
  exit 1
fi

Fix syntax of es-rotate send_nsca for Icinga
Fix syntax of es-rotate send_nsca for Icinga

The format of the send_nsca were sending was:

    $fqdn	$MESSAGE	$CODE

But actually it should be:

    $fqdn	es-rotate	$CODE	$MESSAGE
