Dynamic asterisk ring group on osmocom with subscriber on demand
Posted: Mon Jul 20, 2026 12:01 am
So again with the help of LLM's i made a asterisk script that reads the autogenerated MSISDN from osmo-hlr and it makes a dynamic ringgroup that rings all available gsm handsets, This guide assummes you already have configured osmo-sip-connector and your asterisk with whatever sip trunk of your liking. FIrst of all you need to modify osmo-sip-connector to pass only the MSISDN to asterisk and not IMSI. You do it like this :
on /etc/osmocom/osmo-sip-connector.cfg
then you need to create the asterisk script :
then paste the following :
(might also need to tweak a few permissions)
After you make it you need to edit /etc/asterisk/extensions.conf and add the incoming from trunk part
After all this restart asterisk and try it out !
Code: Select all
app
no use-imsithen you need to create the asterisk script :
Code: Select all
sudo nano /var/lib/asterisk/agi-bin/gsm_ring_group.agiCode: Select all
#!/bin/bash
HLR_DB=/var/lib/osmocom/hlr.db
# consume the AGI environment handshake (required, even if unused)
while read -r line; do
[ -z "$line" ] && break
done
DIALSTRING=""
while IFS='|' read -r msisdn; do
[ -z "$msisdn" ] && continue
if [ -z "$DIALSTRING" ]; then
DIALSTRING="PJSIP/${msisdn}@osmo-connector"
else
DIALSTRING="${DIALSTRING}&PJSIP/${msisdn}@osmo-connector"
fi
done < <(sqlite3 "$HLR_DB" "SELECT msisdn FROM subscriber WHERE msisdn IS NOT NULL AND msisdn != '' AND last_lu_seen IS NOT NULL AND last_lu_seen >= datetime('now', '-4 hours');")
echo "SET VARIABLE DIALSTRING \"${DIALSTRING}\""Code: Select all
sudo chmod +x /var/lib/asterisk/agi-bin/gsm_ring_group.agi
sudo chown asterisk:asterisk /var/lib/asterisk/agi-bin/gsm_ring_group.agi(might also need to tweak a few permissions)
Code: Select all
ls -la /var/lib/osmocom/hlr.db
sudo setfacl -m u:asterisk:r /var/lib/osmocom/hlr.dbCode: Select all
[from-voip-laptopfm]
exten => s,1,NoOp(Incoming call from voip-laptopfm - building GSM ring group)
same => n,AGI(gsm_ring_group.agi)
same => n,GotoIf($["${DIALSTRING}" = ""]?nohandsets)
same => n,Dial(${DIALSTRING},30)
same => n,Hangup()
same => n(nohandsets),NoOp(No known GSM handsets currently attached)
same => n,Hangup()
; in case FreePBX ever passes a DID digit-string instead of 's'
exten => 611,1,Goto(s,1)