Dynamic asterisk ring group on osmocom with subscriber on demand

Post Reply
User avatar
laptopfm
Site Admin
Posts: 3
Joined: Thu Jun 12, 2025 1:48 am
Location: Greece
Contact:

Dynamic asterisk ring group on osmocom with subscriber on demand

Post by laptopfm »

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 :

Code: Select all

app
 no use-imsi
on /etc/osmocom/osmo-sip-connector.cfg

then you need to create the asterisk script :

Code: Select all

sudo nano /var/lib/asterisk/agi-bin/gsm_ring_group.agi
then paste the following :

Code: 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.db
After you make it you need to edit /etc/asterisk/extensions.conf and add the incoming from trunk part

Code: 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)
After all this restart asterisk and try it out !
Attachments
20260720_025701.jpg
-laptopfm
Post Reply