Asterisk Manager Events when using realtime PJSIP

I am not receiving AMI events when using PJSIP endpoints in realtime. I do receive them when I configure endpoints statically in pjsip.conf. Is there any configuration needed to receive AMI events also when endpoints are configured as realtime?

Here my sorcery.conf for realtime PJSIP

[res_pjsip]
endpoint=realtime,ps_endpoints
auth=realtime,ps_auths
aor=realtime,ps_aors
domain_alias=realtime,ps_domain_aliases
contact=realtime,ps_contacts

[res_pjsip_publish_asterisk]
asterisk-publication=realtime,ps_asterisk_publications

[res_pjsip_endpoint_identifier_ip]
identify=realtime,ps_endpoint_id_ips

[res_pjsip_outbound_publish]
outbound-publish=realtime,ps_outbound_publishes

[res_pjsip_pubsub]
inbound-publication=realtime,ps_inbound_publications

What events are you specifically referring to?

When using chan_sip I trap “peerstatus”, “newstate” and “hangup”. I have seen PJSIP is throwing some additional events, like ContactStatus that seems interesting too. When using PJSIP realtime, I can see only “ChallengeSent” and “SuccessfulAuth” events from PJSIP endpoints.

You’re going to need to be specific in what events you are expecting that aren’t appearing and give further information about the configuration - such as the configuration in realtime for endpoints and AORs and what exactly is going on at the time.

Thank you. I am looking for “peerstatus” event or any other event I can use to understand if the PJSIP endpoint is registered or not.

Then that would be ContactStatus. It should be raised even if realtime is in use, provided things are configured correctly.

I see the ContactStatus event, you are right, I am missing some pieces.
I receive the ContactStatus event with ContactStatus => Created when the phone registers (so I can trace the registration with this event), but immediately after another ContactStatus event with ContactStatus => Unknown.
If I check the asterisk console, I see the endpoint listed in state “Not in use” when the phone is registered, but it continues to be in state “Not in use” when the phone is not registered while it should move to “Unavailable”

So it seems my asterisk is not detecting when the phone disconnects.

What is the configuration of the endpoint and AOR? That will have an impact on things.

Here the data stored in the tables. You’ll be really kind to point me where I am missing the relevant info…

mysql> select * from ps_endpoints where id=‘199-DEVEL’\G;
*************************** 1. row ***************************
tech_id: 35
id: 199-DEVEL
te_id: 1
transport: transport-udp
aors: 199-DEVEL
auth: 199-DEVEL
context: authenticated
disallow: all
allow: ulaw:20;alaw:20;g729:20
direct_media: no
connected_line_method: NULL
direct_media_method: NULL
direct_media_glare_mitigation: NULL
disable_direct_media_on_nat: NULL
dtmf_mode: auto
external_media_address: NULL
force_rport: yes
ice_support: NULL
identify_by: NULL
mailboxes: 199@DEVEL
moh_suggest: NULL
outbound_auth: NULL
outbound_proxy: NULL
rewrite_contact: yes
rtp_ipv6: NULL
rtp_symmetric: yes
send_diversion: NULL
send_pai: NULL
send_rpid: NULL
timers_min_se: NULL
timers: NULL
timers_sess_expires: NULL
callerid: Leandro PJSIP <199>
callerid_privacy: NULL
callerid_tag: NULL
100rel: NULL
aggregate_mwi: NULL
trust_id_inbound: NULL
trust_id_outbound: NULL
use_ptime: NULL
use_avpf: NULL
media_encryption: NULL
inband_progress: NULL
call_group: NULL
pickup_group: NULL
named_call_group: NULL
named_pickup_group: NULL
device_state_busy_at: NULL
fax_detect: NULL
t38_udptl: NULL
t38_udptl_ec: NULL
t38_udptl_maxdatagram: NULL
t38_udptl_nat: NULL
t38_udptl_ipv6: NULL
tone_zone: NULL
language:
one_touch_recording: NULL
record_on_feature: NULL
record_off_feature: NULL
rtp_engine: NULL
allow_transfer: NULL
allow_subscribe: NULL
sdp_owner: NULL
sdp_session: NULL
tos_audio: NULL
tos_video: NULL
sub_min_expiry: NULL
from_domain: NULL
from_user: NULL
mwi_from_user: NULL
dtls_verify: NULL
dtls_rekey: NULL
dtls_cert_file: NULL
dtls_private_key: NULL
dtls_cipher: NULL
dtls_ca_file: NULL
dtls_ca_path: NULL
dtls_setup: NULL
srtp_tag_32: NULL
media_address: NULL
redirect_method: NULL
set_var: NULL
message_context: NULL
force_avp: NULL
media_use_received_transport: NULL
accountcode: DEVEL
media_encryption_optimistic: NULL
user_eq_phone: NULL
rpid_immediate: NULL
g726_non_standard: NULL
rtp_keepalive: NULL
rtp_timeout: NULL
rtp_timeout_hold: NULL
bind_rtp_to_media_address: NULL
cos_audio: NULL
cos_video: NULL
deny: NULL
permit: NULL
acl: NULL
contact_deny: NULL
contact_permit: NULL
contact_acl: NULL
voicemail_extension: NULL
mwi_subscribe_replaces_unsolicited: NULL
subscribe_context: NULL
fax_detect_timeout: NULL
contact_user: NULL
asymmetric_rtp_codec: NULL

mysql> select * from ps_aors where id=‘199-DEVEL’\G;
*************************** 1. row ***************************
id: 199-DEVEL
contact: NULL
default_expiration: NULL
mailboxes: 199@DEVEL
max_contacts: 99
minimum_expiration: NULL
remove_existing: NULL
qualify_frequency: NULL
authenticate_qualify: NULL
maximum_expiration: NULL
outbound_proxy: NULL
support_path: NULL
qualify_timeout: NULL
voicemail_extension: NULL

mysql> select * from ps_auths where id=‘199-DEVEL’\G;
*************************** 1. row ***************************
id: 199-DEVEL
auth_type: userpass
nonce_lifetime: NULL
md5_cred: NULL
password: ******************
realm: NULL
username: 199-DEVEL

You have not set a “qualify_frequency” on the AOR, so Asterisk will not use an OPTIONS request to know when a device is reachable or unreachable.

1 Like

That worked! As soon as I added qualify_timeout and qualify_frequency, I started receiving PeerStatus and ContactStatus events.

Really thank you!