Prototype: type(var, type)

Return type: string

Description: Returns whether a variable var is of type type

Arguments:

  • var: string - Variable identifier - in the range: .*
  • type: - Enable detailed type decription - one of
    • true
    • false
    • yes
    • no
    • on
    • off

This function compares the type description of var with the string type. The function expects a variable identifier as the first argument and a type string as the second argument. The type accepts both the type and an optional subtype. The function evaluates to false by default if the variable or the type string is wrong.

To see the possible data types and their subtypes, see type()

Example:

code
body common control
{
      bundlesequence => { "example" };
}

bundle agent example
{
  vars:
      "foo"
        data => '{ "bar": true }';    
      "a" string => "hello";
  classes:
      "isdata"
        expression => is_type("foo", "data");
      "isdata_boolean"
        expression => is_type("foo[bar]", "data boolean");
      "isstring"
        expression => is_type("a", "string");
      "isint"
        expression => is_type("a", "int");


  reports:
      isdata::
        "'foo' is of type 'data'";
      isdata_boolean::
        "'foo[bar]' is of type 'data boolean'";
      isstring::
        "'a' is of type 'string'";
      isint::
        "'a' is of type 'int'";
}

Output:

code
R: 'foo' is of type 'data'
R: 'foo[bar]' is of type 'data boolean'
R: 'a' is of type 'string'

History:

  • Introduced in 3.26.0