Hi Rodrigo,
Follows the final iRule:
rule MBLB-HSM {
when CLIENT_ACCEPTED {
set client_closed 0
TCP::collect
log local0. "Client Connected !"
}
periodically checks if the client connection closed, if so, also closes associated server connection.
when CLIENT_CLOSED {
set client_closed 1
}
Triggered when a connection has been established with the target node
when SERVER_CONNECTED {
after 1000 -periodic if {$client_closed} {TCP::close}
TCP::collect
}
when CLIENT_DATA {
binary scan [TCP::payload] cc head rlen
log local0. "Header = $head -- Length = $rlen"
if {($head == 0)} {
if {[TCP::payload length] < [expr {2 + $rlen}]} {
TCP::collect expr {2 + $rlen - [TCP::payload length]}
return
}
}
TCP::release [expr {$rlen + 2}]
TCP::notify request
TCP::collect
}
when SERVER_DATA {
TCP::release [TCP::payload length]
TCP::notify response
TCP::collect
log local0. "Received server respose !"
}
}
I´ve also created a health monitor for HSM:
monitor HSM_PING {
defaults from external
interval 10
timeout 31
args "5"
run "/usr/bin/monitors/hsm.pl"
}
/usr/bin/monitors/hsm.pl
!/usr/bin/perl
use strict;
use IO::Socket;
my $IP = $ARGV[0];
$IP =~ s/::ffff://g;
my $PORT = $ARGV[1];
my $TIMEOUT = $ARGV[2];
my $HSMPING="\x{00}\x{08}0000NO00";
my $res=hsm_probe ($HSMPING);
if ($res =~ m/0000NP00/) {
print "UP" . "\n";
exit 0;
}
exit 255;
sub hsm_probe {
my $line = $_[0];
my $data;
chomp ($line);
my $HSM_port = $PORT;
my $HSM_host = $IP;
eval {
local $SIG{ALRM} = sub { die 'Timed Out'; };
alarm $TIMEOUT;
my $sock = IO::Socket::INET->new(
PeerAddr => $HSM_host,
PeerPort => $HSM_port,
Proto => 'tcp',
)
|| die "Couldn't connect to $HSM_host:$HSM_port: $!";
$sock->autoflush(1);
print $sock $line;
$sock->recv($data, 26);
close $sock;
alarm 0;
return $data;
1;
} or do { alarm 0; return "ERROR"; }
}
My best regards,
Carlos Covolo