max

Table of Contents

Prototype: max(list, sortmode)

Return type: string

Description: Return the maximum of the items in list according to sortmode (same sort modes as in sort()).

This function can accept many types of data parameters.

Arguments:

  • list: string - CFEngine variable identifier or inline JSON - in the range: .*
  • sortmode: - Sorting method: lex or int or real (floating point) or IPv4/IPv6 or MAC address - one of
    • lex
    • int
    • real
    • IP
    • ip
    • MAC
    • mac

Example:

body common control
{
      bundlesequence => { "test" };
}

bundle agent test
{
  vars:
      # the behavior will be the same whether you use a data container or a list
      # "mylist" slist => { "foo", "1", "2", "3000", "bar", "10.20.30.40" };
      "mylist" data => parsejson('["foo", "1", "2", "3000", "bar", "10.20.30.40"]');
      "mylist_str" string => format("%S", mylist);

      "max_int" string => max(mylist, "int");
      "max_lex" string => max(mylist, "lex");
      "max_ip" string => max(mylist, "ip");

      "min_int" string => min(mylist, "int");
      "min_lex" string => min(mylist, "lex");
      "min_ip" string => min(mylist, "ip");

      "mean" real => mean(mylist);
      "variance" real => variance(mylist);

  reports:
      "my list is $(mylist_str)";

      "mean is $(mean)";
      "variance is $(variance) (use eval() to get the standard deviation)";

      "max int is $(max_int)";
      "max IP is $(max_ip)";
      "max lexicographically is $(max_lex)";

      "min int is $(min_int)";
      "min IP is $(min_ip)";
      "min lexicographically is $(min_lex)";
}

Output:

R: my list is ["foo","1","2","3000","bar","10.20.30.40"]
R: mean is 502.200000
R: variance is 1497376.000000 (use eval() to get the standard deviation)
R: max int is 3000
R: max IP is 10.20.30.40
R: max lexicographically is foo
R: min int is bar
R: min IP is 1
R: min lexicographically is 1

History: Was introduced in version 3.6.0 (2014). canonify mode was introduced in 3.9.0. The collecting function behavior was added in 3.9.

See also: sort(), variance(), sum(), mean(), min(), about collecting functions, and data documentation.