0

When Redis Sentinel notifies about events, it does not provide the name of the Redis master.

An excerpt from the config:

# sentinel notification-script <master-name> <script-path>
#
# Call the specified notification script for any sentinel event that is
# generated in the WARNING level (for instance -sdown, -odown, and so forth).
# This script should notify the system administrator via email, SMS, or any
# other messaging system, that there is something wrong with the monitored
# Redis systems.
#
# The script is called with just two arguments: the first is the event type
# and the second the event description.

So there only is the event type (e.g. +odown) and the event description, which in case of +odown simply is master. Somehow I feel this is lacking important information. We do not only want to notify users that something has changed but where it changed.

You can't register a script with additional parameters, e.g.

sentinel notification-script <master-name> "<script-path> <master-name>"

Redis will use the value as a whole and check if it exists and is executable.

We solved this by creating small wrapper scripts, one for each master instance.

$ cat /some/path/notify-master42.sh
#!/bin/sh
/some/path/notify.sh master42 $1 $2

This wrapper script then is attached to the master:

sentinel notification-script <master-name> notification-script /some/path/notify-<master-name>.sh

That's a bit uncomfortable but not too bad, as long as you have a fixed number of masters and do not create them on the fly over the net.

You can register new masters by simply interacting with the sentinel over the net. (redis-cli -h <host> -p <port> sentinel whatever...) But creating those wrapper scripts is more complicated. Not that this is impossible, but it feels like jumping through burning hoops for nothing.

Is there a way to notify including master names:

  • without patching redis
  • without having wrapper scripts

?

udondan
  • 57,263
  • 20
  • 190
  • 175

1 Answers1

1

Yes, you do it by using the correct event.

"So there only is the event type (e.g. +odown) and the event description, which in case of +odown simply is master. Somehow I feel this is lacking important information. We do not only want to notify users that something has changed but where it changed."

In the case of +odown there is no other information to be had. All +odown means is the master server went down. At this point nothing else has happened. If you want to update something based on the fail-over (which happens after +odown) you need to look at the appropriate event: switch-master. The switch-master event is what happens when a failover completes.

Taken directly from the documentation:

switch-master <master name> <oldip> <oldport> <newip> <newport> -- The master new IP and address is the specified one after a configuration change. This is the message most external users are interested in.

So have your script look for and act upon the switch-master event to get the information about what changed. No more burning hoops to jump through.

The Real Bill
  • 14,884
  • 8
  • 37
  • 39
  • I do not only want to notify when failover happens. I am notifying also on +/- odwon/sdown. – udondan Aug 26 '15 at 15:55
  • i cannot get the notification on +/- odown/sdown as described,neither! i can just get the notification '+new-epoch xx'! – pigman Feb 03 '21 at 06:31