I'm trying to configure HOMER sip capture server to do some accounting of the cases when "503 Service Unavailable" message arrives from capture agents.
I've implemented the following to record the source IPs from which 503 message originates.
onreply_route { ...................... ...................... ......................
else if(status == "503") { if($sht(a=>alarm::503) == $null) { $sht(a=>alarm::503) = 0; $sht(a=>alarm::$si::503) = 0; } xlog("Got 503"); xlog("($sht(a=>alarm::$si::503))"); $sht(a=>alarm::$si::503) = $sht(a=>alarm::$si::503) + 1; } ................... ................... ...................
The following route supposed run periodically to update the databases.
}
route[TIMER_STATS] {
..................... .....................
xlog("($sht(a=>alarm::$si::503))"); if($sht(a=>alarm::$si::503) > 0) { sql_query("cb", "INSERT INTO alarm_data (create_date, type, total, description, source_ip) VALUES(NOW(), 'Too Many 503', $sht(a=>alarm::$si::503), 'service unavailable', $si)"); xlog("adding stuff to db"); } $sht(a=>alarm::503) = 0; $sht(a=>alarm::$si::503) = 0;
}
But the xlog("adding stuff to db") never executed. But in the first block of code, the log message to print the value $sht(a=>alarm::$si::503), which is shown to be non zero.
Don't understand why its not working.
Hello,
The $si is the source ip of the sip packet. Bu in a rtimer route there is no packet received from the network.
So your config is not going to work for what you want to do.
You can try to use mqueue to push sql queries from sip worker to rtimer as you need to write something to database.
Cheers, Daniel
On Wednesday, September 3, 2014, aft aftnix@gmail.com wrote:
On Wed, Sep 3, 2014 at 11:36 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Should i push $si using mq_add() and fetch it using mq_fetch()?
On 04/09/14 09:19, aft wrote:
It should work with pushing $si as well.
I was thinking to do the check in onreply route and push the entire sql query, so the rtimer route just execute it.
Cheers, Daniel
On Thu, Sep 4, 2014 at 1:57 PM, Daniel-Constantin Mierla miconda@gmail.com wrote:
Well i don't think it will work that way. Because :
[1] I need to access a=>alarm::$si::503 WHEN the timer goes off to see how many 503s received. So if i push the sql array , i will not get the correct value of a=>alarm::$si::503.
[2] Also I can't access alarm::$si::503. If i push $si to mqueue, then only sensible key is $si itself. And i can't access $si in timer route.
So I guess the only solution this, is not a hash table, but a array or list of hashes, where i don't have to worry about "keys".
Like this :
An array of hashes will be made where key::value is like "source_ip::number of 503s"
Whenever a 503 arrives, i will check if the ip is already in the table. If not then i will add a new key value entry.
In timer route, i will just iterate over the array of hashes.
Now how should i achieve this?