Skip to content

Check plugins - check-tcp

check-tcp is a plug-in that monitors connections to servers via TCP.

Configurable options

OptionShortDescriptionDefault value
--serviceSpecify a service name. see [Supported services](#Supported services)
--hostname-HHost name or IP address to check for communication
--port-pPort number to check for communication
--send-sString to be sent to server
--expect-pattern-eRegular expression patterns expected in responses from the server
--quit-qString to be sent when disconnecting from the server
--ssl-STLS connection required or notfalse
--unix-sock-UUnix socket
--no-check-certificateWhether or not certificate verification is requiredfalse
--status-asOverwrite the monitoring status. For Example, If you specify UNKNOWN=CRITICAL, the monitoring status will become CRITICAL when it is UNKNOWN. Multiple values can be specified, separated by commas.
--timeout-tConnection timeout time (sec)10
--maxbytes-mDisconnects when more than the specified number of bytes of data is received
--delay-dLatency between sending data and polling for a response (sec)
--warning-wResponse time as Warning (sec)
--critical-cResponse time as Critical (sec)
--escape-EEscape if the string specified by --quit contains \n \r \t \c. If not specified, add \r\n at the end of the string specified by --quit.false
--error-warning-WSet the alert status to WARNING when the plugin terminates abnormallyCRITICAL
--expect-closed-CVerify that the port/unixsock is closed. If the port/unixsock is closed, OK status returned; if open, Critical or Warning status is returned depending on the value of the --error-warning. This option only verifies the connection.false

Supported services

If you specify the corresponding service name in the --service option, the check will be performed for each corresponding option.

Service nameportsendexpect-patternquitssl
FTP21^220QUIT
POP110^\+OKQUIT
SPOP995^\+OKQUIT
IMAP143^\* OKa1 LOGOUT
SIMAP993^\* OKa1 LOGOUT
SMTP25^220QUIT
SSMTP465^220QUIT
GEARMAN7003version\n\A[0-9]+\.[0-9]+\n\z

Example configuration

The following is a configuration that checks for connections on port 4224 of localhost, and if the connection takes more than 3 seconds, it is set to Warning, and if it takes more than 5 seconds, it is set to Critical.

toml
[plugin.checks.check-tcp-sample]
command = ["check-tcp", "-H", "localhost", "-p", "4224", "-w", "3", "-c", "5"]

To verify the above settings by executing directly from a terminal or other means, execute as follows.

check-tcp -H localhost -p 4224 -w 3 -c 5

To specify an IPv6 address, enclose it in single-byte brackets [] like [::1].

toml
[plugin.checks.check-tcp-v6-sample]
command = ["check-tcp", "-H", "[::1]", "-p", "4224", "-w", "3", "-c", "5"]

Tips

The check-tcp plugin can check the correctness of simple message exchanges during connection checking.

The --service option checks messages according to the supported protocols, but you can also use --send or --expect-pattern to monitor your own protocols.

For example, to check that the reason phrase in the HTTP response status line is the expected message, the following configuration can be used.

toml
[plugin.checks.tcp_http404]
command = ["check-tcp", "-H", "localhost", "-p", "80", "-s", "GET / HTTP/1.1\\r\\n\\r\\n", "-e", "HTTP/1.1 404 Bad Request", "-E"]

To check the operation in advance, perform the following.

check-tcp -H localhost -p 80 -s "GET / HTTP/1.1\r\n\r\n" -e "HTTP/1.1 404 Bad Request" -E

Repository

https://github.com/mackerelio/go-check-plugins/tree/master/check-tcp