Prototype: isconnectable(hostname, port, timeout)

Return type: boolean

Description: Checks whether a port is connectable

Arguments:

  • hostname: string - Host name, domain name or IP address - in the range: .*
  • port: string - Port number - in the range: .*
  • timeout: int - Connection timeout (in seconds) - in the range: 0,99999999999

This function checks whether a hostname:port is connectable within timeout in seconds, before it times out. If timeout is 0, the connection blocks forever. timeout defaults to 30 s.

Example:

code
body common control
{
  bundlesequence => { "example" };
}
bundle agent example 
{
  classes:
    "isconnectable" expression => isconnectable("localhost", 22, "30");

  reports:
    isconnectable::
      "Port is connectable";
    !isconnectable::
      "Port is not connectable";
}

Output:

code
R: Port is connectable

History:

  • Introduced in 3.26.0