#!/usr/bin/bash
# notify user about event
# Use some envirenment variables:
# EVENT - event name (NODE_CRASHED)
# SRC_NODE_ID - node identifier
# RESOURCE - resource identifier
#
# Copyright (c) 2013-2017, Parallels International GmbH
#
# Our contact details: Parallels International GmbH, Vordergasse 59, 8200
# Schaffhausen, Switzerland.
#

. /usr/share/shaman/functions

verify_caller

if [ -z "$EVENT" ]; then
	echo "EVENT environment variable undefined" 1>&2
	exit 1
fi

case "$EVENT" in
	NODE_CRASHED)
	# node $SRC_NODE_ID crashed
	;;

	RES_RELOC)
	# resource $RESOURCE was relocated
	;;

	GLOBAL_MESSAGE)
	# $CLUSTER_NAME is set to the name of vstorage cluster
	# $MESSAGE contains the global message

	# if the cluster name is provided, then post cluster event
	if [ "$CLUSTER_NAME" ]; then
		# all messages from stderr will end up in shaman-monitor.log
		vstorage -c "$CLUSTER_NAME" --timeout 3 put-event --sub=tools "$MESSAGE"
	fi
	;;
	*)
		echo "Unknown event $EVENT" 1>&2
		exit 2
		;;
esac

exit 0
