Theme
A simple TCP health monitor
One of the functions added to SyncJS in Syncplify AFT! v4.0.0 is TcpConnect. It performs a quick connect and disconnect cycle against any host on any port and returns whether the connection succeeded, that is, whether something is listening on that port on that host.
This is ideal for very simple health monitor scripts. Here is an example:
javascript
var host = "your.host.com";
var port = 443;
var alertTo = "alerts@yourdomain.com";
var alertFrom = "aft-monitor@yourdomain.com";
// TcpConnect returns true if the TCP handshake succeeds within the timeout.
// We use a 5 second timeout (5000 ms).
if (TcpConnect(host, port, 5000)) {
Log.Info(host + ":" + port + " is reachable, all good");
} else {
var subject = "ALERT: " + host + ":" + port + " is unreachable";
var body = "The TCP connectivity check for " + host + ":" + port + " failed.\n" +
"The host may be down, the port may be blocked, or the network may be unreachable.\n\n" +
"Please investigate immediately.";
Log.Error(host + ":" + port + " is unreachable, sending alert to " + alertTo);
if (!SendMail(alertFrom, alertTo, subject, body)) {
Log.Error("alert email could not be sent, check the SMTP configuration in the AFT! settings");
}
}Simple, nothing fancy. If the host is up, the script logs a line; if the host is down, it emails you. Schedule it as a cron job in AFT! and you have a monitor.
As of v4.0.0, Syncplify AFT! is no longer just file transfer as code: with the power and flexibility of SyncJS you can do a lot more than in the past.