SIP/device is ringing capture

Hello.
Is it possible to capture ringing devices?
For example if phone a calls to phone b, in full.log i see
sip/b is ringing
Can i insert some other operations in this event?
For example, query to database or something like this

and function inserts uniqueid in db maybe…
Is it possible to add some “jobs” in this event and how(where) this can be done?