Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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