I figured this finally out and all works for me very well.
In usrloc dbmode i set value of 3 (its saving immediately changes into DB).

In request route for REGISTER method i set t_on_reply("MANAGE_REPLY_REGISTER" and for REGISTER with expires set to 0 i set t_on_reply("MANAGE_REPLY_UNREGISTER") (used pseudovariable $expires(max)).
I stored Contact header in $avp(contact) for unREGISTER request for further use when calling unregister().

Then in onreply_route for MANAGE_REPLY_REGISTER i call save lcoation and in MANAGE_REPLY_UNREGISTER for reply code 200 i call unregister function with the stored contact (i had to remove < > and display name using re.subst).

So far it looks to work perfect. 


pon., 18 lis 2019 o 13:38 Voip support <voipexpert0@gmail.com> napisał(a):

Thanks again for all replies... I need to try it out - did not have time for it yet.

I think i will go for the onreply_route answer and try to save location in this place.

pon., 18 lis 2019 o 06:23 Joel Serrano <joel@textplus.com> napisał(a):
Yes sir! Works perfectly!

To give you a quick example:

1) Add in the appropriate place for the REGISTER request:   t_on_reply("MANAGE_REG_REPLY");
2) Create a new onreply route: 

# Manage registration incoming replies
onreply_route[MANAGE_REG_REPLY] {
    if(status=~"2[0-9][0-9]") {
        if (save("location", "0x04")) {
            xlog("L_NOTICE", "[usrloc] saved user location\n");
        }
    }
}


Note1: In my setup, I needed to strictly simulate asterisk (chan_sip) registrations, so only one AoR was allowed, thus the flags 0x04, if you are using PJSIP you might not need it.
Note2: With this example code, a "unregister" (REGISTER with expires=0) will not remove the AoR from Kamailio, to achieve that I check independently if the header Expires exists and is 0, or if the contact param Expires exists and is 0, and in that case I use the unregister() function instead of the save().

Hope it helps!
Joel.



On Sun, Nov 17, 2019 at 5:42 PM Ovidiu Sas <osas@voipembedded.com> wrote:
Did it work calling save() on the reply route?

-ovidiu

On Thu, Nov 14, 2019 at 6:20 PM Voip support <voipexpert0@gmail.com> wrote:
>
>   I am using kamailio 5.3.
>
> Ovidiu Sas, i will try this tomorrow today is bit late. Maybe it could work.
>
> David Villasmil , i know i can use SQLOPS but i was thinking of easier method of doing this.
> By successful REGISTER i mean save only REGISTER attempt that authenticated correctly at SIP server and in 200 OK a binding was returned.
> Same if the binding is later removed i would like remove it from database. I need this because when i run REGISTER over kamailio to destination SIP server i see all register from same IP.
> I need to be able to check what was the real source IP of client REGISTER.
>
> Regards,
> Tomasz
>
>
>
> pt., 15 lis 2019 o 00:16 Mike from ApoloCore <mike@apolocore.com> napisał(a):
>>
>> I am using kamailio 5.3.
>>
>> Ovidiu Sas, i will try this tomorrow today is bit late. Maybe it could work.
>>
>> David Villasmil , i know i can use SQLOPS but i was thinking of easier method of doing this.
>> By successful REGISTER i mean save only REGISTER attempt that authenticated correctly at SIP server and in 200 OK a binding was returned.
>> Same if the binding is later removed i would like remove it from database. I need this because when i run REGISTER over kamailio to destination SIP server i see all register from same IP.
>> I need to be able to check what was the real source IP of client REGISTER.
>>
>> Regards,
>> Tomasz
>>
>>
>>
>>
>> czw., 14 lis 2019 o 23:33 Ovidiu Sas <osas@voipembedded.com> napisał(a):
>>>
>>> Try to use save() when you process the 200 ok reply for REGISTER in
>>> the reply route.
>>>
>>> Regards,
>>> Ovidiu Sas
>>>
>>> On Thu, Nov 14, 2019 at 3:40 PM Voip support <voipexpert0@gmail.com> wrote:
>>> >
>>> > I setup kamailio to forward REGISTER packets using dispatcher to two servers main and backup.
>>> >
>>> > The routing logic is quite simple i use the dispatcher probing mechanism to detect if my main dispatcher set id (one server) is active or inactive once it detect a failure all packets are sent to secondary SIP server to achieve High Availability.
>>> >
>>> > I am looking for module or a way to save into kamailio database client information such as IP address, register username (from FROM header), digest username (authorization username), call-id for successful registration.
>>> >
>>> > I tried to use registrar module but once i used function save("location") the client was registered on kamailio and packets was not forwarded to main/secondary SIP server (like dispatcher stopped working, the destination did not override).
>>> >
>>> > REGISTER is sent to SIP URI of kamailio.
>>> >
>>> > Please let me know if you have any idea how to make this data update in database (insert an entry on fresh successfull REGISTER, delete on expired or removed binding).
>>> >
>>> > Best regards,
>>> > Tomasz
>>> >
>>> > _______________________________________________
>>> > Kamailio (SER) - Users Mailing List
>>> > sr-users@lists.kamailio.org
>>> > https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>
>>>
>>>
>>> --
>>> VoIP Embedded, Inc.
>>> http://www.voipembedded.com
>>>
>>> _______________________________________________
>>> Kamailio (SER) - Users Mailing List
>>> sr-users@lists.kamailio.org
>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users@lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users



--
VoIP Embedded, Inc.
http://www.voipembedded.com

_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users