A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.cfengine.com/latest/reference-functions-selectservers.html below:

selectservers - CFEngine 3.26 Docs

Prototype: selectservers(hostlist, port, query, regex, maxbytes, array)

Return type: int

Description: Returns the number of tcp servers from hostlist which respond with a reply matching regex to a query send to port, and populates array with their names.

The regular expression is anchored. If query is empty, then no reply checking is performed (any server reply is deemed to be satisfactory), otherwise at most maxbytes bytes are read from the server and matched.

This function allows discovery of all the TCP ports that are active and functioning from an ordered list, and builds an array of their names. This allows maintaining a list of pretested failover alternatives.

Arguments:

Example:

code

bundle agent example
{
vars:

 "hosts" slist => { "slogans.iu.hio.no", "eternity.iu.hio.no", "nexus.iu.hio.no" };
 "fhosts" slist => { "www.cfengine.com", "www.cfengine.org" };

 "up_servers" int =>  selectservers("@(hosts)","80","","","100","alive_servers");
 "has_favicon" int =>
        selectservers(
            "@(hosts)", "80",
        "GET /favicon.ico HTTP/1.0$(const.n)Host: www.cfengine.com$(const.n)$(const.n)",
        "(?s).*OK.*",
        "200", "favicon_servers");

classes:

  "someone_alive" expression => isgreaterthan("$(up_servers)","0");

  "has_favicon" expression => isgreaterthan("$(has_favicon)","0");

reports:
    "Number of active servers $(up_servers)";

  someone_alive::
    "First server $(alive_servers[0]) fails over to $(alive_servers[1])";

  has_favicon::
    "At least $(favicon_servers[0]) has a favicon.ico";

}

If there is a multi-line response from the server, special care must be taken to ensure that newlines are matched, too. Note the use of (?s) in the example, which allows . to also match newlines in the multi-line HTTP response.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4