diff --git a/Documentation/Monitors/Monitor-Common.md b/Documentation/Monitors/Monitor-Common.md index 7ec599991..f85c1a546 100644 --- a/Documentation/Monitors/Monitor-Common.md +++ b/Documentation/Monitors/Monitor-Common.md @@ -82,6 +82,12 @@ The following substitutions will be made to the parameter value: * `$SYNCEDLIST` will be replaced with a list of server IPs and ports that are synced Galera nodes * `$PARENT` will be replaced with the IP and port of the parent node of the server who initiated the event. For master-slave setups, this will be the master if the initiating server is a slave. +* `$CHILDREN` will be replaced with the IPs and ports of the child nodes of the server who initiated + the event. For master-slave setups, this will be a list of slave servers if the initiating server is a master. + +The expanded variable value can be an empty string if no servers match the +variable's requirements. For example, if no masters are available `$MASTERLIST` +will expand into an empty string. For example, the previous example will be executed as: diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 15f6c2067..cccda7afb 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -1165,6 +1165,33 @@ static MXS_MONITOR_SERVERS* find_parent_node(MXS_MONITOR_SERVERS* servers, return rval; } +static std::string child_nodes(MXS_MONITOR_SERVERS* servers, + MXS_MONITOR_SERVERS* parent) +{ + std::stringstream ss; + + if (parent->server->node_id > 0) + { + bool have_content = false; + + for (MXS_MONITOR_SERVERS* node = servers; node; node = node->next) + { + if (node->server->master_id == parent->server->node_id) + { + if (have_content) + { + ss << ","; + } + + ss << "[" << node->server->name << "]:" << node->server->port; + have_content = true; + } + } + } + + return ss.str(); +} + /** * Launch a script * @param mon Owning monitor @@ -1205,6 +1232,11 @@ monitor_launch_script(MXS_MONITOR* mon, MXS_MONITOR_SERVERS* ptr, const char* sc externcmd_substitute_arg(cmd, "[$]PARENT", ss.str().c_str()); } + if (externcmd_matches(cmd, "$CHILDREN")) + { + externcmd_substitute_arg(cmd, "[$]CHILDREN", child_nodes(mon->databases, ptr).c_str()); + } + if (externcmd_matches(cmd, "$EVENT")) { externcmd_substitute_arg(cmd, "[$]EVENT", mon_get_event_name(ptr));