Forum Discussion
I was getting a TCL error (TCL error: /Common/LogRule - can't read "client": no such variable while executing "log local0.info "Client $client -> VIP: $vip -> Node: $node"") when I created an iRule by copying/pasting the TCP logger rule in hoolio's first post and found I had to remove some quotation marks to properly set the variables. I'm running 11.6.0 Build 5.123.429. I also slightly modified it so it logs both when the connection is made and disconnected.
Here's what I used:
when CLIENT_ACCEPTED {
set vip [IP::local_addr]:[TCP::local_port]
}
when SERVER_CONNECTED {
set client [IP::client_addr]:[TCP::client_port]
set node [IP::server_addr]:[TCP::server_port]
log local0.info "Connected: Client $client -> VIP: $vip -> Node: $node"
}
when CLIENT_CLOSED {
log local0.info "Disconnected: Client $client -> VIP: $vip -> Node: $node"
}
This was a super helpful thread, thanks hoolio!
It seems like the error is saying the "node" variable doesn't exist so what you could do is add an IF/ELSE statement that checks whether the variable exists before writing to the log. Here's an example given the script you posted:
when CLIENT_ACCEPTED {
set vip [IP::local_addr]:[TCP::local_port]
set client [IP::client_addr]:[TCP::client_port]
}
when SERVER_CONNECTED {
set node [IP::server_addr]:[TCP::server_port]
log local0.info "Connected: Client $client -> VIP: $vip -> Node: $node"
}
when CLIENT_CLOSED {
log local0.info "Disconnected: Client $client -> VIP: $vip"
}
when SERVER_CLOSED {
if {[info exists node]} {
log local0.info "A client has disconnected on Node: $node"
} else {
do nothing
}
}