Hello,
I'm learning Kamailio. My ultimate goal is to be able to route SIP messages from User Agents to specific FS boxes.

I'm starting with routing REGISTER messages.
I used app_perl to randomly lookup one of the FS box's IP Address from postgres database, then I stored the IP in avp and then in hash. It seemed like overkill but it was the only way I could keep the FS IP address in memory between the first REGISTER and REGISTER with Auth.

my app_perl script sets the IP as follows:

my $sth = $dbh->prepare("SELECT ip_address FROM host_machine WHERE is_online = true ORDER BY random() LIMIT 1");
$sth->execute();
my $host_ip_address = $sth->fetchrow();
Kamailio::AVP::add(10, "sip:$host_ip_address:5060");

And here is my kamailio.cfg for REGISTERs

route[REGISTRAR]
{

if (!is_method("REGISTER|PUBLISH"))
return;

if (is_present_hf("Authorization")) {
add_path_received();
$avp(i:10) = $sht(a=>$ci::dest_server);
avp_pushto("$du", "$avp(i:10)");
} else {
perl_exec("random_server");
avp_pushto("$du", "$avp(i:10)");
$sht(a=>$ci::dest_server) = $avp(i:10);

}
t_relay();

exit;
}


"random_server" is the perl script to get the FS IP address...
Seems crude but works... 
I'm sure there is probably a more elegant way to do what im trying so any advice and criticism is appreciated, thank you!

/V