I might look into global variables:
https://devcentral.f5.com/articles/irules-101-03-variables
I've never had the need to use them myself so you might want to load test it, but maybe it could look something like this:
when RULE_INIT {
set ::alertSent 0
}
when HTTP_REQUEST {
if {[active_members [LB::server pool]] < 1 } {
if { $::alertSent == 0 } {
set conn [connect -timeout 100 -idle 30 -status conn_status x.x.x.x:x]
set postdata "POST /whatever/whatever/ HTTP/1.1\r\n"
append postdata "Content-Type: application/json;charset=UTF-8\r\n"
append postdata "Accept: */*\r\n"
append postdata "Host: x.x.x.x:x\r\n"
append postdata "accept-encoding: gzip, deflate\r\n"
append postdata "content-length: $jsonlen\r\n\r\n"
set send_info [send -timeout 100 -status send_status $conn $postdata]
set recv_2kbytes [recv -timeout 300 20 $conn]
set length_recv [string length $recv_2kbytes]
close $conn
set ::alertSent 1
}
} else {
set ::alertSent 1
}
}