Skip to content

Instantly share code, notes, and snippets.

@javier-lopez
Created July 23, 2013 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javier-lopez/6066888 to your computer and use it in GitHub Desktop.
Save javier-lopez/6066888 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
[ -s /tmp/logstash_alert ] || exit 1
_mail()
{ #send mail, return 0 on success, 1 otherwise
#requires: libio-socket-ssl-perl, libnet-ssleay-perl and sendemail
case $1 in
gmail)
shift
sendemail -f "$1" -t "$2" -u "$3" -m "$4" -s smtp.gmail.com:587 -o tls=yes -xu "$5" -xp "$6"
;;
*)
sendemail -f "$1" -t "$2" -u "$3" -m "$4" -s "$5" -xu "$6" -xp "$7" > /dev/null 2>&1
;;
esac
[ $? -eq 0 ] && return 0 || return 1
}
_mail gmail "noreply@domain.com" "recipient@domain.com" "alarm :$(date +%d-%m-%Y)" "$(cat /tmp/logstash_alert)" "username" "password"
status=$?
[ $status != 0 ] && exit $status || { cat /dev/null > /tmp/logstash_alert; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment