Movatterモバイル変換


[0]ホーム

URL:


CFEngine documentation homepage

readtcp

Suggest changes
Table of contents

Prototype:readtcp(hostnameip, port, sendstring, maxbytes)

Return type:string

The return value iscached.

Description: Connects to tcpport ofhostnameip, sendssendstring,reads at mostmaxbytes from the response and returns those.

If the send string is empty, no data are sent or received from thesocket. Then the function only tests whether the TCP port is alive andreturns an empty string.

Not all Unix TCP read operations respond to signals for interruption, sopoorly formed requests can block thecf-agent process. Always test TCPconnections fully before deploying.

Arguments:

  • host:string - Host name or IP address of server socket - in the range:.*
  • port:string - Port number or service name - in the range:.*
  • sendstring:string - Protocol query string - in the range:.*
  • maxbytes:int - Maximum number of bytes to read - in the range:0,99999999999

Example:

code
bodycommoncontrol{bundlesequence=>{"example"};}bundleagentexample{vars:"my80"string=>readtcp("myserver.com","80","GET /index.html HTTP/1.1$(const.r)$(const.n)Host: myserver.com$(const.r)$(const.n)$(const.r)$(const.n)",20);classes:"server_ok"expression=>regcmp("[^\n]*200 OK.*\n.*","$(my80)");reports:server_ok::"Server is alive";!server_ok::"Server is not responding - got$(my80)";}

Output:

code
R: Server is alive

Notes: Note that on some systems the timeout mechanism does not seem tosuccessfully interrupt the waiting system calls so this might hang if you sendan incorrect query string. This should not happen, but the cause has yet to bediagnosed.

Still need help?

Chat Ask a question on Github Mailing list
Version 
master3.24 (LTS)3.21 (LTS)view all versions

[8]ページ先頭

©2009-2025 Movatter.jp