Various options can be set in the ``options`` parameter:
- - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none'.
+ - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random').
+ - ``backupSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random').
- ``source``: Source IP address to check from
More sophisticated test that attempts an actual http(s) connection to
``url``. In addition, multiple groups of IP addresses can be supplied. The
- first set with a working (available) IP address is used.
+ first set with a working (available) IP address is used. URL is considered up if
+ HTTP response code is 200 and optionally if the content matches ``stringmatch``
+ option.
:param string url: The url to retrieve.
:param addresses: List of lists of IP addresses to check the URL on.
Various options can be set in the ``options`` parameter:
- - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none'.
- - ``defaultSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none'.
+ - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random').
+ - ``backupSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random').
- ``source``: Source IP address to check from
- ``stringmatch``: check ``url`` for this string, only declare 'up' if found
vector<ComboAddress> candidates, unavailables;
opts_t opts;
vector<ComboAddress > conv;
+ std::string selector;
if(options)
opts = *options;
unavailables.push_back(rem);
}
}
- if(candidates.empty()) {
- // if no IP is available, use selector on the whole set
+ if(!candidates.empty()) {
+ // use regular selector
+ selector = getOptionValue(options, "selector", "random");
+ } else {
+ // All units are down, apply backupSelector on all candidates
candidates = std::move(unavailables);
+ selector = getOptionValue(options, "backupSelector", "random");
}
- vector<ComboAddress> res = useSelector(getOptionValue(options, "selector", "random"), bestwho, candidates);
+ vector<ComboAddress> res = useSelector(selector, bestwho, candidates);
return convIpListToString(res);
});
}
}
- // All units down, apply defaultSelector on all candidates
+ // All units down, apply backupSelector on all candidates
vector<ComboAddress> ret{};
for(const auto& unit : candidates) {
ret.insert(ret.end(), unit.begin(), unit.end());
}
- vector<ComboAddress> res = useSelector(getOptionValue(options, "defaultSelector", "random"), bestwho, ret);
+ vector<ComboAddress> res = useSelector(getOptionValue(options, "backupSelector", "random"), bestwho, ret);
return convIpListToString(res);
});