Add CHILDREN to monitor scripts
The CHILDREN parameter expands to a list of server IPs and ports that are direct descendants of the server that initiated the event. Also added a note that the variables can expand to empty strings if nothing matches the criteria of the variable.
This commit is contained in:
parent
9080072de5
commit
ab777c76c7
@ -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:
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user