3.6 Named Expressions

In most cases, load estimation function is common for all servers (perhaps with server-dependent set of coefficients and/or variable bindings). To simplify configuration, such a common function can be defined once and then used by another ‘server’ definitions. It is defined as a named expression, i.e. an expression that can be referred to by its name.

Named expressions are defined using the ‘expression’ statement outside of ‘server’ block. Such statements take two arguments: the name of the expression and its definition, e.g.:

 
expression load "sqrt(k * d(out)**2 + m * la1**2)";

Named expressions can be invoked from another expressions using the ‘@’ operator, followed by expression's name. For example, the following statement in ‘server’ block:

 
  expression "@load";

is in fact equivalent to the expression defined above. The ‘@’ construct can, of course, also be used as a term in arithmetic calculations, e.g.:

 
  expression "2 * @load + 1";

A default expression is a named expression which is implicitly applied for ‘server’ statements that lack ‘expression’ statement. Default expression is defined using the ‘default-expression’ statement:

 
default-expression "load";

To finish this section, here is an example configuration declaring two servers which use the same default expression, but supply different sets of coefficients:

 
expression load "sqrt(k * d(out)**2 + m * la1**2)";
default-expression "load";

server srv01 {
  host 192.168.10.6;
  community "public";
  variable out "IF-MIB::ifOutOctets.3";
  variable la1 "UCD-SNMP-MIB::laLoadFloat.1";
  constant k 1.5;
  constant m 1.8;
}

server srv02 {
  host 192.168.10.1;
  community "private";
  variable out "IF-MIB::ifOutOctets.3";
  variable la1 "UCD-SNMP-MIB::laLoadFloat.1";
  constant k 2.5;
  constant m 2.2;
}